diff --git a/Makefile b/Makefile index 5afda377d0fac4e25038e8eaf42546f6f5a27401..b394ae75fd1528b657b2ee0aba815ca3932e94d5 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ -LIBEXECDIR = /usr/local/nagios/libexec/ +PREFIX = /usr/local/nagios +LIBEXECDIR = $(PREFIX)/libexec/ SCRIPTS = check_cups check_glsa check_saned check_lpd check_hddtemp \ check_link_status check_true check_lysrdiff check_syslog \ check_ping check_enodia_monitored check_hostextinfo \ check_hydra check_datorhandbok check_no_server check_iostatE \ - check_nfs_server check_svcs + check_nfs_server check_svcs check_zfs all:; @@ -32,6 +33,11 @@ dist: src/lyskom/lyskom.h \ src/lyskom/notify_lyskom.c; \ do cp $$i $$base/$$i || exit 1; done; \ + find bin rules site-rules -type d -print \ + | sed "s%^%$$base/%" | xargs mkdir || exit 1 ; \ + find bin rules site-rules -type f -print \ + | sed -e '/\~$$/d' -e '/#$$/d' \ + | while read f ; do cp $$f $$base/$$f || exit 1; done || exit 1; \ tar cfz $$base.tar.gz $$base || exit 1; \ rm -r $$base diff --git a/bin/compile b/bin/compile new file mode 100755 index 0000000000000000000000000000000000000000..f06a38faf4b15aab37029679d4c29eebec3866a6 --- /dev/null +++ b/bin/compile @@ -0,0 +1,7 @@ +#!/bin/sh + +. bin/utils/checkargs.sh + +bin/compile-nrpe $CFGDIR || exit 1 +bin/compile-nagios-plugins $CFGDIR || exit 1 +bin/compile-local $CFGDIR || exit 1 diff --git a/bin/compile-local b/bin/compile-local new file mode 100755 index 0000000000000000000000000000000000000000..1afb579ca5bdf098330a9fd35e5be3cfa156674b --- /dev/null +++ b/bin/compile-local @@ -0,0 +1,13 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +# By default, we don't need to compile anything. Some sites may want +# to compile the LysKOM utilities, and they can arrange to do so using +# the install-local.sh hook. + +run_hook install-local.sh diff --git a/bin/compile-nagios-plugins b/bin/compile-nagios-plugins new file mode 100755 index 0000000000000000000000000000000000000000..8173bd7642b166bc3f90a833aae904387c30f886 --- /dev/null +++ b/bin/compile-nagios-plugins @@ -0,0 +1,24 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh +. bin/utils/check-nagios-plugins-src.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +if [ -f ../nagios-plugins-*/Makefile ] +then + echo ../nagios-plugins-*/Makefile exists. Not running configure. >&2 +else + echo Running ../nagios-plugins-*/configure >&2 + (cd ../nagios-plugins-* && ./configure --prefix=$prefix) +fi + +if [ -f ../nagios-plugins-*/src/nagios-plugins ] +then + echo ../nagios-plugins-*/src/nagios-plugins exists. Not running make. >&2 +else + echo Running make in ../nagios-plugins-* >&2 + (cd ../nagios-plugins-* && make) +fi diff --git a/bin/compile-nrpe b/bin/compile-nrpe new file mode 100755 index 0000000000000000000000000000000000000000..ee49a3d48969193377551c66e0b2527c41a418c2 --- /dev/null +++ b/bin/compile-nrpe @@ -0,0 +1,25 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh +. bin/utils/check-nrpe-src.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +if [ -f ../nrpe-*/Makefile ] +then + echo ../nrpe-*/Makefile exists. Not running configure. >&2 +else + echo Running ../nrpe-*/configure >&2 + opts=`contents nrpe-config-opts` + (cd ../nrpe-* && ./configure --prefix=$prefix $opts) +fi + +if [ -f ../nrpe-*/src/nrpe ] +then + echo ../nrpe-*/src/nrpe exists. Not running make. >&2 +else + echo Running make in ../nrpe-* >&2 + (cd ../nrpe-* && make) +fi diff --git a/bin/config b/bin/config new file mode 100755 index 0000000000000000000000000000000000000000..b2ece097b94e6d89049e2c6467f94751de1ec3a5 --- /dev/null +++ b/bin/config @@ -0,0 +1,5 @@ +#!/bin/sh + +. bin/utils/checkargs.sh + +bin/config-nrpe $CFGDIR || exit 1 diff --git a/bin/config-nrpe b/bin/config-nrpe new file mode 100755 index 0000000000000000000000000000000000000000..a0e40a52ffd68852cb055b19bfe90642249cd790 --- /dev/null +++ b/bin/config-nrpe @@ -0,0 +1,45 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +run_hook config-nrpe-prehook.sh + +installfile () { + fn=$1 + + src=`findcfg $fn.in` + + if [ -z "$src" ] + then + echo cannot find $fn.in + exit 1 + fi + + sed < $src \ + -e "s%@PREFIX@%$prefix%g" \ + > $prefix/etc/$fn || exit 1 +} + +installfile nrpe.cfg +installfile nrpe-os.cfg +installfile nrpe-os-site.cfg + +# This fragment should install nrpe-host-auto.cfg. +source_fragment nrpe-host-auto.sh + +if [ -f $prefix/etc/nrpe-host-manual.cfg ] +then : +else + echo '# Enter host-specific commands in this file.' \ + >> $prefix/etc/nrpe-host-manual.cfg +fi + +# This fragment should ensure that nrpe is started from inetd (or +# xinetd, or something similar). +source_fragment config-nrpe.sh + +run_hook config-nrpe-posthook.sh diff --git a/bin/install b/bin/install new file mode 100755 index 0000000000000000000000000000000000000000..71874620d25d4cf5fbc002cbdfa476f8e48fa934 --- /dev/null +++ b/bin/install @@ -0,0 +1,8 @@ +#!/bin/sh + +. bin/utils/checkargs.sh + +bin/install-nrpe $CFGDIR || exit 1 +bin/install-nagios-plugins $CFGDIR || exit 1 +bin/install-local $CFGDIR || exit 1 + diff --git a/bin/install-local b/bin/install-local new file mode 100755 index 0000000000000000000000000000000000000000..1b1728f98ce914d0f229262a2526c94f151d08c7 --- /dev/null +++ b/bin/install-local @@ -0,0 +1,9 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +make install PREFIX=$prefix || exit 1 diff --git a/bin/install-nagios-plugins b/bin/install-nagios-plugins new file mode 100755 index 0000000000000000000000000000000000000000..a9450517751b5cd1d9aa1be399774fb8c5b7be0b --- /dev/null +++ b/bin/install-nagios-plugins @@ -0,0 +1,14 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh +. bin/utils/check-nrpe-src.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +run_hook install-nagios-plugins-prehook.sh + +(cd ../nagios-plugins-* && make install) + +run_hook install-nagios-plugins-posthook.sh diff --git a/bin/install-nrpe b/bin/install-nrpe new file mode 100755 index 0000000000000000000000000000000000000000..da580abeaad396b22c9e1dd33aef4ff84744650a --- /dev/null +++ b/bin/install-nrpe @@ -0,0 +1,22 @@ +#!/bin/sh + +. bin/utils/functions.sh +. bin/utils/checkargs.sh +. bin/utils/check-nrpe-src.sh + +source_fragment set-prefix.sh +source_fragment setup-env.sh + +if [ -f ../nrpe-*/src/nrpe ] +then : +else + echo Cannot find nrpe binary >&2 + exit 1 +fi + +run_hook install-nrpe-prehook.sh + +mkdir -p $prefix/bin $prefix/etc +cp ../nrpe-*/src/nrpe $prefix/bin + +run_hook install-nrpe-posthook.sh diff --git a/bin/utils/check-nagios-plugins-src.sh b/bin/utils/check-nagios-plugins-src.sh new file mode 100644 index 0000000000000000000000000000000000000000..c8c9704af8d1d4821d4263609a061e2cf66d7d53 --- /dev/null +++ b/bin/utils/check-nagios-plugins-src.sh @@ -0,0 +1,8 @@ +if [ `ls -1d ../nagios-plugins-* | wc -l` -eq 1 ] \ + && [ -d ../nagios-plugins-* ] \ + && [ -f ../nagios-plugins-*/nagios-plugins.spec ] +then : +else + echo cannot find unique nagios-plugins source in ../nagios-plugins-* >&2 + exit 1 +fi diff --git a/bin/utils/check-nrpe-src.sh b/bin/utils/check-nrpe-src.sh new file mode 100644 index 0000000000000000000000000000000000000000..183ac5d6ef05023b3f70b58c40b1b18d0580f12e --- /dev/null +++ b/bin/utils/check-nrpe-src.sh @@ -0,0 +1,8 @@ +if [ `ls -1d ../nrpe-* | wc -l` -eq 1 ] \ + && [ -d ../nrpe-* ] \ + && [ -f ../nrpe-*/nrpe.spec ] +then : +else + echo cannot find unique nrpe source in ../nrpe-* >&2 + exit 1 +fi diff --git a/bin/utils/checkargs.sh b/bin/utils/checkargs.sh new file mode 100644 index 0000000000000000000000000000000000000000..3c9024ab1fe469e8df1f20edca32a08bed73241d --- /dev/null +++ b/bin/utils/checkargs.sh @@ -0,0 +1,31 @@ +usage () { + echo $0: usage: $0 cfgdir >&2 +} + +if [ $# != 1 ] +then + usage + exit 1 +fi + +if [ "x$1" = x-h ] || [ "x$1" = x--help ] +then + usage + exit 0 +fi + +CFGDIR=$1 + +if [ -d $CFGDIR ] +then : +else + echo $0: %CFGDIR: not a directory >&2 + exit 1 +fi + +if [ -f $CFGDIR/os ] +then : +else + echo $CFGDIR: bad config dir: no "os" file present >&2 + exit 1 +fi diff --git a/bin/utils/functions.sh b/bin/utils/functions.sh new file mode 100644 index 0000000000000000000000000000000000000000..eb8ee6e6f6c2b2a0aa96cab6041d8939d9d7c13f --- /dev/null +++ b/bin/utils/functions.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +findcfg () { + cfgdir=$CFGDIR + file=$1 + + if [ -f $cfgdir/$file ] + then + echo $cfgdir/$file + return + fi + + os=`cat $cfgdir/os` + + while : + do + cfgdir=`dirname $cfgdir` + if [ -z "`echo $cfgdir|grep site-rules`" ] + then + break + fi + + if [ -f $cfgdir/$file ] + then + echo $cfgdir/$file + return + fi + done + + if [ -f rules/$os/$file ] + then + echo rules/$os/$file + return + fi + + if [ -f rules/$file ] + then + echo rules/$file + return + fi + + return +} + +source_fragment () { + fn=`findcfg $1` + if [ -z "$fn" ] + then + echo Fatal error: fragment $1 not found. >&2 + exit 1 + else + . ./$fn + fi +} + +run_hook () { + hook=`findcfg $1` + if [ -n "$hook" ] + then + . ./$hook + fi +} + +contents () { + fn=`findcfg $1` + if [ -n "$fn" ] + then + cat "$fn" + fi +} + +tempfile () { + mktemp -t $1.XXXXXX 2>/dev/null && exit 0 + tempfile -p $1 2>/dev/null && exit 0 + echo /tmp/$1.$$ && exit 0 + exit 1 +} diff --git a/check_zfs b/check_zfs new file mode 100644 index 0000000000000000000000000000000000000000..f3a880ef6e1577ecef90b8362fd8398912e043ed --- /dev/null +++ b/check_zfs @@ -0,0 +1,43 @@ +#!/bin/sh + +PATH=/usr/sbin:bin +export PATH + +if [ $# -ne 1 ] +then + echo usage: $0 poolname >&2 + exit 3 +fi + +POOL=$1 + +health=`zpool list -H -o health $POOL` +size=`zpool list -H -o size $POOL` +avail=`zpool list -H -o available $POOL` + +bytes () { + echo $1 | sed -e 's/G/ * 1024M/' -e 's/M/ * 1024K/' -e 's/K/ * 1024/' | xargs expr +} + +capacity=`expr 100 - 100 '*' \`bytes $avail\` / \`bytes $size\`` + +if [ x"$health" != xONLINE ] +then + echo "CRITICAL - $POOL state is $health ($capacity% used) | size=$size avail=$avail health=$health" + exit 2 +fi + +if [ $capacity -gt 95 ] +then + echo "CRITICAL - $POOL: $capacity% used | size=$size avail=$avail health=$health" + exit 2 +fi + +if [ $capacity -gt 90 ] +then + echo "WARNING - $POOL: $capacity% used | size=$size avail=$avail health=$health" + exit 1 +fi + +echo "OK - $POOL: $capacity% used | size=$size avail=$avail health=$health" +exit 0 diff --git a/rules/nrpe-os-site.cfg.in b/rules/nrpe-os-site.cfg.in new file mode 100644 index 0000000000000000000000000000000000000000..c55309b106f14850105a04d050510e708204ce41 --- /dev/null +++ b/rules/nrpe-os-site.cfg.in @@ -0,0 +1,2 @@ +# This file is centrally managed. Do not edit. Source: +# svn+ssh://lsvn.lysator.liu.se/svnroot/nagios-plugins/trunk/nagios-plugins diff --git a/rules/nrpe-os.cfg.in b/rules/nrpe-os.cfg.in new file mode 100644 index 0000000000000000000000000000000000000000..c55309b106f14850105a04d050510e708204ce41 --- /dev/null +++ b/rules/nrpe-os.cfg.in @@ -0,0 +1,2 @@ +# This file is centrally managed. Do not edit. Source: +# svn+ssh://lsvn.lysator.liu.se/svnroot/nagios-plugins/trunk/nagios-plugins diff --git a/rules/nrpe.cfg.in b/rules/nrpe.cfg.in new file mode 100644 index 0000000000000000000000000000000000000000..dc919dd4eace9feae8416c7c394c4142feb9a2cb --- /dev/null +++ b/rules/nrpe.cfg.in @@ -0,0 +1,28 @@ +# This file is centrally managed. Do not edit. Source: +# svn+ssh://lsvn.lysator.liu.se/svnroot/nagios-plugins/trunk/nagios-plugins + +pid_file=/var/run/nrpe.pid +server_port=5666 +nrpe_user=nagios +nrpe_group=nagios +dont_blame_nrpe=0 +debug=0 +command_timeout=60 +connection_timeout=300 + +# OS-specific commands added by the lysator-nagios-plugins framework. +include=@PREFIX@/etc/nrpe-os.cfg + +# OS-and-site-specific commands, also from the lysator-nagios-plugins +# framework. +include=@PREFIX@/etc/nrpe-os-site.cfg + +# Commands derived automatically from the current host configuration +# the the lysator-nagios-plugins framework. +include=@PREFIX@/etc/nrpe-host-auto.cfg + +# Extra commands added manually by the host administrator. This file +# will not be overwritten by the next install of +# lysator-nagios-plugins, so this is the proper place to adde +# host-specific check commands. +include=@PREFIX@/etc/nrpe-host-manual.cfg diff --git a/rules/set-prefix.sh b/rules/set-prefix.sh new file mode 100644 index 0000000000000000000000000000000000000000..10437ca2d105f1a5086e712a8158b94a111e03f7 --- /dev/null +++ b/rules/set-prefix.sh @@ -0,0 +1 @@ +prefix=/usr/local diff --git a/rules/solaris10/config-nrpe.sh b/rules/solaris10/config-nrpe.sh new file mode 100755 index 0000000000000000000000000000000000000000..d449872fe05c44c22c44f9ce48c31b965dfe9808 --- /dev/null +++ b/rules/solaris10/config-nrpe.sh @@ -0,0 +1,17 @@ +# Install the service. +getent services nrpe >/dev/null +if [ $? = 2 ] +then + echo 'nrpe 5666/tcp # Nagios NRPE' >> /etc/services +fi + +# Install the SVC +if svcs svc:/network/nrpe/tcp >/dev/null 2>&1 +then : +else + NRPECFG=`tempfile` + echo "nrpe stream tcp nowait nagios $prefix/bin/nrpe $prefix/bin/nrpe -c $prefix/etc/nrpe.cfg --inetd" > $NRPECFG + inetconv -i $NRPECFG + rm $NRPECFG + inetadm -m svc:/network/nrpe/tcp tcp_wrappers=TRUE +fi diff --git a/rules/solaris10/nrpe-host-auto.sh b/rules/solaris10/nrpe-host-auto.sh new file mode 100644 index 0000000000000000000000000000000000000000..f83db0d93baf948102b9a28fb5a74645e9ad86b0 --- /dev/null +++ b/rules/solaris10/nrpe-host-auto.sh @@ -0,0 +1,36 @@ +FILESYSTEMS=`tempfile nrpfs` +ZPOOLS=`tempfile nrzfs` +trap "rm -f $FILESYSTEMS $ZPOOLS" 0 + +# Create a host-specific config file. +{ df -F ufs; df -F tmpfs; } \ +| awk '{ print $1 }' \ +| tee $FILESYSTEMS \ +| while read mp + do + dev=`mount|awk '$1 == "'$mp'" { print $3 }'` + case $dev in + /*) arg=$dev;; + swap) arg=$mp;; + *) echo unknown: mp=$mp dev=$dev >&2 + arg=$mp;; + esac + echo $arg `echo $mp | sed -e 's%^/$%/root%' -e 's%/%-%g'` + done \ +|awk '{ print "command[check-disk" $2 "]='$prefix'/libexec/check_disk " $1 }'\ +> $prefix/etc/nrpe-host-auto.cfg + +# FIXME: We need a check_zpool command, that checks the status of the pool, +# and the capacity of the root zfs of that pool, and maybe also recursively +# checks all child zfs. +if [ -f /usr/sbin/zpool ] +then + /usr/sbin/zpool list -H -o name \ + | tee $ZPOOLS \ + | awk '{ + print "command[check-zfs-" $1 "]='$prefix'/libexec/check_zfs " $1 + }' \ + >> $prefix/etc/nrpe-host-auto.cfg +else + : > $ZPOOLS +fi diff --git a/rules/solaris10/nrpe-os.cfg.in b/rules/solaris10/nrpe-os.cfg.in new file mode 100644 index 0000000000000000000000000000000000000000..ec5e166f57ae4bb634862adb70bfbae6d7ceb548 --- /dev/null +++ b/rules/solaris10/nrpe-os.cfg.in @@ -0,0 +1,5 @@ +# This file is centrally managed. Do not edit. Source: +# svn+ssh://lsvn.lysator.liu.se/svnroot/nagios-plugins/trunk/nagios-plugins + +command[check-iostatE]=@PREFIX@/libexec/check_iostatE -C @PREFIX@/etc/check_iostatE.cfg +command[check-svcs]=@PREFIX@/libexec/check_svcs diff --git a/rules/solaris10/setup-env.sh b/rules/solaris10/setup-env.sh new file mode 100644 index 0000000000000000000000000000000000000000..1571494dae15975a2b2beae4b2dd23e38d247558 --- /dev/null +++ b/rules/solaris10/setup-env.sh @@ -0,0 +1,2 @@ +PATH=/bin:/sbin:/usr/sbin:/usr/ccs/bin:/usr/sfw/bin +export PATH diff --git a/site-rules/lysator/nrpe-config-opts b/site-rules/lysator/nrpe-config-opts new file mode 100644 index 0000000000000000000000000000000000000000..1235075f5738db7f190b8c2316b513ea12260e37 --- /dev/null +++ b/site-rules/lysator/nrpe-config-opts @@ -0,0 +1 @@ +--disable-ssl diff --git a/site-rules/lysator/set-prefix.sh b/site-rules/lysator/set-prefix.sh new file mode 100644 index 0000000000000000000000000000000000000000..70791bd9debdf1fde87c2f38ee84988e722dfe50 --- /dev/null +++ b/site-rules/lysator/set-prefix.sh @@ -0,0 +1 @@ +prefix=/opt/nrpe diff --git a/site-rules/lysator/solaris10/config-nrpe-posthook.sh b/site-rules/lysator/solaris10/config-nrpe-posthook.sh new file mode 100755 index 0000000000000000000000000000000000000000..a243ca803b73dfc045bd219e35e67809c4b21c66 --- /dev/null +++ b/site-rules/lysator/solaris10/config-nrpe-posthook.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +echo +echo BEGIN `hostname | sed 's/\..*//'` nagiosadmin +sed 's/^/fs /' $FILESYSTEMS +sed 's/^/zfs /' $ZPOOLS +echo END diff --git a/site-rules/lysator/solaris10/install-nrpe-posthook.sh b/site-rules/lysator/solaris10/install-nrpe-posthook.sh new file mode 100755 index 0000000000000000000000000000000000000000..3f367f04f525ae011dc0025b87fe1084ee873a97 --- /dev/null +++ b/site-rules/lysator/solaris10/install-nrpe-posthook.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Install gawk locally, as check_iostatE needs it. +if [ -f /opt/lysator/bin/gawk ] +then : +else + if [ -f /usr/local/bin/gawk ] + then + mkdir -p /opt/lysator/bin + cp /usr/local/bin/gawk /opt/lysator/bin + else + echo '*** No gawk found, so not installed in /opt/lysator/bin.' >&2 + echo '*** check_iostatE might fail!' >&2 + fi +fi diff --git a/site-rules/lysator/solaris10/os b/site-rules/lysator/solaris10/os new file mode 100644 index 0000000000000000000000000000000000000000..753d8acc01d5842d5d53d72ee6e21aff9da89282 --- /dev/null +++ b/site-rules/lysator/solaris10/os @@ -0,0 +1 @@ +solaris10 diff --git a/src/lyskom/Makefile b/src/lyskom/Makefile index 20907e7a8408f206f76172da824e7da260b9d875..a48f498fac5803138378ac065c212ff66387ae21 100644 --- a/src/lyskom/Makefile +++ b/src/lyskom/Makefile @@ -1,6 +1,7 @@ # Makefile for lyskom Nagios utilities -LIBEXECDIR=/usr/local/nagios/libexec/ +PREFIX=/usr/local/nagios +LIBEXECDIR=$prefix/libexec/ PROGS=notify_lyskom check_lyskom COBJS=lyskom.o buffer.o