LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Scripting SNMP walks and populating files (http://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-snmp-walks-and-populating-files-4175453830/)

xenner 03-12-2013 05:44 PM

Shell Scripting SNMP walks and populating files
 
Hi,

So, I would generally go through and discover this myself, but unfortunately, time is of the essence and I am now turning to the community to assist me.. Please help, and I will love you forever!! (Not really, cos I don't actually know you, and that would be weird.)

So, I've been asked to do some nagios config, which I don't have a problem with.. Then, I was given a list of 1000 items to monitor.. Fine, I've done that, and now I have 1000 different cfg files...
Now, I've been given different variables for each item which will be unique to each device I'm monitoring... That's when my brain decided that being awake all night with a baby, and coming to work with little to no sleep was all too much, and it's turning off.

Can someone please give me some guidance, (And speak slowly with explanations) with the following task, it should be simple.

I need to run
snmpwalk -v2c -cfctmonitor 10.x.x.x 1.3.6.1.2.1.2.2.1.2

This should give me some Interface names.. In this case, I would grep out IF-MIB::ifDescr.4 = STRING: ATM0/0/0 AND IF-MIB::ifDescr.8 = STRING: ATM0/0/0.0-aal5 layer

Then, depending if this actually came back with the results I want (So, an 'if' statement), then I'd like to run the next snmpwalk, this time against: 1.3.6.1.2.1.2.2.1.8."x" (x=whatever output the above turned up (the 4 and the 8 from the previous statement, as they held the correct strings).

Then, I need to determine the speed of these interaces using the OID of... 1.3.6.1.2.1.2.2.1.2.4."x" (Where x = the 4 and 8 as previously discovered). Then, from all of those details I got, I need to add them into all the config files that turn up this response.

So basically, I would begin all of this by determining the IP address from each file and running the walks against those ips in a sequential order.
ip_address = for i in $(cat router_list.txt) ;do grep address "$i" |awk '{print $2}' ;done
---- Router_list.txt has a list of all files in the directory----

please help me, you guys are awesome, and no doubt you've already done something similar.

Thanks!!!

Habitual 03-12-2013 07:33 PM

Quote:

Originally Posted by xenner (Post 4910302)
snmpwalk -v2c -cfctmonitor 10.x.x.x 1.3.6.1.2.1.2.2.1.2

This should give me some Interface names.. In this case, I would grep out IF-MIB::ifDescr.4 = STRING: ATM0/0/0 AND IF-MIB::ifDescr.8 = STRING: ATM0/0/0.0-aal5 layer

Then, depending if this actually came back with the results I want (So, an 'if' statement), then I'd like to run the next snmpwalk, this time against: 1.3.6.1.2.1.2.2.1.8."x" (x=whatever output the above turned up (the 4 and the 8 from the previous statement, as they held the correct strings).

Then, I need to determine the speed of these interaces using the OID of... 1.3.6.1.2.1.2.2.1.2.4."x" (Where x = the 4 and 8 as previously discovered). Then, from all of those details I got, I need to add them into all the config files that turn up this response.

So basically, I would begin all of this by determining the IP address from each file and running the walks against those ips in a sequential order.
ip_address = for i in $(cat router_list.txt) ;do grep address "$i" |awk '{print $2}' ;done
---- Router_list.txt has a list of all files in the directory----

please help me, you guys are awesome, and no doubt you've already done something similar.

Thanks!!!

You need a loop script to hit an snmp-enabled router? I could go on for days, but it is not clear to me what your actual request is.
It sounds like you have all the right parts to make this work but perhaps are unsure how to proceed?

Please let us know...

Subscribed with interest...

Nagios - Grrr. Arg...

xenner 03-12-2013 07:42 PM

You're right on!!! I don't know how to proceed... I have an idea, but that's it :(

So, I have 1000 routers to get their ID's off.

I have 1000 .cfg files with the ip address's listed of each router.

I just don't know how to go through all the files in one swoop, and assigning the particular OID check against the ones that work, and different OID's to the ones that don't work (Runninga defferent script using an "If OID is != to 'blah'; then do <x>) (As we have multiple router types here and the Network guy refuses to give me the OID's for each router.. Grrrr, leaving me to find them myself).


How many brackets can we have? :)

Does that explanation help a little.../? Perhaps?

Thank you for your assistance.

Habitual 03-12-2013 08:27 PM

Quote:

Originally Posted by xenner (Post 4910355)
You're right on!!! I don't know how to proceed... I have an idea, but that's it :(

So, I have 1000 routers to get their ID's off.

I have 1000 .cfg files with the ip address's listed of each router.

I just don't know how to go through all the files in one swoop, and assigning the particular OID check against the ones that work, and different OID's to the ones that don't work (Runninga defferent script using an "If OID is != to 'blah'; then do <x>) (As we have multiple router types here and the Network guy refuses to give me the OID's for each router.. Grrrr, leaving me to find them myself).

How many brackets can we have? :)

Does that explanation help a little.../? Perhaps?

Thank you for your assistance.

You only need the list of IPs to run smpwalk against. ;)
get those, 1 per line from the 1000 .cfg files and into your home directory as hosts.ips

Code:

for i in $(echo 4 8) ; do snmpwalk -v2c -cfctmonitor $(cat ~/hosts.ips) ifSpeed.$i ; done
should do something, I hope. :)
If it works, great, if not, well, I'll look at it some more, or someone smarter than I will toss in a solution. You are not that far away from
giving an evil grin at the "Network guy". Bwhaahahahaha


All times are GMT -5. The time now is 03:41 AM.