Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_udp_port

Rating
7 votes
Favoured:
2
Current Version
1.1
Last Release Date
2014-06-09
Compatible With
  • Nagios 3.x
  • Nagios 4.x
  • Nagios XI
Owner
License
GPL
Hits
40956
Files:
FileDescription
check_udp_portThe script
Nagios CSP

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
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
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}'`
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
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}
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
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.
bywillamowius, December 9, 2014
1 of 1 people found this review helpful
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"`