diff --git a/node/node.d/smart_.in b/node/node.d/smart_.in index 1c8f340ef7..147d278cb5 100755 --- a/node/node.d/smart_.in +++ b/node/node.d/smart_.in @@ -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 : @@ -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: @@ -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 : @@ -185,23 +185,24 @@ 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 : @@ -209,12 +210,14 @@ def get_hard_drive_name() : 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) @@ -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()