Page 1 of 1
how to check open sockets on port 502*
Posted: Tue Sep 25, 2018 9:50 am
by Zagon007
hi all
I need a hint, help or whatever:
i have to check the number of open socket on 502* (5020,5021,5022, ecc every 502X ports) with a number of connections by 500 (warning alert) at 1000 (critical alert) connections.
i'm tring to use this command:
netstat -nao | grep ":502" | wc –l
by defining a new command in nagios cfg, but seems somethig gone wrong
Can someone give me a hint ?
Re: how to check open sockets on port 502*
Posted: Tue Sep 25, 2018 1:22 pm
by npolovenko
Hello,
@Zagon007. Does running this command from the command line give you the desired output?
netstat -nao | grep ":502" | wc –l
If so you need to put the command in a shell script, put the script in the /usr/local/nagios/etc/libexec folder, create a new check command and assign it to a service check.
$USER1$/your_check
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://nagios-plugins.org/doc/guidelines.html
Also, running the netstat command as the nagios user may or may not give you the desired output. So you'll need to give the sudoers priveledges to the plugin(by adding the path to the sudoers file).
Re: how to check open sockets on port 502*
Posted: Wed Sep 26, 2018 4:36 am
by Zagon007
npolovenko wrote:Hello,
@Zagon007. Does running this command from the command line give you the desired output?
netstat -nao | grep ":502" | wc –l
yes it does.
It counts the open sockets:
[nagios@server libexec]$ ./open_socket_test.sh
669
previously i've add the script file in the nrpe configuration:
command[open_socket]=/usr/lib/nagios/plugins/open_socket.sh -w 1000 -c 2000
Amd added the command to the nagios checks:
define service {
use generic-service
host_name i-XXXXXXXXXXX
service_description Custom memory checker In Bash
check_command open_socket
}
and restarted the service nagios on the server.
I've also added the path to the sudoes users
if i launch the script on the client it works, if i try one launch, remotely, it fails with a time out connection response.
Re: how to check open sockets on port 502*
Posted: Wed Sep 26, 2018 11:21 am
by npolovenko
@Zagon007, So you added this nrpe command to the nrpe.cfg file on the remote server, right? Not on the Nagios XI server.
command[open_socket]=/usr/lib/nagios/plugins/open_socket.sh -w 1000 -c 2000
This command utilizes the service on the local machine:
define service {
use generic-service
host_name i-XXXXXXXXXXX
service_description Custom memory checker In Bash
check_command open_socket
}
To use the nrpe agent the command should look like this:
define service {
use generic-service
host_name i-XXXXXXXXXXX
service_description Custom memory checker In Bash
check_command check_nrpe!open_socket! -a ' -w 1000 -c 2000'
}
Also, before you start working on the definitions I suggest running the nrpe command from the command line on the Nagios server:
/usr/local/nagios/libexec/check_nrpe -H remote_server_ip -c open_socket -a ' -w 1000 -c 2000'
*Please show me the output.