Method: Zabbix::Monitor#get_events

Defined in:
lib/zmonitor.rb

#get_eventsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zmonitor.rb', line 71

def get_events()
  current_time = Time.now.to_i # to be used in getting event durations, but it really depends on the master
  triggers = unacked_triggers = @api.trigger.get_active(@min_severity, @hide_maintenance, @hide_acknowledged_alerts, @priority_list) # Call the API for a list of active triggers
  unacked_triggers = @api.trigger.get_active(@min_severity, @hide_maintenance, 1, @priority_list) if @hide_acknowledged_alerts == 0 # Call it again to get just those that are unacknowledged
  current_events = []
  triggers.each do |t|
    next if t['hosts'][0]['status'] == '1' or t['items'][0]['status'] == '1' # skip disabled items/hosts that the api call returns
    current_events << {
      :id => t['triggerid'].to_i,
      :time => t['lastchange'].to_i,
      :fuzzytime => fuzz(current_time - t['lastchange'].to_i),
      :severity => t['priority'].to_i,
      :hostname => t['host'],
      :description => t['description'].gsub(/ (on(| server) |to |)#{t['host']}/, '')#,
    }
  end
  current_events.each do |e|
    s = unacked_triggers.select{ |t| t['triggerid'] == "#{e[:id]}" }
    e[:acknowledged] = s[0] ? 0 : 1
  end
  # Sort the events decreasing by severity, and then descending by duration (smaller timestamps at top)
  return current_events.sort_by { |t| [ -t[:severity], t[:time] ] }
end