url = $url; } public function connect( $username, $password) { $response = Http::withoutVerifying()->post($this->url . "/api_jsonrpc.php", [ "jsonrpc" => "2.0", "method" => "user.login", "params" => [ "username" => $username, "password" => $password, ], "id" => $this->id, "auth" => null, ]); if (!$response->successful()) { throw new Exception("Unable To Authenticated", 1); } $responseObject = $response->json(); if (isset($responseObject['error'])) { throw new Exception($responseObject['error']['data'], $responseObject['error']['code']); } $this->token = $response['result']; $this->id++; } public function hosts($params = []) { if (empty($this->token)) { throw new Exception("you need to connect first", 1); } $response = Http::withoutVerifying()->post($this->url . "/api_jsonrpc.php", [ "jsonrpc" => "2.0", "method" => "host.get", "params" => $params, "id" => $this->id, "auth" => $this->token, ]); if (!$response->successful()) { throw new Exception("Unable To Request", 1); } $responseObject = $response->json(); if (isset($responseObject['error'])) { throw new Exception($responseObject['error']['data'], $responseObject['error']['code']); } $this->id++; return collect($responseObject["result"]); } public function hostGroups($params = []) { if (empty($this->token)) { throw new Exception("you need to connect first", 1); } $response = Http::withoutVerifying()->post($this->url . "/api_jsonrpc.php", [ "jsonrpc" => "2.0", "method" => "hostgroup.get", "params" => $params, "id" => $this->id, "auth" => $this->token, ]); if (!$response->successful()) { throw new Exception("Unable To Request", 1); } $responseObject = $response->json(); if (isset($responseObject['error'])) { throw new Exception($responseObject['error']['data'], $responseObject['error']['code']); } $this->id++; return collect($responseObject["result"]); } public function maintenances($params = []){ return $this->request( [ "jsonrpc" => "2.0", "method" => "maintenance.get", "params" => $params, "id" => $this->id, "auth" => $this->token, ]); } /*Helpers*/ private function request($body = []){ if (empty($this->token)) { throw new Exception("you need to connect first", 1); } $response = Http::withoutVerifying()->post($this->url . "/api_jsonrpc.php", $body); if (!$response->successful()) { throw new Exception("Unable To Request", 1); } $responseObject = $response->json(); if (isset($responseObject['error'])) { throw new Exception($responseObject['error']['data'], $responseObject['error']['code']); } $this->id++; return collect($responseObject["result"]); } }