Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Tue Sep 25, 2018 8:40 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: smartmontools - hdd temperature checker script
PostPosted: Wed Sep 01, 2004 6:12 am 
Offline

Joined: Wed Sep 01, 2004 5:49 am
Posts: 3
i've wrote a script that uses the smartmontools to grep the temperature
of a certain harddisk. it requires the smartmontools package (smartctl)
and has to have root-privileges to read the smartmon-data of the
harddrive (-> sudo the smartctl command) as you probably won't run the
script as root.

there is one argument the script needs. in my case it is "-d scsi /dev/sda"
for one of the scsidrives and "-d 3ware,0 /dev/sdc" for a ide drive in my
3ware-raid.

as i could only include one file, i've added the template and will include
the php-code of the script within my post. you can configure one more
value in the source, as you might think harddrives are allowed to be
hotter than 40 degrees centigrade.
hdtemp.php:

#!/usr/local/bin/php -f
<?php
$parm = $_SERVER["argv"][1];
$max_allowed = 40; // <- maximum temperature for drives...

$foo=exec("/usr/bin/sudo /usr/local/sbin/smartctl -a $parm | egrep -i \"Celsius|Current\" | grep Temp");
$foo=explode(" ",$foo);
$foo=$foo[sizeof($foo)-1];
$foo=explode(" ",trim(ltrim($foo)));
$foo="temp:".intval($foo[0])." allowed:".$max_allowed;
echo $foo;
?>

* change the path to the php-cli as you wish. -f allows the script not to show the X-powerde-by stuff.

as i mentioned above, you have to be able to run smartctl as non-root
user, so sudo it, here is the line you have to add in /etc/sudoers:

nobody ALL=NOPASSWD:/usr/local/sbin/smartctl

*nobody can be replaced by the user you let the datagathering run


i hope that post helps und you'll use it ;o)


Attachments:
File comment: the data template
cacti_data_template_hdtemp_mit_option.xml [4.35 KiB]
Downloaded 2482 times
File comment: the template for graphs and so on
cacti_graph_template_hdtemp.xml [7.3 KiB]
Downloaded 2149 times
Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 5:00 pm 
Offline
Cacti User
User avatar

Joined: Mon Apr 26, 2004 7:18 am
Posts: 68
Location: Switzerland
hello

this is what i was searching for , since weeks ! thanx a lot.

i got that scipt partialy running

1. import of XML (successful)
2. i had to modify the path for smartctl in the php script > /usr/sbin/smartctl (successful)
3. generating the graph - empty but ... (successful)
4. sudo is working fine for the user I let the data gathering

>> afer 1h still no data in the graph !

debugging :

for debugging I was checking the comand /usr/bin/sudo /usr/sbin/smartctl -a -d ata /dev/hda

result : (successful)
Code:
=== START OF INFORMATION SECTION ===
Device Model:     Maxtor 6E040L0
Serial Number:    E1Q48FPE
Firmware Version: NAR61EA0
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  ATA/ATAPI-7 T13 1532D revision 0
Local Time is:    Tue Sep 14 00:09:08 2004 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x80) Offline data collection activity
                                        was never started.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                 (1021) seconds.
Offline data collection
capabilities:                    (0x5b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        No Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        No General Purpose Logging support.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        (  17) minutes.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  3 Spin_Up_Time            0x0027   252   252   063    Pre-fail  Always       -       974
  4 Start_Stop_Count        0x0032   253   253   000    Old_age   Always       -       8
  5 Reallocated_Sector_Ct   0x0033   253   253   063    Pre-fail  Always       -       0
  6 Read_Channel_Margin     0x0001   253   253   100    Pre-fail  Offline      -       0
  7 Seek_Error_Rate         0x000a   253   252   000    Old_age   Always       -       0
  8 Seek_Time_Performance   0x0027   249   247   187    Pre-fail  Always       -       57223
  9 Power_On_Minutes        0x0032   247   247   000    Old_age   Always       -       1040h+08m
10 Spin_Retry_Count        0x002b   252   252   157    Pre-fail  Always       -       0
11 Calibration_Retry_Count 0x002b   252   252   223    Pre-fail  Always       -       0
12 Power_Cycle_Count       0x0032   253   253   000    Old_age   Always       -       10
192 Power-Off_Retract_Count 0x0032   253   253   000    Old_age   Always       -       8
193 Load_Cycle_Count        0x0032   253   253   000    Old_age   Always       -       29
194 Temperature_Celsius     0x0032   253   253   000    Old_age   Always       -       41
195 Hardware_ECC_Recovered  0x000a   253   252   000    Old_age   Always       -       3402
196 Reallocated_Event_Count 0x0008   253   253   000    Old_age   Offline      -       0
197 Current_Pending_Sector  0x0008   253   253   000    Old_age   Offline      -       0
198 Offline_Uncorrectable   0x0008   253   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0008   199   199   000    Old_age   Offline      -       0
200 Multi_Zone_Error_Rate   0x000a   253   252   000    Old_age   Always       -       0
201 Soft_Read_Error_Rate    0x000a   253   252   000    Old_age   Always       -       7
202 TA_Increase_Count       0x000a   253   252   000    Old_age   Always       -       0
203 Run_Out_Cancel          0x000b   253   252   180    Pre-fail  Always       -       0
204 Shock_Count_Write_Opern 0x000a   253   252   000    Old_age   Always       -       0
205 Shock_Rate_Write_Opern  0x000a   253   252   000    Old_age   Always       -       0
207 Spin_High_Current       0x002a   252   252   000    Old_age   Always       -       0
208 Spin_Buzz               0x002a   252   252   000    Old_age   Always       -       0
209 Offline_Seek_Performnce 0x0024   253   253   000    Old_age   Offline      -       0
99 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0
100 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0
101 Unknown_Attribute       0x0004   253   253   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%      1926         -

SMART Selective self-test log data structure revision number 1
SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.



then I tried the whole command :
/usr/bin/sudo /usr/sbin/smartctl -a -d ata /dev/hda | egrep -i \"Celsius|Current\" | grep Temp

result :
/usr/bin/sudo /usr/sbin/smartctl -a -d ata /dev/hda | egrep -i \"Celsius|Current\" | grep Temp
bash: Current": command not found


I'm shure "the evil is in the detail" ;)

Where did I make the mistake ?
Thank you for your help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 2:58 pm 
Offline

Joined: Wed Sep 01, 2004 5:49 am
Posts: 3
.) well,.. using " in php can only be done when escape'ing the character -> \"
so if you are trying it on the shell, just do:

... egrep -i "Celsius|Current" | grep Temp

or (if you are more common to regualr expression) just formulate an egrep-string which does all in one, (without the pipe)...


.) still, the php-file should have worked, so try executing it (without the cacti cmd.php) by just starting the script ;o)


ps: liebe grüsse in die schweiz ;o)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 3:46 pm 
Offline

Joined: Wed Sep 01, 2004 5:49 am
Posts: 3
you also have to give 1 paramter to the script in my case it would be:

hdtemp.php "-d scsi /dev/sda" for the first scsi-drive, or
hdtemp.php "-d 3ware,0 /dev/sdc" for the first ide drive in my 3ware-raid or
hdtemp.php "/dev/hda" for a regular ide-drive...

if you didn't give this paramter to the script, it wouldn't know what to read. so maybe you mistake was in cacti where you have to enter that paramter.


a friend of mine hinted, that you could increase speed, when doing smartctl -A and not smartctl -a, which causes smartctl to read less information from the drive...

cheers


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 09, 2004 10:52 pm 
Quote:
My graphs render, but they do not contain any data.
if only some of your graphs are not updating correctly, double check the Maximum Value field for all data sources used by these graphs. If the value being fed to the .rrd file exceeds its Maximum Value, RRDTool will insert an Unknown and you will see no data on the graph.


In your script the Maximum Value Stands is 50 ==> Max Value is 40 + x = 50 ==> if the Temperature is above 10 ° Celsius you SEE NOTHING

i took me about 2 days to get to this error ^^

but thx for this script anyway :)


Top
  
 
 Post subject:
PostPosted: Sat Oct 09, 2004 10:56 pm 
ohh man, got it wrong, script stopt working once again ...

i dont get it ... this script works, then i add aditional drives, and the script stops working :(((


Top
  
 
 Post subject: my script for smartctl (on FreeBSD)
PostPosted: Tue Oct 12, 2004 7:29 am 
Here's my shell script for running smartctl, developed on FreeBSD (havn't tried it on any other OS yet):

----- begin script -----
#!/bin/sh
temp_celsius="`/usr/local/bin/sudo /usr/local/sbin/smartctl -A $1 | egrep Temperature_Celsius | cut -c86-`"
echo "$temp_celsius"
------ end script ------

The other option is to use awk instead of cut:

sudo /usr/local/sbin/smartctl -A ad4 | egrep Temperature_Celsius | awk '{print $10}'

and really the 'echo "$temp_celsius"' doesn't need to be there, it could just be one line.

I've added the following to sudoers:
----- begin sudoers adds -----
Cmnd_Alias CACTI_CMDS = /usr/local/sbin/smartctl -A [a-z][a-z][0-9]
cacti ALL = NOPASSWD: CACTI_CMDS
----- end sudoers adds -----


Top
  
 
 Post subject: One little thing
PostPosted: Wed Dec 01, 2004 3:09 pm 
Offline
User avatar

Joined: Wed Dec 01, 2004 2:05 pm
Posts: 1
Location: Belgrade
Great job Maxxmaster. Thanks for the templates.
I just finished my hdtemp setup.

Your instructions were slightly incomplete.
I changed the input_string tag in both templates to suit my cacti installation.
This is the point when data appeared in graphs.
Maybe sumsum referred to this.
It looks good.

Rgds.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 3:54 pm 
thx a lot
working great


Top
  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 7:11 pm 
Offline

Joined: Tue Apr 25, 2006 2:36 am
Posts: 2
hi
i have a problem with drawing the graph from this script:

Code:
#!/bin/sh
sudo /usr/local/sbin/smartctl -A /dev/ad6 | egrep Temperature_Celsius | awk '{print $10}'

when executed as user cacti, gives correct result:

Quote:
[email protected]# /usr/local/share/cacti/scripts/hddtemp.sh
40

but the graph remains blank and says nan...

here's the cacti's log:

LOW wrote:
04/26/2006 02:05:01 AM - CMDPHP: Poller[0] Host[0] DS[35] WARNING: Result from CMD not valid. Partial Result:

DEBUG wrote:
04/26/2006 01:50:02 AM - CMDPHP: Poller[0] Host[0] DS[35] WARNING: Result from CMD not valid. Partial Result:
04/26/2006 01:50:02 AM - CMDPHP: Poller[0] Host[0] DS[35] CMD: /usr/local/share/cacti/scripts/hddtemp.sh, output: U
04/26/2006 01:50:02 AM - CMDPHP: Poller[0] DEBUG: SQL Exec: "insert into poller_output (local_data_id,rrd_name,time,output) values (35,'hdd_temp','2006-04-26 01:50:01','U')"


please, help me!

FreeBSD 6.0-RELEASE-p6
cacti-0.8.6h_4
apache-2.0.55_4
php4-4.4.2_1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 11:50 am 
Offline

Joined: Mon Jul 31, 2006 11:47 am
Posts: 7
Location: Austria
guest wrote:
Quote:
My graphs render, but they do not contain any data.
if only some of your graphs are not updating correctly, double check the Maximum Value field for all data sources used by these graphs. If the value being fed to the .rrd file exceeds its Maximum Value, RRDTool will insert an Unknown and you will see no data on the graph.


In your script the Maximum Value Stands is 50 ==> Max Value is 40 + x = 50 ==> if the Temperature is above 10 ° Celsius you SEE NOTHING

i took me about 2 days to get to this error ^^

but thx for this script anyway :)


sorry but I think I am too silly

what means this and where are I have to chance the values.
I changed the value for allowed in the php script to 50.
and what or where should I change the rest ? my harddisk has a temp between 30 and 45


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 11:50 am 
Offline

Joined: Mon Jul 31, 2006 11:47 am
Posts: 7
Location: Austria
delete


Last edited by gotchi on Mon Jul 31, 2006 11:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 1:23 pm 
Offline

Joined: Mon Jul 31, 2006 11:47 am
Posts: 7
Location: Austria
hi

I tried everything really everyting but this error makes me crazy
07/31/2006 08:20:13 PM - CACTID: Poller[0] Host[1] ERROR: Empty result [127.0.0.1]: '/usr/share/cacti/site/scripts/hdtemp.php /dev/hda'

i set up sudo to let www-data run the smartctl as root. it works.
its a debian sarge installation and I installed it via aptitude.

all other scripts are working these script wont work with the poller - starting it as root - all fine
starting it as a user who I also added to the sudoers all fine

what can I do?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 6:05 pm 
Offline

Joined: Mon Jul 31, 2006 11:47 am
Posts: 7
Location: Austria
ok now its really late here in austria

the hd temp script worked for a short time, now I get all errors out of the cacti.log except one:

08/01/2006 01:00:15 AM - CACTID: Poller[0] Host[1] WARNING: Result from SCRIPT not valid. Partial Result: temp:42 allowed:50 ...

and this makes me crazy - cause with this error no graph drawing is possible.

please please help me :cry: :cry:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 6:22 pm 
Offline

Joined: Mon Jul 31, 2006 11:47 am
Posts: 7
Location: Austria
new information
using cacti 086c and cactid 086d from debian sarge install

using cmd.php as poller works without this error.

i will go to bed - perhaps someone have a solution for me tomorrow.

thanx


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group