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

C2 API - Add and List downtimes #5623

Closed
wants to merge 16 commits into from
Closed
136 changes: 136 additions & 0 deletions doc/fr/api/clapi/objects/realtime_downtimes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
=========
Realtime Downtimes
=========

Overview
--------

Object name: **RTDOWNTIME**

Show host realtime downtime
---------------------------

In order to list available realtime 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;start_time;end_time;comment_data;duration;fixed
generic-host;admin;1506423060;1506426660;'generic-comment';3600;1

Columns are the following:

================================= ===========================================================================
Column Description
================================= ===========================================================================
Host_name Name of the host

Author Name of the author

Actual_start Beginning of downtime

Actual_end End of downtime

Comment_data Short description of the realtime downtime

Duration Duration of Downtime

Fixed Downtime starts and stops at the exact start and end times

================================= ===========================================================================

Show service realtime downtime
------------------------------

In order to list available realtime 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;service_name;author;start_time;end_time;comment_data;duration;fixed
generic-host;generic-service;admin;1506423060;1506426660;'generic-comment';3600;1

Columns are the following:

================================= ===========================================================================
Column Description
================================= ===========================================================================
Host_name Name of the host

Service_name Name of the service

Author Name of the author

Actual_start Beginning of downtime

Actual_end End of downtime

Comment_data Short description of the realtime downtime

Duration Duration of Downtime

Fixed Downtime starts and stops at the exact start and end times

================================= ===========================================================================

Realtime Downtime for : Addhost, addhostgroup, addservice, addservicegroup
-----------------------------------------------------------

If you want to associate a host, host group, service or service group to a realtime downtime, use the
**ADD** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a add -v "HOST;generic_host;start_time;end_time;fixed;duration;withservices;comment"
[root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a add -v "SVC;generic_host|generic_service;start_time;end_time;fixed;duration;withservices;comment"
[root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a add -v "HG;generic_hostgroup;start_time;end_time;fixed;duration;withservices;comment"
[root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a add -v "SG;generic_servicegroup;start_time;end_time;fixed;duration;withservices;comment"

The required parameters are the following:

========= ============================================
Order Description
========= ============================================
1 Value you want to associate

2 Name of the host (Name of the service)

3 Beginning of downtime

4 End of downtime

5 Downtime starts and stops at the exact start and end times (0/1)

6 Duration of Downtime

7 Associate services (0/1)

8 Short description of the realtime downtime

========= ============================================

Add instance realtime downtime
------------------------------

In order to add a new realtime downtime for a poller, use the **ADD** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o RTDOWNTIME -a add -v "HOST;generic_poller;start_time;end_time;fixed;duration;withservices;comment"

The required parameters are the following:

========= ============================================
Order Description
========= ============================================
1 Value you want to associate

2 Name of the poller

3 Beginning of downtime

4 End of downtime

5 Downtime starts and stops at the exact start and end times (0/1)

6 Duration of Downtime

7 Associate services (0/1)

8 Short description of the realtime downtime

========= ============================================
2 changes: 1 addition & 1 deletion lib/Centreon/Object/Downtime/Downtime.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2005-2015 CENTREON
* Copyright 2005-2017 CENTREON
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
Expand Down
112 changes: 112 additions & 0 deletions lib/Centreon/Object/Downtime/RtDowntime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/*
* Copyright 2005-2017 CENTREON
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation ; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses>.
*
* Linking this program statically or dynamically with other modules is making a
* combined work based on this program. Thus, the terms and conditions of the GNU
* General Public License cover the whole combination.
*
* As a special exception, the copyright holders of this program give CENTREON
* permission to link this program with independent modules to produce an executable,
* regardless of the license terms of these independent modules, and to copy and
* distribute the resulting executable under terms of CENTREON choice, provided that
* CENTREON also meet, for each linked independent module, the terms and conditions
* of the license of that module. An independent module is a module which is not
* derived from this program. If you modify this program, you may extend this
* exception to your version of the program, but you are not obliged to do so. If you
* do not wish to do so, delete this exception statement from your version.
*
* For more information : contact@centreon.com
*
*/

require_once "Centreon/Object/Object.php";

/**
* Used for interacting with downtime objects
*
* @author Baldo Guillaume
*/
class Centreon_Object_RtDowntime extends Centreon_Object
{
protected $table = "downtimes";
protected $name = "downtime_name";
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
*/
public function getHostDowntimes($hostList = array())
{
$hostFilter = '';

// Remplace les pipe par des virgules pour la requêtes SQL
if (!empty($hostList)) {
$hostFilter = "AND h.name IN ('" . implode("','", $hostList) . "') ";
}

$query = "SELECT name, author, actual_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 " .
$hostFilter .
"ORDER BY actual_start_time";

return $this->getResult($query, array(), "fetchAll");
}

/**
* @param array $svcList
* @return array
*/
public function getSvcDowntimes($svcList = array())
{
$serviceFilter = '';

if (!empty($svcList)) {
$serviceFilter = 'AND (';
$filterTab = array();
for ($i = 0; $i < count($svcList); $i += 2) {
$hostname = $svcList[$i];
$serviceDescription = $svcList[$i + 1];
$filterTab[] = '(h.name = "' . $hostname . '" AND s.description = "' . $serviceDescription . '")';
}
$serviceFilter .= implode(' AND ', $filterTab) . ') ';
}

$query = "SELECT h.name, s.description, author, actual_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 " .
$serviceFilter .
"AND d.actual_end_time IS NULL " .
"ORDER BY actual_start_time";

return $this->getResult($query, array(), "fetchAll");
}
}
Loading