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



116
117
118
119
# File 'lib/zabbixapi/classes/graphs.rb', line 116

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.



111
112
113
114
# File 'lib/zabbixapi/classes/graphs.rb', line 111

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
62
63
64
65
66
67
68
69
70
71
# File 'lib/zabbixapi/classes/graphs.rb', line 43

def get_ids_by_host(data)
  ids = []
  graphs = {}

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

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

    if filter.nil?
      ids.push(graphs[name])
    elsif /#{filter}/ =~ name
      ids.push(graphs[name])
    end
  end

  ids
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.



79
80
81
82
83
84
85
86
87
# File 'lib/zabbixapi/classes/graphs.rb', line 79

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.



95
96
97
98
99
100
101
102
103
# File 'lib/zabbixapi/classes/graphs.rb', line 95

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