Page 4 of 5

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 23, 2016 6:36 am
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?

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 23, 2016 9:07 am
by tgriep
Good news. Yes, if the check interval is set to 5 minutes, then it will run every 5 minutes.

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 23, 2016 9:36 am
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

Re: Syntax Command Check_netstat_conn

Posted: Wed Mar 23, 2016 2:39 pm
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"

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 6:48 am
by ednaldojta
How would the script along with the syntax
netstat -an | grep 5666 | wc -l?

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 9:44 am
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.

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 11:07 am
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!

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 2:31 pm
by hsmith
Is this script working for you?

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 3:01 pm
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.

Re: Syntax Command Check_netstat_conn

Posted: Mon Mar 28, 2016 7:15 pm
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
################################