×
Create a new article
Write your page title here:
We currently have 3,187 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,187Articles

    Nagios/submitFakeChecks

    Simple Nagios command Script[edit]

    This script is an example of submitting 'static' / 'passive' check directly to nagios cmd file

    #!/bin/bash
    # Script to "fake out the zzz dummy host"
    # Scans for hosts called 'zzz-dummy' in the nagios log and submits 'fake' check results for them.
    nagiosLog="/opt/nagios/var/nagios.log"
    nagiosCommand="/opt/nagios/var/rw/nagios.cmd"
    #nagiosCommand="/var/tmp/zzzzz.log"
    
    now=`perl -e "print time;"` # we need the current time in unix time (perl makes this simpler)
    OS=`uname -s`;      # we check OS as in Solaris we need to use nawk instead of awk
    ORIG_IFS=$IFS ; IFS=$'\n'   #We change the separator to make parsing simpler with (n)awk (other wise it would use " " )
     
    
    case $OS in
    
    SunOS)
    
     for check in $(grep " STATE: zzz-dummy"  $nagiosLog | nawk -F": " '{print $2}' |sort -u ) ; do
       echo $check | nawk -F";" -v now=$now '{ 
        printf( "[%u] DISABLE_SVC_NOTIFICATIONS;"$1";"$2"\n", now )
        printf( "[%u] DISABLE_SVC_CHECK;"$1";"$2"\n", now )
        printf( "[%u] PROCESS_SERVICE_CHECK_RESULT;"$1";"$2";0;ok - FAKED out dummy host\n", now )
        printf( "[%u] PROCESS_HOST_CHECK_RESULT;"$1";0;ok - FAKED out dummy host\n", now )
       }' >> $nagiosCommand
     done
     
    ;;
    
    Linux)
    
     for check in $(grep " STATE: zzz-dummy"  $nagiosLog | awk -F": " '{print $2}' |sort -u ) ; do
       echo $check | awk -F";" now="$now"'{ 
        printf( "[%u] DISABLE_SVC_NOTIFICATIONS;"$1";"$2"\n", now )
        printf( "[%u] DISABLE_SVC_CHECK;"$1";"$2"\n", now )
            printf( "[%u] PROCESS_SERVICE_CHECK_RESULT;"$1";"$2";0;ok - FAKED out dummy host\n", now )      
            printf( "[%u] PROCESS_HOST_CHECK_RESULT;"$1";0;ok - FAKED out dummy host\n", now )      
       }' >> $nagiosCommand
     done 
    ;;
    
    *)
     echo " failed OS check  " >> /var/tmp/zzzzz.log
    ;;
    esac
    
    
    IFS=$ORIG_IFS
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.