diff --git a/doc/en/api/clapi/objects/realtime_downtimes.rst b/doc/en/api/clapi/objects/realtime_downtimes.rst index 1ccb5446963..de85d687713 100644 --- a/doc/en/api/clapi/objects/realtime_downtimes.rst +++ b/doc/en/api/clapi/objects/realtime_downtimes.rst @@ -14,14 +14,16 @@ In order to list available real time downtimes, use the **SHOW** action:: You can use the value "HOST" to display all the downtimes:: [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a show -v "HOST;generic-host" - host_name;author;actual_start_time;actual_end_time;start_time;end_time;comment_data;duration;fixed - generic-host;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 + id;host_name;author;actual_start_time;actual_end_time;start_time;end_time;comment_data;duration;fixed + 6;generic-host;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 Columns are the following : ================================= =========================================================================== Column Description ================================= =========================================================================== +id Name of the downtime + Host_name Name of the host Author Name of the author @@ -49,14 +51,16 @@ In order to list available real time downtimes, use the **SHOW** action:: You can use the value "SVC" to display all the downtimes:: [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a show -v "SVC;generic-host,generic-service" - host_name;service_name;author;start_time;end_time;comment_data;duration;fixed - generic-host;generic-service;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 + id;host_name;service_name;author;start_time;end_time;comment_data;duration;fixed + 42;generic-host;generic-service;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 Columns are the following : ================================= =========================================================================== Column Description ================================= =========================================================================== +id Name of the downtime + Host_name Name of the host Service_name Name of the service @@ -170,3 +174,21 @@ Order Description 7 Short description of the real time downtime ========= ============================================ + + +Cancel a real time downtime +------------------------------ + +In order to cancel a real time downtime, use the **CANCEL** action:: +To get the value of the id, use the **SHOW** action:: + + [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a CANCEL -v "6|42" + +The required parameters are the following : + +========= ============================================ +Order Description +========= ============================================ +1 Id of downtime + +========= ============================================ diff --git a/doc/fr/api/clapi/objects/realtime_downtimes.rst b/doc/fr/api/clapi/objects/realtime_downtimes.rst index 1ccb5446963..de85d687713 100644 --- a/doc/fr/api/clapi/objects/realtime_downtimes.rst +++ b/doc/fr/api/clapi/objects/realtime_downtimes.rst @@ -14,14 +14,16 @@ In order to list available real time downtimes, use the **SHOW** action:: You can use the value "HOST" to display all the downtimes:: [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a show -v "HOST;generic-host" - host_name;author;actual_start_time;actual_end_time;start_time;end_time;comment_data;duration;fixed - generic-host;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 + id;host_name;author;actual_start_time;actual_end_time;start_time;end_time;comment_data;duration;fixed + 6;generic-host;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 Columns are the following : ================================= =========================================================================== Column Description ================================= =========================================================================== +id Name of the downtime + Host_name Name of the host Author Name of the author @@ -49,14 +51,16 @@ In order to list available real time downtimes, use the **SHOW** action:: You can use the value "SVC" to display all the downtimes:: [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a show -v "SVC;generic-host,generic-service" - host_name;service_name;author;start_time;end_time;comment_data;duration;fixed - generic-host;generic-service;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 + id;host_name;service_name;author;start_time;end_time;comment_data;duration;fixed + 42;generic-host;generic-service;admin;2017/09/28 14:21;N/A;2017/09/26 17:00;2017/09/30 19:00;'generic-comment';3600;1 Columns are the following : ================================= =========================================================================== Column Description ================================= =========================================================================== +id Name of the downtime + Host_name Name of the host Service_name Name of the service @@ -170,3 +174,21 @@ Order Description 7 Short description of the real time downtime ========= ============================================ + + +Cancel a real time downtime +------------------------------ + +In order to cancel a real time downtime, use the **CANCEL** action:: +To get the value of the id, use the **SHOW** action:: + + [root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a CANCEL -v "6|42" + +The required parameters are the following : + +========= ============================================ +Order Description +========= ============================================ +1 Id of downtime + +========= ============================================ diff --git a/lib/Centreon/Object/Downtime/RtDowntime.php b/lib/Centreon/Object/Downtime/RtDowntime.php index cfdbcd8f6d7..7de8329f678 100644 --- a/lib/Centreon/Object/Downtime/RtDowntime.php +++ b/lib/Centreon/Object/Downtime/RtDowntime.php @@ -66,7 +66,7 @@ public function getHostDowntimes($hostList = array()) $hostFilter = "AND h.name IN ('" . implode("','", $hostList) . "') "; } - $query = "SELECT name, author, actual_start_time , actual_end_time, " . + $query = "SELECT internal_id, name, author, actual_start_time , actual_end_time, " . "start_time, end_time, comment_data, duration, fixed " . "FROM downtimes d, hosts h " . "WHERE d.host_id = h.host_id " . @@ -99,7 +99,7 @@ public function getSvcDowntimes($svcList = array()) $serviceFilter .= implode(' AND ', $filterTab) . ') '; } - $query = "SELECT h.name, s.description, author, actual_start_time, actual_end_time, " . + $query = "SELECT d.internal_id, h.name, s.description, author, actual_start_time, actual_end_time, " . "start_time, end_time, comment_data, duration, fixed " . "FROM downtimes d, hosts h, services s " . "WHERE d.service_id = s.service_id " . @@ -113,4 +113,15 @@ public function getSvcDowntimes($svcList = array()) return $this->getResult($query); } + + /** + * @param $id + * @return array + */ + public function getCurrentDowntime($id) + { + $query = "SELECT * FROM downtimes WHERE ISNULL(actual_end_time) " . + " AND end_time > " . time() . " AND internal_id = " . $id; + return $this->getResult($query, array(), 'fetch'); + } } diff --git a/tests/rest_api/realtime_rest_api.postman_collection.json b/tests/rest_api/realtime_rest_api.postman_collection.json index ef1e3add88b..3cd537bc0ef 100644 --- a/tests/rest_api/realtime_rest_api.postman_collection.json +++ b/tests/rest_api/realtime_rest_api.postman_collection.json @@ -6054,6 +6054,9 @@ " \"items\": {", " \"type\": \"object\",", " \"properties\": {", + " \"id\": {", + " \"type\": \"string\"", + " },", " \"host_name\": {", " \"type\": \"string\"", " },", @@ -6089,7 +6092,7 @@ " }", " },", " \"additionalProperties\": false,", - " \"required\": [\"host_name\", \"service_name\", \"author\", \"actual_start_time\", \"actual_end_time\", \"start_time\", \"end_time\", \"comment_data\", \"duration\", \"fixed\", \"url\"]", + " \"required\": [\"id\", \"host_name\", \"service_name\", \"author\", \"actual_start_time\", \"actual_end_time\", \"start_time\", \"end_time\", \"comment_data\", \"duration\", \"fixed\", \"url\"]", " }", "}", "", @@ -6161,6 +6164,9 @@ " \"items\": {", " \"type\": \"object\",", " \"properties\": {", + " \"id\": {", + " \"type\": \"string\"", + " },", " \"host_name\": {", " \"type\": \"string\"", " },", @@ -6193,7 +6199,7 @@ " }", " },", " \"additionalProperties\": false,", - " \"required\": [\"host_name\", \"author\", \"actual_start_time\", \"actual_end_time\", \"start_time\", \"end_time\", \"comment_data\", \"duration\", \"fixed\", \"url\"]", + " \"required\": [\"id\", \"host_name\", \"author\", \"actual_start_time\", \"actual_end_time\", \"start_time\", \"end_time\", \"comment_data\", \"duration\", \"fixed\", \"url\"]", " }", "}", "", diff --git a/www/class/centreon-clapi/centreonRtDowntime.class.php b/www/class/centreon-clapi/centreonRtDowntime.class.php index e28f00c3bfd..0a41b73236d 100644 --- a/www/class/centreon-clapi/centreonRtDowntime.class.php +++ b/www/class/centreon-clapi/centreonRtDowntime.class.php @@ -229,6 +229,7 @@ public function show($parameters = null) public function showHost($hostList) { $fields = array( + 'id', 'host_name', 'author', 'actual_start_time', @@ -324,6 +325,7 @@ public function showSvc($svcList) $existingService = array(); $fields = array( + 'id', 'host_name', 'service_name', 'author', @@ -730,4 +732,38 @@ private function addInstanceDowntime( throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ' INSTANCE : ' . implode('|', $unknownPoller)); } } + + /** + * @param null $parameters + * @throws CentreonClapiException + */ + public function cancel($parameters = null) + { + if (empty($parameters) || is_null($parameters)) { + throw new CentreonClapiException(self::MISSINGPARAMETER); + } + $listDowntime = explode('|', $parameters); + $unknownDowntime = array(); + + foreach ($listDowntime as $downtime) { + $infoDowntime = $this->object->getCurrentDowntime($downtime); + + if ($infoDowntime) { + $hostName = $this->hostObject->getHostName($infoDowntime['host_id']); + if (is_null($infoDowntime['service_id'])) { + $this->externalCmdObj->deleteDowntime('HOST', array($hostName . ';' . $downtime => 'on')); + } else { + $this->externalCmdObj->deleteDowntime('SVC', array($hostName . ';' . $downtime => 'on')); + } + } else { + $unknownDowntime[] = $downtime; + } + } + + if (count($unknownDowntime)) { + throw new CentreonClapiException( + self::OBJECT_NOT_FOUND . ' DOWNTIME ID : ' . implode('|', $unknownDowntime) + ); + } + } }