Syntax Command Check_netstat_conn

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
ednaldojta
Posts: 103
Joined: Tue Apr 07, 2015 7:52 am

Re: Syntax Command Check_netstat_conn

Post by ednaldojta »

Everything worked! Thank you very much! The fight was great but we did it!


: D: D: D

Just a question. If the check is Nagios every 5 minutes for example. Then it will run the "netstat -an | grep 5666 | wc -l" every 5 minutes right?
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Syntax Command Check_netstat_conn

Post by tgriep »

Good news. Yes, if the check interval is set to 5 minutes, then it will run every 5 minutes.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ednaldojta
Posts: 103
Joined: Tue Apr 07, 2015 7:52 am

Re: Syntax Command Check_netstat_conn

Post by ednaldojta »

Friends, just one more thing! how do I put the status CRITICAL, WARNING, etc. and starting the parameters generate an alert in Nagios?

He also did not ta generating graphic
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Syntax Command Check_netstat_conn

Post by rkennedy »

The script should be returning performance data, is it not working for you?

As this is just a simple script, you'll need to manually edit these in the bash file. This page does a good job explaining what lt (less than), and ge (greater or equal) do http://tldp.org/LDP/abs/html/comparison-ops.html

I've added some comments to help make sense of it, does this make sense?

Code: Select all

#OK is <80
#WARNING is 80-90
#CRITICAL is >90

#anything less than 80 is OK
if [ $count -lt 80 ]
then
        state="OK"
#anything greater or equal to 80, AND less than 90.
elif [ $count -ge 80 ] && [ $count -lt 90 ]
then
        state="WARNING"
#greater or equal to 90
elif [ $count -ge 90 ]
then
        state="CRITICAL"
Former Nagios Employee
ednaldojta
Posts: 103
Joined: Tue Apr 07, 2015 7:52 am

Re: Syntax Command Check_netstat_conn

Post by ednaldojta »

How would the script along with the syntax
netstat -an | grep 5666 | wc -l?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Syntax Command Check_netstat_conn

Post by rkennedy »

What exactly are you asking?

The modified part above is not the entire script, it is only there to outline the changes needed for warning / critical thresholds.
Former Nagios Employee
ednaldojta
Posts: 103
Joined: Tue Apr 07, 2015 7:52 am

Re: Syntax Command Check_netstat_conn

Post by ednaldojta »

Yes, I got it!
my script is basic. It is just like is below.

##############################
#! / Bin / bash
# Status CRITICAL - WARNING - OK - WARNING
STAT1 = OK
STAT2 = WARNING
stat3 = CRITICAL
port1 = 5666
port2 = 9012
port3 = 8080
port4 = 443
port5 = 9015
arg1 = `netstat -an | grep $ port1 | wc -l `
if [ "$ arg1" -lt 2]
Then
echo "$ arg1 Connections is $ STAT1"
elif [ "$ arg1" -gt 2]
Then
echo "$ arg1 Connections is $ STAT2"
else
echo "$ arg1 Connections is $ arg3"
fi
################################

How would this syntax within this scritp.
Basically! I'm want this syntax

"Netstat -an | grep 5666 | wc -l"
and starting from a certain number of connections it becomes critical, ok or warning!
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Syntax Command Check_netstat_conn

Post by hsmith »

Is this script working for you?
Former Nagios Employee.
me.
ednaldojta
Posts: 103
Joined: Tue Apr 07, 2015 7:52 am

Re: Syntax Command Check_netstat_conn

Post by ednaldojta »

Yes, but only with this script I can not change the status OK for worning or CRITICAL starting from a certain number of connections.
I want to run this scritp with a trasheroud.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Syntax Command Check_netstat_conn

Post by Box293 »

You need to define the exit code and exit using that code.

Code: Select all

##############################
#! / Bin / bash
# Status CRITICAL - WARNING - OK - WARNING
STAT1 = OK
STAT2 = WARNING
stat3 = CRITICAL
port1 = 5666
port2 = 9012
port3 = 8080
port4 = 443
port5 = 9015
exitcode = 3
arg1 = `netstat -an | grep $ port1 | wc -l `
if [ "$ arg1" -lt 2]
Then
echo "$ arg1 Connections is $ STAT1"
exitcode = 0
elif [ "$ arg1" -gt 2]
Then
echo "$ arg1 Connections is $ STAT2"
exitcode = 1
else
echo "$ arg1 Connections is $ arg3"
exitcode = 2
fi
exit $exitcode
################################
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked