user.get

説明

integer/array user.get(object parameters)

このメソッドは、指定されたパラメーターに基づいてユーザー情報を取得します。

このメソッドは、どのタイプのユーザーでも利用できます。このメソッドを呼び出す権限は、ユーザーロールの設定で無効にできます。詳細はユーザーの役割を参照してください。

パラメータ

(object) 取得したい出力内容を定義するパラメーター

このメソッドは、次のパラメーターを受け付けます。

Zabbix 7.0.9以降、AdminタイプとUserタイプのユーザーがユーザーメディア、権限、またはロール情報をリクエストした場合、自分のユーザー情報のみ取得できます。具体例はRetrieving users as Adminを参照してください。 :::

パラメータ タイプ 説明
mediaids ID/array 指定されたメディアを使用するユーザーのみを返します
mediatypeids ID/array 指定されたメディアタイプを使用するユーザーのみを返します
userids ID/array 指定されたユーザーIDを持つユーザーのみを返します
usrgrpids ID/array 指定されたユーザーグループに属するユーザーのみを返します
getAccess flag ユーザー権限に関する情報を追加で返します。

ユーザーごとに次のプロパティを返します。
gui_access - (integer)フロントエンド認証方法。 利用可能な値はユーザーグループオブジェクトgui_accessプロパティを参照してください。
debug_mode - (integer)デバッグが有効かどうか。 値:0 - 無効,1 - 有効
users_status - (integer)ユーザーが無効かどうか。 値:0 - 有効,1 - 無効
selectMedias query mediasプロパティにて、ユーザーが使用しているメディアを返します
selectMediatypes query mediatypesプロパティにて、ユーザーが使用しているメディアタイプを返します
selectUsrgrps query usrgrpsプロパティにて、ユーザーが属するユーザーグループを返します
selectRole query roleプロパティにて、ユーザーロールを返します
filter object ここで指定したフィルターに完全一致する結果のみを返します。

キーにプロパティ名、値に一致させたい値(単一または配列)を指定したオブジェクトを受け付けます。

text data typeのプロパティには対応していません。

AdminタイプとUserタイプのユーザーが、所属するユーザーグループのユーザーの情報をリクエストする際に使用できるUserオブジェクトのプロパティ(Zabbix 7.0.9以降): userid, name, surname, username.
output query ここで指定したUserオブジェクトプロパティを返します。

Zabbix 7.0.9以降、AdminタイプとUserタイプのユーザーが取得できるプロパティ:
- 自分自身のユーザー情報の場合: userid, attempt_clock, attempt_failed, attempt_ip, autologin, autologout, lang, name, provisioned, refresh, roleid, rows_per_page, surname, theme, timezone, url, username.
- 所属するユーザーグループのユーザーの場合: userid, name, surname, username.

デフォルト値: extend.
search object 指定されたパターンに一致する結果を返します。(大文字・小文字は区別されません)

キーにプロパティ名、値に検索したい文字列を指定したオブジェクトを受け付けます。追加のオプションが指定されていない場合は、LIKE "%…%"による部分一致検索が行われます。

stringおよびtext タイプのみ対応しています。

Zabbix 7.0.9以降、AdminタイプとUserタイプのユーザーが、所属するユーザーグループのユーザーの情報をリクエストする際に取得できるUserオブジェクト のプロパティ: name, surname, username.
sortfield string/array 指定されたプロパティで結果をソートします。

指定可能な値: userid, username.
countOutput boolean これらのパラメータは reference commentaryを参照してください。
editable boolean
excludeSearch boolean
limit integer
preservekeys boolean
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

戻り値

(integer/array) 次のいずれかを返します:

  • オブジェクトの配列
  • countOutputパラメータが使用されている場合、取得されたオブジェクトの数

ユーザーの取得

設定済みの全ユーザーを取得します

Request:

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

Response:

{
    "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
}

管理者 としてユーザーの情報を取得する

管理者 タイプのユーザーとして、自分のユーザーに関する詳細データと、ユーザーグループ内のユーザーの限定データを取得します。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "user.get",
    "params": {
        "output": "extend",
        "getAccess": true,
        "selectMedias": "extend",
        "selectMediatypes": "extend",
        "selectUsrgrps": "extend",
        "selectRole": "extend"
    },
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "userid": "1",
            "username": "Admin",
            "name": "Zabbix",
            "surname": "Administrator",
            "usrgrps": [
                {
                    "usrgrpid": "7",
                    "name": "Zabbix administrators",
                    "gui_access": "0",
                    "users_status": "0",
                    "debug_mode": "0",
                    "mfa_status": "0"
                }
            ]
        },
        {
            "userid": "3",
            "username": "database-admin",
            "name": "John",
            "surname": "Doe",
            "url": "",
            "autologin": "0",
            "autologout": "0",
            "lang": "default",
            "refresh": "30s",
            "theme": "default",
            "attempt_failed": "0",
            "attempt_ip": "",
            "attempt_clock": "0",
            "rows_per_page": "50",
            "timezone": "default",
            "roleid": "2",
            "provisioned": "0",
            "gui_access": "0",
            "debug_mode": "0",
            "users_status": "0",
            "usrgrps": [
                {
                    "usrgrpid": "7",
                    "name": "Zabbix administrators",
                    "gui_access": "0",
                    "users_status": "0",
                    "debug_mode": "0",
                    "mfa_status": "0"
                }
            ],
            "medias": [
                {
                    "mediaid": "2",
                    "mediatypeid": "1",
                    "sendto": [
                        "[email protected]"
                    ],
                    "active": "0",
                    "severity": "63",
                    "period": "1-7,00:00-24:00",
                    "provisioned": 0
                }
            ],
            "mediatypes": [
                {
                    "mediatypeid": "1",
                    "type": "0",
                    "name": "Email",
                    "status": "0",
                    "description": "",
                    "maxattempts": "3"
                }
            ],
            "role": {
                "roleid": "2",
                "name": "Admin role",
                "type": "2",
                "readonly": "0"
            }
        }
    ],
    "id": 1
}

ユーザーデータ取得

ID"12"のユーザーのデータを取得します

Request:

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

Response:

{
  "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.