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

script.get

説明

integer/array script.get(object parameters)

このメソッドで、指定されたパラメーターに従ってスクリプトを取得できます。

すべてのgetメソッドに共通するこれらのパラメーターについてはリファレンス解説ページで詳しく説明されています。

パラメータ

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

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

パラメータ タイプ 説明
groupids string/array 指定されたホストグループで実行できるスクリプトのみを返します
hostids string/array 指定されたホストで実行できるスクリプトのみを返します
scriptids string/array 指定されたIDのスクリプトのみを返します
usrgrpids string/array 指定されたユーザーグループのユーザーが実行できるスクリプトのみを返します
selectGroups query スクリプトを実行できるホストグループを含むgroupsプロパティを返します
selectHosts query スクリプトを実行できるホストを含む[hosts][hosts](/manual/api/reference/host/object)プロパティを返します
selectActions query スクリプトが関連付けられているアクションを含むactionsプロパティを返します
sortfield string/array 指定されたプロパティで結果を並べ替えます。

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

すべてのスクリプトを取得する

構成済みのすべてのスクリプトを取得します

Request:

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

Response:

{  "jsonrpc": "2.0",  "result": [   {  "scriptid": "1",  "name": "Ping",  "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",  "host_access": "2",  "usrgrpid": "0",  "groupid": "0",  "description": "",  "confirmation": "",  "type": "0",  "execute_on": "1",  "timeout": "30s",  "parameters": []  },  {  "scriptid": "2",  "name": "Traceroute",  "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",  "host_access": "2",  "usrgrpid": "0",  "groupid": "0",  "description": "",  "confirmation": "",  "type": "0",  "execute_on": "1",  "timeout": "30s",  "parameters": []  },  {  "scriptid": "3",  "name": "Detect operating system",  "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",  "host_access": "2",  "usrgrpid": "7",  "groupid": "0",  "description": "",  "confirmation": "",  "type": "0",  "execute_on": "1",  "timeout": "30s",  "parameters": []  },  {  "scriptid": "4",  "name": "Webhook",  "command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.Log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.Log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}",  "host_access": "2",  "usrgrpid": "7",  "groupid": "0",  "description": "",  "confirmation": "",  "type": "5",  "execute_on": "1",  "timeout": "30s",  "parameters": [  {  "name": "token",  "value": "{$WEBHOOK.TOKEN}"  },  {  "name": "host",  "value": "{HOST.HOST}"  },  {  "name": "v",  "value": "2.2"  }  ]  }  ],  "id": 1 }

参照

ソース

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