Pavleck, Jeremy D. wrote:
Greetings,
I'm creating a more or less 'dashboard' where people can enter the
server name, then I'll snmpget a bunch of different oids and show the
status of the device.
Now the problem is snmpget doesn't allow multiple OIDs in one go, so I
have to snmpget(server, community, oid1);, snmpget(server, community,
oid2);, snmpget(server, community, oid3);, etc etc.
I can't always use snmpwalkoid(), especially on really long trees where
I only need 4-5 different items.
So how would you handle this? And array of OIDs and a foreach? Just
using an array of OIDs and a foreach loop would make for a nice compact bit
of code. seems reasonable to do given that snmpget() seems to be a blocking
function.
curious as to what people suggest, as I'm very new to PHP but.. Oddly
falling in love with it fast.
Also, another question since I'm on the topic.
If I know that an snmpwalkoid will always return a set number of values,
I make an array with my 'table of contents' and then use array_combine
to take the keys from my ToC with the values from the returned walk.
Now, with certain things (Like the Compaq logical disk oids) it will
return a varied amount of things, such as 2 logical drives, 3 logical
drives, etc.
Now, would it work if I did something like this?
Create my 'table of contents' key array, Snmpwalkoid(), then move
through both at once and dump it to a new array:
Since the key from the snmpwalkoid() is the OID, I'd have my ToC matched
against the key in the walk array and essentially do string matching
So if .cpqDaPhyDrvModel.0.128 is found, it puts "Drive Model: " as the
key then it looks at the next OID in the array and sees it is
.cpqDaPhyDrvModel.0.129, so it puts it in as "Drive Model 2: ".
the asnwer to your second question is "most probably" - I can't say for sure because
I don't fully grok the question ... but I do know that php array are very very
flexible in their nature so the chances that they can do want you want is quite high :-)
I hope you guys are getting this. It's so clear in my head!
I'm telling you, I use a half dozen languages here because I have to, as
glue between systems, and the 2 things that always get me are arrays and
map/hashes. Some day I hope to figure this out!
the thig to remember about php arrays is that they are arrays in the classic sense BUT
at the same time they are also hashes (in the sens that you may be used to in langauges such
as perl) - numeric keys and associative keys can be mixed and matched as and when you like
it. the one caveat is that php will auto cast numeric strings into numeric keys so that
the following 2 are equivelant:
$r = array(1 => "test");
$r = array("1" => "test");
---
mix'n'match array key types:
$r = array("foo", "bar", "qux", "a" => "foo", "b" => "bar", "c" => "qux");
var_dump($r);
hint: you get an array with 6 items in it!
HTH
Jeremy Pavleck
Sr. Network Engineer - Systems Management
IT Networks and Infrastructure
Capella University
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php