* TCP and UDP (Generic)

check_udp_port

Description:

Simple shell script that uses nmap utility to check if a remote host is listening on a UDP port and what that service is

Current Version

1.1

Last Release Date

2014-06-09

Compatible With

  • Nagios 3.x
  • Nagios 4.x
  • Nagios XI

Owner

License

GPL


Project Files
Project Notes
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) Add a Review
fix f_result
by rkutsch, May 31, 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}'`



Stopped working
by Doubravka, August 31, 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



Permissions and return state
by leire, May 31, 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}



tip for openvpn
by andy232, August 31, 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



Eliminate MAC-statement
by crefeld, April 30, 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.



Nice, but one bug
by willamowius, December 31, 2014

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"`



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.3 (7)
Favorites
2
Views
40,796