Class: Opticon::Notifier::SNMPTrap
- Inherits:
-
Object
- Object
- Opticon::Notifier::SNMPTrap
- Defined in:
- lib/opticon/notifier.rb
Overview
Sends failure notifications as SNMP traps.
The notification is sent using the ‘snmptrap` command-line utility, part of the Net-SNMP perl package. You will have to install Net-SNMP prior to using this notifier. On Linux machines this is generally as easy as `apt-get install net-snmp` or `smart install net-snmp`. On Windows machines, you’re on your own.
In the future the net-snmp requirement may be swapped in favor of using the native Ruby SNMP library, but for now you need net-snmp.
Instance Attribute Summary collapse
-
#enterprise_oid ⇒ Object
Returns the value of attribute enterprise_oid.
-
#snmp_community ⇒ Object
Returns the value of attribute snmp_community.
-
#snmp_persistent_dir ⇒ Object
Returns the value of attribute snmp_persistent_dir.
-
#to_host ⇒ Object
Returns the value of attribute to_host.
Instance Method Summary collapse
-
#initialize(to_host, snmp_community, options = {}) ⇒ SNMPTrap
constructor
A new instance of SNMPTrap.
- #notify(failures) ⇒ Object
Constructor Details
#initialize(to_host, snmp_community, options = {}) ⇒ SNMPTrap
Returns a new instance of SNMPTrap.
94 95 96 97 98 99 |
# File 'lib/opticon/notifier.rb', line 94 def initialize(to_host, snmp_community, = {}) @to_host = to_host @snmp_community = snmp_community @enterprise_oid = [:enterprise_oid] || '1.3.6.1.4.1.3.1.1' @snmp_persistent_dir = [:snmp_persistent_dir] || '/tmp' end |
Instance Attribute Details
#enterprise_oid ⇒ Object
Returns the value of attribute enterprise_oid.
91 92 93 |
# File 'lib/opticon/notifier.rb', line 91 def enterprise_oid @enterprise_oid end |
#snmp_community ⇒ Object
Returns the value of attribute snmp_community.
91 92 93 |
# File 'lib/opticon/notifier.rb', line 91 def snmp_community @snmp_community end |
#snmp_persistent_dir ⇒ Object
Returns the value of attribute snmp_persistent_dir.
91 92 93 |
# File 'lib/opticon/notifier.rb', line 91 def snmp_persistent_dir @snmp_persistent_dir end |
#to_host ⇒ Object
Returns the value of attribute to_host.
91 92 93 |
# File 'lib/opticon/notifier.rb', line 91 def to_host @to_host end |
Instance Method Details
#notify(failures) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/opticon/notifier.rb', line 101 def notify(failures) failures = [failures] unless failures.kind_of? Array if ARGV.include?("-v") puts "Sending SNMP trap(s) to #{to_host} regarding #{failures.size} failures:" failures.each{|f| puts " #{f.}"} end failures.each do |f| oid = '1.3.1.2.1.1.0' typ = 's' # TODO: make msg format configurable msg = ("Opticon Test Failure on URL #{f.uri} :: #{f.}").gsub(/"/, '\"') debug = "-d" if ARGV.include?("-v") cmd = %{snmptrap -v 1 #{debug} -c #{snmp_community} #{to_host} #{enterprise_oid} #{ENV['HOSTNAME']} 6 0 '' #{oid} #{typ} "#{msg}"} puts ">> #{cmd}" if ARGV.include?("-v") # Band-aid fix for bug in Net-SNMP. # See http://sourceforge.net/tracker/index.php?func=detail&aid=1588455&group_id=12694&atid=112694 ENV['SNMP_PERSISTENT_DIR'] ||= snmp_persistent_dir `#{cmd}` end end |