Class: Zabbirc::Op
- Inherits:
-
Object
- Object
- Zabbirc::Op
- Defined in:
- lib/zabbirc/op.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#irc_user ⇒ Object
readonly
Returns the value of attribute irc_user.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
- #add_channel(channel) ⇒ Object
- #event_notified(event) ⇒ Object
- #host_settings(name, host_groups) ⇒ Object
-
#initialize(zabbix_user) ⇒ Op
constructor
A new instance of Op.
- #interested_in?(event) ⇒ Boolean
- #interesting_priorities(host_groups) ⇒ Object
- #primary_channel ⇒ Object
- #remove_channel(channel) ⇒ Object
- #set_irc_user(irc_user) ⇒ Object
- #synchronize(&block) ⇒ Object
- #unset_irc_user ⇒ Object
Constructor Details
#initialize(zabbix_user) ⇒ Op
Returns a new instance of Op.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/zabbirc/op.rb', line 5 def initialize zabbix_user raise ArgumentError, 'zabbix_user' if zabbix_user.nil? @login= zabbix_user.alias @zabbix_user = zabbix_user @notified_events = {} @channels = Set.new @setting = Setting.new @mutex = Mutex.new end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
4 5 6 |
# File 'lib/zabbirc/op.rb', line 4 def channels @channels end |
#irc_user ⇒ Object (readonly)
Returns the value of attribute irc_user.
4 5 6 |
# File 'lib/zabbirc/op.rb', line 4 def irc_user @irc_user end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
4 5 6 |
# File 'lib/zabbirc/op.rb', line 4 def login @login end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
4 5 6 |
# File 'lib/zabbirc/op.rb', line 4 def nick @nick end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
4 5 6 |
# File 'lib/zabbirc/op.rb', line 4 def setting @setting end |
Instance Method Details
#add_channel(channel) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/zabbirc/op.rb', line 47 def add_channel channel synchronize do @setting.fetch :primary_channel, channel.name @channels << channel end end |
#event_notified(event) ⇒ Object
82 83 84 85 |
# File 'lib/zabbirc/op.rb', line 82 def event_notified event @notified_events[event.id] = Time.now clear_notified_events end |
#host_settings(name, host_groups) ⇒ Object
77 78 79 80 |
# File 'lib/zabbirc/op.rb', line 77 def host_settings name, host_groups settings = host_groups.collect{|hg| setting.get name, host_group_id: hg.id } settings.uniq end |
#interested_in?(event) ⇒ Boolean
67 68 69 70 71 72 73 74 75 |
# File 'lib/zabbirc/op.rb', line 67 def interested_in? event host_groups = event.host_groups return false if host_settings(:notify, host_groups).all?{|x| x == false } return false if @notified_events.key? event.id return false if event.value == :ok and host_settings(:notify_recoveries, host_groups).all?{|x| x == false } interesting_priorities(host_groups).any? do |interesting_priority| event.priority >= interesting_priority end end |
#interesting_priorities(host_groups) ⇒ Object
41 42 43 44 45 |
# File 'lib/zabbirc/op.rb', line 41 def interesting_priorities host_groups host_settings(:events_priority, host_groups).collect do |setting| Priority.new setting end end |
#primary_channel ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zabbirc/op.rb', line 30 def primary_channel synchronize do return nil if @channels.empty? channel = @channels.find{|c| c.name == @setting.get(:primary_channel) } return channel if channel channel = @channels.first @setting.set(:primary_channel, channel.name) channel end end |
#remove_channel(channel) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zabbirc/op.rb', line 54 def remove_channel channel synchronize do @channels.delete channel if channel == @setting.get(:primary_channel) @setting.set :primary_channel, @channels.first.try(:name) end unset_irc_user if @channels.empty? true end end |
#set_irc_user(irc_user) ⇒ Object
20 21 22 23 |
# File 'lib/zabbirc/op.rb', line 20 def set_irc_user irc_user @irc_user = irc_user @nick = irc_user.nick end |
#synchronize(&block) ⇒ Object
16 17 18 |
# File 'lib/zabbirc/op.rb', line 16 def synchronize &block @mutex.synchronize &block end |
#unset_irc_user ⇒ Object
25 26 27 28 |
# File 'lib/zabbirc/op.rb', line 25 def unset_irc_user @irc_user = nil @nick = nil end |