Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


Hardisk Temperature
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
mandrk



Joined: 12 May 2005
Posts: 21
Location: Romania

PostPosted: Mon Jun 30, 2008 4:42 am    Post subject: Hardisk Temperature Reply with quote

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
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Mon Jun 30, 2008 8:20 am    Post subject: Reply with quote

try this:

Code:

/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:

/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'.
Back to top
mandrk



Joined: 12 May 2005
Posts: 21
Location: Romania

PostPosted: Mon Jun 30, 2008 11:24 am    Post subject: Reply with quote

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,
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Mon Jun 30, 2008 12:35 pm    Post subject: Reply with quote

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.
Back to top
mandrk



Joined: 12 May 2005
Posts: 21
Location: Romania

PostPosted: Mon Jun 30, 2008 1:38 pm    Post subject: Reply with quote

Quote:
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
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Mon Jun 30, 2008 1:47 pm    Post subject: Reply with quote

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
Back to top
mandrk



Joined: 12 May 2005
Posts: 21
Location: Romania

PostPosted: Mon Jun 30, 2008 1:57 pm    Post subject: Reply with quote

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
Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12604
Location: Muenster, Germany

PostPosted: Mon Jun 30, 2008 3:03 pm    Post subject: Reply with quote

Please provide /full/path/to/grep and same for awk
Reinhard
Back to top
mandrk



Joined: 12 May 2005
Posts: 21
Location: Romania

PostPosted: Mon Jun 30, 2008 3:36 pm    Post subject: Reply with quote

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:
Back to top
koocotte



Joined: 16 Jun 2008
Posts: 4

PostPosted: Tue Jul 01, 2008 7:58 am    Post subject: Reply with quote

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.
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Tue Jul 01, 2008 8:52 am    Post subject: Reply with quote

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.

Quote:

-rwxr-xr-x 1 apache apache 91 Jun 30 09:54 hddtemp.sh



SP32-20080701-095111.gif
 Description:
 Filesize:  27.12 KB
 Viewed:  4367 Time(s)

SP32-20080701-095111.gif


Back to top
koocotte



Joined: 16 Jun 2008
Posts: 4

PostPosted: Tue Jul 01, 2008 10:58 am    Post subject: Reply with quote

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:
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:
su - www-data
cd /var/www/html/cacti/scripts
./hdtemp.sh


Did you look into /var/log/cacti/poller-error.log?
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Tue Jul 01, 2008 11:36 am    Post subject: Reply with quote

Quote:

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.
Back to top
koocotte



Joined: 16 Jun 2008
Posts: 4

PostPosted: Tue Jul 01, 2008 12:26 pm    Post subject: Reply with quote

streaker69 wrote:
Quote:

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
Back to top
streaker69
Cacti Pro User


Joined: 27 Mar 2006
Posts: 647
Location: Psychic Amish Network Administrator

PostPosted: Tue Jul 01, 2008 12:53 pm    Post subject: Reply with quote

koocotte wrote:
streaker69 wrote:
Quote:

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 



Powered by phpBB © 2001, 2005 phpBB Group