Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Last active December 19, 2015 00:09
Show Gist options
  • Save jhrcz/5866769 to your computer and use it in GitHub Desktop.
Save jhrcz/5866769 to your computer and use it in GitHub Desktop.
nagios check_cluster generator

nagios check_cluster generator v2

why

  • minimize manual configuration
  • minize notifications from cluster hosts when clustered services are all down (notify only from new fake cluster host)

use

  • copy the SAMPLE.cfg.sh to clu-{MYNODEPREFIX}.cfg.sh
  • chmod +x
  • run it

info

with included sample settings,this generates 3 config files for nagios:

  • clu-{MYNODEPREFIX}-clu-deps-GEN.cfg - dependency of real services on cluster checks
  • clu-{MYNODEPREFIX}-clu-host-GEN.cfg - fake host with assigned cluster checks
  • clu-{MYNODEPREFIX}-clu-services-GEN.cfg - all services on real nodes
#!/bin/bash
source $1
#####
exec > clu-${NODE_PREFIX}clu-deps-GEN.cfg
echo "
#
# WARNING: this is generated file
#
"
for SERVICE in $SERVICES
do
for i in `seq 1 $NODES`
do
echo "
define servicedependency{
host_name ${NODE_PREFIX}X-clu
service_description CLU:$SERVICE
dependent_host_name ${NODE_PREFIX}$i${NODE_SUFFIX}
dependent_service_description $SERVICE
execution_failure_criteria n
notification_failure_criteria c
}
"
done
done
#####
exec > clu-${NODE_PREFIX}clu-host-GEN.cfg
echo "
#
# WARNING: this is generated file
#
"
echo "
define host {
host_name ${NODE_PREFIX}X-clu
alias ${NODE_PREFIX}X-clu
address 127.0.0.1
use ${HOST_TEMPLATE}
}
"
#####
exec > clu-${NODE_PREFIX}clu-services-GEN.cfg
echo "
#
# WARNING: this is generated file
#
"
for SERVICE in $SERVICES
do
echo "
define service {
use SYSMON-MIT-HA
host_name ${NODE_PREFIX}X-clu
service_description CLU:$SERVICE
"
echo -n ' check_command check_service_cluster!"'"$SERVICE"'"!0!'"$(($NODES - 1))"'!'
for i in `seq 1 $NODES` ; do echo -n '$SERVICESTATEID:'"${NODE_PREFIX}$i${NODE_SUFFIX}:$SERVICE"'$,' ; done | sed -e 's/,$//' ; echo
echo '
max_check_attempts 1
}
'
done
#!/bin/bash clu-checks-GENERATOR.sh
NODES=8
NODE_PREFIX=my-hostprefix-
NODE_SUFFIX=.domain.xxx
SERVICES="sys:cluster sys:libvirt-cross"
HOST_TEMPLATE=generic-host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment