Class: ZabbixManager::Usergroups

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

Instance Method Summary collapse

Methods inherited from Basic

#add, #all, #create, #create_or_update, #default_options, #delete, #destroy, #dump_by_id, #get, #get_full_data, #get_id, #get_ids, #get_ids_by_identify, #get_key_ids, #get_key_ids_by_identify, #get_or_create, #get_or_create_keys, #get_raw, #hash_equals?, #initialize, #keys, #log, #merge_hashes, #normalize_array, #normalize_hash, #parse_keys, #request_raw, #symbolize_keys, #update

Constructor Details

This class inherits a constructor from ZabbixManager::Basic

Instance Method Details

#add_user(data) ⇒ Object

使用 Zabbix API 将用户添加到用户组



34
35
36
# File 'lib/zabbix_manager/classes/usergroups.rb', line 34

def add_user(data)
  update_users(data)
end

#identifyObject

用于通过 Zabbix API 识别特定 Usergroup 对象的 id 字段名称



16
17
18
# File 'lib/zabbix_manager/classes/usergroups.rb', line 16

def identify
  "name"
end

#keyObject

用于 Usergroup 对象通过 Zabbix API 的键字段名称



11
12
13
# File 'lib/zabbix_manager/classes/usergroups.rb', line 11

def key
  "usrgrpid"
end

#method_nameObject

用于通过 Zabbix API 与 Usergroups 交互的方法名称



6
7
8
# File 'lib/zabbix_manager/classes/usergroups.rb', line 6

def method_name
  "usergroup"
end

#permissions(data) ⇒ Object

使用 Zabbix API 设置用户组的权限



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zabbix_manager/classes/usergroups.rb', line 21

def permissions(data)
  permission = data[:permission] || 2
  result = @client.api_request(
    method: "usergroup.update",
    params: {
      usrgrpid: data[:usrgrpid],
      rights: data[:hostgroupids].map { |t| { permission: permission, id: t } }
    }
  )
  result ? result["usrgrpids"][0].to_i : nil
end

#update_users(data) ⇒ Object

使用 Zabbix API 更新用户组中的用户



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

def update_users(data)
  user_groups = data[:usrgrpids].map do |t|
    {
      usrgrpid: t,
      userids: data[:userids]
    }
  end
  result = @client.api_request(
    method: "usergroup.update",
    params: user_groups
  )
  result ? result["usrgrpids"][0].to_i : nil
end