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

fix(downtimes): apply dt on resources linked to a poller #7955

Merged
merged 5 commits into from
Oct 10, 2019
Merged
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
97 changes: 52 additions & 45 deletions www/include/monitoring/downtime/AddDowntime.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2005-2018 Centreon
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
Expand Down Expand Up @@ -48,14 +48,15 @@
$centreonGMT = new CentreonGMT($pearDB);
$centreonGMT->getMyGMTFromSession(session_id(), $pearDB);
$hostStr = $centreon->user->access->getHostsString("ID", $pearDBO);
$host_acl_id = preg_split('/,/', str_replace("'", "", $hostStr));
$hostAclId = preg_split('/,/', str_replace("'", "", $hostStr));

$hObj = new CentreonHost($pearDB);
$serviceObj = new CentreonService($pearDB);
$resource_id = isset($resource_id) ? $resource_id : 0;
$resourceId = $resourceId ?? 0;

if (!$centreon->user->access->checkAction("host_schedule_downtime")
&& !$centreon->user->access->checkAction("service_schedule_downtime")) {
&& !$centreon->user->access->checkAction("service_schedule_downtime")
) {
require_once _CENTREON_PATH_ . "www/include/core/errors/alt_error.php";
} else {
/*
Expand All @@ -74,18 +75,18 @@
$redirect = $form->addElement('hidden', 'o');
$redirect->setValue($o);

if (isset($_GET["host_id"]) &&
!isset($_GET["service_id"])
if (isset($_GET["host_id"])
&& !isset($_GET["service_id"])
) {
$disabled = "disabled";
$host_name = $hObj->getHostName($_GET['host_id']);
} elseif (isset($_GET["host_id"]) &&
isset($_GET["service_id"])
$hostName = $hObj->getHostName($_GET['host_id']);
} elseif (isset($_GET["host_id"])
&& isset($_GET["service_id"])
) {
$disabled = "disabled";
$serviceParameters = $serviceObj->getParameters($_GET['service_id'], array('service_description'));
$serviceDisplayName = $serviceParameters['service_description'];
$host_name = $hObj->getHostName($_GET['host_id']);
$hostName = $hObj->getHostName($_GET['host_id']);
} else {
$disabled = " ";
}
Expand Down Expand Up @@ -194,15 +195,17 @@
);

/* Host Parents */
if (0 != $resource_id) {
if (0 !== $resourceId) {
$attrPoller1 = array_merge(
$attrPoller,
array(
'defaultDatasetRoute' => './api/internal.php?object=centreon_configuration_poller' .
'&action=defaultValues&target=resources&field=instance_id&id=' . $resource_id)
'&action=defaultValues&target=resources&field=instance_id&id=' . $resourceId)
);

$form->addElement('select2', 'poller_id', _("Pollers"), array(), $attrPoller1);
} else {
$form->addElement('select2', 'poller_id', _("Pollers"), array(), $attrPoller);
}

$chbx = $form->addElement(
Expand Down Expand Up @@ -300,9 +303,9 @@
}
$form->setDefaults(array('duration_scale' => $defaultScale));

$with_services[] = $form->createElement('radio', 'with_services', null, _("Yes"), '1');
$with_services[] = $form->createElement('radio', 'with_services', null, _("No"), '0');
$form->addGroup($with_services, 'with_services', _("Set downtime for hosts services"), '&nbsp;');
$withServices[] = $form->createElement('radio', 'with_services', null, _("Yes"), '1');
$withServices[] = $form->createElement('radio', 'with_services', null, _("No"), '0');
$form->addGroup($withServices, 'with_services', _("Set downtime for hosts services"), '&nbsp;');

$form->addElement('textarea', 'comment', _("Comments"), $attrsTextarea);

Expand Down Expand Up @@ -382,19 +385,19 @@
}
}

if (isset($_POST['host_or_centreon_time']['host_or_centreon_time']) &&
$_POST['host_or_centreon_time']['host_or_centreon_time']
if (isset($_POST['host_or_centreon_time']['host_or_centreon_time'])
&& $_POST['host_or_centreon_time']['host_or_centreon_time']
) {
$host_or_centreon_time = $_POST['host_or_centreon_time']['host_or_centreon_time'];
$hostOrCentreonTime = $_POST['host_or_centreon_time']['host_or_centreon_time'];
} else {
$host_or_centreon_time = "0";
$hostOrCentreonTime = "0";
}

$dt_w_services = false;
$applyDtOnServices = false;
if (isset($values['with_services']) &&
$values['with_services']['with_services'] == 1
) {
$dt_w_services = true;
$applyDtOnServices = true;
}

/* concatenating the chosen dates before sending them to ext_cmd */
Expand All @@ -421,13 +424,13 @@
$concatenatedEnd,
$_POST["persistant"],
$duration,
$dt_w_services,
$host_or_centreon_time
$applyDtOnServices,
$hostOrCentreonTime
);
}
} elseif ($values['downtimeType']['downtimeType'] == 0 &&
isset($_POST['hostgroup_id']) &&
is_array($_POST['hostgroup_id'])
} elseif ($values['downtimeType']['downtimeType'] == 0
&& isset($_POST['hostgroup_id'])
&& is_array($_POST['hostgroup_id'])
) {
/*
* Set a downtime for hostgroup
Expand All @@ -436,16 +439,16 @@
foreach ($_POST['hostgroup_id'] as $hg_id) {
$hostlist = $hg->getHostGroupHosts($hg_id);
foreach ($hostlist as $host_id) {
if ($centreon->user->access->admin || in_array($host_id, $host_acl_id)) {
if ($centreon->user->access->admin || in_array($host_id, $hostAclId)) {
$ecObj->addHostDowntime(
$host_id,
$_POST["comment"],
$concatenatedStart,
$concatenatedEnd,
$_POST["persistant"],
$duration,
$dt_w_services,
$host_or_centreon_time
$applyDtOnServices,
$hostOrCentreonTime
);
}
}
Expand All @@ -463,7 +466,7 @@
foreach ($_POST["service_id"] as $value) {
$info = explode('-', $value);
if ($centreon->user->access->admin ||
in_array($info[0], $host_acl_id)
in_array($info[0], $hostAclId)
) {
$ecObj->addSvcDowntime(
$info[0],
Expand All @@ -473,18 +476,19 @@
$concatenatedEnd,
$_POST["persistant"],
$duration,
$host_or_centreon_time
$hostOrCentreonTime
);
}
}
} elseif ($values['downtimeType']['downtimeType'] == 3) {
/*
* Set a downtime for a service group list
*/
foreach ($_POST["servicegroup_id"] as $sg_id) {
$query = "SELECT host_id, service_id FROM services_servicegroups WHERE servicegroup_id = :sgId";
$stmt = $pearDBO->prepare($query);
$stmt->bindValue(':sgId', $sg_id, PDO::PARAM_INT);
foreach ($_POST["servicegroup_id"] as $sgId) {
$stmt = $pearDBO->prepare(
"SELECT host_id, service_id FROM services_servicegroups WHERE servicegroup_id = :sgId"
);
$stmt->bindValue(':sgId', $sgId, PDO::PARAM_INT);
$stmt->execute();

while ($row = $stmt->fetch()) {
Expand All @@ -496,20 +500,23 @@
$concatenatedEnd,
$_POST["persistant"],
$duration,
$host_or_centreon_time
$hostOrCentreonTime
);
}
}
} elseif ($values['downtimeType']['downtimeType'] == 4) {
/*
* Set a downtime for poller
*/
foreach ($_POST['poller_id'] as $poller_id) {
$DBRESULT = $pearDBO->query("SELECT host_id FROM hosts WHERE instance_id = " .
$poller_id . "AND enabled = 1");
while ($row = $DBRESULT->fetch()) {
foreach ($_POST['poller_id'] as $pollerId) {
$stmt = $pearDBO->prepare(
"SELECT host_id FROM hosts WHERE instance_id = :poller_id AND enabled = 1"
);
$stmt->bindValue(':poller_id', $pollerId, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch()) {
if ($centreon->user->access->admin ||
in_array($row['host_id'], $host_acl_id)
in_array($row['host_id'], $hostAclId)
) {
$ecObj->addHostDowntime(
$row['host_id'],
Expand All @@ -518,8 +525,8 @@
$concatenatedEnd,
$_POST["persistant"],
$duration,
$dt_w_services,
$host_or_centreon_time
$applyDtOnServices,
$hostOrCentreonTime
);
}
}
Expand All @@ -545,10 +552,10 @@
if (isset($_GET['service_id']) &&
isset($_GET['host_id'])
) {
$tpl->assign('host_name', $host_name);
$tpl->assign('host_name', $hostName);
$tpl->assign('service_description', $serviceDisplayName);
} elseif (isset($_GET['host_id'])) {
$tpl->assign('host_name', $host_name);
$tpl->assign('host_name', $hostName);
}

$tpl->assign('seconds', _("seconds"));
Expand Down