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

usermacro.get

説明

integer/array usermacro.get(object parameters)

このメソッドを使用すると、指定されたパラメーターに従ってホストマクロとグローバルマクロを取得できます。

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

パラメータ

(object) 目的の出力を定義するパラメーター

このメソッドは、次のパラメーターをサポートしています

パラメータ タイプ 説明
globalmacro flag ホストマクロの代わりにグローバル マクロを返します
globalmacroids string/array 指定された ID を持つグローバルマクロのみを返します
groupids string/array 指定されたホストグループのホストまたはテンプレートに属するホストマクロのみを返します
hostids string/array 指定されたホストまたはテンプレートに属するマクロのみを返します
hostmacroids string/array 指定された ID を持つホストマクロのみを返します
inherited boolean "true"に設定すると、テンプレートから継承されたホストプロトタイプユーザーマクロのみが返されます
selectGroups query groupsプロパティでホストマクロが属するホスト グループを返します。

ホストマクロを取得する場合にのみ使用されます。
selectHosts query hostsマクロがホスト プロパティに属するホストを返します。

ホスト マクロを取得する場合にのみ使用されます。
selectTemplates query templates プロパティでホストマクロが属するテンプレートを返します。

ホストマクロを取得する場合にのみ使用されます。
sortfield string/array 指定されたプロパティで結果を並べ替えます。

使用可能な値: macro
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パラメータが使用されている場合、取得されたオブジェクトの数

ホストのホストマクロの取得

ホスト"10198"に定義されているすべてのホストマクロを取得します。

Request:

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

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "hostmacroid": "9",
                   "hostid": "10198",
                   "macro": "{$INTERFACE}",
                   "value": "eth0",
                   "description": "",
                   "type": "0"
               },
               {
                   "hostmacroid": "11",
                   "hostid": "10198",
                   "macro": "{$SNMP_COMMUNITY}",
                   "value": "public",
                   "description": "",
                   "type": "0"
               }
           ],
           "id": 1
       }

Retrieving host macros for a template

Retrieve host macros defined for template "10265" that contain "STATUS" in the macro name.

Request:

{
           "jsonrpc": "2.0",
           "method": "usermacro.get",
           "params": {
               "output": "extend",
               "hostids": "10265",
               "search": {
                   "macro": "STATUS"
               }
           },
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "hostmacroid": "6709",
                   "hostid": "10265",
                   "macro": "{$APACHE.STATUS.HOST}",
                   "value": "",
                   "description": "The hostname or IP address of the Apache status page host.",
                   "type": "0",
                   "automatic": "0",
                   "config": {
                       "type": "1",
                       "priority": "1",
                       "section_name": "",
                       "label": "Apache status host",
                       "description": "Hostname or IP address of the Apache status page host.",
                       "required": "1",
                       "regex": "",
                       "options": []
                   }
               },
               {
                   "hostmacroid": "814",
                   "hostid": "10265",
                   "macro": "{$APACHE.STATUS.PATH}",
                   "value": "server-status?auto",
                   "description": "The URL path of the Apache status page.",
                   "type": "0",
                   "automatic": "0",
                   "config": {
                       "type": "1",
                       "priority": "3",
                       "section_name": "",
                       "label": "Apache status page path",
                       "description": "URL path of the Apache status page.",
                       "required": "1",
                       "regex": "",
                       "options": []
                   }
               },
               {
                   "hostmacroid": "815",
                   "hostid": "10265",
                   "macro": "{$APACHE.STATUS.PORT}",
                   "value": "80",
                   "description": "The port of the Apache status page.",
                   "type": "0",
                   "automatic": "0",
                   "config": {
                       "type": "1",
                       "priority": "2",
                       "section_name": "",
                       "label": "Apache status page port",
                       "description": "In the range from 1 to 65535 inclusive.",
                       "required": "1",
                       "regex": "^-?([0-9]+|(([0-9]+)\\.([0-9]+)))$",
                       "options": []
                   }
               },
               {
                   "hostmacroid": "816",
                   "hostid": "10265",
                   "macro": "{$APACHE.STATUS.SCHEME}",
                   "value": "http",
                   "description": "The request scheme, which may be either HTTP or HTTPS.",
                   "type": "0",
                   "automatic": "0",
                   "config": {
                       "type": "2",
                       "priority": "4",
                       "section_name": "",
                       "label": "Request scheme",
                       "description": "Request scheme, which may be either HTTP or HTTPS.",
                       "required": "0",
                       "regex": "",
                       "options": [
                           {
                               "value": "http",
                               "text": "HTTP"
                           },
                           {
                               "value": "https",
                               "text": "HTTPS"
                           }
                       ]
                   }
               }
           ],
           "id": 1
       }

グローバルマクロの取得

すべてのグローバルマクロを取得します。

Request:

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

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "globalmacroid": "6",
                   "macro": "{$SNMP_COMMUNITY}",
                   "value": "public",
                   "description": "",
                   "type": "0"
               }
           ],
           "id": 1
       }

ソース

CUserMacro::get() in ui/include/classes/api/services/CUserMacro.php.