Class: ZabbixApi::Items

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

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #delete, #destroy, #dump_by_id, #get, #get_full_data, #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

#create_or_update(data) ⇒ Integer

Create or update Item object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name and hostid to properly identify Items 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.


78
79
80
81
# File 'lib/zabbixapi/classes/items.rb', line 78

def create_or_update(data)
  itemid = get_id(name: data[:name], hostid: data[:hostid])
  itemid ? update(data.merge(itemid: itemid)) : create(data)
end

#default_optionsHash

The default options used when creating Item objects via Zabbix API

Returns:

  • (Hash)

20
21
22
23
24
25
26
27
28
29
30
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
# File 'lib/zabbixapi/classes/items.rb', line 20

def default_options
  {
    name: nil,
    key_: nil,
    hostid: nil,
    delay: 60,
    history: 3600,
    status: 0,
    type: 7,
    snmp_community: '',
    snmp_oid: '',
    value_type: 3,
    data_type: 0,
    trapper_hosts: 'localhost',
    snmp_port: 161,
    units: '',
    multiplier: 0,
    delta: 0,
    snmpv3_securityname: '',
    snmpv3_securitylevel: 0,
    snmpv3_authpassphrase: '',
    snmpv3_privpassphrase: '',
    formula: 0,
    trends: 86400,
    logtimefmt: '',
    valuemapid: 0,
    delay_flex: '',
    authtype: 0,
    username: '',
    password: '',
    publickey: '',
    privatekey: '',
    params: '',
    ipmi_sensor: ''
  }
end

#get_or_create(data) ⇒ Integer

Get or Create Item object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name and hostid to properly identify Items 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.


63
64
65
66
67
68
69
70
# File 'lib/zabbixapi/classes/items.rb', line 63

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

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

#indentifyString

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

Returns:

  • (String)

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

def indentify
  'name'
end

#method_nameString

The method name used for interacting with Items via Zabbix API

Returns:

  • (String)

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

def method_name
  'item'
end