Switch Port Capacity Alert

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
and1100
Posts: 93
Joined: Mon Mar 25, 2013 8:37 am

Switch Port Capacity Alert

Post 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.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Switch Port Capacity Alert

Post 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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
and1100
Posts: 93
Joined: Mon Mar 25, 2013 8:37 am

Re: Switch Port Capacity Alert

Post by and1100 »

Wow, awesome. Thank you!

I will give this a shot and let you know if I have any issues.
and1100
Posts: 93
Joined: Mon Mar 25, 2013 8:37 am

Re: Switch Port Capacity Alert

Post 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!
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Switch Port Capacity Alert

Post by abrist »

Dump the -H from the check_command:

Code: Select all

check_command check_ports!10.10.1.2 secret 5
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
and1100
Posts: 93
Joined: Mon Mar 25, 2013 8:37 am

Re: Switch Port Capacity Alert

Post 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?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Switch Port Capacity Alert

Post 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
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked