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_key_ids, #get_key_ids_by_identify, #get_or_create, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #key, #keys, #log, #merge_params, #normalize_array, #normalize_hash, #parse_keys, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#ack_problemArray, NilClass

Note:

自动确认14天前的问题单

Acknowledged problems according to the given parameters.

Returns:

  • (Array, NilClass)

    Array of matching objects

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/zabbix_manager/classes/problems.rb', line 95

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:  "本次告警通过 zabbix_api 关闭"
    }
  )
  result.empty? ? nil : result.map { |i| { eventids: i["eventids"] } }
end

#allHash

Get full/extended Zabbix data for Problem objects from API

Returns:

  • (Hash)

    Array of matching objects

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



86
87
88
# File 'lib/zabbix_manager/classes/problems.rb', line 86

def all
  get_full_data({})
end

#dump_by_id(data) ⇒ Hash

Dump Problem object data by key from Zabbix API

Parameters:

  • data (Hash)

    Should include desired object’s key and value

Returns:

  • (Hash)

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zabbix_manager/classes/problems.rb', line 28

def dump_by_id(data)
  log "[DEBUG] Call #{method_name}.dump_by_id with parameters: #{data.inspect}"

  @client.api_request(
    method: "#{method_name}.get",
    params: {
      filter: {
        identify.to_sym => data[identify.to_sym]
      },
      output: "extend"
    }
  )
end

#get_full_data(data) ⇒ Hash

Get full/extended Problem data from Zabbix API

Parameters:

  • data (Hash)

    Should include object’s id field name (identify) and id value

Returns:

  • (Hash)

Raises:

  • (ZbxError)

    Error returned when there is a problem with the Zabbix API call.

  • (HttpError)

    Error raised when HTTP status from Zabbix Server response is not a 200 OK.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/zabbix_manager/classes/problems.rb', line 48

def get_full_data(data)
  log "[DEBUG] Call #{method_name}.get_full_data with parameters: #{data.inspect}"

  data = symbolize_keys(data)

  @client.api_request(
    method: "#{method_name}.get",
    params: {
      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

#identifyString

The id field name used for identifying specific Problem objects via Zabbix API

Returns:

  • (String)


18
19
20
# File 'lib/zabbix_manager/classes/problems.rb', line 18

def identify
  "name"
end

#method_nameString

The method name used for interacting with Hosts via Zabbix API

Returns:

  • (String)


11
12
13
# File 'lib/zabbix_manager/classes/problems.rb', line 11

def method_name
  "problem"
end