#!/bin/bash

# 
# check_ipmi_sdr_ok: Check status of all ipmi sensors.  This relies on
# "ok" or not in the status field.  The check_ipmi_sensors does a little
# more work to determine things for itself - it also has much higher run
# time and may not be suitable for all hosts.  This should be fine to
# run even on the most kitted up servers.
#
# Donated to the public domain by Nicolai Langfeldt (janl@linpro.no)
#

ipmitool sdr list all | gawk -F'|' '
BEGIN { 
	PROBLEM=0; # Nagios exitstatus
	MSG="Not OK:";
}

# Remove extraneous spaces to make output prettier
{ gsub(/\t/," "); gsub(/ +/," "); gsub(/ +\|/,"|"); gsub(/\| +/,"|") }

# Skip lines with ns in third(last) column
/\|ns$/ { next; };

{ if ($3 !~ /ok/) {
	PROBLEM=2;
	MSG = sprintf("%s %s", MSG, $1);
  }
}

END {
    if (PROBLEM == 2) {
	print MSG;
    } else {
	print "All sensors OK"
    }
    exit PROBLEM;
}
'
