New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snmp_getnext_multi() function #8052

Merged
merged 4 commits into from Jan 9, 2018

Conversation

Projects
None yet
4 participants
@neg2led
Copy link
Contributor

neg2led commented Jan 9, 2018

Added snmp_getnext_multi() function using syntax of existing snmp_get_multi() function.

This replicates the snmp_get_multi() function but calls snmpgetnext instead, returning an array like so;

array(1) {
  [4]=>
  array(2) {
    ["dot11manufacturerProductName"]=>
    string(15) "UAP-AC-Pro-Gen2"
    ["dot11manufacturerProductVersion"]=>
    string(35) "BZ.qca956x.v3.7.37.6065.170118.0908"
  }
}

This replicates the output of snmp_get_multi() - we won't know the index in advance, but consistency of outputs seems worth doing.

See #8005 for further details :)

DO NOT DELETE THIS TEXT

Please note

Please read this information carefully. You can run ./scripts/pre-commit.php to check your code before submitting.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926

@murrant

This comment has been minimized.

Copy link
Member

murrant commented Jan 9, 2018

Because this is getnext, perhaps omitting the index seems appropriate. Otherwise, how will you find the data in the result array?

For example we get firstOid and secondOid, but first oid is at index 32 and the second index is at index 43

Now we have an array like this:

array(
    32 => array('firstOid' => 'value'),
    43 => array('secondOid' => 'value),
)

You'd have to iterate through the array and search for the right oid.

I think this makes more sense:

array(
    'firstOid' => 'value',
    'secondOid' => 'value',
)
@neg2led

This comment has been minimized.

Copy link
Contributor Author

neg2led commented Jan 9, 2018

I was looking to preserve the index number without having to account for it being a part of the key, since it's something that isn't known at the time of calling the function (and might be different for each returned result). We could return this;

array(
   'firstOid.index' => 'value',
   'secondOid.index' => 'value',
)

But now our calling routine won't know what it should be looking for as a key. Maybe a bit of both?

array(
    firstOid => array('value' => 'sometext', 'index' => 'somenumber'),
    secondOid => array('value' => 'sometext', 'index' => 'somenumber'),
)

Then it's as simple as $data['firstOid']['value'] but the index isn't lost along the way - If we don't mind losing the index entirely then I'm totally happy to strip it, though.

@murrant

This comment has been minimized.

Copy link
Member

murrant commented Jan 9, 2018

No, I'd say if you want to preserve the index use the (as of yet unwritten) snmp_getnext_multi_oid()

@neg2led

This comment has been minimized.

Copy link
Contributor Author

neg2led commented Jan 9, 2018

Makes sense. Done and done :)

@scrutinizer-notifier

This comment has been minimized.

Copy link

scrutinizer-notifier commented Jan 9, 2018

The inspection completed: 1 new issues, 1 updated code elements

@murrant murrant merged commit 81fbe95 into librenms:master Jan 9, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

@laf laf added the Feature label Jan 9, 2018

@neg2led neg2led deleted the neg2led:snmp-getnext-multi branch Jan 9, 2018

@lock

This comment has been minimized.

Copy link

lock bot commented May 16, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed.

@lock lock bot locked as resolved and limited conversation to collaborators May 16, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.