FreeDSx / SNMP

A Pure PHP SNMP Library.
MIT License
57 stars 13 forks source link

Equivalent for snmp_bulk_walk #3

Closed simPod closed 5 years ago

simPod commented 5 years ago

Is there a way, how to get sub tree for lets say 1.3.6.1.2.1.47.1.1.1.1.2? I studied the docs but couldn't find a way how to get array of sub tree results. Thanks!

ChadSikorra commented 5 years ago

You could pass a start and end OID to the walk() method. I just realized that the current walk does not behave like the snmpwalk command. Such that it continues past the subtree like you'd expect (when specifying a start). I should probably change this behavior. You could also use the getBulk() method of the client. I do not have getbulk worked into the walk utility yet.

ChadSikorra commented 5 years ago

I've added some additional logic for the walk helper to behave more as expected. I'll soon commit it after I look it over a bit more and add some docs. It will now stop at the end of the subtree by default. And calls to hasOids() and isComplete() will take the next OID in the tree into account if subtree is specified.

ChadSikorra commented 5 years ago

Added commit https://github.com/FreeDSx/SNMP/commit/e99d6bd96f79e8186cba4a26b2b956a3fecb303d. So now you should be able to do...

$walk = $snmp->walk('1.3.6.1.2.1.47.1.1.1.1.2');

...and get just that subtree. Let me know if it doesn't work as expected for you.

ChadSikorra commented 5 years ago

I have also optimized the walk component to use GetBulk requests by default if using SNMP v2/v3. This makes it way faster by default. For example, a typical complete walk at the default start OID on my machine now talks about 1.5 seconds instead of more than 2 minutes.

Closing this out. Feel free to open it again if you still have issues.

simPod commented 5 years ago

Just tested it. It seems faster than ext-snmp 🤔 Looks promising

simPod commented 5 years ago

@ChadSikorra I decided to finish the task I started but when I run

$walk = $snmp->walk('1.3.6.1.2.1.47.1.1.1.1.2'); it returns no items (count = 0). isComplete() returns true. Any idea what am I doing wrong?

When manually querying the oid using snmpbulkwalk it returns results.

I'm using v0.4.

ChadSikorra commented 5 years ago

What does snmbulkwalk it return in that case (ending OID)? Does a walk starting at 1.3.6.1.2.1.47.1.1.1 return the full tree?

simPod commented 5 years ago

The thing is that .1.3.6.1.2.1.47.1.1.1.1.2 is already a tree. Returns
.1.3.6.1.2.1.47.1.1.1.1.2.1
.1.3.6.1.2.1.47.1.1.1.1.2.2
.1.3.6.1.2.1.47.1.1.1.1.2.1000
etc.

.1.3.6.1.2.1.47.1.1.1.1 has the same behaviour

Any idea?

image

simPod commented 5 years ago

Ok sorry. I should go home today already. I just realised I can debug it :D Gimme few mins

simPod commented 5 years ago

https://github.com/FreeDSx/SNMP/pull/5