Adding SNMP traps to rubygod?

45 views
Skip to first unread message

rubymono

unread,
Sep 4, 2012, 9:57:21 PM9/4/12
to god...@googlegroups.com
Greetings,

I am interested in having rubygod send SNMP traps on events, has anyone else implemented this or have any suggestions on how best to implement? Thanks for any thoughts

Chris Cosby

unread,
Sep 5, 2012, 9:39:59 PM9/5/12
to god...@googlegroups.com
There are of course several ways to do this. Here are some meanderings.

1) Use God's syslog output and rsyslog's omsnmp module. Done with a little bit of config of rsyslog

2) Write some code
 a) gem install snmp
 c) Create something like this in the config file (note: not tested, just out of my head)
# Define the custom Syslogger event contact handler
require 'snmp'
module God
  module Contacts
    class SNMPTrap < Contact
      class << self
        attr_accessor :level, :message
      end

      def valid?
        valid = true
        valid &= complain("Attribute 'level' must be specified", self) unless arg(:level)
        valid
      end

      attr_accessor :level, :message

      def notify(message, time, priority, category, host)
        SNMPTrapObjectThingy.doSomething(arg(:level), arg(:message) || message)
      rescue Object => e
        applog(nil, :info, "SNMPTrap failed")
        applog(nil, :debug, e.backtrace.join("\n"))
      end
    end
  end
end

God.contact(:SNMPTrap) do |c|
  c.name = 'Log_Flapping'
  c.message = "Thing is restarting too quickly"
  c.level = :warn
end

God.watch do |w|
  w.lifecycle do |on|
    on.condition(:flapping) do |c|
      c.notify = 'Log_Flapping'
    end
  end
end

On Tue, Sep 4, 2012 at 9:57 PM, rubymono <johnc...@gmail.com> wrote:
Greetings,

I am interested in having rubygod send SNMP traps on events, has anyone else implemented this or have any suggestions on how best to implement? Thanks for any thoughts

--
You received this message because you are subscribed to the Google Groups "god.rb" group.
To view this discussion on the web visit https://groups.google.com/d/msg/god-rb/-/ifQOrhgC-ScJ.
To post to this group, send email to god...@googlegroups.com.
To unsubscribe from this group, send email to god-rb+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/god-rb?hl=en.



--
chris -at- microcozm -dot- net
== If you wish to make an apple pie from scratch, you must first invent the universe. - Carl Sagan
=== My crypto keys: http://www.microcozm.net/~ccosby/keys/
Reply all
Reply to author
Forward
0 new messages