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.
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...
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.
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:
#!/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.
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.
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