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#
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