aboutsummaryrefslogtreecommitdiffstats
path: root/sitesummary-update-nagios
diff options
context:
space:
mode:
Diffstat (limited to 'sitesummary-update-nagios')
-rwxr-xr-xsitesummary-update-nagios65
1 files changed, 65 insertions, 0 deletions
diff --git a/sitesummary-update-nagios b/sitesummary-update-nagios
new file mode 100755
index 0000000..96db4ee
--- /dev/null
+++ b/sitesummary-update-nagios
@@ -0,0 +1,65 @@
+#!/bin/sh
+#
+# Author: Petter Reinholdtsen
+
+set -e
+
+nodes=/usr/sbin/sitesummary-nodes
+nagiosopts=""
+
+# Specifies where to save the automatically generated nagios
+# configuration. Add NAGIOSCFG="/etc/nagios3/sitesummary.cfg" to
+# /etc/default/nagios3 to get Nagios to use this automatically
+# generated configuration
+NAGIOSDIR=/var/lib/sitesummary
+
+if [ -f /etc/sitesummary/collector.cfg ] ; then
+ . /etc/sitesummary/collector.cfg
+fi
+
+# The storage area is not configurable, because too many scripts have
+# it hardcoded
+entriesdir=/var/lib/sitesummary/entries
+
+generate_nagios_config() {
+ (
+ $nodes -n $nagiosopts
+
+ if [ -f $NAGIOSDIR/nagios-generated.cfg.post ] ; then
+ cat $NAGIOSDIR/nagios-generated.cfg.post
+ fi
+
+ true
+ ) > $NAGIOSDIR/nagios-generated.cfg.new && \
+ chmod a+r $NAGIOSDIR/nagios-generated.cfg.new
+ if [ ! -s $NAGIOSDIR/nagios-generated.cfg.new ] || \
+ cmp -s $NAGIOSDIR/nagios-generated.cfg.new \
+ $NAGIOSDIR/nagios-generated.cfg
+ then
+ rm $NAGIOSDIR/nagios-generated.cfg.new
+ false
+ else
+ mv $NAGIOSDIR/nagios-generated.cfg.new $NAGIOSDIR/nagios-generated.cfg
+ true
+ fi
+}
+
+# Only enable if nagios v3 and sitesummary is installed.
+if [ -f /etc/init.d/nagios3 ] && [ -x $nodes ]; then
+ # Only reload nagios if the configuration changed
+ if generate_nagios_config ; then
+ # subshell to avoid passing all variables from
+ # /etc/default/nagios3 to other parts of this script
+ (
+ if [ -r /etc/default/nagios3 ] ; then
+ . /etc/default/nagios3
+ fi
+ # Only reload nagios if the sitesummary config is the active
+ # one and nagios3 is currently running.
+ if [ /etc/nagios3/sitesummary.cfg = "$NAGIOSCFG" ] && \
+ invoke-rc.d nagios3 status >/dev/null ; then
+ invoke-rc.d nagios3 reload >/dev/null
+ fi
+ )
+ fi
+fi