You are viewing documentation for the development version, it may be incomplete.
Join our translation project and help translate Zabbix documentation into your native language.

script.getscriptsbyhosts

Descripció

object script.getscriptsbyhosts(object parameters)

Aquest mètode permet recuperar tots els scripts disponibles en l'equip donat o un script específic si es proporciona l'ID de l'script. Quan es proporciona l'entrada manual, substitueix la macro {MANUALINPUT} pel valor especificat.

Aquest mètode és disponible per a usuaris de qualsevol tipus. Els permisos per cridar al mètode es poden revocar a la configuració del rol d'usuari. Veieu Rols d'usuari per a més informació.

Paràmetres

(objecte/matriu) El mètode admet un objecte o matriu d'objectes amb els paràmetres següents.

Paràmetre Tipus Descripció
hostid ID ID de l'equip per a retornar scripts.
Ha d'ésser únic.

Comportament del paràmetre:
- obligatori
scriptid ID ID de l'script a retornar.
manualinput string Valor del valor de macro {MANUALINPUT} proporcionat per l'usuari.

Valors de retorn

(objecte) Retorna un objecte amb ID d'equip com a propietats i matrius de scripts disponibles com a valors. Si es proporciona l'ID d'script, el valor associat és una matriu que conté l'script específic.

El mètode ampliarà automàticament les macros al text de "confirmació", Text del "indicador d'entrada manual" i "url".

Si es proporciona el paràmetre d'entrada manual, la macro {MANUALINPUT} es resoldrà amb el valor especificat.

Exemples

Recuperar scripts per ID d'equip

Recupera tots els scripts disponibles dels equips "30079" i "30073".

Petició:

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyhosts",
           "params": [
              {
                 "hostid":  "30079"
              },
              {
                 "hostid":  "30073"
              }
           ],
           "id": 1
       }

Resposta:

{
           "jsonrpc": "2.0",
           "result": {
               "30079": [
                   {
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "4",
                       "name": "Open Zabbix page",
                       "command": "",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "Are you sure you want to open page *UNKNOWN*?",
                       "type": "6",
                       "execute_on": "2",
                       "timeout": "30s",
                       "scope": "2",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "Zabbix page to open:",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "dashboard.view,discovery.view",
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   }
               ],
               "30073": [
                   {
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "4",
                       "name": "Open Zabbix page",
                       "command": "",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "Are you sure you want to open page *UNKNOWN*?",
                       "type": "6",
                       "execute_on": "2",
                       "timeout": "30s",
                       "scope": "2",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                       "new_window": "1",
                       "manualinput": "1",
                       "manualinput_prompt": "Zabbix page to open:",
                       "manualinput_validator_type": "1",
                       "manualinput_validator": "dashboard.view,discovery.view",
                       "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_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   }
               ]
           },
           "id": 1
       }

Retrieve specific script with manualinput value.

Retrieve script with ID "4" on host "30079" with manualinput value "dashboard.view".

Request:

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyhosts",
           "params": [
             {
               "hostid":  "30079",
               "scriptid": "4",
               "manualinput": "dashboard.view"
             }
         ],
           "id": 1
       }

Resposta:

{
           "jsonrpc": "2.0",
           "result": {
             "30079": [
               {
                 "scriptid": "4",
                 "name": "Open Zabbix page",
                 "command": "",
                 "host_access": "2",
                 "usrgrpid": "0",
                 "groupid": "0",
                 "description": "",
                 "confirmation": "Are you sure you want to open page dashboard.view?",
                 "type": "6",
                 "execute_on": "2",
                 "timeout": "30s",
                 "scope": "2",
                 "port": "",
                 "authtype": "0",
                 "username": "",
                 "password": "",
                 "publickey": "",
                 "privatekey": "",
                 "menu_path": "",
                 "url": "http://localhost/ui/zabbix.php?action=dashboard.view",
                 "new_window": "1",
                 "manualinput": "1",
                 "manualinput_prompt": "Zabbix page to open:",
                 "manualinput_validator_type": "1",
                 "manualinput_validator": "dashboard.view,discovery.view",
                 "manualinput_default_value": "",
                 "parameters": []
               }
             ]
           },
           "id": 1
       }

Font

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