Merge pull request #34 from pandorafms/feature/ticket#2404-planned-downtimes-acl

Ended, tested and aproved
This commit is contained in:
Alejandro Gallardo Escobar 2015-07-16 13:48:41 +01:00
commit f14b07014f
6 changed files with 633 additions and 506 deletions

View File

@ -25,7 +25,8 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
return;
}
$config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $config["past_planned_downtimes"] : 1;
// Default
set_unless_defined ($config["past_planned_downtimes"], 1);
require_once ('include/functions_users.php');
@ -81,45 +82,59 @@ $id_agent = (int) get_parameter ('id_agent');
$insert_downtime_agent = (int) get_parameter ('insert_downtime_agent');
$delete_downtime_agent = (int) get_parameter ('delete_downtime_agent');
$groups = users_get_groups ();
// User groups with AW permission for ACL checks
$user_groups_aw = array_keys(users_get_groups($config['id_user'], 'AW'));
// INSERT A NEW DOWNTIME_AGENT ASSOCIATION
if ($insert_downtime_agent === 1) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
$agents = (array) get_parameter ('id_agents');
$module_names = (array) get_parameter ('module');
$all_modules = false;
if (empty($module_names)) {
$all_modules = true;
}
else {
//It is empty.
if ($module_names[0] == "0")
$all_modules = true;
}
$all_modules = (empty($module_names) || in_array(0, $module_names));
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed == 1) {
// 'Is running' check
$is_running = (bool) db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
}
else {
$num_agents = count($agents);
for ($a = 0; $a < $num_agents; $a++) {
$id_agente_dt = $agents[$a];
foreach ($agents as $agent_id) {
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $agent_id);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
continue;
}
$values = array(
'id_downtime' => $id_downtime,
'id_agent' => $id_agente_dt,
'id_agent' => $agent_id,
'all_modules' => $all_modules
);
$result = db_process_sql_insert('tplanned_downtime_agents', $values);
if ($result && !$all_modules) {
foreach ($module_names as $module_name) {
$module = modules_get_agentmodule_id($module_name, $id_agente_dt);
$module = modules_get_agentmodule_id($module_name, $agent_id);
if (empty($module))
continue;
$values = array(
'id_downtime' => $id_downtime,
'id_agent' => $id_agente_dt,
'id_agent' => $agent_id,
'id_agent_module' => $module["id_agente_modulo"]
);
$result = db_process_sql_insert('tplanned_downtime_modules', $values);
@ -140,8 +155,29 @@ if ($delete_downtime_agent === 1) {
$id_da = (int) get_parameter ('id_downtime_agent');
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed == 1) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// 'Is running' check
$is_running = (bool) db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
}
else {
@ -160,11 +196,11 @@ if ($delete_downtime_agent === 1) {
// UPDATE OR CREATE A DOWNTIME (MAIN DATA, NOT AGENT ASSOCIATION)
if ($create_downtime || $update_downtime) {
$check = db_get_value ('name', 'tplanned_downtime', 'name', $name);
$check = (bool) db_get_value ('name', 'tplanned_downtime', 'name', $name);
$datetime_from = strtotime ($once_date_from . ' ' . $once_time_from);
$datetime_to = strtotime ($once_date_to . ' ' . $once_time_to);
$now = strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT));
$now = time();
if ($type_execution == 'once' && !$config["past_planned_downtimes"] && $datetime_from < $now) {
ui_print_error_message(__('Not created. Error inserting data. Start time must be higher than the current time' ));
@ -186,6 +222,15 @@ if ($create_downtime || $update_downtime) {
else {
$sql = '';
if ($create_downtime) {
// Check AW permission on new downtime
if (!in_array($id_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
if (trim(io_safe_output($name)) != '') {
if (!$check) {
$values = array(
@ -230,44 +275,65 @@ if ($create_downtime || $update_downtime) {
}
}
else if ($update_downtime) {
$has_been_executed = db_get_value ('executed', 'tplanned_downtime', 'name', $name);
$old_downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
// Check AW permission on OLD downtime
if (empty($old_downtime) || !in_array($old_downtime['id_group'], $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// Check AW permission on NEW downtime group
if (!in_array($id_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// 'Is running' check
$is_running = (bool) $old_downtime['executed'];
$values = array();
if (trim(io_safe_output($name)) == '') {
ui_print_error_message(__('Planned downtime must have a name'));
}
else if ($has_been_executed == 1 && $type_execution == 'once') {
// When running only certain items can be modified for the 'once' type
else if ($is_running && $type_execution == 'once') {
$values = array(
'description' => $description,
'date_to' => $datetime_to,
'id_user' => $config['id_user']
);
}
else if ($has_been_executed == 1) {
ui_print_error_message(__('No updates. Planned Downtime has been executed'));
else if ($is_running) {
ui_print_error_message(__('Cannot be modified while the downtime is being executed'));
}
else {
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group,
'only_alerts' => 0,
'monday' => $monday,
'tuesday' => $tuesday,
'wednesday' => $wednesday,
'thursday' => $thursday,
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'periodically_time_from' => $periodically_time_from,
'periodically_time_to' => $periodically_time_to,
'periodically_day_from' => $periodically_day_from,
'periodically_day_to' => $periodically_day_to,
'type_downtime' => $type_downtime,
'type_execution' => $type_execution,
'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user']
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group,
'only_alerts' => 0,
'monday' => $monday,
'tuesday' => $tuesday,
'wednesday' => $wednesday,
'thursday' => $thursday,
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'periodically_time_from' => $periodically_time_from,
'periodically_time_to' => $periodically_time_to,
'periodically_day_from' => $periodically_day_from,
'periodically_day_to' => $periodically_day_to,
'type_downtime' => $type_downtime,
'type_execution' => $type_execution,
'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user']
);
if ($config["dbtype"] == 'oracle') {
$values['periodically_time_from'] = '1970/01/01 ' . $values['periodically_time_from'];
@ -358,8 +424,17 @@ if ($id_downtime > 0) {
$result = db_get_row_sql ($sql);
// Permission check for the downtime with the AW user groups
if (empty($result) || !in_array($result['id_group'], $user_groups_aw) ){
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
$name = (string) $result["name"];
$id_group = (int) $result['id_group'];
$description = (string) $result["description"];
$type_downtime = (string) $result['type_downtime'];
@ -384,11 +459,11 @@ if ($id_downtime > 0) {
$saturday = (bool) $result['saturday'];
$sunday = (bool) $result['sunday'];
$executed = (bool) $result['executed'];
$running = (bool) $result['executed'];
}
// when the planned down time is in execution, only action to postpone on once type is enabled and the other are disabled.
$disabled_in_execution = $executed ? 1 : 0;
// when the planned downtime is in execution, only action to postpone on once type is enabled and the other are disabled.
$disabled_in_execution = (int) $running;
$table = new StdClass();
$table->class = 'databox filters';
@ -555,33 +630,42 @@ if ($id_downtime > 0) {
// Show available agents to include into downtime
echo '<h4>' . __('Available agents') . ':</h4>';
$filter_group = get_parameter("filter_group", 0);
$filter_group = (int) get_parameter("filter_group", 0);
// User AW groups to str for the filter
$id_groups_str = implode(",", $user_groups_aw);
if (empty($id_groups_str)) {
// Restrictive filter on error. This will filter all the downtimes
$id_groups_str = '-1';
}
$filter_cond = '';
if ($filter_group > 0)
$filter_cond = " AND id_grupo = $filter_group ";
$sql = sprintf ("SELECT tagente.id_agente, tagente.nombre,
tagente.id_grupo
$sql = sprintf("SELECT tagente.id_agente, tagente.nombre
FROM tagente
WHERE tagente.id_agente NOT IN (
SELECT tagente.id_agente
FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d
) AND disabled = 0 $filter_cond
ORDER by tagente.nombre", $id_downtime);
$downtimes = db_get_all_rows_sql ($sql);
$data = array ();
if ($downtimes) {
foreach ($downtimes as $downtime) {
if (check_acl ($config["id_user"], $downtime['id_grupo'], "AW")) {
$data[$downtime['id_agente']] = $downtime['nombre'];
}
}
}
) AND disabled = 0 %s
AND tagente.id_grupo IN (%s)
ORDER BY tagente.nombre", $id_downtime, $filter_cond, $id_groups_str);
$agents = db_get_all_rows_sql ($sql);
if (empty($agents))
$agents = array();
$agent_ids = extract_column($agents, 'id_agente');
$agent_names = extract_column($agents, 'nombre');
// item[<id>] = <name>;
$agents = array_combine($agent_ids, $agent_names);
if ($agents === false)
$agents = array();
$disabled_add_button = false;
if (empty($data) || $disabled_in_execution) {
if (empty($agents) || $disabled_in_execution) {
$disabled_add_button = true;
}
@ -595,7 +679,7 @@ if ($id_downtime > 0) {
echo "<form method=post action='index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&insert_downtime_agent=1&id_downtime=$id_downtime'>";
echo html_print_select ($data, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
echo html_print_select ($agents, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
echo '<h4>' . __('Available modules:') .
ui_print_help_tip (__('Only for type Quiet for downtimes.'), true) . '</h4>';
@ -613,17 +697,20 @@ if ($id_downtime > 0) {
//Start Overview of existing planned downtime
echo '<h4>'.__('Agents planned for this downtime').':</h4>';
$sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id,
tagente.id_os, tagente.id_agente, tagente.id_grupo,
tagente.ultimo_contacto, tplanned_downtime_agents.all_modules
FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime);
// User the $id_groups_str built before
$sql = sprintf("SELECT ta.nombre, tpda.id,
ta.id_os, ta.id_agente, ta.id_grupo,
ta.ultimo_contacto, tpda.all_modules
FROM tagente ta
INNER JOIN tplanned_downtime_agents tpda
ON ta.id_agente = tpda.id_agent
AND tpda.id_downtime = %d
WHERE ta.id_grupo IN (%s)",
$id_downtime, $id_groups_str);
$downtimes_agents = db_get_all_rows_sql ($sql);
$downtimes = db_get_all_rows_sql ($sql);
if ($downtimes === false) {
echo '<div class="nf">' .
__('There are no scheduled downtimes') . '</div>';
if (empty($downtimes_agents)) {
echo '<div class="nf">' . __('There are no agents') . '</div>';
}
else {
$table = new stdClass();
@ -638,24 +725,24 @@ if ($id_downtime > 0) {
$table->head[3] = __('Last contact');
$table->head['count_modules'] = __('Modules');
if (!$executed) {
if (!$running) {
$table->head[5] = __('Actions');
$table->align[5] = "center";
$table->size[5] = "5%";
}
foreach ($downtimes as $downtime) {
foreach ($downtimes_agents as $downtime_agent) {
$data = array ();
$data[0] = $downtime['nombre'];
$data[0] = $downtime_agent['nombre'];
$data[1] = db_get_sql ("SELECT nombre
FROM tgrupo
WHERE id_grupo = " . $downtime["id_grupo"]);
WHERE id_grupo = " . $downtime_agent["id_grupo"]);
$data[2] = ui_print_os_icon($downtime["id_os"], true, true);
$data[2] = ui_print_os_icon($downtime_agent["id_os"], true, true);
$data[3] = $downtime["ultimo_contacto"];
$data[3] = $downtime_agent["ultimo_contacto"];
if ($type_downtime == 'disable_agents_alerts') {
$data['count_modules'] = __("All alerts");
@ -664,7 +751,7 @@ if ($id_downtime > 0) {
$data['count_modules'] = __("Entire agent");
}
else {
if ($downtime["all_modules"]) {
if ($downtime_agent["all_modules"]) {
$data['count_modules'] = __("All modules");
}
else {
@ -672,19 +759,19 @@ if ($id_downtime > 0) {
}
}
if (!$executed) {
if (!$running) {
$data[5] = '';
if ($type_downtime != 'disable_agents_alerts' && $type_downtime != 'disable_agents') {
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' .
$data[5] = '<a href="javascript:show_editor_module(' . $downtime_agent["id_agente"] . ');">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
}
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&id_agent=' . $downtime["id_agente"] .
'&delete_downtime_agent=1&id_downtime_agent=' . $downtime["id"] . '&id_downtime=' . $id_downtime . '">' .
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&id_agent=' . $downtime_agent["id_agente"] .
'&delete_downtime_agent=1&id_downtime_agent=' . $downtime_agent["id"] . '&id_downtime=' . $id_downtime . '">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
}
$table->data['agent_' . $downtime["id_agente"]] = $data;
$table->data['agent_' . $downtime_agent["id_agente"]] = $data;
}
html_print_table ($table);
}

View File

@ -20,9 +20,10 @@ require_once ("../../include/functions.php");
require_once ("../../include/functions_db.php");
require_once ("../../include/functions_users.php");
require_once ("../../include/functions_groups.php");
require_once ("../../include/functions_reporting.php");
$config["id_user"] = $_SESSION["id_usuario"];
if (! check_acl ($config['id_user'], 0, "AW")) {
if (! check_acl ($config['id_user'], 0, "AR")) {
db_pandora_audit("ACL Violation", "Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
@ -43,75 +44,80 @@ $module_name = !empty($module_id) ? (string) get_parameter('module_name') : "";
$separator = (string) get_parameter("separator", ";");
$items_separator = (string) get_parameter("items_separator", ",");
// SQL QUERY CREATION
$where_values = "1=1";
$groups = users_get_groups();
$groups_string = implode (",", array_keys ($groups));
$where_values .= " AND id_group IN ($groups_string)";
if (!empty($groups)) {
// SQL QUERY CREATION
$where_values = "1=1";
if (!empty($search_text)) {
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
}
$groups_string = implode (",", array_keys ($groups));
$where_values .= " AND id_group IN ($groups_string)";
if (!empty($execution_type)) {
$where_values .= " AND type_execution = '$execution_type'";
}
if (!empty($date_from)) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_from >= '".strtotime("$date_from 00:00:00")."'))";
}
if (!empty($date_to)) {
$periodically_monthly_w = "type_periodicity = 'monthly' AND (periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_time_to >= '".date('d', strtotime($date_to))."')";
$periodically_weekly_days = array();
$date_from_aux = strtotime($date_from);
$date_end = strtotime($date_to);
$days_number = 0;
while ($date_from_aux <= $date_end && $days_number < 7) {
$weekday_actual = strtolower(date('l', $date_from_aux));
$periodically_weekly_days[] = "$weekday_actual = 1";
$date_from_aux = $date_from_aux + SECONDS_1DAY;
$days_number++;
if (!empty($search_text)) {
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
}
$periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")";
$periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))";
$once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'";
$where_values .= " AND (($periodically_w) OR ($once_w))";
}
if (!empty($execution_type)) {
$where_values .= " AND type_execution = '$execution_type'";
}
if (!$show_archived) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))";
}
if (!empty($date_from)) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_from >= '".strtotime("$date_from 00:00:00")."'))";
}
if (!empty($agent_id)) {
$where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)";
}
if (!empty($date_to)) {
$periodically_monthly_w = "type_periodicity = 'monthly'
AND ((periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_day_to >= '".date('d', strtotime($date_to))."')
OR (periodically_day_from > periodically_day_to
AND (periodically_day_from <= '".date('d', strtotime($date_from))."' OR periodically_day_to >= '".date('d', strtotime($date_to))."')))";
$periodically_weekly_days = array();
$date_from_aux = strtotime($date_from);
$date_end = strtotime($date_to);
$days_number = 0;
if (!empty($module_id)) {
$where_values .= " AND (id IN (SELECT id_downtime
FROM tplanned_downtime_modules
WHERE id_agent_module = $module_id)
OR id IN (SELECT id_downtime
FROM tplanned_downtime_agents tpda, tagente_modulo tam
WHERE tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo = $module_id
AND tpda.all_modules = 1))";
}
while ($date_from_aux <= $date_end && $days_number < 7) {
$weekday_actual = strtolower(date('l', $date_from_aux));
$periodically_weekly_days[] = "$weekday_actual = 1";
$sql = "SELECT *
FROM tplanned_downtime
WHERE $where_values
ORDER BY type_execution DESC, date_from DESC";
$downtimes = @db_get_all_rows_sql($sql);
$date_from_aux = $date_from_aux + SECONDS_1DAY;
$days_number++;
}
$periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")";
$periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))";
$once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'";
$where_values .= " AND (($periodically_w) OR ($once_w))";
}
if (!$show_archived) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))";
}
if (!empty($agent_id)) {
$where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)";
}
if (!empty($module_id)) {
$where_values .= " AND (id IN (SELECT id_downtime
FROM tplanned_downtime_modules
WHERE id_agent_module = $module_id)
OR id IN (SELECT id_downtime
FROM tplanned_downtime_agents tpda, tagente_modulo tam
WHERE tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo = $module_id
AND tpda.all_modules = 1))";
}
$sql = "SELECT *
FROM tplanned_downtime
WHERE $where_values
ORDER BY type_execution DESC, date_from DESC";
$downtimes = @db_get_all_rows_sql($sql);
}
if (!empty($downtimes)) {
ob_clean();
@ -139,61 +145,8 @@ if (!empty($downtimes)) {
$group = ucfirst(io_safe_output(groups_get_name($downtime['id_group'])));
$type = ucfirst(io_safe_output($downtime['type_downtime']));
$execution_type = ucfirst(io_safe_output($downtime['type_execution']));
switch ($downtime['type_execution']) {
case 'once':
$execution_date = date ("Y-m-d H:i", $downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
date ("Y-m-d H:i", $downtime['date_to']);
break;
case 'periodically':
switch ($downtime['type_periodicity']) {
case 'weekly':
$execution_date = __('Weekly:');
$execution_date .= "&nbsp;";
if ($downtime['monday']) {
$execution_date .= __('Mon');
$execution_date .= "&nbsp;";
}
if ($downtime['tuesday']) {
$execution_date .= __('Tue');
$execution_date .= "&nbsp;";
}
if ($downtime['wednesday']) {
$execution_date .= __('Wed');
$execution_date .= "&nbsp;";
}
if ($downtime['thursday']) {
$execution_date .= __('Thu');
$execution_date .= "&nbsp;";
}
if ($downtime['friday']) {
$execution_date .= __('Fri');
$execution_date .= "&nbsp;";
}
if ($downtime['saturday']) {
$execution_date .= __('Sat');
$execution_date .= "&nbsp;";
}
if ($downtime['sunday']) {
$execution_date .= __('Sun');
$execution_date .= "&nbsp;";
}
$execution_date .= "&nbsp;(" . $downtime['periodically_time_from'];
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$execution_date = __('Monthly:');
$execution_date .= __('From day') . "&nbsp;" . $downtime['periodically_day_from'];
$execution_date .= "/" . __('To day') . "&nbsp;";
$execution_date .= $downtime['periodically_day_to'];
$execution_date .= "&nbsp;(" . $downtime['periodically_time_from'];
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
break;
}
break;
}
$execution_date = io_safe_output($execution_date);
$execution_date = io_safe_output(reporting_format_planned_downtime_dates($downtime));
$affected_items = array();

View File

@ -18,7 +18,10 @@ global $config;
check_login();
if (! check_acl ($config['id_user'], 0, "AW")) {
$read_permisson = check_acl ($config['id_user'], 0, "AR");
$write_permisson = check_acl ($config['id_user'], 0, "AW");
if (! $read_permisson) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
@ -28,6 +31,7 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
require_once ('include/functions_users.php');
require_once ('include/functions_events.php');
require_once ('include/functions_planned_downtimes.php');
require_once ('include/functions_reporting.php');
$malformed_downtimes = planned_downtimes_get_malformed();
$malformed_downtimes_exist = !empty($malformed_downtimes) ? true : false;
@ -52,7 +56,6 @@ ui_print_page_header(
true,
"");
$delete_downtime = (int) get_parameter ('delete_downtime');
$id_downtime = (int) get_parameter ('id_downtime', 0);
$stop_downtime = (bool) get_parameter ('stop_downtime');
@ -60,138 +63,47 @@ $stop_downtime = (bool) get_parameter ('stop_downtime');
if ($stop_downtime) {
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_execution']) {
case 'once':
$date_stop = date ("Y-m-j", get_system_time ());
$time_stop = date ("h:iA", get_system_time ());
$values = array(
'executed' => 0,
'date_to' => strtotime($date_stop . ' ' . $time_stop)
);
$result = db_process_sql_update('tplanned_downtime',
$values, array ('id' => $id_downtime));
break;
case 'periodically':
break;
// Check AW permission on the downtime
if (empty($downtime) || ! check_acl ($config['id_user'], $downtime['id_group'], "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
ui_print_result_message($result,
__('Succesful stopped the Downtime'),
__('Unsuccesful stopped the Downtime'));
$result = planned_downtimes_stop($downtime);
if ($result) {
events_create_event ("Manual stop downtime ".
$downtime['name'] . " (" . $downtime['id'] . ") by " .
$config['id_user'], 0, 0, EVENT_STATUS_NEW, $config["id_user"],
"system", 1);
db_pandora_audit("Planned Downtime management",
"Manual stop downtime " . $downtime['name'] . " (ID " . $downtime['id'] . ")",
false, true);
//Reenabled the Agents or Modules or alerts...depends of type
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_downtime']) {
case 'quiet':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
if ($agent['all_modules']) {
$result = db_process_sql_update('tagente',
array('quiet' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
else {
$modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
array('id_agent' => $agent['id_agent'],
'id_downtime' => $id_downtime));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'tagente_modulo',
array('quiet' => 0),
array('id_agente_modulo' =>
$module['id_agent_module']));
if ($result)
$count++;
}
}
}
break;
case 'disable_agents':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$result = db_process_sql_update('tagente',
array('disabled' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
break;
case 'disable_agents_alerts':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$modules = db_get_all_rows_filter(
'tagente_modulo',
array('id_agente' => $agent['id_agent']));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'talert_template_modules',
array('disabled' => 0),
array('id_agent_module' =>
$module['id_agente_modulo']));
if ($result)
$count++;
}
}
break;
}
ui_print_info_message(
sprintf(__('Enabled %s elements from the downtime'), $count));
if ($result === false) {
ui_print_error_message(__('An error occurred stopping the planned downtime'));
}
else {
echo $result['message'];
}
}
$delete_downtime = (int) get_parameter ('delete_downtime');
// DELETE WHOLE DOWNTIME!
if ($delete_downtime) {
$result = db_process_sql_delete('tplanned_downtime', array('id' => $id_downtime));
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
if ($result === false) {
ui_print_error_message(__('Not deleted. Error deleting data'));
// Check AW permission on the downtime
if (empty($downtime) || ! check_acl ($config['id_user'], $downtime['id_group'], "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// The downtime shouldn't be running!!
if ($downtime['executed']) {
ui_print_error_message(__('This planned downtime is running'));
}
else {
ui_print_success_message(__('Successfully deleted'));
$result = db_process_sql_delete('tplanned_downtime', array('id' => $id_downtime));
ui_print_result_message($result,
__('Successfully deleted'),
__('Not deleted. Error deleting data'));
}
}
@ -263,31 +175,7 @@ $row[] = __('Module') . '&nbsp;' . html_print_autocomplete_modules('module_name'
$row[] = html_print_submit_button('Search', 'search', false, 'class="sub search"', true);
$table_form->data[] = $row;
// View available downtimes present in database (if any of them)
$table = new StdClass();
$table->class = 'databox data';
//Start Overview of existing planned downtime
$table->width = '100%';
$table->cellstyle = array();
$table->data = array();
$table->head = array();
$table->head[0] = __('Name #Ag.');
$table->head[1] = __('Description');
$table->head[2] = __('Group');
$table->head[3] = __('Type');
$table->head[4] = __('Execution');
$table->head[5] = __('Configuration');
$table->head[6] = __('Running');
$table->head[7] = __('Stop downtime');
$table->head[8] = __('Edit');
$table->head[9] = __('Delete');
$table->align[2] = "center";
$table->align[6] = "center";
$table->align[7] = "center";
$table->align[8] = "center";
$table->align[9] = "center";
// End of table filter
$groups = users_get_groups ();
if (!empty($groups)) {
@ -443,121 +331,115 @@ else {
echo "</form>";
ui_pagination($downtimes_number, "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&$filter_params_str", $offset);
// User groups with AW permission
$groupsAW = users_get_groups($config['id_user'], 'AW');
$groupsAW = array_keys($groupsAW);
// View available downtimes present in database (if any of them)
$table = new StdClass();
$table->class = 'databox data';
$table->width = '100%';
$table->cellstyle = array();
$table->head = array();
$table->head['name'] = __('Name #Ag.');
$table->head['description'] = __('Description');
$table->head['group'] = __('Group');
$table->head['type'] = __('Type');
$table->head['execution'] = __('Execution');
$table->head['configuration'] = __('Configuration');
$table->head['running'] = __('Running');
if ($write_permisson) {
$table->head['stop'] = __('Stop downtime');
$table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete');
}
$table->align = array();
$table->align['group'] = "center";
$table->align['running'] = "center";
if ($write_permisson) {
$table->align['stop'] = "center";
$table->align['edit'] = "center";
$table->align['delete'] = "center";
}
$table->data = array();
foreach ($downtimes as $downtime) {
$data = array();
$total = db_get_sql ("SELECT COUNT(id_agent)
FROM tplanned_downtime_agents
WHERE id_downtime = ".$downtime["id"]);
$data[0] = $downtime['name']. " ($total)";
$data[1] = $downtime['description'];
$data[2] = ui_print_group_icon ($downtime['id_group'], true);
$data['name'] = $downtime['name']. " ($total)";
$data['description'] = $downtime['description'];
$data['group'] = ui_print_group_icon ($downtime['id_group'], true);
$type_text = array('quiet' => __('Quiet'),
'disable_agents' => __('Disabled Agents'),
'disable_agents_alerts' => __('Disabled only Alerts'));
$data[3] = $type_text[$downtime['type_downtime']];
$data['type'] = $type_text[$downtime['type_downtime']];
$execution_text = array('once' => __('once'),
'periodically' => __('Periodically'));
$data[4] = $execution_text[$downtime['type_execution']];
$data['execution'] = $execution_text[$downtime['type_execution']];
switch ($downtime['type_execution']) {
case 'once':
$data[5] = date ("Y-m-d H:i:s", $downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
date ("Y-m-d H:i:s", $downtime['date_to']);
break;
case 'periodically':
switch ($downtime['type_periodicity']) {
case 'weekly':
$data[5] = __('Weekly:');
$data[5] .= "&nbsp;";
if ($downtime['monday']) {
$data[5] .= __('Mon');
$data[5] .= "&nbsp;";
}
if ($downtime['tuesday']) {
$data[5] .= __('Tue');
$data[5] .= "&nbsp;";
}
if ($downtime['wednesday']) {
$data[5] .= __('Wed');
$data[5] .= "&nbsp;";
}
if ($downtime['thursday']) {
$data[5] .= __('Thu');
$data[5] .= "&nbsp;";
}
if ($downtime['friday']) {
$data[5] .= __('Fri');
$data[5] .= "&nbsp;";
}
if ($downtime['saturday']) {
$data[5] .= __('Sat');
$data[5] .= "&nbsp;";
}
if ($downtime['sunday']) {
$data[5] .= __('Sun');
$data[5] .= "&nbsp;";
}
$data[5] .= "&nbsp;(" . $downtime['periodically_time_from'];
$data[5] .= "-" . $downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data[5] = __('Monthly:');
$data[5] .= __('From day') . "&nbsp;" . $downtime['periodically_day_from'];
$data[5] .= "/" . __('To day') . "&nbsp;";
$data[5] .= $downtime['periodically_day_to'];
$data[5] .= "&nbsp;(" . $downtime['periodically_time_from'];
$data[5] .= "-" . $downtime['periodically_time_to'] . ")";
break;
}
break;
}
$data['configuration'] = reporting_format_planned_downtime_dates($downtime);
if ($downtime["executed"] == 0) {
$data[6] = html_print_image ("images/pixel_red.png", true,
array ('width' => 20, 'height' => 20, 'alt' => __('Executed')));
$data['running'] = html_print_image ("images/pixel_red.png", true,
array ('width' => 20, 'height' => 20, 'title' => __('Not running')));
}
else {
$data[6] = html_print_image ("images/pixel_green.png", true,
array ('width' => 20, 'height' => 20, 'alt' => __('Not executed')));
$data['running'] = html_print_image ("images/pixel_green.png", true,
array ('width' => 20, 'height' => 20, 'title' => __('Running')));
}
if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) {
// If user have writting permissions
if (in_array($downtime['id_group'], $groupsAW)) {
// Stop button
if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) {
$data['stop'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' .
'&stop_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cancel.png", true, array("title" => __('Stop downtime')));
}
else {
$data['stop'] = "";
}
$data[7] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' .
'&stop_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime')));
// Edit & delete buttons
if ($downtime["executed"] == 0) {
// Edit
$data['edit'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">' .
html_print_image("images/config.png", true, array("title" => __('Update'))) . '</a>';
// Delete
$data['delete'] = '<a id="delete_downtime" href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list'.
'&delete_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cross.png", true, array("title" => __('Delete')));
}
else if ($downtime["executed"] == 1 && $downtime['type_execution'] == 'once') {
// Edit
$data['edit'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime=' . $downtime['id'] . '">' .
html_print_image("images/config.png", true, array("title" => __('Update'))) . '</a>';
// Delete
$data['delete']= __('N/A');
}
else {
$data['edit']= '';
$data['delete']= '';
}
}
else {
$data[7] = "";
}
if ($downtime["executed"] == 0) {
$data[8] = '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&amp;edit_downtime=1&amp;id_downtime='.$downtime['id'].'">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '</a>';
$data[9] = '<a id="delete_downtime" href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list'.
'&delete_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete')));
}
elseif ($downtime["executed"] == 1
&& $downtime['type_execution'] == 'once') {
$data[8] = '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&amp;' .
'edit_downtime=1&amp;id_downtime=' . $downtime['id'] . '">' .
html_print_image("images/config.png", true,
array("border" => '0', "alt" => __('Update'))) . '</a>';
$data[9]= "N/A";
}
else {
$data[8]= "N/A";
$data[9]= "N/A";
$data['stop'] = '';
$data['edit'] = '';
$data['delete'] = '';
}
if (!empty($malformed_downtimes_exist) && isset($malformed_downtimes[$downtime['id']])) {
@ -571,23 +453,28 @@ else {
array_push ($table->data, $data);
}
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
echo '<br>';
// CSV export button
echo '<div style="display: inline;">';
html_print_button(__('Export to CSV'), 'csv_export', false,
"location.href='godmode/agentes/planned_downtime.export_csv.php?$filter_params_str'", 'class="sub next"');
echo '</div>';
echo '&nbsp;';
echo '<form method="post" action="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor" style="display: inline;">';
html_print_submit_button (__('Create'), 'create', false, 'class="sub next"');
echo '</form>';
// Create button
if ($write_permisson) {
echo '&nbsp;';
echo '<form method="post" action="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor" style="display: inline;">';
html_print_submit_button (__('Create'), 'create', false, 'class="sub next"');
echo '</form>';
}
echo '</div>';
}
ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/");
?>

View File

@ -17,10 +17,16 @@
include_once($config['homedir'] . "/include/functions_io.php");
include_once($config['homedir'] . "/include/functions_db.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_groups.php");
$get_modules_downtime = (bool)get_parameter('get_modules_downtime', 0);
$delete_module_from_downtime = (bool)get_parameter('delete_module_from_downtime', 0);
$add_module_into_downtime = (bool)get_parameter('add_module_into_downtime', 0);
ob_clean();
$get_modules_downtime = (bool)get_parameter('get_modules_downtime', 0);
$delete_module_from_downtime = (bool)get_parameter('delete_module_from_downtime', 0);
$add_module_into_downtime = (bool)get_parameter('add_module_into_downtime', 0);
// User groups with AW permission for ACL checks
$user_groups_aw = array_keys(users_get_groups($config['id_user'], 'AW'));
if ($get_modules_downtime) {
$return = array();
@ -28,38 +34,58 @@ if ($get_modules_downtime) {
$return['in_agent'] = array();
$return['in_downtime'] = array();
$id_agent = (int)get_parameter('id_agent', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$none_value = (bool)get_parameter('none_value', false);
$id_agent = (int) get_parameter('id_agent', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$none_value = (bool) get_parameter('none_value', false);
$rows = db_get_all_rows_filter('tplanned_downtime_modules',
array('id_agent' => $id_agent, 'id_downtime' => $id_downtime));
if (empty($rows))
$rows = array();
$id_modules_downtime = array();
foreach ($rows as $row) {
$id_modules_downtime[$row['id_agent_module']] = true;
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$modules = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent));
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$filter = array(
'id_agent' => $id_agent,
'id_downtime' => $id_downtime
);
$downtime_modules = db_get_all_rows_filter('tplanned_downtime_modules', $filter);
if (empty($downtime_modules))
$downtime_modules = array();
$downtime_module_ids = extract_column($downtime_modules, 'id_agent_module');
$downtime_modules = array_fill_keys($downtime_module_ids, true);
$filter = array(
'id_agente' => $id_agent
);
$modules = db_get_all_rows_filter('tagente_modulo', $filter);
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
if (empty($id_modules_downtime[$module['id_agente_modulo']])) {
$return['in_agent'][$module['id_agente_modulo']] = io_safe_output($module['nombre']);
}
else {
$return['in_downtime'][$module['id_agente_modulo']] = io_safe_output($module['nombre']);
}
}
$module_ids = extract_column($modules, 'id_agente_modulo');
$module_names = extract_column($modules, 'nombre');
$modules = array_combine($module_ids, $module_names);
if ($none_value) {
$return['in_downtime'] = array_intersect_key($modules, $downtime_modules);
$return['in_agent'] = array_diff($modules, $return['in_downtime']);
if ($none_value)
$return['in_agent'][0] = __('None');
}
echo json_encode($return);
exit;
return;
}
if ($delete_module_from_downtime) {
@ -68,45 +94,65 @@ if ($delete_module_from_downtime) {
$return['all_modules'] = 0;
$return['id_agent'] = 0;
$id_module = (int)get_parameter('id_module', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$id_module = (int) get_parameter('id_module', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($id_agent === false || $agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$is_running = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
$return['executed'] = 1;
echo json_encode($return);
exit;
return;
}
$row = db_get_row_filter('tplanned_downtime_modules',
array('id_agent_module' => $id_module,
'id_downtime' => $id_downtime));
$return['id_agent'] = $row['id_agent'];
$result = db_process_sql_delete('tplanned_downtime_modules',
array('id_downtime' => $id_downtime,
'id_agent_module' => $id_module));
$return['id_agent'] = $id_agent;
$filter = array(
'id_agent_module' => $id_module,
'id_downtime' => $id_downtime
);
$result = db_process_sql_delete('tplanned_downtime_modules', $filter);
if ($result) {
$rows = db_get_all_rows_filter('tplanned_downtime_modules',
array('id_downtime' => $id_downtime,
'id_agent' => $row['id_agent']));
db_clean_cache();
$filter = array(
'id_agent' => $id_agent,
'id_downtime' => $id_downtime
);
$rows = db_get_all_rows_filter('tplanned_downtime_modules', $filter);
if (empty($rows)) {
db_process_sql_update('tplanned_downtime_agents',
array('all_modules' => 1),
array('id_agent' => $row['id_agent'],
'id_downtime' => $id_downtime));
$values = array('all_modules' => 1);
db_process_sql_update('tplanned_downtime_agents', $values, $filter);
$return['all_modules'] = 1;
$return['id_agent'] = $row['id_agent'];
$return['id_agent'] = $id_agent;
}
$return['correct'] = 1;
}
echo json_encode($return);
exit;
return;
}
if ($add_module_into_downtime) {
@ -114,15 +160,33 @@ if ($add_module_into_downtime) {
$return['correct'] = 0;
$return['name'] = '';
$id_agent = (int)get_parameter('id_agent', 0);
$id_module = (int)get_parameter('id_module', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$id_agent = (int) get_parameter('id_agent', 0);
$id_module = (int) get_parameter('id_module', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$is_running = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
$return['executed'] = 1;
echo json_encode($return);
exit;
return;
}
$values = array();
@ -144,7 +208,7 @@ if ($add_module_into_downtime) {
}
echo json_encode($return);
exit;
return;
}
?>

View File

@ -2457,7 +2457,7 @@ function array2XML($data, $root = null, $xml = NULL) {
function extract_column ($array, $column) {
$column_is_arr = is_array($column);
return array_map(function($item) {
return array_map(function($item) use ($column_is_arr, $column) {
if ($column_is_arr) {
return array_reduce($column, function($carry, $col) use ($item) {
$carry[$col] = $item[$col];

View File

@ -25,7 +25,7 @@ global $config;
/**
* Include the usual functions
*/
// require_once($config["homedir"] . "/include/functions.php");
require_once($config["homedir"] . "/include/functions_ui.php");
// enterprise_include_once('include/functions_inventory.php');
function planned_downtimes_check_dates ($type_execution = 'once', $type_periodicity = '', $datetime_from = false, $datetime_to = false, $periodically_time_from = false, $periodically_time_to = false, $periodically_day_from = false, $periodically_day_to = false) {
@ -518,4 +518,140 @@ function planned_downtimes_migrate_malformed_downtimes_copy_items ($original_dow
return $new_planned_downtimes_exists;
}
/**
* Stop a planned downtime.
*
* @param array Planned downtime data.
*
* @return mixes False on error or an array with the result and a message of the operation.
*/
function planned_downtimes_stop ($downtime) {
$result = false;
$message = '';
if (empty($downtime))
return false;
switch ($downtime['type_execution']) {
case 'once':
$values = array(
'executed' => 0,
'date_to' => time()
);
$result = db_process_sql_update('tplanned_downtime',
$values, array ('id' => $id_downtime));
break;
case 'periodically':
return false;
break;
}
$message .= ui_print_result_message($result,
__('Succesful stopped the Downtime'),
__('Unsuccesful stopped the Downtime'),
true);
if ($result) {
events_create_event ("Manual stop downtime ".
$downtime['name'] . " (" . $downtime['id'] . ") by " .
$config['id_user'], 0, 0, EVENT_STATUS_NEW, $config["id_user"],
"system", 1);
db_pandora_audit("Planned Downtime management",
"Manual stop downtime " . $downtime['name'] . " (ID " . $downtime['id'] . ")",
false, true);
//Reenabled the Agents or Modules or alerts...depends of type
switch ($downtime['type_downtime']) {
case 'quiet':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
if ($agent['all_modules']) {
$result = db_process_sql_update('tagente',
array('quiet' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
else {
$modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
array('id_agent' => $agent['id_agent'],
'id_downtime' => $id_downtime));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'tagente_modulo',
array('quiet' => 0),
array('id_agente_modulo' =>
$module['id_agent_module']));
if ($result)
$count++;
}
}
}
break;
case 'disable_agents':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$result = db_process_sql_update('tagente',
array('disabled' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
break;
case 'disable_agents_alerts':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$modules = db_get_all_rows_filter(
'tagente_modulo',
array('id_agente' => $agent['id_agent']));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'talert_template_modules',
array('disabled' => 0),
array('id_agent_module' =>
$module['id_agente_modulo']));
if ($result)
$count++;
}
}
break;
}
$message .= ui_print_info_message(
sprintf(__('Enabled %s elements from the downtime'), $count), true);
}
return array('result' => $result, 'message' => $message);
}
?>