Skip to content

Instantly share code, notes, and snippets.

@doublemarket
Created June 7, 2013 10:25
Show Gist options
  • Save doublemarket/5728392 to your computer and use it in GitHub Desktop.
Save doublemarket/5728392 to your computer and use it in GitHub Desktop.
Force check specific service for the host
#!/bin/sh
# force check specific service for the host
# using Nagios external commands
NOW=`date +%s`
CMDFILE='/var/spool/nagios/cmd/nagios.cmd'
# check service for the host
f_check() {
/usr/bin/printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%s\n" $NOW $HOST $SERVICE $NOW > $CMDFILE
if [ $? -eq 0 ] ;then
echo
echo "Success"
echo "Issued command : [$NOW] SCHEDULE_FORCED_SVC_CHECK;$HOST;$SERVICE;$NOW"
else
echo "Error"
exit 1
fi
}
f_usage() {
echo
echo " Force check specific service for the host"
echo " using Nagios external commands"
echo
echo " usage: sh $0 hostname servicename"
echo
}
# MAIN
if [ $# -eq 2 ] ;then
HOST=$1
SERVICE=$2
f_check
else
f_usage
exit 1
fi
@Rohlik
Copy link

Rohlik commented Aug 2, 2019

/usr/bin/printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%s\n" $NOW $HOST "$SERVICE" $NOW > $CMDFILE is better, cause it is support servicename with spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment