aboutsummaryrefslogtreecommitdiffstats
path: root/sitesummary-update-nagios
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2010-01-26 08:16:17 +0000
committerPetter Reinholdtsen <pere@hungry.com>2010-01-26 08:16:17 +0000
commitecd7d82d31d5d25217296f7fdb5827cc2e2e4b65 (patch)
tree868e12f640f87b4d47161411db232a86f88f8c68 /sitesummary-update-nagios
parent989bae77db15afb690a0bba81fbcf6ed32109165 (diff)
downloadsitesummary-ecd7d82d31d5d25217296f7fdb5827cc2e2e4b65.tar.gz
sitesummary-ecd7d82d31d5d25217296f7fdb5827cc2e2e4b65.tar.bz2
sitesummary-ecd7d82d31d5d25217296f7fdb5827cc2e2e4b65.tar.xz
Restructure cron job, move munin and nagios updating code to
separate scripts to make it possible to update them individually.
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