/** * Conectar con la API de Zabbix * * @throws \Exception */ private function connect() { try { $this->Zabbix = ZabbixApiLoader::getAPI($this->backend->getVersion()); $this->Zabbix->setApiUrl($this->backend->getUrl()); $this->Zabbix->userLogin(array('user' => $this->backend->getUser(), 'password' => $this->backend->getPass())); } catch (\Exception $e) { error_log(Language::t($e->getMessage())); throw $e; } }
if (!$action || !$data) { Response::printJSON('Petición inválida'); } else { $data = json_decode($data); if (json_last_error() !== 0) { Response::printJSON('Petición inválida'); } } try { switch ($action) { case 'smdBackend': $url = $data->url . '?action=' . $data->action . '&token=' . $data->token; $json = Util::getDataFromUrl($url); break; case 'zabbixBackend': $ZabbixLoader = new ZabbixApiLoader(); $Zabbix = $ZabbixLoader->getAPI($data->version); $Zabbix->setApiUrl($data->url); $Zabbix->userLogin(array('user' => $data->user, 'password' => $data->pass)); $version = $Zabbix->apiinfoVersion(); Response::printJSON('V ' . $version, 0); break; default: Response::printJSON('Petición inválida'); } } catch (Exception $e) { Response::printJSON($e->getMessage()); } if (isset($json) && !empty($json)) { header('Content-type: application/json'); exit($json);