| 370 | == Using Ruby scripts == |
| 371 | libsnmp reference: http://snmplib.rubyforge.org/doc/index.html |
| 372 | |
| 373 | Ruby has libsnmp-ruby, a library for SNMP, available. SB9 didn't come with it, so it was installed: |
| 374 | {{{ |
| 375 | apt-get install libsnmp-ruby |
| 376 | }}} |
| 377 | A messy irb test of the library: |
| 378 | {{{ |
| 379 | irb(main):002:0> require 'snmp' |
| 380 | irb(main):004:0> agent_hostname = "172.16.100.10" |
| 381 | => "172.16.100.10" |
| 382 | irb(main):005:0> agent_comm = "NET" |
| 383 | => "NET" |
| 384 | irb(main):007:0> s = SNMP::Manager.new(:Host => agent_hostname, :Community =>agent_comm, :Port => 161) |
| 385 | => #<SNMP::Manager:0xb79d5d98 @snmp_version=:SNMPv2c, @port=161, @transport=#<SNMP::UDPTransport:0xb79d5d5c @socket=#<UDPSocket:0xb79d5d34>>, @write_community="NET", @host="172.16.100.10", @retries=5, @community="NET", @mib=#<SNMP ... #this goes on for a while |
| 386 | irb(main):009:0> response = s.get(["1.3.6.1.2.1.1.1.0"]) |
| 387 | => #<SNMP::Response:0xb79c2d10 @error_index=0, @error_status=0, @request_id=856260869, @varbind_list=[#<SNMP::VarBind:0xb79c2900 @value="ALAXALA AX3640S AX-3640-48T2XW-L [AX3640S-48T2XW] Switching software Ver. 10.7 [OS-L3L]", @name=[1.3.6.1.2.1.1.1.0]>]> |
| 388 | irb(main):035:0> rstring = "#{response.varbind_list.to_s}" |
| 389 | => "[name=1.3.6.1.2.1.1.1.0, value=ALAXALA AX3640S AX-3640-48T2XW-L [AX3640S-48T2XW] Switching software Ver. 10.7 [OS-L3L] (OCTET STRING)]" |
| 390 | }}} |