Class: ZabbixManager::Roles
- Defined in:
- lib/zabbix_manager/classes/roles.rb
Instance Method Summary collapse
-
#dump_by_id(data) ⇒ Array<Hash>
按角色 ID 获取角色详情及完整规则。.
-
#get_ids_by_name(data) ⇒ Array<String>
按角色名称查询所有匹配的角色 ID。.
-
#identify ⇒ String
返回用于唯一识别角色的业务字段名。.
-
#key ⇒ String
返回角色对象的主键字段名。.
-
#method_name ⇒ String
返回 Zabbix API 中角色对象的方法名前缀。.
-
#rules(data) ⇒ Integer
更新指定角色的权限规则。.
Methods inherited from Basic
#add, #all, #create, #create_or_update, #create_raw, #default_options, #delete, #delete_raw, #destroy, #get, #get_full_data, #get_id, #get_or_create, #get_raw, #hash_equals?, #identity_filter, #initialize, #keys, #log, #normalize_hash, #parse_keys, #update, #update_raw
Constructor Details
This class inherits a constructor from ZabbixManager::Basic
Instance Method Details
#dump_by_id(data) ⇒ Array<Hash>
按角色 ID 获取角色详情及完整规则。
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/zabbix_manager/classes/roles.rb', line 53 def dump_by_id(data) log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}" @client.api_request( method: "role.get", params: { output: "extend", selectRules: "extend", roleids: data[:id] } ) end |
#get_ids_by_name(data) ⇒ Array<String>
按角色名称查询所有匹配的角色 ID。
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/zabbix_manager/classes/roles.rb', line 72 def get_ids_by_name(data) result = @client.api_request( method: "role.get", params: { filter: { name: data[:name] }, output: "extend" } ) result.filter_map do |rule| rule["roleid"] end end |
#identify ⇒ String
返回用于唯一识别角色的业务字段名。
22 23 24 |
# File 'lib/zabbix_manager/classes/roles.rb', line 22 def identify "name" end |
#key ⇒ String
返回角色对象的主键字段名。
15 16 17 |
# File 'lib/zabbix_manager/classes/roles.rb', line 15 def key "roleid" end |
#method_name ⇒ String
返回 Zabbix API 中角色对象的方法名前缀。
8 9 10 |
# File 'lib/zabbix_manager/classes/roles.rb', line 8 def method_name "role" end |
#rules(data) ⇒ Integer
更新指定角色的权限规则。
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/zabbix_manager/classes/roles.rb', line 32 def rules(data) attributes = data.deep_symbolize_keys raise Invalid, "roleid is required" if attributes[:roleid].blank? raise Invalid, "rules is required" if attributes[:rules].blank? result = @client.api_request( method: "role.update", params: { roleid: attributes[:roleid], rules: attributes[:rules] } ) result.fetch("roleids").first.to_i end |