url = $url; $this->apiKey = $apiKey; } public function zabbixRequest($method, $params) { $data = array( 'jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => 1 ); $options = array( 'http' => array( 'header' => "Content-Type: application/json\r\n" . "Authorization: Bearer " . $this->apiKey . "\r\n", 'method' => 'POST', 'content' => json_encode($data) ) ); $context = stream_context_create($options); $result = file_get_contents($this->url, false, $context); return json_decode($result, true); } public function getAllCongestionInterfaces() { $response = $this->zabbixRequest('item.get', array( 'search' => array('name' => array("Congestion")), )); return $response['result']; } public function getHostById($hostId) { $response = $this->zabbixRequest('host.get', array( 'hostids' => $hostId )); return $response['result']; } public function getItemValues($itemIds, $limit = 15) { $response = $this->zabbixRequest('history.get', array( 'itemids' => $itemIds, 'output' => 'extend', 'sortfield' => 'clock', 'sortorder' => 'DESC', 'limit' => $limit )); return $response['result']; } public function getHosts($hostname) { $response = $this->zabbixRequest('host.get', array( 'search' => array('name' => array($hostname)) )); return $response['result']; } public function getHostInterfaceItems($hostId) { $response = $this->zabbixRequest('item.get', array( 'hostids' => $hostId, 'output' => ['itemid','name_resolved', 'key_', 'units'], 'search' => ['name' => ["Bits received", "Bits sent"]], 'searchByAny' => true, 'sortfield' => 'name' )); return $response['result']; } public function getICMPItems($hostId) { $response = $this->zabbixRequest('item.get', array( 'hostids' => $hostId, 'search' => array('name' => array("ICMP")) )); return $response['result']; } public function getUptimeItems($hostId) { $response = $this->zabbixRequest('item.get', array( 'hostids' => $hostId, 'search' => array('name' => array("Uptime")) )); return $response['result']; } public function getHostInterfaces($hostIds) { $response = $this->zabbixRequest('hostinterface.get', array('hostids' => $hostIds)); return $response['result']; } public function createTask($itemid) { $response = $this->zabbixRequest('task.create', array( 'type' => 6, 'request' => array( 'itemid' => $itemid ) )); return $response['result']; } }