Class: ZabbixManager::Users

Inherits:
Basic
  • Object
show all
Defined in:
lib/zabbix_manager/classes/users.rb

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #create_or_update, #create_raw, #default_options, #delete, #delete_raw, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_or_create, #get_raw, #hash_equals?, #identity_filter, #initialize, #log, #normalize_hash, #parse_keys, #update, #update_raw

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#add_medias(data) ⇒ Integer?

为指定用户添加媒介配置,当前通过 user.update 完成。

Parameters:

  • data (Hash)

    包含 userids 和 media

Returns:

  • (Integer, nil)

    首个已更新用户的 ID

Raises:

  • (ApiError)

    Zabbix API 返回业务错误时抛出

  • (TransportError)

    Zabbix 服务返回非成功 HTTP 状态时抛出



57
58
59
# File 'lib/zabbix_manager/classes/users.rb', line 57

def add_medias(data)
  medias_helper(data, "update")
end

#identifyString

返回用于唯一识别用户的业务字段名。

Returns:

  • (String)

    用户对象的业务标识字段名



29
30
31
# File 'lib/zabbix_manager/classes/users.rb', line 29

def identify
  "alias"
end

#keyString

返回用户对象的主键字段名。

Returns:

  • (String)

    用户对象的主键字段名



22
23
24
# File 'lib/zabbix_manager/classes/users.rb', line 22

def key
  "userid"
end

#keysString

返回用户对象批量结果中的 ID 字段名。

Returns:

  • (String)

    用户 ID 复数字段名



15
16
17
# File 'lib/zabbix_manager/classes/users.rb', line 15

def keys
  "userids"
end

#medias_helper(data, action) ⇒ Integer?

按指定动作批量更新用户媒介配置。

Parameters:

  • data (Hash)

    包含 userids 和 media

  • action (String)

    user API 的动作名

Returns:

  • (Integer, nil)

    首个已更新用户的 ID



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zabbix_manager/classes/users.rb', line 38

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

#method_nameString

返回 Zabbix API 中用户对象的方法名前缀。

Returns:

  • (String)

    用户对象的方法名前缀



8
9
10
# File 'lib/zabbix_manager/classes/users.rb', line 8

def method_name
  "user"
end

#update_medias(data) ⇒ Integer?

批量替换指定用户的媒介配置。

Parameters:

  • data (Hash)

    包含 userids 和 media

Returns:

  • (Integer, nil)

    首个已更新用户的 ID

Raises:

  • (ApiError)

    Zabbix API 返回业务错误时抛出

  • (TransportError)

    Zabbix 服务返回非成功 HTTP 状态时抛出



67
68
69
# File 'lib/zabbix_manager/classes/users.rb', line 67

def update_medias(data)
  medias_helper(data, "update")
end