Sha256: 884caaafdcc85008664da0248dfdc55f40245d60fd3624aa4a4327954b21db61

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

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

    # The keys field name used for User objects via Zabbix API
    #
    # @return [String]
    def keys
      'userids'
    end

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

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

    def medias_helper(data, action)
      result = @client.api_request(
        method: "user.#{action}",
        params: {
          users: data[:userids].map { |t| { userid: t } },
          medias: data[:media]
        }
      )
      result ? result['mediaids'][0].to_i : nil
    end

    # Add media to users using Zabbix API
    #
    # @param data [Hash] Needs to include userids and media to mass add media to users
    # @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 (media)
    def add_medias(data)
      medias_helper(data, 'addMedia')
    end

    # Update media for users using Zabbix API
    #
    # @param data [Hash] Needs to include userids and media to mass update media for users
    # @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 (user)
    def update_medias(data)
      medias_helper(data, 'updateMedia')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zabbixapi-4.1.2 lib/zabbixapi/classes/users.rb
zabbixapi-4.1.1 lib/zabbixapi/classes/users.rb