Dashboard Widget for harddrive SMART status



  • hey,

    i've put togehter a dashboard widget that shows the SMART status of the drives installed in the system. i hacked it together mainly from the code of the wake on lan widget and it looks like it work for me at the moment. but i think its a good idea if some people look over the code :)

    
    require_once("guiconfig.inc");
    require_once("pfsense-utils.inc");
    require_once("functions.inc");
    $devs = array();
    ?>
    
    		echo '';
    		echo '';
    		echo '';
    		?>
    
    // Get all AD* and DA* (IDE and SCSI) devices currently installed and st$
    exec("ls /dev | grep '^[ad][da][0-9]\{1,2\}$'", $devs);
    
    if(count($devs) > 0)  {
    	foreach($devs as $dev)  {
    
    		$dev_state =  exec("smartctl -a /dev/$dev | grep result: | awk '{print $6}'");
    		$dev_ident =  exec("diskinfo -v /dev/$dev | grep ident | awk '{print $1}'");
    		##erste Spalte: Drives ausgeben
    		echo '' . "\n";
    
    		##zweite Spalte 
    		echo '' . "\n";
    
    		##dritte Spalte: smartstatus ausgeben
    		echo '' . "\n"; #tabellenspalte
    
    	}
    }
    ?>
    
    		  **<center>' . gettext("Drive") . '</center>**  |  **<center>' . gettext("Ident") . '</center>**  |  **<center>' . gettext("SMART Status") . '</center>**  |			
    | ';
    		echo '/dev/'. $dev ;
    		echo ' | 
    
    <center>' . "\n";
    		echo $dev_ident ;
    		echo '</center>
    
     | '; #tabellenspalte
    
    		if($dev_state == "PASSED") 
    			echo "$dev_state
    "; ##gruener Hintergrund bei PASSED
    		else
    			echo "$dev_state
    "; ##roter Hintergrund sonst
    		echo ' |	
    
    <center>[SMART Status](diag_smart.php)</center>
    
    

    If you want to use the widget, create a new file with the editor of your choice /usr/local/www/widgets/widgets/smart.widget.php and paste the code above in. But again, its a quick and dirty piece of code, use at your own risk!

    Greetz, marcel :)


  • Rebel Alliance Developer Netgate



  • i have tried to clean up the code, minor changes are:

    • (i hope) code is now more easy to read (but remains horrible :) ) if somebody want to modify it to his needs
    • copyright added (i hope its ok in this manner ?)
    • in the 3. column the SMART state is alligned centered now
    • the code of the widget consists now of exact 42 lines :)

    @ jimp: thank you for commiting to git. :)

    
    /* License: same as pfSense. based on code from wake_on_lan.widget.php and others. use at your own risk ! */
    
    require_once("guiconfig.inc");
    require_once("pfsense-utils.inc");
    require_once("functions.inc");
    ?>
    
    		echo '';
    		echo '';
    		echo '';
    		?>
    
    $devs = array();
    ## Get all AD* and DA* (IDE and SCSI) devices currently installed and st$
    exec("ls /dev | grep '^[ad][da][0-9]\{1,2\}$'", $devs); ## leant from orginal SMART status screen 
    
    if(count($devs) > 0)  {
    	foreach($devs as $dev)  {	## for each found drive do
    		$dev_ident = exec("diskinfo -v /dev/$dev | grep ident   | awk '{print $1}'"); ## get identifier from drive
    		$dev_state = exec("smartctl -a /dev/$dev | grep result: | awk '{print $6}'"); ## get SMART state from drive
    
    		echo '' . "\n"; 		## 1\. cell in row: device 
    		echo '' . "\n"; 	## 2\. cell in row: identifier
    
    		## 3\. cell in row: SMART state 
    		echo '' . "\n"; 
    	}
    }
    ?>
    
    		  **<center>' . gettext("Drive") . '</center>**  |  **<center>' . gettext("Ident") . '</center>**  |  **<center>' . gettext("SMART Status") . '</center>**  |			
    | '    . '/dev/'. $dev . ' | 
    
    <center>' . "\n" . $dev_ident . '</center>
    
     |		 
    
    <center>';
    		if($dev_state == "PASSED") 	## if SMART state is "PASSED", draw background green
    			echo "$dev_state
    ";
    		else 						## at any other SMART state, draw background red
    			echo "$dev_state
    ";
    		echo '</center>
    
     |
    
    <center>[SMART Status](diag_smart.php)</center>
    
    

    greets, Marcel


  • Rebel Alliance

    Thanks Marcel
    I just made a couple of changes, to match the  pfSense dashboard colors scheme:

    
    "PASSED", draw background lightgreen --> 90EE90
    
    any other SMART state, draw background lightcoral --> F08080
    
    

    If anyone is interested, can download the smart.widget.php (ready to use) from: http://ptt.4mg.com/pfSense/

    EDIT: File Reuploaded to include the Changes made by Jimp


  • Rebel Alliance Developer Netgate

    Made some further optimizations and fixed the license up:

    https://github.com/bsdperimeter/pfsense/commit/c91e242e607c6ff2376350108255dbadcdb039e0


Log in to reply