Page 1 of 1

Port Descriptions

Posted: Wed Sep 18, 2013 10:03 am
by and1100
Hi,

I have Nagios monitoring ports on our switches, however I've found that hard-coding the port description tags into my switch.cfg has been a tedious task and I foresee this becoming an issue as we grow bigger. Is there a simpler and quicker way of doing this?

As it is now, I am making an individual defined service for each port on the switch and coding the switch description associated with it in the service_description...

example:

Code: Select all

##############################
#######switch ETH STATUS#######
##############################


define service{
        use                     generic-service
        host_name               switch
        service_description     Eth 1 [description here]
        check_command           check_snmp!-H 10.7.x.x -P 2c -C secret -o ifOperStatus.1 -r '1|6'
        max_check_attempts      2
        check_interval          1
        retry_check_interval    1
        check_period            24x7
        notification_interval   5
        notification_period     24x7
        contact_groups          admins
        }

define service{
        use                     generic-service
        host_name               switch
        service_description     Eth 2 [description here]
        check_command           check_snmp!-H 10.7.x.x -P 2c -C secret -o ifOperStatus.2 -r '1|6'
        max_check_attempts      2
        check_interval          1
        retry_check_interval    1
        check_period            24x7
        notification_interval   5
        notification_period     24x7
        contact_groups          admins
        }
I've done this for almost every important switch and port, however, is there a way to script it into Nagios to pull the description straight from the switch? Any ideas or tips to simplify this process would be most welcome.

Thank you!

Re: Port Descriptions

Posted: Wed Sep 18, 2013 11:24 am
by abrist
and1100 wrote:I've done this for almost every important switch and port, however, is there a way to script it into Nagios to pull the description straight from the switch? Any ideas or tips to simplify this process would be most welcome.
Yes, this is possible. It will require some scripting. Here is some psuedo code:

Code: Select all

#!/bin/bash
SWITCH_IP=$1
SWITCH_HOSTNAME=$2
snmpwalk $SWITCH_IP portDesc_oid > /tmp/ports
while read line
do 
DESC = cat $line | awk '{ print $field_with_desc }'  
PORT = cat $line | awk '{ print $field_with_port }'

cat template.cfg | sed 's/_hostname/$SWITCH_HOSTNAME/gc' |sed 's/_service_desc/$DESC/gc' | sed 's/_command/<the command to check the $PORT>/gc' >> /tmp/$SWITCH_HOSTNAME.cfg

done < /tmp/ports
<etc> 
This code above * WILL NOT* work, it is just to get the wheels moving. The idea being that you use a template config file with some variables for hostname, service_description, etc (prepended with '_' so the script can easily use sed to replace). You then walk the mib for the port descriptions, dump it to a temp file, and then iterate through each line building a config for each port. The description grabbed from the walk replaces the '_service_description' from the config. The same applies for any other necessary parts of the config.

Re: Port Descriptions

Posted: Wed Sep 18, 2013 4:35 pm
by and1100
Hi abrist,

Thank you for this. I will experiment with it let you know if I have any questions.

Thanks again!

Re: Port Descriptions

Posted: Wed Sep 18, 2013 4:59 pm
by abrist
No problem. If you flesh out a real script I can help with debugging. Dynamic scripts and automated nagios configs are fun!

Re: Port Descriptions

Posted: Thu Sep 19, 2013 7:34 am
by HFroyen
If you worked out a script it would be nice if you could let us all know how you did it or post the script!
I'm also very interested in this because we have serveral Nagios instances monitoring a lot of servers and their services (also hardware) and it is all configured quiet static!
A dynamic solution would be very nice 8-)

Re: Port Descriptions

Posted: Thu Sep 19, 2013 9:14 am
by slansing
Sounds like you have some fans and1100! :) We can keep this thread open in case you get back to this project.