simple nagios port check
Date: June 18, 2008
here is a simple little nagios script to check the status of a port with ouput – sounds stupid but i needed it to check 2 specific ports for ouput and it works.
#!/bin/bash
if [ -z $2 ]; then
if [ -z $1 ]; then
printf "needs \$1 & \$2 (address & port number)\n"
exit 2
else
printf "needs \$2 (port number)\n"
exit 2
fi
fi
function port {
if [ $? -ne 0 ] ; then
printf "warning: "
if [ $? -eq 6 ]; then
echo "cant resolve host - check dns"
exit 2
fi
if [ $? -eq 7 ]; then
echo "cant connect to host"
exit 2
fi
printf "port may be closed\n"
else
printf "port is open\n"
exit 0
fi
}
curl -s -o "/dev/null" ${1}:${2}
## -o writes output to file instead of stdout
## -s runs silent mode
port;
syntax: port_check.sh <address of machine> <port>
simple enough right ??
Just what I needed. Excellent.
Do you mean that we should create that script in /usr/local/nagios/libexec/port_check.sh and then call it from commands.cfg ?
yes
this doesn’t work.
thanks, this worked like a charm..how do it make it work to produce graph for nagiosgraph
check_tcp -H HOSTIPHERE -p PORTNUMBERHERE
how it can check the port?
Why not use check_tcp. It’s a common nagios plugin
i also use the check_tcp plugin. easy to handle…
check_tcp works like a charm. Also thanks for the tips of the blogger~