Difference between revisions of "Simple way to read SMART status from harddisk via SNMP"

From Bitbull Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
[[Category:Nagios]]
 
 
 
i really like to monitor my hosts with snmp, because its implemented on every device and on every OS.<br>
 
i really like to monitor my hosts with snmp, because its implemented on every device and on every OS.<br>
 
sometimes you need to search a pattern in output of a special comand, eg smartctl.<br>
 
sometimes you need to search a pattern in output of a special comand, eg smartctl.<br>
Line 10: Line 8:
  
 
;configure snmpd
 
;configure snmpd
vi /etc/snmp/snmpd.conf
+
* vi /etc/snmp/snmpd.conf
---
 
 
  syscontact      admin@bitbull.ch
 
  syscontact      admin@bitbull.ch
 
  rouser          safereader auth
 
  rouser          safereader auth
Line 22: Line 19:
 
  # exec smart-sda /bin/sh -c "/usr/sbin/smartctl -H /dev/sda | /bin/sed '/^SMART Health Status:/!d;s/.*: //'"  
 
  # exec smart-sda /bin/sh -c "/usr/sbin/smartctl -H /dev/sda | /bin/sed '/^SMART Health Status:/!d;s/.*: //'"  
  
---
+
 
/etc/init.d/snmpd restart
+
* /etc/init.d/snmpd restart
  
 
  snmpwalk -v1 -c L0cal localhost .1.3.6.1.4.1.2021.8.1
 
  snmpwalk -v1 -c L0cal localhost .1.3.6.1.4.1.2021.8.1
Line 29: Line 26:
  
 
*on nagios host
 
*on nagios host
vi /etc/nagios-plugins/config/custom.cfg  
+
* vi /etc/nagios-plugins/config/custom.cfg  
---
+
 
 
  # search for pattern in snmp output
 
  # search for pattern in snmp output
 
  define command{
 
  define command{
Line 36: Line 33:
 
         command_line    /usr/lib/nagios/plugins/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o '$ARG2$' -r '$ARG3$'
 
         command_line    /usr/lib/nagios/plugins/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o '$ARG2$' -r '$ARG3$'
 
         }
 
         }
  ---
+
   
 
+
  * vi /etc/nagios3/conf.d/hosts-mydomain.com.cfg
  vi /etc/nagios3/conf.d/hosts-mydomain.com.cfg
+
   
  ---
 
 
  define service{
 
  define service{
 
  use                    generic-service ; Inherit values from a template
 
  use                    generic-service ; Inherit values from a template
Line 47: Line 43:
 
  check_command          check_snmp_output!rEADoNLY!UCD-SNMP-MIB::extOutput.1!PASSED
 
  check_command          check_snmp_output!rEADoNLY!UCD-SNMP-MIB::extOutput.1!PASSED
 
         }
 
         }
 +
  
 
  /etc/init.d/nagios3 restart
 
  /etc/init.d/nagios3 restart
 +
 +
[[Category:Nagios]]

Revision as of 11:14, 5 August 2020

i really like to monitor my hosts with snmp, because its implemented on every device and on every OS.
sometimes you need to search a pattern in output of a special comand, eg smartctl.
this was my way to solve the problem ... have you a more elegant way ... please let me know!

  • monitor disks on this host
install needed software
apt-get install smartmontools snmpd
configure snmpd
  • vi /etc/snmp/snmpd.conf
syscontact      admin@bitbull.ch
rouser          safereader auth
rwuser          safewriter priv

rocommunity     rEADoNLY snmpd.mydomain.com
rocommunity     L0cal localhost

exec smart-sda /bin/sh -c "/usr/sbin/smartctl -H /dev/sda | /bin/sed '1,/===/d;/^$/d'"
# exec smart-sda /bin/sh -c "/usr/sbin/smartctl -H /dev/sda | /bin/sed '/^SMART Health Status:/!d;s/.*: //'" 


  • /etc/init.d/snmpd restart
snmpwalk -v1 -c L0cal localhost .1.3.6.1.4.1.2021.8.1


  • on nagios host
  • vi /etc/nagios-plugins/config/custom.cfg
# search for pattern in snmp output
define command{
        command_name    check_snmp_output
        command_line    /usr/lib/nagios/plugins/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o '$ARG2$' -r '$ARG3$'
        }

* vi /etc/nagios3/conf.d/hosts-mydomain.com.cfg

define service{
use                     generic-service ; Inherit values from a template
host_name               myserver
service_description     Disk sda health
normal_check_interval   720
check_command           check_snmp_output!rEADoNLY!UCD-SNMP-MIB::extOutput.1!PASSED
        }


/etc/init.d/nagios3 restart