Hardisk Temperature

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

mandrk
Posts: 21
Joined: Thu May 12, 2005 1:32 am
Location: Romania
Contact:

Hardisk Temperature

Post by mandrk »

I try to monitor my hardisk temperature.
I put in /scripts the hddtemp.sh with content:
-----------
/usr/sbin/smartctl -a /dev/hda | grep -i temperature | awk '{printf $10}';
-----------
The output is:
----
root@mydomain /var/www/html/cacti/scripts> \ #./hdtemp.sh
44root@mydomain/var/www/html/cacti/scripts> \ #
-----
I create a Data Input Methods with Input Type: Scripts/Command
<path_cacti>/scripts/hdtemp.sh
I create a Data Template and Graph Template.
This 3 stepts is required for own script!
http://docs.cacti.net/node/200

i have grafic but with nan values
In logs i see:
06/30/2008 12:30:02 PM - CMDPHP: Poller[0] Host[1] DS[9] CMD: /var/www/html/cacti/scripts/hdtemp.sh, output: U
06/30/2008 12:30:02 PM - CMDPHP: Poller[0] Host[1] DS[9] WARNING: Result from CMD not valid. Partial Result:

-----------
Why output: U
other log looks like:
06/30/2008 12:30:02 PM - CMDPHP: Poller[0] Host[1] DS[4] CMD: perl /var/www/html/cacti/scripts/linux_memory.pl SwapFree:, output: 1048592
06/30/2008 12:30:02 PM - CMDPHP: Poller[0] Host[1] DS[3] CMD: perl /var/www/html/cacti/scripts/linux_memory.pl MemFree:, output: 30304

with values after output:
Like i say, if i run the script in command line i have output. A number
I try to put in Data Input Methods:
<path_cacti>/scripts/hdtemp.sh
/bin/bash /var/www/html/cacti/scripts/hdtemp.sh

I miss something .
I think most of configuration in ok but the script in not executed right
Last edited by mandrk on Mon Jun 30, 2008 3:39 pm, edited 1 time in total.
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

try this:

Code: Select all

/usr/sbin/smartctl -a /dev/hda | grep -i temperature | awk '{printf $10"\n"}';
You could also make your script a little more dynamic by doing this:

Code: Select all

/usr/sbin/smartctl -a /dev/$1 | grep -i emperature | awk '{printf $10"\n"}';
then pass which device into the script:

./hddtemp.sh hdb1

or whatever.

Then when you configure your Data Input Query, you could set it up to ask the user which harddrive they want to query for temp.

I've also removed the 't' from Temperature, just in case some drives have it capitalized or not. After all, not many other words end in 'emperature'.
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
mandrk
Posts: 21
Joined: Thu May 12, 2005 1:32 am
Location: Romania
Contact:

Post by mandrk »

Same result!
In the log i see
----------------------
06/30/2008 07:20:02 PM - CMDPHP: Poller[0] Host[1] DS[9] CMD: /var/www/html/cacti/scripts/hdtemp.sh, output: U
06/30/2008 07:20:02 PM - CMDPHP: Poller[0] Host[1] DS[9] WARNING: Result from CMD not valid. Partial Result: .
--------------------
The dynamic stuff is very cool,
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

mandrk wrote:Same result!
In the log i see
----------------------
06/30/2008 07:20:02 PM - CMDPHP: Poller[0] Host[1] DS[9] CMD: /var/www/html/cacti/scripts/hdtemp.sh, output: U
06/30/2008 07:20:02 PM - CMDPHP: Poller[0] Host[1] DS[9] WARNING: Result from CMD not valid. Partial Result: .
--------------------
The dynamic stuff is very cool,
You have in your first post that you named the file hddtemp.sh and in your log file it's listed as hdtemp.sh

Looks like a typo in your Data Input Query for the script.
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
mandrk
Posts: 21
Joined: Thu May 12, 2005 1:32 am
Location: Romania
Contact:

Post by mandrk »

Looks like a typo in your Data Input Query for the script.
No is ok!. In my first post i write hddtemp.sh. Is a misstype. The true filname is hdtemp.sh.

Step: 1
CREATE DATA INPUT METHODS
Input type : Script /Command
I use the <path_cacti>/scripts/hdtemp.sh Data Input Methods with 1 Output field named Input. I don't use input field yet ( you dynamic script must wait a lite bit :) . I must make this simple script to work.
Step2:
CREATE DATA TEMPLATE
I use the Data Input Method just created
Step3:
Create a Graph Template Items
Step4:
Make a grafic.
The grafic is maked after 1 cicle with nan value.
:(. wait for other some cicle...nan value
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

did you chown the file to the user that runs cacti?

for example:

chown -R apache:apache hdtemp.sh

did you make the file executable?

chmod +x hdtemp.sh
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
mandrk
Posts: 21
Joined: Thu May 12, 2005 1:32 am
Location: Romania
Contact:

Post by mandrk »

I give chmod 777
Yes make executable from first time with chmod +x hdtemp.sh

4 -rwxr-xr-x 1 root root 166 Jun 30 09:11 diskfree.sh
4 -rwxrwxrwx 1 root root 250 Jun 30 21:39 hdtemp.sh
4 -rw-r--r-- 1 root root 174 Feb 12 02:57 linux_memory.pl
4 -rw-r--r-- 1 root root 282 Feb 12 02:57 loadavg_multi.pl
4 -rw-r--r-- 1 root root 401 Feb 12 02:57 loadavg.pl

Diskfree runs without problem under root
Diskfree.sh returns me the:
root@mydomain /var/www/html/cacti/scripts> \ #./diskfree.sh
megabytes:14772384 percent:49megabytes:17329792 percent:10megabytes:77043 percent:18megabytes:257708 percent:0megabytes:10598280 percent:57root@mydomain /var/www/html/cacti/scripts> \ #

hdtemp return some type of data
root@mydomain /var/www/html/cacti/scripts> \ #./hdtemp.sh
43root@mydomain /var/www/html/cacti/scripts> \ #

I try to put in hdtemp.sh
/usr/sbin/smartctl -a /dev/hda | grep -i temperature | awk '{printf "Input:"$10}' ;

That returns me value:
root@mydomain /var/www/html/cacti/scripts> \ #./hdtemp.sh
Input:43root@mydomain /var/www/html/cacti/scripts> \ #

Same result
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please provide /full/path/to/grep and same for awk
Reinhard
mandrk
Posts: 21
Joined: Thu May 12, 2005 1:32 am
Location: Romania
Contact:

Post by mandrk »

gandalf wrote:Please provide /full/path/to/grep and same for awk
Reinhard
Done!
replace my line with :
/usr/sbin/smartctl -a /dev/hda | /bin/grep -i temperature | /bin/awk '{printf $10}';

The result in command line is :
root@mydomain /var/www/html/cacti/scripts> \ #/usr/sbin/smartctl -a /dev/hda | /bin/grep -i temperature | /bin/awk '{printf $10}';
42root@mydomain /var/www/html/cacti/scripts> \ #

If i put print not printf the result is
root@mydomain /var/www/html/cacti/scripts> \ #/usr/sbin/smartctl -a /dev/hda | /bin/grep -i temperature | /bin/awk '{print $10}';
42
root@mydomain /var/www/html/cacti/scripts> \ #

The 42 value is printed to new line.
What is good choice for cacti
printf or print?

I don't now Perl to try the script in perl language


In loggs :
06/30/2008 11:30:02 PM - CMDPHP: Poller[0] Host[1] DS[11] CMD: /var/www/html/cacti/scripts/hdtemp.sh, output: U
06/30/2008 11:30:02 PM - CMDPHP: Poller[0] Host[1] DS[11] WARNING: Result from CMD not valid. Partial Result:
koocotte
Posts: 4
Joined: Mon Jun 16, 2008 5:29 am

Post by koocotte »

mandrk wrote:Diskfree runs without problem under root
...
I try to put in hdtemp.sh
/usr/sbin/smartctl -a /dev/hda | grep -i temperature | awk '{printf "Input:"$10}' ;
smartctl require root user. Cacti cron job is usually run under an apache or www-data user and can not use smartctl.

You need to configure sudo, or write a setuid wrapper.
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

koocotte wrote:
mandrk wrote:Diskfree runs without problem under root
...
I try to put in hdtemp.sh
/usr/sbin/smartctl -a /dev/hda | grep -i temperature | awk '{printf "Input:"$10}' ;
smartctl require root user. Cacti cron job is usually run under an apache or www-data user and can not use smartctl.

You need to configure sudo, or write a setuid wrapper.
I have the exact same script that he was working with yesterday running on my box, apparently it's running as apache, without any issues.
-rwxr-xr-x 1 apache apache 91 Jun 30 09:54 hddtemp.sh
Attachments
SP32-20080701-095111.gif
SP32-20080701-095111.gif (27.12 KiB) Viewed 11143 times
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
koocotte
Posts: 4
Joined: Mon Jun 16, 2008 5:29 am

Post by koocotte »

streaker69 wrote:I have the exact same script that he was working with yesterday running on my box, apparently it's running as apache, without any issues.
This is frightening.

streaker69, can you post the result of
ls -l /usr/sbin/smartctl /dev/hda
changing /dev/hda according to you system?

I have

Code: Select all

brw-rw---- 1 root disk   8, 0 2008-05-14 23:04 /dev/sda
-rwxr-xr-x 1 root root 157284 2006-09-29 15:50 /usr/sbin/smartctl
mandrk, can you identify under which user cacti cron job is running and try to execute it under this identity? Mine is running under www-data as specified in /etc/cron.d/cacti.

Code: Select all

su - www-data
cd /var/www/html/cacti/scripts
./hdtemp.sh
Did you look into /var/log/cacti/poller-error.log?
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

rw-r----- 1 root disk 3, 65 Jun 30 08:45 /dev/hdb1
-rwxr-xr-x 1 root root 187224 May 24 12:42 /usr/sbin/smartctl
I tested his script out against my second HD in this machine, as the first HD doesn't report Temp.
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
koocotte
Posts: 4
Joined: Mon Jun 16, 2008 5:29 am

Post by koocotte »

streaker69 wrote:
rw-r----- 1 root disk 3, 65 Jun 30 08:45 /dev/hdb1
-rwxr-xr-x 1 root root 187224 May 24 12:42 /usr/sbin/smartctl
I tested his script out against my second HD in this machine, as the first HD doesn't report Temp.
Your second HD is labelled /dev/hdb and not /dev/hdb1
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

koocotte wrote:
streaker69 wrote:
rw-r----- 1 root disk 3, 65 Jun 30 08:45 /dev/hdb1
-rwxr-xr-x 1 root root 187224 May 24 12:42 /usr/sbin/smartctl
I tested his script out against my second HD in this machine, as the first HD doesn't report Temp.
Your second HD is labelled /dev/hdb and not /dev/hdb1
Either one returns the same values.
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests