Port Descriptions

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

Port Descriptions

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

Re: Port Descriptions

Post 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.
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: Port Descriptions

Post by and1100 »

Hi abrist,

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

Thanks again!
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Port Descriptions

Post by abrist »

No problem. If you flesh out a real script I can help with debugging. Dynamic scripts and automated nagios configs are fun!
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.
HFroyen
Posts: 5
Joined: Mon Sep 09, 2013 3:23 am

Re: Port Descriptions

Post 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-)
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Port Descriptions

Post by slansing »

Sounds like you have some fans and1100! :) We can keep this thread open in case you get back to this project.
Locked