-
Notifications
You must be signed in to change notification settings - Fork 3
Utilities: mib2rb
jbreeden edited this page Nov 8, 2014
·
1 revision
mib2rb uses ERB files to convert MIB definitions into arbitrarily formatted output. This allows the user to create ERB templates to output HTML tables, text reports, Ruby programs, or any other artifact based on the contents of the MIB.
In addition, mib2rb has a default template built-in that displays the requested MIB sub-tree in a human readable format, making it similar to snmptranslate
[/c/projects/net-snmp2/bin] $ ./mib2rb system
SNMPv2-MIB::system
- oid: 1.3.6.1.2.1.1
- type: 0
- file: c:/usr/share/snmp/mibs/SNMPv2-MIB.txt
- descr: ""
- enums: NONE
- parent: mib-2(1.3.6.1.2.1)
- peers: transmission(10), inetAddressMIB(76), snmp(11), ianaifType(30), interfaces(2), ifMIB(31), icmp(5), ip(4), ipMIB(48), tcp(6), tcpMIB(49), udp(7), udpMIB(50), host(25), egp(8), at(3), notificationLogMIB(92), dismanEventMIB(88)
- next:
- next_peer: 1.3.6.1.2.1.30
- children: sysORTable(9), sysORLastChange(8), sysServices(7), sysLocation(6), sysName(5), sysContact(4), sysUpTime(3), sysObjectID(2), sysDescr(1)
SNMPv2-MIB::sysORTable
- oid: 1.3.6.1.2.1.1.9
- type: 0
- file: c:/usr/share/snmp/mibs/SNMPv2-MIB.txt
- descr: "The (conceptual) table listing the capabilities of
the local SNMP application acting as a command
responder with respect to various MIB modules.
SNMP entities having dynamically-configurable support
of MIB modules will have a dynamically-varying number
of conceptual rows."
- enums: NONE
- parent: system(1.3.6.1.2.1.1)
- peers: sysORLastChange(8), sysServices(7), sysLocation(6), sysName(5), sysContact(4), sysUpTime(3), sysObjectID(2), sysDescr(1)
- next: 1.3.6.1.6.3.1.1.5.5
- next_peer: 1.3.6.1.2.1.1.8
- children: sysOREntry(1)
SNMPv2-MIB::sysOREntry
- oid: 1.3.6.1.2.1.1.9.1
- type: 0
- file: c:/usr/share/snmp/mibs/SNMPv2-MIB.txt
- descr: "An entry (conceptual row) in the sysORTable."
- enums: NONE
- parent: sysORTable(1.3.6.1.2.1.1.9)
- peers:
- next: 1.3.6.1.6.3.1.2.2.12
- next_peer:
- children: sysORUpTime(4), sysORDescr(3), sysORID(2), sysORIndex(1)
...(truncated)...
[/c/projects/net-snmp2/bin] $ ./mib2rb --help
Usage: mib2rb [OPTION]... ROOT_NODE [ERB_FILE]
Description
Prints a mib subtree according to the ERB_FILE.
Within the ERB file, the `root` variable contains the
Net::SNMP::Node object corresponding to ROOT_NODE, and
`nodes` is a collection of the root & all descendants.
Options
-h, Prints this usage information.
Aliases: --help
-l LEVEL Set the log level.
Logs are piped to STDERR, so you can redirect
STDOUT to a file without worrying about logs
getting into the output.
Values: debug, info, warn, error, fatal, none
Default: none
Aliases: --log-level
-f FORMAT Select the output format.
If this option is supplied with an ERB file,
the option is ignored and the file is used instead.
Values: [d]efault, [j]son
Default: default
Aliases: --format
Arguments
ROOT_NODE [Required] The root node of the mib tree to translate.
May be specified as numeric oid or mib name.
ERB_FILE [Optional] The template file to use for output.
Default: Builtin template specifying human readable output.
(See below)
Default ERB_FILE Template
-------------------------
<% nodes.each do |node| -%>
<%= node.module.nil? ? "" : "#{node.module.name}::" %><%= node.label %>
- oid: <%= node.oid %>
- type: <%= node.type %>
- file: <%= node.module.file unless node.module.nil? %>
- descr: <%= "\"#{node.description}\"" %>
- enums: <%=
if !(node.enums.count == 0)
node.enums.map { |e| "#{e[:label]}(#{e[:value]})" }.join(", ")
else
"NONE"
end
%>
- parent: <%= "#{node.parent.label}(#{node.parent.oid})" unless node.parent.nil? %>
- peers: <%= node.peers.map { |n| "#{n.label}(#{n.subid})"}.join(", ") %>
- next: <%= node.next.oid unless node.next.nil? %>
- next_peer: <%= node.next_peer.oid unless node.next_peer.nil? %>
- children: <%=
if node.children.count > 0
node.children.map { |n| "#{n.label}(#{n.subid})"}.join(", ")
else
"NONE"
end
%>
<% end -%>