Class: ZabbixManager::Problems

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbix_manager/classes/problems.rb

Instance Method Summary collapse

Methods inherited from Basic

#add, #create, #create_or_update, #default_options, #delete, #destroy, #get, #get_id, #get_ids, #get_ids_by_identify, #get_key_ids, #get_key_ids_by_identify, #get_or_create, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_hashes, #normalize_array, #normalize_hash, #parse_keys, #request_raw, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#ack_problemObject

根据给定参数自动确认问题



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zabbix_manager/classes/problems.rb', line 67

def ack_problem
  time_from = 90.days.ago.at_beginning_of_day.to_i
  time_till = 7.days.ago.at_beginning_of_day.to_i
  event_ids = []

  get_full_data(time_from: time_from, time_till: time_till).each do |item|
    event_ids << item["eventid"]
  end
  return if event_ids.empty?

  result = @client.api_request(
    method: "event.acknowledge",
    params: {
      eventids: event_ids,
      action:   2,
      message:  "本次告警符合自动刷新规则,已通过接口处理且刷新时间为:#{Time.now}"
    }
  )
  result.empty? ? nil : result.map { |i| { eventids: i["eventids"] } }
end

#allObject

获取所有问题对象的完整/扩展 Zabbix 数据



62
63
64
# File 'lib/zabbix_manager/classes/problems.rb', line 62

def all
  get_full_data({})
end

#dump_by_id(data) ⇒ Object

通过键值对从 Zabbix API 转储问题对象数据



19
20
21
22
23
24
25
26
27
28
# File 'lib/zabbix_manager/classes/problems.rb', line 19

def dump_by_id(data)
  log "[DEBUG] 调用 #{method_name}.dump_by_id 方法,参数: #{data.inspect}"

  get_raw({
            filter: {
              identify.to_sym => data[identify.to_sym]
            },
            output: "extend"
          })
end

#get_full_data(data) ⇒ Object

从 Zabbix API 获取完整/扩展的问题数据



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zabbix_manager/classes/problems.rb', line 31

def get_full_data(data)
  log "[DEBUG] 调用 #{method_name}.get_full_data 方法,参数: #{data.inspect}"

  data = symbolize_keys(data)

  get_raw({
            filter:                {
              identify.to_sym => data[identify.to_sym]
            },
            eventids:              data[:eventids] || nil,
            groupids:              data[:groupids] || nil,
            hostids:               data[:hostids] || nil,
            objectids:             data[:objectids] || nil,
            applicationids:        data[:applicationids] || nil,
            tags:                  data[:tags] || nil,
            time_from:             data[:time_from] || nil,
            time_till:             data[:time_till] || nil,
            eventid_from:          data[:eventid_from] || nil,
            eventid_till:          data[:eventid_till] || nil,
            recent:                data[:recent] || false,
            sortfield:             data[:sortfield] || ["eventid"],
            sortorder:             data[:sortorder] || "DESC",
            countOutput:           data[:countOutput] || nil,
            output:                "extend",
            selectAcknowledges:    "extend",
            selectTags:            "extend",
            selectSuppressionData: "extend"
          })
end

#identifyObject

识别特定问题对象的 id 字段名称



14
15
16
# File 'lib/zabbix_manager/classes/problems.rb', line 14

def identify
  "name"
end

#method_nameObject

与 Zabbix API 交互的问题方法名称



9
10
11
# File 'lib/zabbix_manager/classes/problems.rb', line 9

def method_name
  "problem"
end