/** * Execute script. * * @param string $data['scriptid'] * @param string $data['hostid'] * * @return array */ public function execute(array $data) { global $ZBX_SERVER, $ZBX_SERVER_PORT; $scriptId = $data['scriptid']; $hostId = $data['hostid']; $scripts = $this->get(array('hostids' => $hostId, 'scriptids' => $scriptId, 'output' => array('scriptid'), 'preservekeys' => true)); if (!isset($scripts[$scriptId])) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } // execute script $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SCRIPT_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); $result = $zabbixServer->executeScript($scriptId, $hostId); if ($result !== false) { // return the result in a backwards-compatible format return array('response' => 'success', 'value' => $result); } else { self::exception(ZBX_API_ERROR_INTERNAL, $zabbixServer->getError()); } }