Class: Zabbirc::OpList
- Inherits:
-
Object
- Object
- Zabbirc::OpList
- Includes:
- Enumerable
- Defined in:
- lib/zabbirc/op_list.rb
Instance Method Summary collapse
- #add(op) ⇒ Object
- #authenticate(name) ⇒ Object (also: #exists?)
- #dump_settings ⇒ Object
- #each(&block) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(ops = nil) ⇒ OpList
constructor
A new instance of OpList.
- #interested ⇒ Object
- #interested_in(event) ⇒ Object
- #load_settings ⇒ Object
- #notify(object) ⇒ Object
- #remove(op) ⇒ Object
Constructor Details
#initialize(ops = nil) ⇒ OpList
Returns a new instance of OpList.
6 7 8 9 10 11 12 13 |
# File 'lib/zabbirc/op_list.rb', line 6 def initialize ops=nil @ops = {} if ops ops.each do |op| add op end end end |
Instance Method Details
#add(op) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/zabbirc/op_list.rb', line 25 def add op if exists? op.login return get(op.login) end @ops[op.login] = op end |
#authenticate(name) ⇒ Object Also known as: exists?
15 16 17 |
# File 'lib/zabbirc/op_list.rb', line 15 def authenticate name @ops.key? name end |
#dump_settings ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/zabbirc/op_list.rb', line 70 def dump_settings dump = {} each do |op| dump[op.login] = op.setting.to_hash end file = File.open(STORED_SETTINGS_FILE, "w") file.puts dump.to_yaml file.close true end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/zabbirc/op_list.rb', line 43 def each &block @ops.values.each &block end |
#get(name) ⇒ Object
21 22 23 |
# File 'lib/zabbirc/op_list.rb', line 21 def get name @ops[name] end |
#interested ⇒ Object
51 52 53 |
# File 'lib/zabbirc/op_list.rb', line 51 def interested self.class.new(find_all{ |op| op.setting.get :notify }) end |
#interested_in(event) ⇒ Object
47 48 49 |
# File 'lib/zabbirc/op_list.rb', line 47 def interested_in event self.class.new(find_all{ |op| op.interested_in? event }) end |
#load_settings ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/zabbirc/op_list.rb', line 82 def load_settings return unless File.exists?(STORED_SETTINGS_FILE) stored_settings = YAML.load_file(STORED_SETTINGS_FILE) stored_settings.each do |login, setting| op = get(login) next unless op op.setting.restore setting end end |
#notify(object) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zabbirc/op_list.rb', line 55 def notify object = case object when String object when Zabbix::Event object.label end group_by(&:primary_channel).each do |channel, ops| next if channel.nil? op_targets = ops.collect{|op| "#{op.nick}:" }.join(" ") channel.send "#{op_targets} #{message}" ops.each{ |op| op.event_notified object } if object.is_a? Zabbix::Event end end |
#remove(op) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zabbirc/op_list.rb', line 32 def remove op case op when String @ops.delete(op) when Op @ops.delete(op.login) else raise ArgumentError, "Stirng or Op expected" end end |