Class: ZabbixApi::Graphs

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbixapi/classes/graphs.rb

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #default_options, #delete, #destroy, #dump_by_id, #get, #get_id, #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 ZabbixApi::Basic

Instance Method Details

#_update(data) ⇒ Object



106
107
108
109
# File 'lib/zabbixapi/classes/graphs.rb', line 106

def _update(data)
  data.delete(:name)
  update(data)
end

#create_or_update(data) ⇒ Integer

Create or update Graph object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name and templateid to properly identify Graphs via Zabbix API

Returns:

  • (Integer)

    Zabbix object id

Raises:

  • (ApiError)

    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.



101
102
103
104
# File 'lib/zabbixapi/classes/graphs.rb', line 101

def create_or_update(data)
  graphid = get_id(name: data[:name], templateid: data[:templateid])
  graphid ? _update(data.merge(graphid: graphid)) : create(data)
end

#get_full_data(data) ⇒ Hash

Get full/extended Graph data from Zabbix API

Parameters:

  • data (Hash)

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

Returns:

  • (Hash)

Raises:

  • (ApiError)

    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.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zabbixapi/classes/graphs.rb', line 23

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

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

#get_ids_by_host(data) ⇒ Array

Get Graph ids for Host from Zabbix API

Parameters:

  • data (Hash)

    Should include host value to query for matching graphs

Returns:

  • (Array)

    Returns array of Graph ids

Raises:

  • (ApiError)

    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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zabbixapi/classes/graphs.rb', line 43

def get_ids_by_host(data)
  result = @client.api_request(
    method: 'graph.get',
    params: {
      filter: {
        host: data[:host]
      },
      output: 'extend'
    }
  )

  result.map do |graph|
    num  = graph['graphid']
    name = graph['name']
    filter = data[:filter]

    num if filter.nil? || /#{filter}/ =~ name
  end.compact
end

#get_items(data) ⇒ Hash

Get Graph Item object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include graphids to properly identify Graph Items via Zabbix API

Returns:

  • (Hash)

Raises:

  • (ApiError)

    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.



69
70
71
72
73
74
75
76
77
# File 'lib/zabbixapi/classes/graphs.rb', line 69

def get_items(data)
  @client.api_request(
    method: 'graphitem.get',
    params: {
      graphids: [data],
      output: 'extend'
    }
  )
end

#get_or_create(data) ⇒ Integer

Get or Create Graph object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name and templateid to properly identify Graphs via Zabbix API

Returns:

  • (Integer)

    Zabbix object id

Raises:

  • (ApiError)

    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.



85
86
87
88
89
90
91
92
93
# File 'lib/zabbixapi/classes/graphs.rb', line 85

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

  unless (id = get_id(name: data[:name], templateid: data[:templateid]))
    id = create(data)
  end

  id
end

#indentifyString

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

Returns:

  • (String)


13
14
15
# File 'lib/zabbixapi/classes/graphs.rb', line 13

def indentify
  'name'
end

#method_nameString

The method name used for interacting with Graphs via Zabbix API

Returns:

  • (String)


6
7
8
# File 'lib/zabbixapi/classes/graphs.rb', line 6

def method_name
  'graph'
end