Question

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.

Was it helpful?

Solution

For entries like switch_stuff1 = 1.5.1.6.* you could simply send first request and after that loop through get_next_request as long as you get data.

However, with config like switch_stuff2 = 1.45.*.12 it is not so simple any more. You can't use get_next_request and you have to iterate over possible values yourself. The problem is that numbers are "usually" continuous but not always and in latter case it makes it quite stressful for the system to just try all possible numbers. At least if you really need to do this then I suggest to cache somehow OIDs that exists and not scan them every time you collect data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top