Class: ZabbixApi::Screens

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

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #create_or_update, #default_options, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_or_create, #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

#delete(data) ⇒ Integer

Delete Screen object using Zabbix API

Parameters:

  • data (String, Array)

    Should include id's of the screens to delete

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.


42
43
44
45
# File 'lib/zabbixapi/classes/screens.rb', line 42

def delete(data)
  result = @client.api_request(method: 'screen.delete', params: [data])
  result.empty? ? nil : result['screenids'][0].to_i
end

#get_or_create_for_host(data) ⇒ Integer

Get or Create Screen object for Host using Zabbix API

Parameters:

  • data (Hash)

    Needs to include screen_name and graphids to properly identify Screens 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.


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
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/zabbixapi/classes/screens.rb', line 53

def get_or_create_for_host(data)
  screen_name = data[:screen_name]
  graphids = data[:graphids]
  screenitems = []
  hsize = data[:hsize] || 3
  valign = data[:valign] || 2
  halign = data[:halign] || 2
  rowspan = data[:rowspan] || 1
  colspan = data[:colspan] || 1
  height = data[:height] || 320 # default 320
  width = data[:width] || 200 # default 200
  vsize = data[:vsize] || [1, (graphids.size / hsize).to_i].max
  screenid = get_id(name: screen_name)

  unless screenid
    # Create screen
    graphids.each_with_index do |graphid, index|
      screenitems << {
        resourcetype: 0,
        resourceid: graphid,
        x: (index % hsize).to_i,
        y: (index % graphids.size / hsize).to_i,
        valign: valign,
        halign: halign,
        rowspan: rowspan,
        colspan: colspan,
        height: height,
        width: width
      }
    end

    screenid = create(
      name: screen_name,
      hsize: hsize,
      vsize: vsize,
      screenitems: screenitems
    )
  end
  screenid
end

#indentifyString

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

Returns:

  • (String)

32
33
34
# File 'lib/zabbixapi/classes/screens.rb', line 32

def indentify
  'name'
end

#method_nameString

The method name used for interacting with Screens via Zabbix API

Returns:

  • (String)

25
26
27
# File 'lib/zabbixapi/classes/screens.rb', line 25

def method_name
  'screen'
end