Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_udp_port
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Simple shell script that uses nmap utility to check if a remote host is listening on a UDP port and what that service is.
Usage:
check_udp_port: -H remote_host -p port -s service_name
-H Name or IP of remote host
-p UDP port number to check
-s Name of the service that should be listening on the port
Critical: if service is 'unknown' or state is not open
Warning: if service name expected does not match service name listening on the port
OK: if the port is open and service name expected matches service name listening.
NOTE for NagiosXI command definition:
nmap requires root perms to scan the port. Add the following to /etc/sudoers:
NAGIOSXI ALL = NOPASSWD:/usr/local/nagios/libexec/check_udp_port *
And the command definition should be:
sudo $USER1$/check_udp_port -H $HOSTNAME$ -p $ARG1$ -s $ARG2$
UPDATES:
-----------------------------
v1.1: made change to egrep statement to include 0-9_- in service names
Usage:
check_udp_port: -H remote_host -p port -s service_name
-H Name or IP of remote host
-p UDP port number to check
-s Name of the service that should be listening on the port
Critical: if service is 'unknown' or state is not open
Warning: if service name expected does not match service name listening on the port
OK: if the port is open and service name expected matches service name listening.
NOTE for NagiosXI command definition:
nmap requires root perms to scan the port. Add the following to /etc/sudoers:
NAGIOSXI ALL = NOPASSWD:/usr/local/nagios/libexec/check_udp_port *
And the command definition should be:
sudo $USER1$/check_udp_port -H $HOSTNAME$ -p $ARG1$ -s $ARG2$
UPDATES:
-----------------------------
v1.1: made change to egrep statement to include 0-9_- in service names
Reviews (6)
byrkutsch, May 5, 2021
#result=`sudo /usr/bin/nmap -sU -p $port -P0 $host`
result=`sudo /usr/bin/nmap -sU -p $port -P0 $host| grep ^${port}/.*`
f_result=`echo $result Nmap done`
p_result=`echo $f_result | awk '{print $1" "$2" "$3}'`
result=`sudo /usr/bin/nmap -sU -p $port -P0 $host| grep ^${port}/.*`
f_result=`echo $result Nmap done`
p_result=`echo $f_result | awk '{print $1" "$2" "$3}'`
byDoubravka, August 18, 2019
Good plugin, been using for a while.
Today I upgraded Debian from 9.9 to 10 and this plugin stopped working.
The problem is probably in grep change
line 50:
f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"`
plugin output:
grep: Invalid range end
CRITICAL:
Does anyone know how to fix this issue?
I am no expert at regex
Thanks
Today I upgraded Debian from 9.9 to 10 and this plugin stopped working.
The problem is probably in grep change
line 50:
f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"`
plugin output:
grep: Invalid range end
CRITICAL:
Does anyone know how to fix this issue?
I am no expert at regex
Thanks
byleire, May 22, 2019
Hello,
I have to give permissions to execute all the users the nmap command
chmod u+s /usr/bin/nmap
And I change exit value at the end, to UNKNOWN state because is confused CRITICAL state.
echo "UNKNOWN: $p_result ------"
exit ${STATE_UNKNOWN}
I have to give permissions to execute all the users the nmap command
chmod u+s /usr/bin/nmap
And I change exit value at the end, to UNKNOWN state because is confused CRITICAL state.
echo "UNKNOWN: $p_result ------"
exit ${STATE_UNKNOWN}
byandy232, August 22, 2016
I changed the following line to avoid problems with services containing "open" in the name, e.g.: openvpn
if [ `echo $f_result | egrep -c 'udp open'` -gt 0 ]; then
if [ `echo $f_result | egrep -c 'udp open'` -gt 0 ]; then
bycrefeld, April 7, 2015
Thanks for this helpful tool.
For some nmap-versions (e.g. nmap 5.21 on opensuse 11.4) you will have to remove an extra line with the MAC-address after the port line to get a valid result string:
PORT STATE SERVICE
177/udp open xdmcp
MAC Address: 00:30:48:11:22:33 (Supermicro Computer)
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
As not being familiar with extended regular expressions I extended the nmap statement:
result=`/usr/bin/nmap -sU -p $port -P0 $host |grep -v MAC`
This works but feel free to find the respective expression for f_result.
For some nmap-versions (e.g. nmap 5.21 on opensuse 11.4) you will have to remove an extra line with the MAC-address after the port line to get a valid result string:
PORT STATE SERVICE
177/udp open xdmcp
MAC Address: 00:30:48:11:22:33 (Supermicro Computer)
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
As not being familiar with extended regular expressions I extended the nmap statement:
result=`/usr/bin/nmap -sU -p $port -P0 $host |grep -v MAC`
This works but feel free to find the respective expression for f_result.
I had to escape the dash in the egrep pattern (using GNU egrep 2.14), but after that it worked great!
f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"`
f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"`