Skip to content

Commit

Permalink
Minor enhancements and minor bug fixes from Nicolas STRANSKY <Nico@ne…
Browse files Browse the repository at this point in the history
…o-lan.net>
  • Loading branch information
LupeChristoph committed Aug 11, 2005
1 parent 4d431ed commit f5bb67e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions node/node.d/smart_.in
Expand Up @@ -111,7 +111,7 @@ def read_values(hard_drive) :
smart_attribute=string.split(l)
smart_values[string.replace(smart_attribute[1],'-','_')]={"value":smart_attribute[3],"threshold":smart_attribute[5]}
elif l[:18]=="ID# ATTRIBUTE_NAME" :
# We start reading the Attributes block
# Start reading the Attributes block
read_values=1
exit_status=smart_output.close()
if exit_status!=None :
Expand All @@ -134,7 +134,7 @@ def read_values(hard_drive) :
except : smart_values["model"]="unknown"

def open_state_file(mode) :
return open(statefiledir+'/smart-'+hard_drive+'.state',mode)
return open(statefiledir+'/smart-'+string.join(hard_drive,"-")+'.state',mode)

def update_state_file() :
try:
Expand All @@ -150,25 +150,25 @@ def print_plugin_values() :
print(key+".value "+smart_values[key]["value"])

def print_config(hard_drive,smart_values) :
if os.path.exists(statefiledir+'/smart-'+hard_drive+'.state'):
if os.path.exists(statefiledir+'/smart-'+string.join(hard_drive,"-")+'.state'):
try :
verboselog('Try to recall previous S.M.A.R.T attributes for '+hard_drive)
verboselog('Try to recall previous S.M.A.R.T attributes for '+string.join(hard_drive,","))
smart_values_state=pickle.load(open_state_file("r"))
except :
verboselog('Error opening existing state file !')
sys.exit(1)
else :
verboselog('No state file, reading S.M.A.R.T values for the first time')
read_values(hard_drive)
read_values(hard_drive[0])
pickle.dump(smart_values,open_state_file("w"))
smart_values_state=smart_values

verboselog('Printing configuration')
print('graph_title S.M.A.R.T values for drive '+hard_drive)
print('graph_title S.M.A.R.T values for drive '+string.join(hard_drive,","))
print('graph_vlabel Attribute S.M.A.R.T value')
print('graph_args --base 1000 --lower-limit 0')
print('graph_category disk')
print('graph_info This graph shows the value of all S.M.A.R.T attributes of drive '+hard_drive+' ('+smart_values_state['model']+'). smartctl_exit_status is the return value of smartctl. A non-zero return value indicates an error, a potential error, or a fault on the drive.')
print('graph_info This graph shows the value of all S.M.A.R.T attributes of drive '+string.join(hard_drive,",")+' ('+smart_values_state['model']+'). smartctl_exit_status is the return value of smartctl. A non-zero return value indicates an error, a potential error, or a fault on the drive.')
attributes=smart_values_state.keys()
attributes.sort()
for key in attributes :
Expand All @@ -185,36 +185,39 @@ def print_config(hard_drive,smart_values) :

def get_hard_drive_name() :
try :
hard_drive=plugin_name[string.rindex(plugin_name,'_')+1:]
hard_drive=[plugin_name[string.rindex(plugin_name,'_')+1:]]
if os.uname()[0]=="SunOS" :
try :
hard_drive_path=hard_drive
if hard_drive[0:4]=="rdsk":
hard_drive=os.path.join("rdsk",hard_drive_path[4:])
elif hard_drive[0:3]=="rmt":
hard_drive=os.path.join("rmt",hard_drive_path[3:])
# if hard_drive name starts with "rdsk" or "rmt", try to reconstruct the path
if hard_drive[0][0:4]=="rdsk":
hard_drive[0]=os.path.join("rdsk",hard_drive[0][4:])
elif hard_drive[0][0:3]=="rmt":
hard_drive[0]=os.path.join("rmt",hard_drive[0][3:])
except :
verboselog('Failed to find SunOS hard_drive')
# For 3ware cards, we have to set multiple plugins for the same hard drive name.
# Let's see if we find a '-' in the drive name.
if hard_drive.find('-')!=-1:
hard_drive=hard_drive[:string.rindex(hard_drive,'-')]
if hard_drive[0].find('-')!=-1:
# Put the drive name and it's number in a list
hard_drive=[hard_drive[0][:string.rindex(hard_drive[0],'-')],hard_drive[0][string.rindex(hard_drive[0],'-')+1:]]
# Chech that the drive exists in /dev
if not os.path.exists('/dev/'+hard_drive):
verboselog('/dev/'+hard_drive+' not found !')
if not os.path.exists('/dev/'+hard_drive[0]):
verboselog('/dev/'+hard_drive[0]+' not found !')
sys.exit(1)
return(hard_drive)
except :
verboselog('No S.M.A.R.T device name found in plugin\'s symlink !')
sys.exit(1)

def find_smart_drives() :
# Try to autodetect Linux, *BSD, SunOS drives. Don't try to autodetect drives on a 3Ware card.
drives=[]
if os.uname()[0]=="Linux" :
if os.path.exists('/sys/block/'):
# Running 2.6, yeah
try :
for drive in os.listdir('/sys/block/') :
if drive[:2] in ['md','fd','lo','ra','dm'] : continue # Ignore MD, Floppy, loop , RAM and LVM devices.
try :
read_values(drive)
drives.append(drive)
Expand Down Expand Up @@ -330,7 +333,7 @@ if len(sys.argv)>1 :

# No argument given, doing the real job:
hard_drive=get_hard_drive_name()
read_values(hard_drive)
read_values(hard_drive[0])
update_state_file()
print_plugin_values()

0 comments on commit f5bb67e

Please sign in to comment.