Class: Net::SNMP::TrapSession
- Defined in:
- lib/net/snmp/trap_session.rb
Instance Attribute Summary
Attributes inherited from Session
#callback, #community, #peername, #port, #requests, #struct, #version
Instance Method Summary collapse
-
#inform(options = {}) ⇒ Object
Send an SNMPv2 inform.
-
#initialize(options = {}) ⇒ TrapSession
constructor
Options.
-
#trap(options = {}) ⇒ Object
Send an SNMPv1 trap.
-
#trap_v2(options = {}) ⇒ Object
Send an SNMPv2 trap.
Methods inherited from Session
#close, #columns, #default_max_repeaters, #errno, #error, #error_message, #get, #get_bulk, #get_next, #method_missing, open, #print_errors, #select, #send_pdu_blocking, #set, #snmp_err, #table, #walk
Methods included from Debug
Constructor Details
#initialize(options = {}) ⇒ TrapSession
Options
-
peername: The address where the trap will be sent
-
port: The port where the trap will be sent (default = 162)
10 11 12 13 14 15 16 17 18 |
# File 'lib/net/snmp/trap_session.rb', line 10 def initialize( = {}) # Unless the port was supplied in the peername... unless [:peername][":"] # ...default to standard trap port [:port] ||= 162 end super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Net::SNMP::Session
Instance Method Details
#inform(options = {}) ⇒ Object
Send an SNMPv2 inform
Options
-
oid: The OID of the inform
-
uptime: Integer indicating the uptime of this agent
-
varbinds: An array of hashes, like those used for PDU#add_varbind
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/net/snmp/trap_session.rb', line 55 def inform( = {}) pdu = build_v2_trap_pdu(Constants::SNMP_MSG_INFORM, ) response = send_pdu(pdu) if response.kind_of?(PDU) response.free # Always free the response PDU :success # If Session#send_pdu didn't raise, we succeeded else # If the result was other than a PDU, that's a problem raise "Unexpected response type for inform: #{response.class}" end end |
#trap(options = {}) ⇒ Object
Send an SNMPv1 trap
Options
-
enterprise: The Oid of the enterprise
-
trap_type: The generic trap type.
-
specific_type: The specific trap type
-
uptime: The uptime for this agent
28 29 30 31 |
# File 'lib/net/snmp/trap_session.rb', line 28 def trap( = {}) pdu = build_v1_trap_pdu() send_pdu(pdu) end |
#trap_v2(options = {}) ⇒ Object
Send an SNMPv2 trap
Options
-
oid: The OID of the inform
-
uptime: Integer indicating the uptime of this agent
TODO: You can only send v1 traps on a v1 session, and same for v2. So, we could always have the client call ‘trap` and just do the right thing based on the session.
43 44 45 46 |
# File 'lib/net/snmp/trap_session.rb', line 43 def trap_v2( = {}) pdu = build_v2_trap_pdu(Constants::SNMP_MSG_TRAP2, ) send_pdu(pdu) end |