这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

Sidebar

Zabbix Summit 2022
Register for Zabbix Summit 2022

查询用户

描述

integer/array user.get(object parameters)

此方法用于根据给定的参数查询用户.

此方法仅适用于Super admin 类型的用户. 可在用户角色配置中撤销对此方法的使用. 参阅角色获取详情.

参数

(object) 定义需要输出的参数.

此方法支持如下参数.

参数 类型 描述
mediaids string/array 仅返回使用了给定媒介的用户.
mediatypeids string/array 仅返回使用了给定媒介类型的用户.
userids string/array 仅返回给定用户ID内的用户.
usrgrpids string/array 仅返回属于给定用户组的用户.
getAccess flag 添加关于用户权限附加信息.

为每个用户添加以下属性:
gui_access - (integer) 用户的前端认证方法. 参考 gui_access 的属性关于 用户组对象 可接受的值列表.
debug_mode - (integer) 表明是否为用户启用了调试功能. 可用值: 0 - 禁用调试模式, 1 - 启用调试模式.
users_status - (integer) 表明用户是否禁用. 可用值: 0 - 启用用户, 1 - 禁用用户.
selectMedias query 媒介 属性中返回用户使用的媒介.
selectMediatypes query 媒介类型 属性中返回用户使用的媒介类型.
selectUsrgrps query 用户组 属性中返回用户所归属的组.
selectRole query 角色 属性中返回用户的角色.
sortfield string/array 根据给定的属性对结果进行排序.

可用值: useridusername.
countOutput boolean 这些参数对于所有的 get 方法是常见的,在 参考说明中有详细描述.
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回:

  • 一个对象数组;
  • 检索对象的计数, 如果, 如果 countOutput 参数被使用.

示例

多用户查询

查询所有已配置的用户.

请求:

{
           "jsonrpc": "2.0",
           "method": "user.get",
           "params": {
               "output": "extend"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

返回:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "userid": "1",
                   "username": "Admin",
                   "name": "Zabbix",
                   "surname": "Administrator",
                   "url": "",
                   "autologin": "1",
                   "autologout": "0",
                   "lang": "en_GB",
                   "refresh": "0s",
                   "theme": "default",
                   "attempt_failed": "0",
                   "attempt_ip": "",
                   "attempt_clock": "0",
                   "rows_per_page": "50",
                   "timezone": "default",
                   "roleid": "3"
               },
               {
                   "userid": "2",
                   "username": "guest",
                   "name": "",
                   "surname": "",
                   "url": "",
                   "autologin": "0",
                   "autologout": "15m",
                   "lang": "default",
                   "refresh": "30s",
                   "theme": "default",
                   "attempt_failed": "0",
                   "attempt_ip": "",
                   "attempt_clock": "0",
                   "rows_per_page": "50",
                   "timezone": "default",
                   "roleid": "4"
               },
               {
                   "userid": "3",
                   "username": "user",
                   "name": "Zabbix",
                   "surname": "User",
                   "url": "",
                   "autologin": "0",
                   "autologout": "0",
                   "lang": "ru_RU",
                   "refresh": "15s",
                   "theme": "dark-theme",
                   "attempt_failed": "0",
                   "attempt_ip": "",
                   "attempt_clock": "0",
                   "rows_per_page": "100",
                   "timezone": "default",
                   "roleid": "1"
               }
           ],
           "id": 1
       }

查询用户数据

查询用户ID是 “12” 的用户数据.

请求:

{
           "jsonrpc": "2.0",
           "method": "user.get",
           "params": {
               "output": ["userid", "username"],
               "selectRole": "extend",
               "userids": "12"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

返回:

{
         "jsonrpc": "2.0",
         "result": [
             {
                 "userid": "12",
                 "username": "John",
                 "role": {
                     "roleid": "5",
                     "name": "Operator",
                     "type": "1",
                     "readonly": "0"
                 }
             }
         ],
         "id": 1
       }

参考

来源
CUser::get() in ui/include/classes/api/services/CUser.php.