On this page
script.get
Beschrijving
integer/array script.get(object parameters)
Met deze methode kunt u scripts ophalen op basis van de opgegeven parameters.
Deze methode is beschikbaar voor gebruikers van elk type. Toestemmingen om de methode te gebruiken kunnen worden ingetrokken in de gebruikersrolinstellingen. Zie Gebruikersrollen voor meer informatie.
Parameters
(object) Parameters die de gewenste uitvoer definiëren.
De methode ondersteunt de volgende parameters.
| Parameter | Type | Beschrijving |
|---|---|---|
| groupids | string/array | Geef alleen scripts terug die kunnen worden uitgevoerd op de opgegeven hostgroepen. |
| hostids | string/array | Geef alleen scripts terug die kunnen worden uitgevoerd op de opgegeven hosts. |
| scriptids | string/array | Geef alleen scripts terug met de opgegeven ID's. |
| usrgrpids | string/array | Geef alleen scripts terug die kunnen worden uitgevoerd door gebruikers in de opgegeven gebruikersgroepen. |
| selectHostGroups | query | Geef een eigenschap hostgroups terug met hostgroepen waarop het script kan worden uitgevoerd. |
| selectHosts | query | Geef een eigenschap hosts terug met hosts waarop het script kan worden uitgevoerd. |
| selectActions | query | Geef een eigenschap actions terug met acties waaraan het script is gekoppeld. |
| sortfield | string/array | Sorteer het resultaat op de opgegeven eigenschappen. Mogelijke waarden: scriptid, name. |
| countOutput | boolean | Deze parameters, die gemeenschappelijk zijn voor alle get-methoden, worden in detail beschreven in het referentiecommentaar. |
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean | |
| selectGroups (verouderd) |
query | Deze parameter is verouderd, gebruik alstublieft selectHostGroups in plaats daarvan.Geef een eigenschap groups terug met hostgroepen waarop het script kan worden uitgevoerd. |
Retourwaarden
(integer/array) Retourneert ofwel:
- een reeks objecten;
- het aantal opgehaalde objecten, als de
countOutputparameter heeft gebruikt.
Voorbeelden
Alle scripts ophalen
Haal alle geconfigureerde scripts op.
{
"jsonrpc": "2.0",
"method": "script.get",
"params": {
"output": "extend"
},
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"parameters": []
},
{
"scriptid": "3",
"name": "Detecteer besturingssysteem",
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"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 'Onverwachte reactie.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.log(3, '[Webhook Script] reactiegegevens: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.log(3, '[Webhook Script] scriptuitvoering mislukt: ' + error);\n throw 'Uitvoering mislukt: ' + error + '.';\n}",
"host_access": "2",
"usrgrpid": "7",
"groupid": "0",
"description": "",
"confirmation": "",
"type": "5",
"execute_on": "1",
"timeout": "30s",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"parameters": [
{
"name": "token",
"value": "{$WEBHOOK.TOKEN}"
},
{
"name": "host",
"value": "{HOST.HOST}"
},
{
"name": "v",
"value": "2.2"
}
]
},
{
"scriptid": "5",
"name": "URL",
"command": "",
"host_access": "2",
"usrgrpid": "0",
"groupid": "0",
"description": "",
"confirmation": "Ga naar {HOST.NAME}?",
"type": "6",
"execute_on": "1",
"timeout": "30s",
"scope": "4",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "http://zabbix/ui/zabbix.php?action=latest.view&hostids[]={HOST.ID}",
"new_window": "0",
"parameters": []
}
],
"id": 1
}
Zie ook
Bron
CScript::get() in ui/include/classes/api/services/CScript.php.