Monitoring custom UDP ports

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rjconroy
Posts: 38
Joined: Fri Feb 02, 2018 11:57 am

Monitoring custom UDP ports

Post by rjconroy »

Long story short, i have a custom app that uses UDP ports i would like to monitor to ensure they are responding/listening/up. I know udp doesnt actually do that but i wasnt quite sure how else to phrase it.

I have been reading thru and trying to use the check_udp option but of course i always get the "With UDP checks, a send/expect string must be specified." message. I have so far been unable to determine what argument to add to the conf files to make this work.

I tried the check_udp_port plugin but had issues with it and apparently could not get the tow work as part of my conf files for the custom services. I m sure it was user error but regardless i was unable to get it to work.

I've been all over google and havent yet found a working example that ive been able to port.

I guess the bottom line is how do i effectively monitor customer UDP ports?

This would seem a simple thing but to date it has me perplexed.
kyang

Re: Monitoring custom UDP ports

Post by kyang »

How exactly did you try to use check_udp_port?

Most of the plugins available on the Nagios Exchange are either using nmap, netstat or some other utility to see whether UDP is being listened on.

Examples: first one is a switch, second one is my Nagios XI Server.

Code: Select all

[root@localhost libexec]# ./check_udp_port -H 192.168.5.xxx -p 161 -s snmp
OK: snmp listening on port 161: 161/udp open snmp

[root@localhost libexec]# ./check_udp_port -H 192.168.4.xxx -p 161 -s snmp
OK: snmp listening on port 161: 161/udp open snmp
There are probably other ways in monitoring UDP, but this is the example.
rjconroy
Posts: 38
Joined: Fri Feb 02, 2018 11:57 am

Re: Monitoring custom UDP ports

Post by rjconroy »

I had tried this in a couple of different ways.

running the command manually as you displayed gave me the output that simply said "Critical:" without anything from the text in the command files that suggested a reason, even though I know the port was open and working.

I did netstat on the host I was checking and determined that technically its java listening on the port in question (its part of an elasticsearch deployment for one of the listening inputs but netstat thinks its java). This command was run from the plugins folder where I placed the sh file in conjunction with the other plugins, and even adjusted permissions.

It was run as root as follows: ./check_udp_port -H 192.168.1.x -p 5141 -s java

I haven't yet determined how to automate this as part of the service conf files as each syntax if checked results in the Nagios service not starting and giving error. so that will be a follow up question is how to define the service for the check_command in the conf files

This is probably easy but its still new to me and working with plugins is not something ive done previously. forgive the silly questions
rjconroy
Posts: 38
Joined: Fri Feb 02, 2018 11:57 am

Re: Monitoring custom UDP ports

Post by rjconroy »

Still no luck, perhaps someone could share a working example of a service definition using check_udp? Or alternatively the same for something working using check_udp_port?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitoring custom UDP ports

Post by tgriep »

To use the check_udp plugin, you have to send a string to the system you are checking and that system has to respond to that command.
Then the plugin checks the response against the expect string.

For example, it I had a server that I sent Hello to and it responds with Goodbye , The command would be as follows

Code: Select all

./check_udp -H xxx.xxx.xxx.xxx -p 5141 -s Hello -e Goodbye
You would have to come up with the send string and the expect string for your server but that is the usage for that check.




The list of options for the check_udp plugin are as follows.
check_udp --help
check_udp v2.2.1 (nagios-plugins 2.2.1)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 1999-2014 Nagios Plugin Development Team
<devel@nagios-plugins.org>

This plugin tests UDP connections with the specified host (or unix socket).

check_udp -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]
[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]
[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]
[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]
[-N <server name indication>]

Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
--extra-opts=[section][@file]
Read options from an ini file. See
https://www.nagios-plugins.org/doc/extra-opts.html
for usage and examples.
-H, --hostname=ADDRESS
Host name, IP Address, or unix socket (must be an absolute path)
-p, --port=INTEGER
Port number (default: none)
-4, --use-ipv4
Use IPv4 connection
-6, --use-ipv6
Use IPv6 connection
-E, --escape
Can use \n, \r, \t or \\ in send or quit string. Must come before send or quit option
Default: nothing added to send, \r\n added to end of quit
-s, --send=STRING
String to send to the server
-e, --expect=STRING
String to expect in server response (may be repeated)
-A, --all
All expect strings need to occur in server response. Default is any
-q, --quit=STRING
String to send server to initiate a clean close of the connection
-r, --refuse=ok|warn|crit
Accept TCP refusals with states ok, warn, crit (default: crit)
-M, --mismatch=ok|warn|crit
Accept expected string mismatches with states ok, warn, crit (default: warn)
-j, --jail
Hide output from TCP socket
-m, --maxbytes=INTEGER
Close connection once more than this number of bytes are received
-d, --delay=INTEGER
Seconds to wait between sending string and polling for response
-D, --certificate=INTEGER[,INTEGER]
Minimum number of days a certificate has to be valid.
1st is #days for warning, 2nd is critical (if not specified - 0).
-S, --ssl
Use SSL for the connection.
-w, --warning=DOUBLE
Response time to result in warning status (seconds)
-c, --critical=DOUBLE
Response time to result in critical status (seconds)
-t, --timeout=INTEGER:<timeout state>
Seconds before connection times out (default: 10)
Optional ":<timeout state>" can be a state integer (0,1,2,3) or a state STRING
-v, --verbose
Show details for command-line debugging (Nagios may truncate output)
Be sure to check out our Knowledgebase for helpful articles and solutions!
rjconroy
Posts: 38
Joined: Fri Feb 02, 2018 11:57 am

Re: Monitoring custom UDP ports

Post by rjconroy »

Thank you for that, ive tried many different methods so far and to date none have worked.
I realize this will be different for various protocols/services... I guess I haven't found the correct syntax for mine.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitoring custom UDP ports

Post by tgriep »

OK, let us know if you have any further questions.
Be sure to check out our Knowledgebase for helpful articles and solutions!
rjconroy
Posts: 38
Joined: Fri Feb 02, 2018 11:57 am

Re: Monitoring custom UDP ports

Post by rjconroy »

Well I would like to see a working example of the syntax for the check udp port in the service definitions of possible?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitoring custom UDP ports

Post by tgriep »

A sample command definition for the plugin

Code: Select all

define command {
       command_name                             check_udp
       command_line                             $USER1$/check_udp -H $HOSTADDRESS$ $ARG1$
}
Sample service using the check_udbcommand

Code: Select all

define service {
	host_name			localhost
	service_description		UDP
	check_command			check_udp!-p 5141 -s "SendString" -e "ReceiveString"
	max_check_attempts		5
	check_interval			5
	retry_interval			1
	check_period			xi_timeperiod_24x7
	notification_interval		60
	notification_period		xi_timeperiod_24x7
	notifications_enabled		0
	register			1
	}
Then all you would have to do it put in a valid SendString and ReceiveString and the check should work for you if the system you are checking does return data.
You would have to contact the author of who ever wrote the software that is running on the remote host for the Strings.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked