Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#result_to_h #2

Merged
merged 6 commits into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SNMP4JR.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.description = %q{High Performance SNMP Library for JRuby which wraps SNMP4J}
s.email = %q{mark.cotner@gmail.com}
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "TODO.rdoc", "lib/SNMP4J.jar", "lib/SNMP4JR.rb", "lib/log4j-1.2.9.jar"]
s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/snmpmulti_async.rb", "examples/snmptarget_get_bulk.rb", "examples/snmptarget_set.rb", "examples/snmptarget_v1get.rb", "examples/snmptarget_v1walk.rb", "examples/snmptarget_walk.rb", "examples/synchronous_get.rb", "init.rb", "lib/SNMP4J.jar", "lib/SNMP4JR.rb", "lib/log4j-1.2.9.jar", "Manifest", "SNMP4JR.gemspec"]
s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/snmpmulti_async.rb", "examples/snmptarget_get_bulk.rb", "examples/snmptarget_set.rb", "examples/snmptarget_v1get.rb", "examples/snmptarget_v1walk.rb", "examples/snmptarget_walk.rb", "examples/synchronous_get.rb", "init.rb", "lib/SNMP4J.jar", "lib/SNMP4JR.rb", "lib/log4j-1.2.9.jar", "SNMP4JR.gemspec"]
s.homepage = %q{http://github.com/awksedgreep/SNMP4JR}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "SNMP4JR", "--main", "README.rdoc"]
s.require_paths = ["lib"]
Expand Down
23 changes: 20 additions & 3 deletions lib/SNMP4JR.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def get(oid = nil)
event = @snmp.send(pdu, snmp_target)
if event.response.nil?
@result = []
@snmp.close
return nil
else
@result = event.response.variable_bindings
Expand All @@ -169,6 +170,7 @@ def get_bulk(oid_list = nil)
event = @snmp.send(pdu, snmp_target)
if event.response.nil?
@result = []
@snmp.close
return nil
else
@result = event.response.variable_bindings
Expand All @@ -187,6 +189,7 @@ def set(oid = '1.3.6.1.2.1.1.4.0', variable = SNMP4JR::SMI::OctetString.new('mar
event = @snmp.set(set_pdu, snmp_target)
if event.response.nil?
@result = []
@snmp.close
return nil
end
return event.response.variable_bindings.get 0
Expand All @@ -201,8 +204,6 @@ def walk(oid = nil)
@request_type = SNMP4JR::Constants::GETNEXT
when (SNMP4JR::MP::Version2c or SNMP4JR::MP::Version3)
@request_type = SNMP4JR::Constants::GETBULK
@max_repetitions = 40
@non_repeaters = 0
end
# tick a pdu for async to return when complete
@pdus_sent += 1
Expand Down Expand Up @@ -309,6 +310,22 @@ def poll_complete?(blocking = true)
end
end

def result_to_h
output = Hash.new
@result.each do |res|
output[res.oid] = res.to_value_string if res.class == Java::OrgSnmp4jSmi::VariableBinding
if res.class == Array
res.each do |hash_event|
hash_event.response.variable_bindings.each do |vb|
output[vb.oid] = vb.to_value_string
end
end
end
end
output
end


def result_to_s
output = ''
@result.each do |res|
Expand Down Expand Up @@ -382,4 +399,4 @@ def poll
snmp.send(target.pdu, target.snmp_target, target, self)
end
end
end
end