This is a translation of the original English documentation page. Help us make it better.

付録 1. 参考文献の解説

表記法

Data types

Zabbix APIは以下のデータ型を入力としてサポートしています:

説明
boolean A boolean value, accepts either true or false.
flag The value is considered to be true if it is passed and not equal to null and false otherwise.
integer A whole number.
float A floating point number.
string A text string.
text A longer text string.
timestamp A Unix timestamp.
array An ordered sequence of values, that is, a plain array.
object An associative array.
query A value which defines, what data should be returned.

Can be defined as an array of property names to return only specific properties, or as one of the predefined values:
extend - returns all object properties;
count - returns the number of retrieved records, supported only by certain subselects.

Zabbix APIは常に文字列または配列としてのみ値を返します。

プロパティラベル

いくつかのオブジェクトのプロパティは、その動作を説明するために短いラベルでマークされています。
以下のラベルが使用されます:

  • readonly - プロパティの値は自動的に設定され、クライアントによって定義または変更されることはありません。
  • constant - プロパティの値は、オブジェクトの作成時に設定することができますが、その後変更することはできません。

Parameter behavior

Some of the operation parameters are marked with short labels to describe their behavior for the operation. The following labels are used:

  • read-only - the value of the parameter is set automatically and cannot be defined or changed by the user, even in some specific conditions (e.g., read-only for inherited objects or discovered objects);
  • write-only - the value of the parameter can be set, but cannot be accessed after;
  • supported - the value of the parameter is not required to be set, but is allowed to be set in some specific conditions (e.g., supported if status of Proxy object is set to "passive proxy");
  • required - the value of the parameter is required to be set.

Parameters that are not marked with labels are optional.

予約ID値 "0"

予約ID値 "0 "は、要素のフィルタリングや参照されているオブジェクトの削除に使用することができます。
例えば、ホストから参照されている proxy を削除するには、proxy_hostid を0に設定し("proxy_hostid": "0")、
サーバオプションの proxyids で監視するホストをフィルターするには、proxyids を0に設定する必要があります("proxyids": "0")

"get" メソッドの共通パラメータ

以下のパラメータは、すべての get メソッドでサポートされています:

パラメータ Type 説明
countOutput boolean Return the number of records in the result instead of the actual data.
editable boolean If set to true return only objects that the user has write permissions to.

Default: false.
excludeSearch boolean Return results that do not match the criteria given in the search parameter.
filter object Return only those results that exactly match the given filter.

Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against.

Doesn't work for text fields.
limit integer Limit the number of records returned.
output query Object properties to be returned.

Default: extend.
preservekeys boolean Use IDs as keys in the resulting array.
search object Return results that match the given wildcard search (case-insensitive).

Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE "%…%" search.

Works only for string and text fields.
searchByAny boolean If set to true return results that match any of the criteria given in the filter or search parameter instead of all of them.

Default: false.
searchWildcardsEnabled boolean If set to true enables the use of "*" as a wildcard character in the search parameter.

Default: false.
sortfield string/array Sort the result by the given properties. Refer to a specific API get method description for a list of properties that can be used for sorting. Macros are not expanded before sorting.

If no value is specified, data will be returned unsorted.
sortorder string/array Order of sorting. If an array is passed, each value will be matched to the corresponding property given in the sortfield parameter.

Possible values are:
ASC - (default) ascending;
DESC - descending.
startSearch boolean The search parameter will compare the beginning of fields, that is, perform a LIKE "…%" search instead.

Ignored if searchWildcardsEnabled is set to true.

ユーザー権限チェック

ユーザは、名前が "MySQL" または "Linux" で始まるホストへの書き込み権限を持っていますか?

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "host.get",
           "params": {
               "countOutput": true,
               "search": {
                   "host": ["MySQL", "Linux"]
               },
               "editable": true,
               "startSearch": true,
               "searchByAny": true
           },
           "auth": "766b71ee543230a1182ca5c44d353e36",
           "id": 1
       }

レスポンス:

{
           "jsonrpc": "2.0",
           "result": "0",
           "id": 1
       }

結果が "0" の場合は、読み取り/書き込み権限を持つホストが存在しないことを意味します。

ミスマッチカウント

名前に "ubuntu "という部分文字列が含まれていないホストの数を数える

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "host.get",
           "params": {
               "countOutput": true,
               "search": {
                   "host": "ubuntu"
               },
               "excludeSearch": true
           },
           "auth": "766b71ee543230a1182ca5c44d353e36",
           "id": 1
       }

レスポンス:

{
           "jsonrpc": "2.0",
           "result": "44",
           "id": 1
       }

ワイルドカードを用いたホストの検索

ホスト名に "server"という単語が含まれ、かつインタフェースポートが "10050 "または "10071 "であるホストを検索する。
その結果をホスト名の降順でソートし、5つのホストに限定する。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "host.get",
           "params": {
               "output": ["hostid", "host"],
               "selectInterfaces": ["port"],
               "filter": {
                   "port": ["10050", "10071"]
               },
               "search": {
                   "host": "*server*"
               },
               "searchWildcardsEnabled": true,
               "searchByAny": true,
               "sortfield": "host",
               "sortorder": "DESC",
               "limit": 5
           },
           "auth": "766b71ee543230a1182ca5c44d353e36",
           "id": 1
       }

レスポンス:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "hostid": "50003",
                   "host": "WebServer-Tomcat02",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },
               {
                   "hostid": "50005",
                   "host": "WebServer-Tomcat01",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },
               {
                   "hostid": "50004",
                   "host": "WebServer-Nginx",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },
               {
                   "hostid": "99032",
                   "host": "MySQL server 01",
                   "interfaces": [
                       {
                           "port": "10050"
                       }
                   ]
               },
               {
                   "hostid": "99061",
                   "host": "Linux server 01",
                   "interfaces": [
                       {
                           "port": "10050"
                       }
                   ]
               }
           ],
           "id": 1
       }

"preservekeys" を使ったワイルドカードによるホスト検索

前のリクエストにパラメータ "preservekeys" を追加すると、結果はオブジェクトのidをキーとする連想配列として返されます。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "host.get",
           "params": {
               "output": ["hostid", "host"],
               "selectInterfaces": ["port"],
               "filter": {
                   "port": ["10050", "10071"]
               },
               "search": {
                   "host": "*server*"
               },
               "searchWildcardsEnabled": true,
               "searchByAny": true,
               "sortfield": "host",
               "sortorder": "DESC",
               "limit": 5,
               "preservekeys": true
           },
           "auth": "766b71ee543230a1182ca5c44d353e36",
           "id": 1
       }

レスポンス:

{
           "jsonrpc": "2.0",
           "result": {
               "50003": {
                   "hostid": "50003",
                   "host": "WebServer-Tomcat02",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },
               "50005": {
                   "hostid": "50005",
                   "host": "WebServer-Tomcat01",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },        
               "50004": {
                   "hostid": "50004",
                   "host": "WebServer-Nginx",
                   "interfaces": [
                       {
                           "port": "10071"
                       }
                   ]
               },
               "99032": {
                   "hostid": "99032",
                   "host": "MySQL server 01",
                   "interfaces": [
                       {
                           "port": "10050"
                       }
                   ]
               },
               "99061": {
                   "hostid": "99061",
                   "host": "Linux server 01",
                   "interfaces": [
                       {
                           "port": "10050"
                       }
                   ]
               }
           },
           "id": 1
       }