snmp 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +193 -0
- data/Rakefile +52 -0
- data/data/ruby/snmp/mibs/ACCOUNTING-CONTROL-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/ADSL-LINE-EXT-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/ADSL-LINE-MIB.yaml +238 -0
- data/data/ruby/snmp/mibs/ADSL-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/AGENTX-MIB.yaml +40 -0
- data/data/ruby/snmp/mibs/APM-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/APPC-MIB.yaml +295 -0
- data/data/ruby/snmp/mibs/APPLETALK-MIB.yaml +284 -0
- data/data/ruby/snmp/mibs/APPLICATION-MIB.yaml +161 -0
- data/data/ruby/snmp/mibs/APPN-DLUR-MIB.yaml +41 -0
- data/data/ruby/snmp/mibs/APPN-MIB.yaml +356 -0
- data/data/ruby/snmp/mibs/APPN-TRAP-MIB.yaml +8 -0
- data/data/ruby/snmp/mibs/APS-MIB.yaml +62 -0
- data/data/ruby/snmp/mibs/ATM-ACCOUNTING-INFORMATION-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/ATM-MIB.yaml +112 -0
- data/data/ruby/snmp/mibs/ATM-TC-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/ATM2-MIB.yaml +182 -0
- data/data/ruby/snmp/mibs/BGP4-MIB.yaml +56 -0
- data/data/ruby/snmp/mibs/BLDG-HVAC-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/BRIDGE-MIB.yaml +63 -0
- data/data/ruby/snmp/mibs/CHARACTER-MIB.yaml +48 -0
- data/data/ruby/snmp/mibs/CIRCUIT-IF-MIB.yaml +21 -0
- data/data/ruby/snmp/mibs/CLNS-MIB.yaml +116 -0
- data/data/ruby/snmp/mibs/COFFEE-POT-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/COPS-CLIENT-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/DECNET-PHIV-MIB.yaml +237 -0
- data/data/ruby/snmp/mibs/DIAL-CONTROL-MIB.yaml +84 -0
- data/data/ruby/snmp/mibs/DIFFSERV-CONFIG-MIB.yaml +15 -0
- data/data/ruby/snmp/mibs/DIFFSERV-DSCP-TC.yaml +2 -0
- data/data/ruby/snmp/mibs/DIFFSERV-MIB.yaml +171 -0
- data/data/ruby/snmp/mibs/DIRECTORY-SERVER-MIB.yaml +52 -0
- data/data/ruby/snmp/mibs/DISMAN-EVENT-MIB.yaml +110 -0
- data/data/ruby/snmp/mibs/DISMAN-EXPRESSION-MIB.yaml +55 -0
- data/data/ruby/snmp/mibs/DISMAN-NSLOOKUP-MIB.yaml +23 -0
- data/data/ruby/snmp/mibs/DISMAN-PING-MIB.yaml +57 -0
- data/data/ruby/snmp/mibs/DISMAN-SCHEDULE-MIB.yaml +32 -0
- data/data/ruby/snmp/mibs/DISMAN-SCRIPT-MIB.yaml +80 -0
- data/data/ruby/snmp/mibs/DISMAN-TRACEROUTE-MIB.yaml +72 -0
- data/data/ruby/snmp/mibs/DLSW-MIB.yaml +193 -0
- data/data/ruby/snmp/mibs/DNS-RESOLVER-MIB.yaml +87 -0
- data/data/ruby/snmp/mibs/DNS-SERVER-MIB.yaml +73 -0
- data/data/ruby/snmp/mibs/DOCS-BPI-MIB.yaml +101 -0
- data/data/ruby/snmp/mibs/DOCS-CABLE-DEVICE-MIB.yaml +107 -0
- data/data/ruby/snmp/mibs/DOCS-IF-MIB.yaml +143 -0
- data/data/ruby/snmp/mibs/DOT12-IF-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/DS0-MIB.yaml +18 -0
- data/data/ruby/snmp/mibs/DS0BUNDLE-MIB.yaml +17 -0
- data/data/ruby/snmp/mibs/DS1-MIB.yaml +118 -0
- data/data/ruby/snmp/mibs/DS3-MIB.yaml +106 -0
- data/data/ruby/snmp/mibs/DSA-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/DSMON-MIB.yaml +219 -0
- data/data/ruby/snmp/mibs/EBN-MIB.yaml +47 -0
- data/data/ruby/snmp/mibs/ENTITY-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/ENTITY-SENSOR-MIB.yaml +16 -0
- data/data/ruby/snmp/mibs/ETHER-CHIPSET-MIB.yaml +79 -0
- data/data/ruby/snmp/mibs/ETHER-WIS.yaml +28 -0
- data/data/ruby/snmp/mibs/EtherLike-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/FDDI-SMT73-MIB.yaml +128 -0
- data/data/ruby/snmp/mibs/FIBRE-CHANNEL-FE-MIB.yaml +122 -0
- data/data/ruby/snmp/mibs/FLOW-METER-MIB.yaml +112 -0
- data/data/ruby/snmp/mibs/FR-ATM-PVC-SERVICE-IWF-MIB.yaml +45 -0
- data/data/ruby/snmp/mibs/FR-MFR-MIB.yaml +52 -0
- data/data/ruby/snmp/mibs/FRAME-RELAY-DTE-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/FRNETSERV-MIB.yaml +109 -0
- data/data/ruby/snmp/mibs/FRSLD-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/Finisher-MIB.yaml +53 -0
- data/data/ruby/snmp/mibs/GSMP-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/HC-ALARM-MIB.yaml +32 -0
- data/data/ruby/snmp/mibs/HC-PerfHist-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/HC-RMON-MIB.yaml +193 -0
- data/data/ruby/snmp/mibs/HCNUM-TC.yaml +2 -0
- data/data/ruby/snmp/mibs/HDSL2-SHDSL-LINE-MIB.yaml +115 -0
- data/data/ruby/snmp/mibs/HOST-RESOURCES-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/HOST-RESOURCES-TYPES.yaml +56 -0
- data/data/ruby/snmp/mibs/HPR-IP-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/HPR-MIB.yaml +81 -0
- data/data/ruby/snmp/mibs/IF-INVERTED-STACK-MIB.yaml +9 -0
- data/data/ruby/snmp/mibs/IF-MIB.yaml +73 -0
- data/data/ruby/snmp/mibs/IGMP-STD-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/INET-ADDRESS-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/INTEGRATED-SERVICES-GUARANTEED-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/INTEGRATED-SERVICES-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/INTERFACETOPN-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/IP-FORWARD-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/IP-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/IPATM-IPMC-MIB.yaml +203 -0
- data/data/ruby/snmp/mibs/IPMROUTE-STD-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/IPOA-MIB.yaml +85 -0
- data/data/ruby/snmp/mibs/IPV6-FLOW-LABEL-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/IPV6-ICMP-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/IPV6-MIB.yaml +88 -0
- data/data/ruby/snmp/mibs/IPV6-MLD-MIB.yaml +30 -0
- data/data/ruby/snmp/mibs/IPV6-TCP-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/IPV6-UDP-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/ISDN-MIB.yaml +71 -0
- data/data/ruby/snmp/mibs/Job-Monitoring-MIB.yaml +43 -0
- data/data/ruby/snmp/mibs/L2TP-MIB.yaml +156 -0
- data/data/ruby/snmp/mibs/MALLOC-MIB.yaml +83 -0
- data/data/ruby/snmp/mibs/MAU-MIB.yaml +110 -0
- data/data/ruby/snmp/mibs/MIOX25-MIB.yaml +38 -0
- data/data/ruby/snmp/mibs/MIP-MIB.yaml +180 -0
- data/data/ruby/snmp/mibs/MPLS-FTN-STD-MIB.yaml +44 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-ATM-STD-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-FRAME-RELAY-STD-MIB.yaml +28 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-GENERIC-STD-MIB.yaml +15 -0
- data/data/ruby/snmp/mibs/MPLS-LDP-STD-MIB.yaml +118 -0
- data/data/ruby/snmp/mibs/MPLS-LSR-STD-MIB.yaml +98 -0
- data/data/ruby/snmp/mibs/MPLS-TC-STD-MIB.yaml +3 -0
- data/data/ruby/snmp/mibs/MPLS-TE-STD-MIB.yaml +120 -0
- data/data/ruby/snmp/mibs/MTA-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/Modem-MIB.yaml +106 -0
- data/data/ruby/snmp/mibs/NETWORK-SERVICES-MIB.yaml +33 -0
- data/data/ruby/snmp/mibs/NHRP-MIB.yaml +163 -0
- data/data/ruby/snmp/mibs/NOTIFICATION-LOG-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/OPT-IF-MIB.yaml +431 -0
- data/data/ruby/snmp/mibs/OSPF-MIB.yaml +150 -0
- data/data/ruby/snmp/mibs/OSPF-TRAP-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/P-BRIDGE-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/PARALLEL-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/PIM-MIB.yaml +66 -0
- data/data/ruby/snmp/mibs/PINT-MIB.yaml +51 -0
- data/data/ruby/snmp/mibs/POWER-ETHERNET-MIB.yaml +36 -0
- data/data/ruby/snmp/mibs/PPP-BRIDGE-NCP-MIB.yaml +25 -0
- data/data/ruby/snmp/mibs/PPP-IP-NCP-MIB.yaml +13 -0
- data/data/ruby/snmp/mibs/PPP-LCP-MIB.yaml +47 -0
- data/data/ruby/snmp/mibs/PPP-SEC-MIB.yaml +20 -0
- data/data/ruby/snmp/mibs/PTOPO-MIB.yaml +39 -0
- data/data/ruby/snmp/mibs/PerfHist-TC-MIB.yaml +2 -0
- data/data/ruby/snmp/mibs/Printer-MIB.yaml +209 -0
- data/data/ruby/snmp/mibs/Q-BRIDGE-MIB.yaml +99 -0
- data/data/ruby/snmp/mibs/RADIUS-ACC-CLIENT-MIB.yaml +26 -0
- data/data/ruby/snmp/mibs/RADIUS-ACC-SERVER-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/RADIUS-AUTH-CLIENT-MIB.yaml +28 -0
- data/data/ruby/snmp/mibs/RADIUS-AUTH-SERVER-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/RDBMS-MIB.yaml +82 -0
- data/data/ruby/snmp/mibs/RFC1065-SMI.yaml +9 -0
- data/data/ruby/snmp/mibs/RFC1155-SMI.yaml +9 -0
- data/data/ruby/snmp/mibs/RFC1158-MIB.yaml +202 -0
- data/data/ruby/snmp/mibs/RFC1213-MIB.yaml +202 -0
- data/data/ruby/snmp/mibs/RFC1269-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/RFC1271-MIB.yaml +214 -0
- data/data/ruby/snmp/mibs/RFC1285-MIB.yaml +104 -0
- data/data/ruby/snmp/mibs/RFC1316-MIB.yaml +42 -0
- data/data/ruby/snmp/mibs/RFC1381-MIB.yaml +60 -0
- data/data/ruby/snmp/mibs/RFC1382-MIB.yaml +169 -0
- data/data/ruby/snmp/mibs/RFC1414-MIB.yaml +10 -0
- data/data/ruby/snmp/mibs/RIPv2-MIB.yaml +34 -0
- data/data/ruby/snmp/mibs/RMON-MIB.yaml +219 -0
- data/data/ruby/snmp/mibs/RMON2-MIB.yaml +282 -0
- data/data/ruby/snmp/mibs/ROHC-MIB.yaml +64 -0
- data/data/ruby/snmp/mibs/ROHC-RTP-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/ROHC-UNCOMPRESSED-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/RS-232-MIB.yaml +54 -0
- data/data/ruby/snmp/mibs/RSVP-MIB.yaml +156 -0
- data/data/ruby/snmp/mibs/RTP-MIB.yaml +57 -0
- data/data/ruby/snmp/mibs/SFLOW-MIB.yaml +22 -0
- data/data/ruby/snmp/mibs/SIP-MIB.yaml +70 -0
- data/data/ruby/snmp/mibs/SLAPM-MIB.yaml +144 -0
- data/data/ruby/snmp/mibs/SMON-MIB.yaml +63 -0
- data/data/ruby/snmp/mibs/SNA-NAU-MIB.yaml +137 -0
- data/data/ruby/snmp/mibs/SNA-SDLC-MIB.yaml +147 -0
- data/data/ruby/snmp/mibs/SNMP-COMMUNITY-MIB.yaml +22 -0
- data/data/ruby/snmp/mibs/SNMP-FRAMEWORK-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/SNMP-MPD-MIB.yaml +11 -0
- data/data/ruby/snmp/mibs/SNMP-NOTIFICATION-MIB.yaml +25 -0
- data/data/ruby/snmp/mibs/SNMP-PROXY-MIB.yaml +17 -0
- data/data/ruby/snmp/mibs/SNMP-REPEATER-MIB.yaml +135 -0
- data/data/ruby/snmp/mibs/SNMP-TARGET-MIB.yaml +29 -0
- data/data/ruby/snmp/mibs/SNMP-USER-BASED-SM-MIB.yaml +35 -0
- data/data/ruby/snmp/mibs/SNMP-USM-DH-OBJECTS-MIB.yaml +21 -0
- data/data/ruby/snmp/mibs/SNMP-VIEW-BASED-ACM-MIB.yaml +37 -0
- data/data/ruby/snmp/mibs/SNMPv2-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/SNMPv2-SMI.yaml +17 -0
- data/data/ruby/snmp/mibs/SNMPv2-TM.yaml +9 -0
- data/data/ruby/snmp/mibs/SNMPv2-USEC-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/SONET-MIB.yaml +131 -0
- data/data/ruby/snmp/mibs/SOURCE-ROUTING-MIB.yaml +30 -0
- data/data/ruby/snmp/mibs/SYSAPPL-MIB.yaml +81 -0
- data/data/ruby/snmp/mibs/TCP-MIB.yaml +27 -0
- data/data/ruby/snmp/mibs/TCPIPX-MIB.yaml +24 -0
- data/data/ruby/snmp/mibs/TN3270E-MIB.yaml +105 -0
- data/data/ruby/snmp/mibs/TN3270E-RT-MIB.yaml +43 -0
- data/data/ruby/snmp/mibs/TOKEN-RING-RMON-MIB.yaml +183 -0
- data/data/ruby/snmp/mibs/TOKENRING-MIB.yaml +58 -0
- data/data/ruby/snmp/mibs/TOKENRING-STATION-SR-MIB.yaml +12 -0
- data/data/ruby/snmp/mibs/TRANSPORT-ADDRESS-MIB.yaml +19 -0
- data/data/ruby/snmp/mibs/TUNNEL-MIB.yaml +23 -0
- data/data/ruby/snmp/mibs/UDP-MIB.yaml +14 -0
- data/data/ruby/snmp/mibs/UPS-MIB.yaml +117 -0
- data/data/ruby/snmp/mibs/VDSL-LINE-MIB.yaml +173 -0
- data/data/ruby/snmp/mibs/VRRP-MIB.yaml +50 -0
- data/data/ruby/snmp/mibs/WWW-MIB.yaml +91 -0
- data/examples/dump.rb +15 -0
- data/examples/get.rb +7 -0
- data/examples/iftable.rb +14 -0
- data/examples/log_traps.rb +23 -0
- data/examples/set.rb +8 -0
- data/examples/walk.rb +9 -0
- data/lib/snmp.rb +10 -0
- data/lib/snmp/agent.rb +74 -0
- data/lib/snmp/ber.rb +332 -0
- data/lib/snmp/manager.rb +502 -0
- data/lib/snmp/mib.rb +259 -0
- data/lib/snmp/pdu.rb +363 -0
- data/lib/snmp/varbind.rb +520 -0
- data/setup.rb +1360 -0
- data/test/test_ber.rb +236 -0
- data/test/test_manager.rb +192 -0
- data/test/test_mib.rb +66 -0
- data/test/test_pdu.rb +184 -0
- data/test/test_varbind.rb +270 -0
- metadata +251 -0
data/lib/snmp/varbind.rb
ADDED
@@ -0,0 +1,520 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2004 David R. Halliday
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This SNMP library is free software. Redistribution is permitted under the
|
6
|
+
# same terms and conditions as the standard Ruby distribution. See the
|
7
|
+
# COPYING file in the Ruby distribution for details.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'snmp/ber'
|
11
|
+
|
12
|
+
include SNMP::BER
|
13
|
+
|
14
|
+
module SNMP
|
15
|
+
|
16
|
+
class UnsupportedValueTag < RuntimeError; end
|
17
|
+
class InvalidIpAddress < ArgumentError; end
|
18
|
+
|
19
|
+
class VarBindList < Array
|
20
|
+
def self.decode(data)
|
21
|
+
list = VarBindList.new
|
22
|
+
varbind_data, remainder = decode_sequence(data)
|
23
|
+
while varbind_data != ""
|
24
|
+
varbind, varbind_data = VarBind.decode(varbind_data)
|
25
|
+
list << varbind
|
26
|
+
end
|
27
|
+
return list, remainder
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(varbind_list=[])
|
31
|
+
super()
|
32
|
+
varbind_list.each do |item|
|
33
|
+
if item.respond_to? :to_str
|
34
|
+
self << ObjectId.new(item.to_str).to_varbind
|
35
|
+
else
|
36
|
+
self << item.to_varbind
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def asn1_type
|
42
|
+
"VarBindList"
|
43
|
+
end
|
44
|
+
|
45
|
+
def encode
|
46
|
+
varbind_data = ""
|
47
|
+
self.each do |varbind|
|
48
|
+
varbind_data << varbind.encode
|
49
|
+
end
|
50
|
+
encode_sequence(varbind_data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Integer
|
55
|
+
include Comparable
|
56
|
+
|
57
|
+
def self.decode(value_data)
|
58
|
+
Integer.new(decode_integer_value(value_data))
|
59
|
+
end
|
60
|
+
|
61
|
+
def asn1_type
|
62
|
+
"INTEGER"
|
63
|
+
end
|
64
|
+
|
65
|
+
def initialize(value)
|
66
|
+
@value = value.to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
def <=>(other)
|
70
|
+
@value <=> other.to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
def coerce(other)
|
74
|
+
if other.kind_of? Fixnum
|
75
|
+
return [other, @value]
|
76
|
+
else
|
77
|
+
return [other.to_f, self.to_f]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
@value.to_s
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_i
|
86
|
+
@value
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_f
|
90
|
+
@value.to_f
|
91
|
+
end
|
92
|
+
|
93
|
+
def encode
|
94
|
+
encode_integer(@value)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Integer32 < Integer
|
99
|
+
def initialize(value)
|
100
|
+
super(value)
|
101
|
+
raise ArgumentError, "Out of range: #{value}" if value < -2147483648
|
102
|
+
raise ArgumentError, "Out of range: #{value}" if value > 2147483647
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class OctetString < String
|
107
|
+
def self.decode(value_data)
|
108
|
+
OctetString.new(value_data)
|
109
|
+
end
|
110
|
+
|
111
|
+
def asn1_type
|
112
|
+
"OCTET STRING"
|
113
|
+
end
|
114
|
+
|
115
|
+
def encode
|
116
|
+
encode_octet_string(self)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class ObjectId < Array
|
121
|
+
include Comparable
|
122
|
+
|
123
|
+
def self.decode(value_data)
|
124
|
+
ObjectId.new(decode_object_id_value(value_data))
|
125
|
+
end
|
126
|
+
|
127
|
+
def asn1_type
|
128
|
+
"OBJECT IDENTIFIER"
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Create an object id. The input is expected to be either a string
|
133
|
+
# in the format "n.n.n.n.n.n" or an array of integers.
|
134
|
+
#
|
135
|
+
def initialize(id)
|
136
|
+
if id.respond_to? :to_str
|
137
|
+
super(make_integers(id.to_str.split(".")))
|
138
|
+
else
|
139
|
+
super(make_integers(id.to_ary))
|
140
|
+
end
|
141
|
+
rescue ArgumentError
|
142
|
+
raise ArgumentError, "'#{id}' not a valid object ID"
|
143
|
+
end
|
144
|
+
|
145
|
+
def to_varbind
|
146
|
+
VarBind.new(self, Null)
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_s
|
150
|
+
self.join('.')
|
151
|
+
end
|
152
|
+
|
153
|
+
def inspect
|
154
|
+
"[#{self.to_s}]"
|
155
|
+
end
|
156
|
+
|
157
|
+
def encode
|
158
|
+
encode_object_id(self)
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Returns true if this ObjectId is a subtree of the provided parent tree
|
163
|
+
# ObjectId. For example, "1.3.6.1.5" is a subtree of "1.3.6.1".
|
164
|
+
#
|
165
|
+
def subtree_of?(parent_tree)
|
166
|
+
unless parent_tree.kind_of? ObjectId
|
167
|
+
parent_tree = ObjectId.new(parent_tree)
|
168
|
+
end
|
169
|
+
if parent_tree.length > self.length
|
170
|
+
false
|
171
|
+
else
|
172
|
+
parent_tree.each_index do |i|
|
173
|
+
return false if parent_tree[i] != self[i]
|
174
|
+
end
|
175
|
+
true
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
def make_integers(list)
|
182
|
+
list.collect{|n| Integer(n)}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class IpAddress
|
187
|
+
class << self
|
188
|
+
def decode(value_data)
|
189
|
+
IpAddress.new(value_data)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def asn1_type
|
194
|
+
"IpAddress"
|
195
|
+
end
|
196
|
+
|
197
|
+
##
|
198
|
+
# Create an IpAddress object. The constructor accepts either a raw
|
199
|
+
# four-octet string or a formatted string of integers separated by dots
|
200
|
+
# (i.e. "10.1.2.3").
|
201
|
+
#
|
202
|
+
def initialize(value_data)
|
203
|
+
if value_data.length > 4
|
204
|
+
value_data = parse_string(value_data)
|
205
|
+
elsif value_data.length != 4
|
206
|
+
raise InvalidIpAddress, "Expected 4 octets or formatted string, got #{value_data.inspect}"
|
207
|
+
end
|
208
|
+
@value = value_data
|
209
|
+
end
|
210
|
+
|
211
|
+
##
|
212
|
+
# Returns a raw four-octet string representing this IpAddress.
|
213
|
+
#
|
214
|
+
def to_str
|
215
|
+
@value.dup
|
216
|
+
end
|
217
|
+
|
218
|
+
##
|
219
|
+
# Returns a formatted, dot-separated string representing this IpAddress.
|
220
|
+
#
|
221
|
+
def to_s
|
222
|
+
octets = []
|
223
|
+
@value.each_byte { |b| octets << b.to_s }
|
224
|
+
octets.join('.')
|
225
|
+
end
|
226
|
+
|
227
|
+
def ==(other)
|
228
|
+
if other.respond_to? :to_str
|
229
|
+
return @value.eql?(other.to_str)
|
230
|
+
else
|
231
|
+
return false
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def eql?(other)
|
236
|
+
self == other
|
237
|
+
end
|
238
|
+
|
239
|
+
def hash
|
240
|
+
@value.hash
|
241
|
+
end
|
242
|
+
|
243
|
+
def encode
|
244
|
+
encode_tlv(IpAddress_TAG, @value)
|
245
|
+
end
|
246
|
+
|
247
|
+
private
|
248
|
+
def parse_string(ip_string)
|
249
|
+
parts = ip_string.split(".")
|
250
|
+
raise InvalidIpAddress, ip_string.inspect if parts.length != 4
|
251
|
+
value_data = ""
|
252
|
+
parts.each do |s|
|
253
|
+
octet = s.to_i
|
254
|
+
raise InvalidIpAddress, ip_string.inspect if octet > 255
|
255
|
+
raise InvalidIpAddress, ip_string.inspect if octet < 0
|
256
|
+
value_data << octet.chr
|
257
|
+
end
|
258
|
+
value_data
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
class UnsignedInteger < Integer
|
264
|
+
def initialize(value)
|
265
|
+
super(value)
|
266
|
+
raise ArgumentError, "Negative integer invalid: #{value}" if value < 0
|
267
|
+
raise ArgumentError, "Out of range: #{value}" if value > 4294967295
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
class Counter32 < UnsignedInteger
|
272
|
+
def self.decode(value_data)
|
273
|
+
Counter32.new(decode_integer_value(value_data))
|
274
|
+
end
|
275
|
+
|
276
|
+
def asn1_type
|
277
|
+
"Counter32"
|
278
|
+
end
|
279
|
+
|
280
|
+
def encode
|
281
|
+
encode_tagged_integer(Counter32_TAG, @value)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
class Gauge32 < UnsignedInteger
|
286
|
+
def self.decode(value_data)
|
287
|
+
Gauge32.new(decode_integer_value(value_data))
|
288
|
+
end
|
289
|
+
|
290
|
+
def asn1_type
|
291
|
+
"Gauge32"
|
292
|
+
end
|
293
|
+
|
294
|
+
def encode
|
295
|
+
encode_tagged_integer(Gauge32_TAG, @value)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
class Unsigned32 < UnsignedInteger
|
300
|
+
def self.decode(value_data)
|
301
|
+
Unsigned32.new(decode_integer_value(value_data))
|
302
|
+
end
|
303
|
+
|
304
|
+
def asn1_type
|
305
|
+
"Unsigned32"
|
306
|
+
end
|
307
|
+
|
308
|
+
def encode
|
309
|
+
encode_tagged_integer(Unsigned32_TAG, @value)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
class TimeTicks < UnsignedInteger
|
314
|
+
def self.decode(value_data)
|
315
|
+
TimeTicks.new(decode_integer_value(value_data))
|
316
|
+
end
|
317
|
+
|
318
|
+
def asn1_type
|
319
|
+
"TimeTicks"
|
320
|
+
end
|
321
|
+
|
322
|
+
def encode
|
323
|
+
encode_tagged_integer(TimeTicks_TAG, @value)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class Opaque < OctetString
|
328
|
+
def self.decode(value_data)
|
329
|
+
Opaque.new(value_data)
|
330
|
+
end
|
331
|
+
|
332
|
+
def asn1_type
|
333
|
+
"Opaque"
|
334
|
+
end
|
335
|
+
|
336
|
+
def encode
|
337
|
+
encode_tlv(Opaque_TAG, self)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
class Counter64 < Integer
|
342
|
+
def self.decode(value_data)
|
343
|
+
Counter64.new(decode_integer_value(value_data))
|
344
|
+
end
|
345
|
+
|
346
|
+
def asn1_type
|
347
|
+
"Counter64"
|
348
|
+
end
|
349
|
+
|
350
|
+
def initialize(value)
|
351
|
+
super(value)
|
352
|
+
raise ArgumentError, "Negative integer invalid: #{value}" if value < 0
|
353
|
+
raise ArgumentError, "Out of range: #{value}" if value > 18446744073709551615
|
354
|
+
end
|
355
|
+
|
356
|
+
def encode
|
357
|
+
encode_tagged_integer(Counter64_TAG, @value)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
class Null
|
362
|
+
class << self
|
363
|
+
def decode(value_data)
|
364
|
+
Null
|
365
|
+
end
|
366
|
+
|
367
|
+
def encode
|
368
|
+
encode_null
|
369
|
+
end
|
370
|
+
|
371
|
+
def asn1_type
|
372
|
+
'Null'
|
373
|
+
end
|
374
|
+
|
375
|
+
def to_s
|
376
|
+
asn1_type
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
class NoSuchObject
|
382
|
+
class << self
|
383
|
+
def decode(value_data)
|
384
|
+
NoSuchObject
|
385
|
+
end
|
386
|
+
|
387
|
+
def encode
|
388
|
+
encode_exception(NoSuchObject_TAG)
|
389
|
+
end
|
390
|
+
|
391
|
+
def asn1_type
|
392
|
+
'noSuchObject'
|
393
|
+
end
|
394
|
+
|
395
|
+
def to_s
|
396
|
+
asn1_type
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
class NoSuchInstance
|
402
|
+
class << self
|
403
|
+
def decode(value_data)
|
404
|
+
NoSuchInstance
|
405
|
+
end
|
406
|
+
|
407
|
+
def encode
|
408
|
+
encode_exception(NoSuchInstance_TAG)
|
409
|
+
end
|
410
|
+
|
411
|
+
def asn1_type
|
412
|
+
'noSuchInstance'
|
413
|
+
end
|
414
|
+
|
415
|
+
def to_s
|
416
|
+
asn1_type
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
class EndOfMibView
|
422
|
+
class << self
|
423
|
+
def decode(value_data)
|
424
|
+
EndOfMibView
|
425
|
+
end
|
426
|
+
|
427
|
+
def encode
|
428
|
+
encode_exception(EndOfMibView_TAG)
|
429
|
+
end
|
430
|
+
|
431
|
+
def asn1_type
|
432
|
+
'endOfMibView'
|
433
|
+
end
|
434
|
+
|
435
|
+
def to_s
|
436
|
+
asn1_type
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
class VarBind
|
442
|
+
attr_accessor :name
|
443
|
+
attr_accessor :value
|
444
|
+
|
445
|
+
class << self
|
446
|
+
def decode(data)
|
447
|
+
varbind_data, remaining_varbind_data = decode_sequence(data)
|
448
|
+
name, remainder = decode_object_id(varbind_data)
|
449
|
+
value, remainder = decode_value(remainder)
|
450
|
+
assert_no_remainder(remainder)
|
451
|
+
return VarBind.new(name, value), remaining_varbind_data
|
452
|
+
end
|
453
|
+
|
454
|
+
ValueDecoderMap = {
|
455
|
+
INTEGER_TAG => Integer,
|
456
|
+
OCTET_STRING_TAG => OctetString,
|
457
|
+
NULL_TAG => Null,
|
458
|
+
OBJECT_IDENTIFIER_TAG => ObjectId,
|
459
|
+
IpAddress_TAG => IpAddress,
|
460
|
+
Counter32_TAG => Counter32,
|
461
|
+
Gauge32_TAG => Gauge32,
|
462
|
+
# note Gauge32 tag same as Unsigned32
|
463
|
+
TimeTicks_TAG => TimeTicks,
|
464
|
+
Opaque_TAG => Opaque,
|
465
|
+
Counter64_TAG => Counter64,
|
466
|
+
NoSuchObject_TAG => NoSuchObject,
|
467
|
+
NoSuchInstance_TAG => NoSuchInstance,
|
468
|
+
EndOfMibView_TAG => EndOfMibView
|
469
|
+
}
|
470
|
+
|
471
|
+
def decode_value(data)
|
472
|
+
value_tag, value_data, remainder = decode_tlv(data)
|
473
|
+
decoder_class = ValueDecoderMap[value_tag]
|
474
|
+
if decoder_class
|
475
|
+
value = decoder_class.decode(value_data)
|
476
|
+
else
|
477
|
+
raise UnsupportedValueTag, value_tag.to_s
|
478
|
+
end
|
479
|
+
return value, remainder
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
def initialize(name, value=Null)
|
484
|
+
if name.kind_of? ObjectId
|
485
|
+
@name = name
|
486
|
+
else
|
487
|
+
@name = ObjectName.new(name)
|
488
|
+
end
|
489
|
+
@value = value
|
490
|
+
end
|
491
|
+
|
492
|
+
def asn1_type
|
493
|
+
"VarBind"
|
494
|
+
end
|
495
|
+
|
496
|
+
def to_varbind
|
497
|
+
self
|
498
|
+
end
|
499
|
+
|
500
|
+
def to_s
|
501
|
+
"[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]"
|
502
|
+
end
|
503
|
+
|
504
|
+
def each
|
505
|
+
yield self
|
506
|
+
end
|
507
|
+
|
508
|
+
def encode
|
509
|
+
data = encode_object_id(@name) << value.encode
|
510
|
+
encode_sequence(data)
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
class ObjectName < ObjectId
|
515
|
+
def asn1_type
|
516
|
+
"ObjectName"
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
end
|