Sha256: ddebef7b3891a4c8c72456cdb3752aeeae3b006d27aeaa7a8bb13e69392f3221

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 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 indentify
      '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

3 entries across 3 versions & 1 rubygems

Version Path
zabbixapi-4.2.0 lib/zabbixapi/classes/valuemaps.rb
zabbixapi-4.1.2 lib/zabbixapi/classes/valuemaps.rb
zabbixapi-4.1.1 lib/zabbixapi/classes/valuemaps.rb