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.
-
#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
-
#initialize(zabbix_user) ⇒ Op
constructor
A new instance of Op.
- #interested_in?(event) ⇒ Boolean
- #interesting_priority ⇒ 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 |
#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
45 46 47 48 49 50 |
# File 'lib/zabbirc/op.rb', line 45 def add_channel channel synchronize do @setting.fetch :primary_channel, channel.name @channels << channel end end |
#event_notified(event) ⇒ Object
72 73 74 75 |
# File 'lib/zabbirc/op.rb', line 72 def event_notified event @notified_events[event.id] = Time.now clear_notified_events end |
#interested_in?(event) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/zabbirc/op.rb', line 65 def interested_in? event return false unless setting.get :notify return false if @notified_events.key? event.id return false if event.value == :ok and not setting.get :notify_recoveries event.priority >= interesting_priority end |
#interesting_priority ⇒ Object
41 42 43 |
# File 'lib/zabbirc/op.rb', line 41 def interesting_priority Priority.new @setting.get(:events_priority) 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
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zabbirc/op.rb', line 52 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 |