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

Commit

Permalink
Api cancel downtime (#5894)
Browse files Browse the repository at this point in the history
* feat(clapi) add cancel downtime

* update doc

* fix test
  • Loading branch information
loiclau committed Nov 17, 2017
1 parent fb2ac05 commit d09252b
Show file tree
Hide file tree
Showing 5 changed files with 6,370 additions and 6,263 deletions.
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

========= ============================================
33 changes: 27 additions & 6 deletions lib/Centreon/Object/Downtime/RtDowntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Centreon_Object_RtDowntime extends Centreon_ObjectRt
protected $primaryKey = "downtime_id";
protected $uniqueLabelField = "comment_data";

public function __construct()
{
parent::__construct();
$this->db = Centreon_Db_Manager::factory('storage');
}

/**
* @param array $hostList
* @return array
Expand All @@ -59,14 +65,16 @@ public function getHostDowntimes($hostList = array())
$hostFilter = "AND h.name IN ('" . implode("','", $hostList) . "') ";
}

$query = "SELECT name, author, actual_start_time , end_time, comment_data, duration, fixed " .
$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 " .
"AND d.cancelled = 0 " .
"AND d.actual_end_time IS NULL " .
"AND service_id IS NULL " .
"AND end_time > UNIX_TIMESTAMP(NOW()) " .
"AND start_time < UNIX_TIMESTAMP(NOW()) " .
$hostFilter .
"ORDER BY actual_start_time";
"ORDER BY actual_start_time, name";

return $this->getResult($query);
}
Expand All @@ -90,16 +98,29 @@ public function getSvcDowntimes($svcList = array())
$serviceFilter .= implode(' AND ', $filterTab) . ') ';
}

$query = "SELECT h.name, s.description, author, actual_start_time , end_time, comment_data, duration, fixed " .
$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 " .
"AND d.host_id = s.host_id " .
"AND s.host_id = h.host_id " .
"AND d.cancelled = 0 " .
"AND end_time > UNIX_TIMESTAMP(NOW()) " .
"AND start_time < UNIX_TIMESTAMP(NOW()) " .
$serviceFilter .
"AND d.actual_end_time IS NULL " .
"ORDER BY actual_start_time";
"ORDER BY actual_start_time, h.name, s.description";

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');
}
}
Loading

0 comments on commit d09252b

Please sign in to comment.