Example #1
0
 private function event()
 {
     if ($this->get_request_method() == "GET" && isset($this->_request['id'])) {
         $event = new Event((int) $this->_request['id']);
         if ($event->fetch()) {
             $domxmldata = $event->getDomXMLElement($this->domxml);
             $this->response($this->finishxml($domxmldata), 200);
         } else {
             $this->error_code = 1;
             $this->error_message = "Event not found";
             $this->response($this->finishxml(), 404);
         }
     } elseif ($this->get_request_method() == "POST" or $this->get_request_method() == "GET" && !isset($this->_request['id']) && count($_GET) > 1) {
         if ($this->isApiKeyValid($this->api_key)) {
             $data = !empty($_POST) ? $_POST : $_GET;
             $event = new Event(false, false, $this->_request['object'], (int) $this->_request['object_id'], $this->_request['action'], $this->_request['data']);
             $event_id = $event->store();
             if ($event_id != false) {
                 header('Location: ' . ConfigLine::configByName('url_to_netmon') . '/api/rest/event/' . $event_id);
             } else {
                 $this->authentication = false;
                 $this->error_code = 2;
                 $this->error_message = "The Event could not be created. Your request seems to miss some data.";
                 $this->response($this->finishxml(), 400);
             }
         } else {
             $this->error_code = 2;
             $this->error_message = "The api_key is not valid.";
             $this->response($this->finishxml(), 401);
         }
     } else {
         $this->response('', 406);
     }
 }