Page 1 of 1

Self created check - wrong info

Posted: Tue Dec 01, 2015 2:38 am
by Anton @ CPB
Hi

I created to check a MySQL instance. The check runs fine within libexec.

Code: Select all

root@nagios:/usr/local/nagios/libexec# ./check_nprobe_mysql 
OK - The times are 59 sec apart
root@nagios:/usr/local/nagios/libexec# 
But not with the check running - See attached png

Herewith the check_nprobe_mysql code

Code: Select all

#!/bin/bash

#Get the date & times from the system and mysql nprobe mysql db
mdatetime=$(date +"%Y-%m-%d %H:%M:%S")
nprobeDateTime=$(mysql --login-path=remote -e "select from_unixtime(FIRST_SWITCHED) from nprobe.flowsflows order by from_unixtime(FIRST_SWITCHED) desc limit 1;" | cut -d')' -f2)

#Convert the dates & time to seconds
systemt=$(date -d "$mdatetime" +%s)
nprobetime=$(date -d "$nprobeDateTime" +%s)

#Get the diffirence between the systtem time and nprobe FIRST_SWITCHED
diff=$((systemt - nprobetime))

#Get the results - Results are measured in seconds
if (("$diff" <= 120))     #Change the OK time to your threshold
        then
                echo "OK - The times are $diff sec apart"
                exit 0
elif (("$diff" > 121)) && (("$diff" <=159)) #Change the WARNING time to your threshold - Between a period ie. currently between 121 sec & 159 sec
                then
                        echo "WARNING - Times are $diff sec apart"
                        exit 1
else
        if (("$diff" > 160))  #Change the CRITICAL time to your threshold - 1 above the last sec from WARNING
                then
                        echo "CRITICAL - Times are $diff sec apart"
                        exit 2
        fi
fi
Don't know if I'm missing anything

Re: Self created check - wrong info

Posted: Tue Dec 01, 2015 2:08 pm
by rkennedy
For debugging purposes, can you have the result echo also systemt and nprobetime in the result so we can try to see where these numbers are coming from?

Then, run it over CLI and Nagios and post the results back.