Discussion:
[Nagios-users] Monitoring Open Ports
Matt Baer
2009-09-29 19:51:07 UTC
Permalink
Is there a way that Nagios can monitor open ports, even if there isn't anything listening on the destination? I'd like to monitor my open ports on my firewall JUST to make sure they're open. I would just specify the port with the normal Nagios command and point it at my public IP address, but obviously, the check will fail unless something is listening on the other end. Basically I want to port scan specific ports. Any ideas?
James Pratt
2009-09-29 20:13:00 UTC
Permalink
-----Original Message-----
Sent: Tuesday, September 29, 2009 3:51 PM
Subject: [Nagios-users] Monitoring Open Ports
Is there a way that Nagios can monitor open ports, even if there isn't anything
listening on the destination? I'd like to monitor my open ports on my firewall JUST to
make sure they're open. I would just specify the port with the normal Nagios
command and point it at my public IP address, but obviously, the check will fail unless
something is listening on the other end. Basically I want to port scan specific ports.
Any ideas?
Sure, just google for "nagios nmap" - I found this one, looks like it may work for you, but may need some modification -


http://ubermonkey.wordpress.com/2006/09/2
Justin Pryzby
2009-09-29 20:16:54 UTC
Permalink
Post by Matt Baer
Is there a way that Nagios can monitor open ports, even if there
isn't anything listening on the destination? I'd like to monitor my
open ports on my firewall JUST to make sure they're open. I would
just specify the port with the normal Nagios command and point it at
my public IP address, but obviously, the check will fail unless
something is listening on the other end. Basically I want to port
scan specific ports. Any ideas?
Can you use check_tcp for this? Otherwise I would write a wrapper
around nmap:

! nmap -oG - -p 22 localhost |cut -sd/ -f2 |grep -Fxvw open

Justin
Marc Powell
2009-09-29 20:27:09 UTC
Permalink
Post by Matt Baer
Is there a way that Nagios can monitor open ports, even if there
isn't anything listening on the destination? I'd like to monitor my
open ports on my firewall JUST to make sure they're open. I would
just specify the port with the normal Nagios command and point it at
my public IP address, but obviously, the check will fail unless
something is listening on the other end. Basically I want to port
scan specific ports. Any ideas?
A quick google for 'nagios nmap' yields this result that looks
promising --

http://ubermonkey.wordpress.com/2006/09/28/nagios-nmap-plugin/

--
Marc
Kevin Keane
2009-09-30 01:09:25 UTC
Permalink
Not sure if my response will help you since I take a slightly different
approach to monitoring basically the same thing. I am monitoring both
the ports actually being listened on, and the iptables configuration.

I'm using netstat -ltunp on the monitored server. Below is the plugin
script I am using. Actually, it really looks for CHANGES in open ports.
The first time it runs, it creates a file /var/run/checkPorts that
contains a list of all currently-open ports. Any time a port opens or
stops listening, the script generates an alert. If you expect a change
in the list of open ports, simply delete the file /var/run/checkPorts.

I also have a similar script that compares the actual iptables filter
tables with the ones specified, to see if the firewall may have opened
some port unexpectedly. That, too, has to run on the monitored machine.

If you want to check from the outside - such as from the nagios server -
you probably need to use nmap or the like, or you may be able to use an
SNMP query or similar to your firewall. Be aware that your firewall may
actually detect that type of probing as an intrusion attempt.

#!/bin/bash

result=0
# the PID in the output of netstat can legitimately change, so
# let's remove it. We also sort to be sure that the ordering
# doesn't cause any headaches later
netstat -ltunp | sed 's;[0-9]*/.*;;' | sort > /tmp/$$.checkPorts
if [ ! -f /var/run/checkPorts ]
then
cp /tmp/$$.checkPorts /var/run/checkPorts
echo -n "Created new compare file"
else
out=$(diff --ignore-all-space /tmp/$$.checkPorts /var/run/checkPorts)
if [ $? -ne 0 ]
then
result=1
echo "$out" | grep '[<>]' | awk '{ print $1, $5, $8; }' | sed -e
:a -e '$!N; s/\n/; /; ta'
else
echo -n "Only expected ports are open"
fi
fi
rm -f /tmp/$$.checkPorts
exit $result
Post by Matt Baer
Is there a way that Nagios can monitor open ports, even if there isn't
anything listening on the destination? I'd like to monitor my open
ports on my firewall JUST to make sure they're open. I would just
specify the port with the normal Nagios command and point it at my
public IP address, but obviously, the check will fail unless something
is listening on the other end. Basically I want to port scan specific
ports. Any ideas?
--
Kevin Keane
Owner
The NetTech
Find the Uncommon: Expert Solutions for a Network You Never Have to Think About

Office: 866-642-7116
http://www.4nettech.com

This e-mail and attachments, if any, may contain confidential and/or proprietary information. Please be advised that the unauthorized use or disclosure of the information is strictly prohibited. The information herein is intended only for use by the intended recipient(s) named above. If you have received this transmission in error, please notify the sender immediately and permanently delete the e-mail and any copies, printouts or attachments thereof.
Matt Baer
2009-10-05 18:43:20 UTC
Permalink
For the most part, this works. However, the problem is that it requires that ALL open ports be accepted as parameters. I want to specify the ports to check. For example, if port 8081 is open, it may not always be open, then I get the stupid notification. I don't want to monitor port 8081, I want to monitor 25,80,110,143, etc.

----- Original Message -----
From: "Marc Powell" <***@ena.com>
To: "Nagios-Users Mailinglist" <Nagios-***@lists.sourceforge.net>
Sent: Tuesday, September 29, 2009 3:27:09 PM GMT -06:00 US/Canada Central
Subject: Re: [Nagios-users] Monitoring Open Ports
Post by Matt Baer
Is there a way that Nagios can monitor open ports, even if there
isn't anything listening on the destination? I'd like to monitor my
open ports on my firewall JUST to make sure they're open. I would
just specify the port with the normal Nagios command and point it at
my public IP address, but obviously, the check will fail unless
something is listening on the other end. Basically I want to port
scan specific ports. Any ideas?
A quick google for 'nagios nmap' yields this result that looks
promising --

http://ubermonkey.wordpress.com/2006/09/28/nagios-nmap-plugin/
--
Marc


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Nagios-users mailing list
Nagios-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
James Pratt
2009-10-05 19:09:17 UTC
Permalink
Well, look on the bright side - It's not that big of a perl script - you can likely modify it to suit your specific need(s). :)
-----Original Message-----
Sent: Monday, October 05, 2009 2:43 PM
To: nagios-users
Subject: Re: [Nagios-users] Monitoring Open Ports
For the most part, this works. However, the problem is that it requires that ALL
open ports be accepted as parameters. I want to specify the ports to check. For
example, if port 8081 is open, it may not always be open, then I get the stupid
notification. I don't want to monitor port 8081, I want to monitor 25,80,110,143,
etc.
----- Original Message -----
Sent: Tuesday, September 29, 2009 3:27:09 PM GMT -06:00 US/Canada Central
Subject: Re: [Nagios-users] Monitoring Open Ports
Post by Matt Baer
Is there a way that Nagios can monitor open ports, even if there isn't
anything listening on the destination? I'd like to monitor my open
ports on my firewall JUST to make sure they're open. I would just
specify the port with the normal Nagios command and point it at my
public IP address, but obviously, the check will fail unless something
is listening on the other end. Basically I want to port scan specific
ports. Any ideas?
A quick google for 'nagios nmap' yields this result that looks promising --
http://ubermonkey.wordpress.com/2006/09/28/nagios-nmap-plugin/
--
Marc
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only
developer event you need to attend this year. Jumpstart your developing skills, take
BlackBerry mobile applications to market and stay ahead of the curve. Join us from
November 9&#45;12, 2009. Register now&#33; http://p.sf.net/sfu/devconf
_______________________________________________
Nagios-users mailing list
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk bei
Marc Powell
2009-10-05 19:27:06 UTC
Permalink
Post by James Pratt
Well, look on the bright side - It's not that big of a perl script -
you can likely modify it to suit your specific need(s). :)
and it appears to be a very very trivial change to boot (but will
break some functionality without further changes)...

If the OP only cares about the functionality of the plugin to check
the open/closed status of listed ports, he can simply change
@nmap_raw = `$nmap_path -P0 -p1-65535 $scan_address`;

to

@nmap_raw = `$nmap_path -P0 -p$allowed_ports $scan_address`;

You can expect this to break other functionality of the plugin like
full host scans, etc, but I believe that this is what the OP is
looking for given this further information.

--
Marc

Loading...