Page 1 of 5

Syntax Command Check_netstat_conn

Posted: Thu Feb 25, 2016 7:39 am
by ednaldojta
Good morning friends!
I'm working on Nagios XI now! I'm new to the platform. I wanted to know how to implement the command syntax "check_netstat_conn" file "commands.cfg" the NagiosXI.
I need to check the number of connections in a HAproxy webservice per port. It's possible?
If another plugin, accept ideas from colleagues!
Thanks for listening! :D :D

Re: Syntax Command Check_netstat_conn

Posted: Thu Feb 25, 2016 11:34 am
by rkennedy
Here's a quick script to accomplish your check. You'll need to execute it remotely using SSH or a remote agent client. You will need to modify this to your needs -

Code: Select all

#!/bin/bash
#this plugin will check netstat (netstat -an|grep :80|wc -l)  for a number and alert accordingly
#to the if statements below.
#OK is <80
#WARNING is 80-90
#CRITICAL is >90

#define file
count=$(/bin/netstat -an | grep :80 | wc -l)

#check $count value
if [ $count -lt 80 ]
then
        state="OK"
elif [ $count -ge 80 ] && [ $count -lt 90 ]
then
        state="WARNING"
elif [ $count -ge 90 ]
then
        state="CRITICAL"
else
        state="UNKNOWN"
fi
echo "$state: $count|count=$count"
Here's a sample -

Code: Select all

[root@suse11 libexec]# netstat -an|grep :80|wc -l
56
[root@suse11 libexec]# ./count.sh
OK: 56|count=56

Re: Syntax Command Check_netstat_conn

Posted: Fri Feb 26, 2016 9:14 am
by ednaldojta
rkennedy!
Thanks for the answer. But I need to know how to implement iso. I need to insert some syntax in commands.cgf file? Or can Execultar this script with SSH Proxy Service NagiosXI own?

Please find attached the image of the service provided by Nagios XI.

Re: Syntax Command Check_netstat_conn

Posted: Fri Feb 26, 2016 11:24 am
by rkennedy
You will need to create a nagios user on the HA proxy machine and setup SSH keys for it to use for authentication. See this document - https://assets.nagios.com/downloads/nag ... ng_SSH.pdf

Then, create a bash script of the contents I wrote for you above, and in the wizard have it execute that script.

To help demonstrate how this will work -
XI will SSH on to your HA Proxy machine and run check_netstat_conn.sh for example, and then the output will be sent back to Nagios XI for your service check.

Re: Syntax Command Check_netstat_conn

Posted: Thu Mar 03, 2016 8:36 am
by ednaldojta
Rkennedy,
Good Morning,
realized step-by-step instructions that you gave me, I managed to connect to the remote server through the NagiosXI with nagios User. But when I check through command nagios, it's me the following message.

Also I had problem when the copy of the key with the command:

ssh-copy-id ~ / nagios nagios @ /name_of_keyfile.ssh.pub remoteip.

I made a copy via scp same. Is there any problem?

Re: Syntax Command Check_netstat_conn

Posted: Thu Mar 03, 2016 12:28 pm
by rkennedy
It looks like you still need to enter your password to SSH (which is what we want to eliminate). Can you check the permissions of the file that you copied over? It should be fine to copy it over using SCP.

Re: Syntax Command Check_netstat_conn

Posted: Thu Mar 03, 2016 12:31 pm
by ednaldojta
The file that you say is the key or the script that will run on the remote?

Re: Syntax Command Check_netstat_conn

Posted: Thu Mar 03, 2016 5:42 pm
by rkennedy
Both actually, they should be owned by nagios.

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 09, 2016 1:10 pm
by ednaldojta
I could not perform operations with root User?
For the tutorial he calls for the creation of a Nagios user, is that right would create a root user?

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 09, 2016 1:32 pm
by rkennedy
You need to create a nagios user, as that is who the check by ssh will authenticate as.