1

I am working on a project that involves SNMP, MIBS and OIDS.

ADDENDUM: I want to have the OIDs translated into names, rather than numeric format. I only have remote access to server.

I get 2 different OID formats when I use LINUX terminal and PHP functions

This is what I do:

  1. In LINUX terminal I type:

    snmpwalk -v 1 -c public ip | less
    

the output is similar to this (short version) enter image description here

  1. Using php

    <?php
    
    $session = new SNMP(SNMP::VERSION_1, ipaddress, "public");
    $session->oid_output_format = SNMP_OID_OUTPUT_FULL;
    $result = $session->walk("");
    print_r($result);
    
    ?>
    

the output is below enter image description here

The issue: How can i get the same format in php similar to linux terminal format?

MAYBE: Is there a command that we can run from LINUX terminal that will change the format php's snmpwalk() returns OIDs ???

Brian
  • 4,958
  • 8
  • 40
  • 56
  • Please clarify your goal. Is it really important that they give identical output, or are you looking for something more specific (for instance, do you want to have the OIDs translated into names, rather than numeric format)? – Jolta Sep 18 '14 at 12:23
  • Also, `snmpwalk` can be configured to give whichever of the two output formats, check the manpage for the `-O` flag. But that might be the opposite of what you want. – Jolta Sep 18 '14 at 12:24
  • Jolta: ok, but php's `snmpwalk()` function has no parameter that specifies in which format to return OIDs. **snmpwalk(host, community, objectid)** – Brian Sep 18 '14 at 15:09
  • The system can have 100s of MIBs, they are not visible to clients. They should be able to remotely see some kind of MIB/OID structure to choose the desired OID. If all OIDs are numeric, they will have no idea about which is whcih – Brian Sep 18 '14 at 15:32

1 Answers1

2

Php has to know about the MIB it is walking, otherwise it can't translate OIDs to variable names. The names and types, etc, are defined in a MIB file.

I don't have access to a php instance to test right now, but according to the documentation this example should work if you have the MIB file:

snmp_read_mib('./FOO-BAR-MIB.txt');
print_r(snmprealwalk('localhost', 'public', 'FOO-BAR-MIB::someTable');

which should ouput something similar to

[FOO-BAR-MIB::someTable.0] => Gauge32: 6

If you don't have the MIB file, you're out of luck. Try getting it from the equipment vendor, or just do a web search for the OID.

Edit: To clarify: There is no way to translate a numeric OID into a variable name without having the MIB file which defines that OID. If you don't have the MIB files on the local machine, you have to find a way to get them there. See also this question.

Community
  • 1
  • 1
Jolta
  • 2,620
  • 1
  • 29
  • 42
  • you can do this for local host, and by knowing MIB's name. But remotely you cannot read the MIB, you have to send snmp walk – Brian Sep 18 '14 at 15:34
  • 1
    this is not what I was looking for, but **+1** for some good hints. I knew about `snmp_read_mib()` my project is to do this remotely. – Brian Sep 18 '14 at 15:58
  • I'm saying that you can't do it remotely. Sorry for that. The network equipment you've querying might have the MIB files locally on them, but they're not obliged to provide the files. Thus why I suggested contacting the vendor, or web searching. There are a few good MIB repositories out there. – Jolta Sep 18 '14 at 16:00