Page 1 of 1

Switch Port Capacity Alert

Posted: Fri May 31, 2013 3:04 pm
by and1100
Hello,

I was not entirely sure if this was possible with Nagios, but are we able to have Nagios check for switch port capacity and send alerts? For example, if our switches are down to 5 free ports ('not connect') I would like Nagios to send an alert for this. I've been trying to think of a way to do this but I'm not really sure how to go about doing so.

Any help would be greatly appreciated.

Thank you.

Re: Switch Port Capacity Alert

Posted: Fri May 31, 2013 3:37 pm
by abrist
This would take a custom script that walks your ports, greps for down, if less that 6, exits with a warning. For example:
check_ports.sh:

Code: Select all

#!/bin/bash
ADDRESS=$1
COMMUNITY=$2
PORTS=$3

COUNT=$(snmpwalk -v1 -c $COMMUNITY $ADDRESS ifOperStatus | grep down | wc -l)

if [ $COUNT -lt $PORTS ]; then
        echo "WARNING! Less than $PORTS ports free | 'ports free'=$COUNT"
        exit 1
else
        echo "OK! $PORTS ports or more free! | 'ports free'=$COUNT"
        exit 0
fi
You would use the script as such:

Code: Select all

./check_ports.sh <ip address> <community string> <number of ports to warn under>
For example:

Code: Select all

./check_ports.sh 127.0.0.1 public 6

Re: Switch Port Capacity Alert

Posted: Fri May 31, 2013 3:51 pm
by and1100
Wow, awesome. Thank you!

I will give this a shot and let you know if I have any issues.

Re: Switch Port Capacity Alert

Posted: Fri May 31, 2013 4:44 pm
by and1100
This works great, however, I am trying to enter it into a cfg.

I've defined the command as follows:

Code: Select all

define command{
        command_name    check_ports
        command_line    $USER1$/check_ports $ARG1$ $ARG2$ $ARG3$
        }
The check_command in the defined service looks like this:

check_command check_ports!-H 10.10.1.2 secret 5

However, it's not working the way it was when I ran the command manually. Any thoughts?

Thanks again!

Re: Switch Port Capacity Alert

Posted: Mon Jun 03, 2013 9:41 am
by abrist
Dump the -H from the check_command:

Code: Select all

check_command check_ports!10.10.1.2 secret 5

Re: Switch Port Capacity Alert

Posted: Mon Jun 24, 2013 4:33 pm
by and1100
Does this have any issues with 52 port switches? It doesn't seem to be reporting for them:


root@vmnagios libexec]# ./check_ports 10.10.8.4 secret 8
Timeout: No Response from 10.10.8.4
WARNING! Less than 8 ports free | 'ports free'=0

However, on our 24 port switches it works fine. Any ideas?

Re: Switch Port Capacity Alert

Posted: Mon Jun 24, 2013 4:38 pm
by sreinhardt
First thought would be that snmp is not enabled on that switch. It seems that you are not getting a response. A simple nmap can verify.

nmap -p 161 -sU 10.10.8.4