packages: nagios-plugin-check_ipmi/check_ipmi (NEW), nagios-plugin-check_ip...

glen glen at pld-linux.org
Thu Dec 9 23:16:52 CET 2010


Author: glen                         Date: Thu Dec  9 22:16:52 2010 GMT
Module: packages                      Tag: HEAD
---- Log message:
- initial plugin, based on php version by op5.org

---- Files affected:
packages/nagios-plugin-check_ipmi:
   check_ipmi (NONE -> 1.1)  (NEW), check_ipmi.cfg (NONE -> 1.1)  (NEW), nagios-plugin-check_ipmi.spec (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/nagios-plugin-check_ipmi/check_ipmi
diff -u /dev/null packages/nagios-plugin-check_ipmi/check_ipmi:1.1
--- /dev/null	Thu Dec  9 23:16:52 2010
+++ packages/nagios-plugin-check_ipmi/check_ipmi	Thu Dec  9 23:16:46 2010
@@ -0,0 +1,119 @@
+#!/bin/sh
+# License: GPL v2
+# Copyright (c) 2007 op5 AB
+# Author: Hugo Hallqvist <dev at op5.com>
+# Author: Elan Ruusamäe <glen at delfi.ee>
+#
+# Ported to pure shell by Elan Ruusamäe
+# Original PHP version:
+# http://git.op5.org/git/?p=nagios/op5plugins.git;a=blob_plain;f=check_ipmi.php;hb=HEAD
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Description: 
+# Nagios plugin for locally checking hardware status (fans, voltage) via ipmi.
+# It utilizes ipmitool to get results from kernel.
+#
+# Usage: check_ipmi <filename>
+# 
+# filename points to a file which is used as a cache for speeding up the check.
+
+PROGRAM=${0##*/}
+PROGPATH=${0%/*}
+. $PROGPATH/utils.sh
+
+IPMITOOL=ipmitool
+
+die() {
+	eval local rc=\$STATEs_$1
+	[ "$rc" ] || rc=$STATE_UNKNOWN
+	echo "$2"
+	exit $rc
+}
+
+usage() {
+	cat <<EOF
+Usage: check_ipmi <filename>
+	
+  	<filename> indicates the cache file for speeding up sensor readings.
+
+EOF
+}
+
+# trim leading and trailing whitespace
+trim() {
+	echo "$*" | sed -e 's/^ *\| *$//g'
+}
+
+create_sdr_cache_file() {
+	local filename="$1"
+
+	# return false if cache already exists (i.e, previous check running)
+	[ -f "$filename" ] && return 1
+
+	touch "$filename"
+	# we run the dump in background
+	$IPMITOOL sdr dump $filename >/dev/null &
+	return 0
+}
+
+## Start of main program ##
+if [ -z "$1" ]; then
+	die UNKNOWN "No databasename given."
+fi
+cache_filename="$1"
+
+if [ ! -s "$cache_filename" ]; then
+	if create_sdr_cache_file $cache_filename; then
+		die UNKNOWN "New database initialized, no results yet."
+	else
+		die CRITICAL "Error initializing database."
+	fi
+fi
+
+t=$(mktemp) || die CRITICAL "Can't create tempfile"
+$IPMITOOL -S $cache_filename sdr > $t || die CRITICAL "Can't run ipmitool sdr"
+# VRD 1 Temp       | 34 degrees C      | ok
+# CMOS Battery     | 3.12 Volts        | ok
+# VCORE            | 0x01              | ok
+
+osensors=0
+bsensors=0
+bad_sensors=''
+oIFS=$IFS IFS='|'
+while read label result status; do
+	case $(trim "$status") in
+	ns)
+		# skip ns (not supported)
+		continue
+		;;
+	ok)
+		# just count them
+		osensors=$((osensors+1))
+		;;
+	*)
+		bsensors=$((bsensors+1))
+		label=$(trim "$label")
+		result=$(trim "$result")
+		status=$(trim "$status")
+		bad_sensors="$bad_sensors($label, $status, $result) ";
+		;;
+	esac
+done < $t
+rm -f $t
+
+if [ "$bad_sensors" ]; then
+	die CRITICAL "$bsensors sensors bad: $bad_sensors"
+fi
+
+die OK "$osensors sensors OK"

================================================================
Index: packages/nagios-plugin-check_ipmi/check_ipmi.cfg
diff -u /dev/null packages/nagios-plugin-check_ipmi/check_ipmi.cfg:1.1
--- /dev/null	Thu Dec  9 23:16:52 2010
+++ packages/nagios-plugin-check_ipmi/check_ipmi.cfg	Thu Dec  9 23:16:46 2010
@@ -0,0 +1,21 @@
+# Usage:
+# check_ipmi
+define command {
+	command_name    check_ipmi
+	command_line    /usr/lib/nagios/plugins/check_ipmi /var/spool/nagios/check_ipmi.sdr
+}
+
+define service {
+	use                     generic-service
+	name                    ipmi
+	register                0
+	service_description     ipmi
+
+	normal_check_interval   120
+	retry_check_interval    15
+	max_check_attempts      3
+
+	notification_interval   240
+
+	check_command           check_ipmi
+}

================================================================
Index: packages/nagios-plugin-check_ipmi/nagios-plugin-check_ipmi.spec
diff -u /dev/null packages/nagios-plugin-check_ipmi/nagios-plugin-check_ipmi.spec:1.1
--- /dev/null	Thu Dec  9 23:16:52 2010
+++ packages/nagios-plugin-check_ipmi/nagios-plugin-check_ipmi.spec	Thu Dec  9 23:16:46 2010
@@ -0,0 +1,71 @@
+# $Revision$, $Date$
+%define		plugin	check_ipmi
+Summary:	Nagios plugin to check IPMI status
+Name:		nagios-plugin-%{plugin}
+Version:	0.1
+Release:	0.2
+License:	GPL v2
+Group:		Networking
+Source0:	%{plugin}
+Source1:	%{plugin}.cfg
+BuildRequires:	rpmbuild(macros) >= 1.552
+Requires:	nagios-common >= 3.2.3-3
+Requires:	nagios-plugins-libs
+Requires:	sudo
+BuildArch:	noarch
+BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%define		_sysconfdir	/etc/nagios/plugins
+%define		plugindir	%{_prefix}/lib/nagios/plugins
+%define		cachedir	/var/spool/nagios
+
+%description
+Nagios plugin to check IPMI status.
+
+%prep
+%setup -qcT
+cp -p %{SOURCE0} %{plugin}
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{plugindir},%{cachedir}}
+install -p %{plugin} $RPM_BUILD_ROOT%{plugindir}/%{plugin}
+sed -e 's, at plugindir@,%{plugindir},' %{SOURCE1} > $RPM_BUILD_ROOT%{_sysconfdir}/%{plugin}.cfg
+touch $RPM_BUILD_ROOT%{cachedir}/%{plugin}.sdr
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%post
+if [ "$1" = 1 ]; then
+	# setup sudo rules on first install
+	%{plugindir}/%{plugin} -S || :
+fi
+
+%postun
+if [ "$1" = 0 ]; then
+	# remove all sudo rules related to us
+	%{__sed} -i -e '/CHECK_IPMI/d' /etc/sudoers
+fi
+
+%triggerin -- nagios-nrpe
+%nagios_nrpe -a %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
+
+%triggerun -- nagios-nrpe
+%nagios_nrpe -d %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
+
+%files
+%defattr(644,root,root,755)
+%attr(640,root,nagios) %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/%{plugin}.cfg
+%attr(755,root,root) %{plugindir}/%{plugin}
+%ghost %{cachedir}/%{plugin}.sdr
+
+%define date	%(echo `LC_ALL="C" date +"%a %b %d %Y"`)
+%changelog
+* %{date} PLD Team <feedback at pld-linux.org>
+All persons listed below can be reached at <cvs_login>@pld-linux.org
+
+$Log$
+Revision 1.1  2010/12/09 22:16:46  glen
+- initial plugin, based on php version by op5.org
+
================================================================


More information about the pld-cvs-commit mailing list