Sha256: fad8c9b06b065d31eca8127f776a8db7f34408aea873282614a02d8885583ccc

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

class ZabbixApi
  class ValueMaps < Basic
    # The method name used for interacting with ValueMaps via Zabbix API
    #
    # @return [String]
    def method_name
      'valuemap'
    end

    # The key field name used for ValueMap objects via Zabbix API
    #
    # @return [String]
    def key
      'valuemapid'
    end

    # The id field name used for identifying specific ValueMap objects via Zabbix API
    #
    # @return [String]
    def identify
      'name'
    end

    # Get or Create ValueMap object using Zabbix API
    #
    # @param data [Hash] Needs to include valuemapids [List] to properly identify ValueMaps via Zabbix API
    # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
    # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
    # @return [Integer] Zabbix object id
    def get_or_create(data)
      log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"

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

    # Create or update Item object using Zabbix API
    #
    # @param data [Hash] Needs to include valuemapids to properly identify ValueMaps via Zabbix API
    # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
    # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
    # @return [Integer] Zabbix object id
    def create_or_update(data)
      valuemapid = get_id(name: data[:name])
      valuemapid ? update(data.merge(valuemapids: [:valuemapid])) : create(data)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
zabbixapi_mgx-7.2.0 lib/zabbixapi/classes/valuemaps.rb
zabbixapi_mgx-5.0.0.pre.alpha2 lib/zabbixapi/classes/valuemaps.rb
zabbixapi_mgx-5.0.0.pre.alpha1 lib/zabbixapi/classes/valuemaps.rb
zabbixapi-5.0.0.pre.alpha1 lib/zabbixapi/classes/valuemaps.rb