nagios-nsca-client cron check example install

cronの結果をnscaに飛ばすためにnagios-nsca-client libmcryptを入れる

nagios-nsca-client redhat9
http://packages.sw.be/nagios-nsca/nagios-nsca-client-2.7.2-2.rh9.rf.i386.rpm

libmcrypt redhat9
http://apt.sw.be/redhat/9/en/i386/RPMS.dag/libmcrypt-2.5.7-1.dag.rh90.i386.rpm

# rpm -Uvh libmcrypt-2.5.7-1.dag.rh90.i386.rpm
# rpm -Uvh nagios-nsca-client-2.7.2-2.rh9.rf.i386.rpm

send_nscaの設定する nscaの受けと同じ設定に
vi /etc/nagios/send_nsca.cfg

submit_check_result作る
vi /etc/nagios/submit_check_result

#!/bin/sh

central_server="example.jp"

# Arguments:
#  $1 = host_name (Short name of host that the service is
#       associated with)
#  $2 = svc_description (Description of the service)
#  $3 = state_string (A string representing the status of
#       the given service - "OK", "WARNING", "CRITICAL"
#       or "UNKNOWN")
#  $4 = plugin_output (A text string that should be used
#       as the plugin output for the service checks)
#

# Convert the state string to the corresponding return code
return_code=-1

case "$3" in
    OK)
        return_code=0
        ;;
    WARNING)
        return_code=1
        ;;
    CRITICAL)
        return_code=2
        ;;
    UNKNOWN)
        return_code=-1
        ;;
    [0-2])
        return_code=$3
        ;;
esac

# pipe the service check info into the send_nsca program, which
# in turn transmits the data to the nsca daemon on the central
# monitoring server

/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/sbin/send_nsca $central_server -c /etc/nagios/send_nsca.cfg

動作確認 submit_check_result

# chmod 700 submit_check_result
# ./submit_check_result remote 'service name' 0 'OK test'
1 data packet(s) sent to host successfully.

nscaに結果を送信するためのscript。afbackupの結果を通信する

#!/bin/sh
# change nagios setting host
SERVER="example.com"
/usr/local/backup/client/bin/incr_backup
#/usr/sbin/incr_backup
if [ $? -ne 0 ]; then
#  echo "Error";
        OUTPUT="BACKUP is Critical"
        STATE=2;
else
#  echo "OK";
        OUTPUT="BACKUP is OK"
        STATE=0;
fi
/etc/nagios/submit_check_result $SERVER PASSIVE_CRON_AFBACKUP $STATE "$OUTPUT"

nscaサーバーのservices.cfg

define service{
use                     generic-service
host_name               example.com
check_period            none
service_description     CRON_AFBACKUP
check_command           service-is-stale
check_freshness         1
freshness_threshold     90000
max_check_attempts      1
active_checks_enabled   0
}

24+1時間(3600*25=90000)更新されない場合はエラーになる

nscaサーバーのcommands.cfg

define command{
    command_name    service-is-stale
    command_line    $USER1$/check_dummy 2 'CRITICAL: Service results are stale!'
}


nagios nscaインストールの参考に
http://www.on-sky.net/~hs/misc/?NSCA+Howto