Class: ZabbixApi::Drules

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbixapi/classes/drules.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 Drule object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name to properly identify Drules 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.


50
51
52
53
# File 'lib/zabbixapi/classes/drules.rb', line 50

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

#default_optionsHash

The default options used when creating Drule objects via Zabbix API

Returns:

  • (Hash)

20
21
22
23
24
25
26
27
# File 'lib/zabbixapi/classes/drules.rb', line 20

def default_options
  {
    name: nil,
    iprange: nil,
    delay: 3600,
    status: 0,
  }
end

#get_or_create(data) ⇒ Integer

Get or Create Drule object using Zabbix API

Parameters:

  • data (Hash)

    Needs to include name to properly identify Drule 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.


35
36
37
38
39
40
41
42
# File 'lib/zabbixapi/classes/drules.rb', line 35

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

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

#indentifyString

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

Returns:

  • (String)

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

def indentify
  'name'
end

#method_nameString

The method name used for interacting with Drules via Zabbix API

Returns:

  • (String)

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

def method_name
  'drule'
end