Class: Net::SnmpPdu

Inherits:
Object
  • Object
show all
Defined in:
lib/net/snmp.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

PduTypes =
[
  :get_request,
  :get_next_request,
  :get_response,
  :set_request,
  :trap,
]
ErrorStatusCodes =

Per RFC1157, pgh 4.1.1

{ # Per RFC1157, pgh 4.1.1
  0 => "noError",
  1 => "tooBig",
  2 => "noSuchName",
  3 => "badValue",
  4 => "readOnly",
  5 => "genErr",
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SnmpPdu

Returns a new instance of SnmpPdu.



95
96
97
98
99
100
101
102
# File 'lib/net/snmp.rb', line 95

def initialize args={}
  @version = args[:version] || 0
  @community = args[:community] || "public"
  @pdu_type = args[:pdu_type] # leave nil unless specified; there's no reasonable default value.
  @error_status = args[:error_status] || 0
  @error_index = args[:error_index] || 0
  @variables = args[:variables] || []
end

Instance Attribute Details

#communityObject

Returns the value of attribute community.



92
93
94
# File 'lib/net/snmp.rb', line 92

def community
  @community
end

#error_indexObject

Returns the value of attribute error_index.



93
94
95
# File 'lib/net/snmp.rb', line 93

def error_index
  @error_index
end

#error_statusObject

Returns the value of attribute error_status.



92
93
94
# File 'lib/net/snmp.rb', line 92

def error_status
  @error_status
end

#pdu_typeObject

Returns the value of attribute pdu_type.



92
93
94
# File 'lib/net/snmp.rb', line 92

def pdu_type
  @pdu_type
end

#request_idObject

Returns the value of attribute request_id.



93
94
95
# File 'lib/net/snmp.rb', line 93

def request_id
  @request_id
end

#variablesObject (readonly)

Returns the value of attribute variables.



92
93
94
# File 'lib/net/snmp.rb', line 92

def variables
  @variables
end

#versionObject

Returns the value of attribute version.



92
93
94
# File 'lib/net/snmp.rb', line 92

def version
  @version
end

Class Method Details

.parse(ber_object) ⇒ Object



85
86
87
88
89
# File 'lib/net/snmp.rb', line 85

def parse ber_object
  n = new
  n.send :parse, ber_object
  n
end

Instance Method Details

#add_variable_binding(name, value = nil) ⇒ Object

– Syntactic sugar



206
207
208
209
# File 'lib/net/snmp.rb', line 206

def add_variable_binding name, value=nil
  @variables ||= []
  @variables << [name, value]
end

#to_ber_stringObject



211
212
213
214
215
216
217
# File 'lib/net/snmp.rb', line 211

def to_ber_string
  [
    version.to_ber,
    community.to_ber,
    pdu_to_ber_string,
  ].to_ber_sequence
end