I have a Perl script that monitors any SNMP enabled service.
The way it works is I have a config file with multiple services, and each service has a list of metrics to collect.
Example:
[switch]
switch_stuff1 = 1.3.6.1.2.1.7.1.0
switch_stuff2 = 1.3.6.1.2.1.7.4.0
switch_stuff3 = 1.3.6.1.2.1.6.2.0
switch_stuff4 = 1.3.6.1.2.1.6.3.0
switch_stuff5 = 1.3.6.1.2.1.6.5.0
[router]
router_stuff1 = 1.3.6.1.2.1.6.8.0
router_stuff2 = 1.3.6.1.2.1.6.8.0
router_stuff3 = 1.3.6.1.2.1.6.9.0
[database]
db_stuff1 = 1.3.6.1.2.1.6.4.0
db_stuff2 = 1.3.6.1.2.1.6.5.0
The script will loop through the config file, obtain the information for all the metrics and write the output to a CSV file.
Now, onto what I need help with.
I was asked to implement logic that would allow the use of wildcards in the SNMP paths to collect. So my config file would now need to look like this:
[switch]
switch_stuff1 = 1.5.1.6.*
switch_stuff2 = 1.45.*.12
So when the collection will happen, it will somehow loop like this:
switch_stuff1
1.5.1.6.0 – found, continue
1.5.1.6.1 – found, continue
1.5.1.6.2 – not found, stop
switch_stuff2
1.45.0.12 – found, continue
1.45.1.12 – found, continue
1.45.2.12 – found, continue
1.45.3.12 – not found, stop
I'm currently using the Net::SNMP library:
http://metacpan.org/pod/Net::SNMP
Would this be possible to do? I was thinking of somehow simulating an "snmpwalk" via the get_entries or get_table methods, but I'm not quite sure if that would work.
If anyone can help out or at least point me in the right direction, it would be greatly appreciated.
Thank you.