Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Api cancel downtime #5894

Merged
merged 5 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions doc/en/api/clapi/objects/realtime_downtimes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

========= ============================================
30 changes: 26 additions & 4 deletions doc/fr/api/clapi/objects/realtime_downtimes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

========= ============================================
15 changes: 13 additions & 2 deletions lib/Centreon/Object/Downtime/RtDowntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 " .
Expand Down Expand Up @@ -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 " .
Expand All @@ -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');
}
}
10 changes: 8 additions & 2 deletions tests/rest_api/realtime_rest_api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6054,6 +6054,9 @@
" \"items\": {",
" \"type\": \"object\",",
" \"properties\": {",
" \"id\": {",
" \"type\": \"string\"",
" },",
" \"host_name\": {",
" \"type\": \"string\"",
" },",
Expand Down Expand Up @@ -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\"]",
" }",
"}",
"",
Expand Down Expand Up @@ -6161,6 +6164,9 @@
" \"items\": {",
" \"type\": \"object\",",
" \"properties\": {",
" \"id\": {",
" \"type\": \"string\"",
" },",
" \"host_name\": {",
" \"type\": \"string\"",
" },",
Expand Down Expand Up @@ -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\"]",
" }",
"}",
"",
Expand Down
36 changes: 36 additions & 0 deletions www/class/centreon-clapi/centreonRtDowntime.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public function show($parameters = null)
public function showHost($hostList)
{
$fields = array(
'id',
'host_name',
'author',
'actual_start_time',
Expand Down Expand Up @@ -324,6 +325,7 @@ public function showSvc($svcList)
$existingService = array();

$fields = array(
'id',
'host_name',
'service_name',
'author',
Expand Down Expand Up @@ -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)
);
}
}
}