script.get

Descripció

integer/array script.get(object parameters)

El mètode permet recuperar scripts segons els paràmetres proveïts.

Aquest mètode és disponible per a usuaris de qualsevol mena. Els permisos per cridar al mètode es poden revocar a les configuracions de rols d'usuari. Per a més informació, veieu Rols d'usuari.

Paràmetres

(objet) Paràmetres que defineixen la sortida esperada.

El mètode admet els paràmetres següents.

Paràmetre Tipus Descripció
groupids ID/array Retorna només scripts que es poden executar als grups d'equips donats.
hostids ID/array Retorna només scripts que es poden executar als equips donats.
scriptids ID/array Retorna només scripts amb els ID donats.
usrgrpids ID/array Retorna només scripts que poden ésser executats pels usuaris dels grups d'usuaris determinats.
selectHostGroups query Retorna una propietat hostgroups amb els grups d'equips on es pot executar l'script.
selectHosts query Retorna una propietat hosts amb els equips en què es pot executar l'script.
selectActions query Retorna una propietat actions amb les accions a les quals està associat l'script.
sortfield string/array Ordena el resultat per les propietats donades.

Els valors possibles són: scriptid i name.
countOutput boolean Aquests paràmetres, comuns a tots els mètodes get, es descriuen als comentaris de referència.
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean
selectGroups
(obsolet)
query Aquest paràmetre és obsolet; si et plau, empra selectHostGroups en el seu lloc.
Retorna la propietat grups amb informació dels grups d'equips on pertany l'equip.

Valors de retorn

(integer/array) Retorna un d'entre:

  • una taula d'objectes;
  • el recompte d'objectes recuperats, si s'empra el paràmetre countOutput.

Exemples

Recuperar tots els scripts

Recupera tots els scripts configurats.

Petició:

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

Resposta:

{
           "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",
                   "manualinput": "0",
                   "manualinput_prompt": "",
                   "manualinput_validator": "",
                   "manualinput_validator_type": "0",
                   "manualinput_default_value": "",
                   "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",
                   "manualinput": "0",
                   "manualinput_prompt": "",
                   "manualinput_validator": "",
                   "manualinput_validator_type": "0",
                   "manualinput_default_value": "",
                   "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",
                   "scope": "2",
                   "port": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "menu_path": "",
                   "url": "",
                   "new_window": "1",
                   "manualinput": "0",
                   "manualinput_prompt": "",
                   "manualinput_validator": "",
                   "manualinput_validator_type": "0",
                   "manualinput_default_value": "",
                   "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",
                   "scope": "2",
                   "port": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "menu_path": "",
                   "url": "",
                   "new_window": "1",
                   "manualinput": "0",
                   "manualinput_prompt": "",
                   "manualinput_validator": "",
                   "manualinput_validator_type": "0",
                   "manualinput_default_value": "",
                   "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": "Go to {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",
                   "manualinput": "0",
                   "manualinput_prompt": "",
                   "manualinput_validator": "",
                   "manualinput_validator_type": "0",
                   "manualinput_default_value": "",
                   "parameters": []
               },
               {
                   "scriptid": "6",
                   "name": "URL with user input",
                   "command": "",
                   "host_access": "2",
                   "usrgrpid": "0",
                   "groupid": "0",
                   "description": "",
                   "confirmation": "Open zabbix page {MANUALINPUT}?",
                   "type": "6",
                   "execute_on": "1",
                   "timeout": "30s",
                   "scope": "2",
                   "port": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "menu_path": "",
                   "url": "http://zabbix/ui/zabbix.php?action={MANUALINPUT}",
                   "new_window": "0",
                   "manualinput": "1",
                   "manualinput_prompt": "Select a page to open:",
                   "manualinput_validator": "dashboard.view,script.list,actionlog.list",
                   "manualinput_validator_type": "1",
                   "parameters": []
               }
           ],
           "id": 1
       }

Veieu també

Font

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