Merge branch 'feature/ticket#1243-PlannedDowntime' into develop
This commit is contained in:
commit
eeb9725334
|
@ -25,6 +25,7 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
|
|||
return;
|
||||
}
|
||||
|
||||
$config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $config["past_planned_downtimes"] : 1;
|
||||
|
||||
require_once ('include/functions_users.php');
|
||||
|
||||
|
@ -51,7 +52,7 @@ $once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT));
|
|||
$periodically_day_from = (int) get_parameter ('periodically_day_from', 1);
|
||||
$periodically_day_to = (int) get_parameter ('periodically_day_to', 31);
|
||||
$periodically_time_from = (string) get_parameter ('periodically_time_from', date(TIME_FORMAT));
|
||||
$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT));
|
||||
$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
|
||||
|
||||
$first_create = (int) get_parameter ('first_create', 0);
|
||||
|
||||
|
@ -152,12 +153,19 @@ if ($create_downtime || $update_downtime) {
|
|||
$datetime_to = strtotime ($once_date_to . ' ' . $once_time_to);
|
||||
$now = strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT));
|
||||
|
||||
if ($datetime_from < $now) {
|
||||
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' ));
|
||||
}
|
||||
else if ($datetime_from >= $datetime_to) {
|
||||
ui_print_error_message(__('Not created. Error inserting data' ).
|
||||
': START >= END');
|
||||
else if ($type_execution == 'once' && $datetime_from >= $datetime_to) {
|
||||
ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end date must be higher than the start date'));
|
||||
}
|
||||
else if ($type_execution == 'periodically'
|
||||
&& (($type_periodicity == 'weekly' && $periodically_time_from >= $periodically_time_to)
|
||||
|| ($type_periodicity == 'monthly' && $periodically_day_from == $periodically_day_to && $periodically_time_from >= $periodically_time_to))) {
|
||||
ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end time must be higher than the start time'));
|
||||
}
|
||||
else if ($type_execution == 'periodically' && $type_periodicity == 'monthly' && $periodically_day_from >= $periodically_day_to) {
|
||||
ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end day must be higher than the start day'));
|
||||
}
|
||||
else {
|
||||
$sql = '';
|
||||
|
@ -323,35 +331,35 @@ $table->data[3][1] = html_print_select(array('quiet' => __('Quiet'),
|
|||
'type_downtime', $type_downtime, 'change_type_downtime()', '', 0, true, false, true,
|
||||
'');
|
||||
$table->data[4][0] = __('Execution');
|
||||
$table->data[4][1] = html_print_select(array('once' => __('once'),
|
||||
$table->data[4][1] = html_print_select(array('once' => __('Once'),
|
||||
'periodically' => __('Periodically')),
|
||||
'type_execution', $type_execution, 'change_type_execution();', '', 0, true);
|
||||
|
||||
$days = array_combine(range(1, 31), range(1, 31));
|
||||
$table->data[5][0] = __('Configure the time');
|
||||
$table->data[5][0] = __('Configure the time') . " " . ui_print_help_icon ('planned_downtime_time', true);;
|
||||
$table->data[5][1] = "
|
||||
<div id='once_time' style='display: none;'>
|
||||
<table>
|
||||
<tr>
|
||||
<td>" .
|
||||
__('From:') .
|
||||
ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) .
|
||||
"</td>
|
||||
<td>".
|
||||
html_print_input_text ('once_date_from', $once_date_from, '', 10, 10, true) .
|
||||
html_print_input_text ('once_time_from', $once_time_from, '', 9, 9, true) .
|
||||
ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) .
|
||||
html_print_input_text ('once_time_from', $once_time_from, '', 9, 9, true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) .
|
||||
"</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>" .
|
||||
__('To:') .
|
||||
ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) .
|
||||
"</td>
|
||||
<td>".
|
||||
html_print_input_text ('once_date_to', $once_date_to, '', 10, 10, true) .
|
||||
html_print_input_text ('once_time_to', $once_time_to, '', 9, 9, true) .
|
||||
ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) .
|
||||
html_print_input_text ('once_time_to', $once_time_to, '', 9, 9, true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) .
|
||||
"</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -359,8 +367,7 @@ $table->data[5][1] = "
|
|||
<div id='periodically_time' style='display: none;'>
|
||||
<table>
|
||||
<tr>
|
||||
<td>" . __('Type Periodicity:') . "</td>
|
||||
<td>".
|
||||
<td>" . __('Type Periodicity:') . " ".
|
||||
html_print_select(array(
|
||||
'weekly' => __('Weekly'),
|
||||
'monthly' => __('Monthly')),
|
||||
|
@ -407,6 +414,7 @@ $table->data[5][1] = "
|
|||
html_print_select($days,
|
||||
'periodically_day_to', $periodically_day_to, '', '', 0, true) .
|
||||
"</td>
|
||||
<td>" . ui_print_help_tip(__('The end day must be higher than the start day'), true) . "</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
|
@ -416,12 +424,16 @@ $table->data[5][1] = "
|
|||
html_print_input_text (
|
||||
'periodically_time_from',
|
||||
$periodically_time_from, '', 7, 7, true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds').
|
||||
".<br>".__('The end time must be higher than the start time'), true) .
|
||||
"</td>
|
||||
<td>" . __('To hour:') . "</td>
|
||||
<td>".
|
||||
html_print_input_text (
|
||||
'periodically_time_to',
|
||||
$periodically_time_to, '', 7, 7, true) .
|
||||
$periodically_time_to, '', 7, 7, true) .
|
||||
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds').
|
||||
".<br>".__('The end time must be higher than the start time'), true) .
|
||||
"</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -511,7 +523,7 @@ if ($id_downtime > 0) {
|
|||
echo html_print_select (array(), "module[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
|
||||
echo "</div>";
|
||||
echo "<br /><br /><br />";
|
||||
html_print_submit_button (__('Add'), '', $disabled_add_button, 'class="sub next"',false);
|
||||
html_print_submit_button (__('Add'), 'add_item', $disabled_add_button, 'class="sub next"',false);
|
||||
echo "</form>";
|
||||
echo "</table>";
|
||||
|
||||
|
@ -969,5 +981,18 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
|
|||
$("#id_agent").blur (function () {
|
||||
$(this).css ("width", "180px");
|
||||
});
|
||||
|
||||
// Warning message about the problems caused updating a past planned downtime
|
||||
var type_execution = "<?php echo $type_execution; ?>";
|
||||
var datetime_from = <?php echo json_encode(strtotime($once_date_from . ' ' . $once_time_from)); ?>;
|
||||
var datetime_now = <?php echo json_encode(strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT))); ?>;
|
||||
var create = <?php echo json_encode($create); ?>;
|
||||
if (!create && (type_execution == 'periodically' || (type_execution == 'once' && datetime_from < datetime_now))) {
|
||||
$("input#submit-updbutton, input#submit-add_item, table#list a").click(function (e) {
|
||||
if (!confirm("<?php echo __('WARNING: If you edit this planned downtime, the data of future SLA reports may be altered'); ?>")) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// 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 for version 2.
|
||||
// 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.
|
||||
|
||||
session_start ();
|
||||
|
||||
require_once ("../../include/config.php");
|
||||
require_once ("../../include/functions.php");
|
||||
require_once ("../../include/functions_db.php");
|
||||
require_once ("../../include/functions_users.php");
|
||||
require_once ("../../include/functions_groups.php");
|
||||
|
||||
$config["id_user"] = $_SESSION["id_usuario"];
|
||||
if (! check_acl ($config['id_user'], 0, "AW")) {
|
||||
db_pandora_audit("ACL Violation", "Trying to access downtime scheduler");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter parameters
|
||||
$offset = (int) get_parameter('offset');
|
||||
$search_text = (string) get_parameter('search_text');
|
||||
$date_from = (string) get_parameter('date_from');
|
||||
$date_to = (string) get_parameter('date_to');
|
||||
$execution_type = (string) get_parameter('execution_type');
|
||||
$show_archived = (bool) get_parameter('archived');
|
||||
$agent_id = (int) get_parameter('agent_id');
|
||||
$agent_name = !empty($agent_id) ? (string) get_parameter('agent_name') : "";
|
||||
$module_id = (int) get_parameter('module_name_hidden');
|
||||
$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($search_text)) {
|
||||
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
$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);
|
||||
html_debug_print($sql);
|
||||
html_debug_print($downtimes);
|
||||
if (!empty($downtimes)) {
|
||||
ob_clean();
|
||||
// Show contentype header
|
||||
Header("Content-type: text/csv");
|
||||
header('Content-Disposition: attachment; filename="pandora_planned_downtime_'.date("Y/m/d H:i:s").'.csv"');
|
||||
|
||||
$titles = array();
|
||||
$titles[] = "id";
|
||||
$titles[] = "name";
|
||||
$titles[] = "description";
|
||||
$titles[] = "group";
|
||||
$titles[] = "type";
|
||||
$titles[] = "execution_type";
|
||||
$titles[] = "execution_date";
|
||||
$titles[] = "affected_items";
|
||||
|
||||
echo implode($separator, $titles);
|
||||
echo chr(13);
|
||||
|
||||
foreach ($downtimes as $downtime) {
|
||||
$id = $downtime['id'];
|
||||
$name = io_safe_output($downtime['name']);
|
||||
$description = io_safe_output($downtime['description']);
|
||||
$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']) .
|
||||
" " . __('to') . " ".
|
||||
date ("Y-m-d H:i", $downtime['date_to']);
|
||||
break;
|
||||
case 'periodically':
|
||||
switch ($downtime['type_periodicity']) {
|
||||
case 'weekly':
|
||||
$execution_date = __('Weekly:');
|
||||
$execution_date .= " ";
|
||||
if ($downtime['monday']) {
|
||||
$execution_date .= __('Mon');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['tuesday']) {
|
||||
$execution_date .= __('Tue');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['wednesday']) {
|
||||
$execution_date .= __('Wed');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['thursday']) {
|
||||
$execution_date .= __('Thu');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['friday']) {
|
||||
$execution_date .= __('Fri');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['saturday']) {
|
||||
$execution_date .= __('Sat');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
if ($downtime['sunday']) {
|
||||
$execution_date .= __('Sun');
|
||||
$execution_date .= " ";
|
||||
}
|
||||
$execution_date .= " (" . $downtime['periodically_time_from'];
|
||||
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
case 'monthly':
|
||||
$execution_date = __('Monthly:');
|
||||
$execution_date .= __('From day') . " " . $downtime['periodically_day_from'];
|
||||
$execution_date .= "/" . __('To day') . " ";
|
||||
$execution_date .= $downtime['periodically_day_to'];
|
||||
$execution_date .= " (" . $downtime['periodically_time_from'];
|
||||
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$execution_date = io_safe_output($execution_date);
|
||||
|
||||
$affected_items = array();
|
||||
|
||||
$sql_agents = "SELECT tpda.id_agent AS agent_id, tpda.all_modules AS all_modules, ta.nombre AS agent_name
|
||||
FROM tplanned_downtime_agents tpda, tagente ta
|
||||
WHERE tpda.id_downtime = $id
|
||||
AND tpda.id_agent = ta.id_agente";
|
||||
$downtime_agents = @db_get_all_rows_sql($sql_agents);
|
||||
|
||||
if (!empty($downtime_agents)) {
|
||||
foreach ($downtime_agents as $downtime_agent) {
|
||||
$downtime_items = array();
|
||||
$downtime_items[] = $downtime_agent['agent_name'];
|
||||
|
||||
if (!$downtime_agent['all_modules']) {
|
||||
$agent_id = $downtime_agent['agent_id'];
|
||||
$sql_modules = "SELECT tpdm.id_agent_module AS module_id, tam.nombre AS module_name
|
||||
FROM tplanned_downtime_modules tpdm, tagente_modulo tam
|
||||
WHERE tpdm.id_downtime = $id
|
||||
AND tpdm.id_agent = $agent_id
|
||||
AND tpdm.id_agent_module = tam.id_agente_modulo";
|
||||
$downtime_modules = @db_get_all_rows_sql($sql_modules);
|
||||
|
||||
if (!empty($downtime_modules)) {
|
||||
foreach ($downtime_modules as $downtime_module) {
|
||||
$downtime_items[] = $downtime_module['module_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$affected_items[] = "[".implode("|", $downtime_items)."]";
|
||||
}
|
||||
}
|
||||
$affected_items = implode(",", $affected_items);
|
||||
|
||||
$values = array();
|
||||
$values[] = $id;
|
||||
$values[] = $name;
|
||||
$values[] = $description;
|
||||
$values[] = $group;
|
||||
$values[] = $type;
|
||||
$values[] = $execution_type;
|
||||
$values[] = $execution_date;
|
||||
$values[] = $affected_items;
|
||||
|
||||
echo implode($separator, $values);
|
||||
echo chr(13);
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo '<div class="nf">'.__('No planned downtime').'</div>';
|
||||
}
|
||||
?>
|
|
@ -180,9 +180,95 @@ if ($delete_downtime) {
|
|||
}
|
||||
}
|
||||
|
||||
$groups = users_get_groups ();
|
||||
// Filter parameters
|
||||
$offset = (int) get_parameter('offset');
|
||||
$search_text = (string) get_parameter('search_text');
|
||||
$date_from = (string) get_parameter('date_from');
|
||||
$date_to = (string) get_parameter('date_to');
|
||||
$execution_type = (string) get_parameter('execution_type');
|
||||
$show_archived = (bool) get_parameter('archived');
|
||||
$agent_id = (int) get_parameter('agent_id');
|
||||
$agent_name = !empty($agent_id) ? (string) get_parameter('agent_name') : "";
|
||||
$module_id = (int) get_parameter('module_name_hidden');
|
||||
$module_name = !empty($module_id) ? (string) get_parameter('module_name') : "";
|
||||
|
||||
$filter_params = array();
|
||||
$filter_params['search_text'] = $search_text;
|
||||
$filter_params['date_from'] = $date_from;
|
||||
$filter_params['date_to'] = $date_to;
|
||||
$filter_params['execution_type'] = $execution_type;
|
||||
$filter_params['archived'] = $show_archived;
|
||||
$filter_params['agent_id'] = $agent_id;
|
||||
$filter_params['agent_name'] = $agent_name;
|
||||
$filter_params['module_id'] = $module_id;
|
||||
$filter_params['module_name'] = $module_name;
|
||||
|
||||
$filter_params_aux = array();
|
||||
foreach ($filter_params as $name => $value) {
|
||||
$filter_params_aux[] = is_bool($value) ? $name."=".(int)$value : "$name=$value";
|
||||
}
|
||||
$filter_params_str = !empty($filter_params_aux) ? implode("&", $filter_params_aux) : "";
|
||||
|
||||
// Table filter
|
||||
$table = new StdClass();
|
||||
$table->class = 'databox';
|
||||
$table->width = '99%';
|
||||
$table->rowstyle = array();
|
||||
$table->rowstyle[0] = "background-color: #f9faf9;";
|
||||
$table->rowstyle[1] = "background-color: #f9faf9;";
|
||||
$table->rowstyle[2] = "background-color: #f9faf9;";
|
||||
$table->data = array();
|
||||
|
||||
$row = array();
|
||||
|
||||
// Search text
|
||||
$row[] = __('Search') . ' ' . html_print_input_text("search_text", $search_text, '', 50, 250, true);
|
||||
// Dates
|
||||
$date_inputs = __('From') . ' ' . html_print_input_text('date_from', $date_from, '', 10, 10, true);
|
||||
$date_inputs .= " ";
|
||||
$date_inputs .= __('To') . ' ' . html_print_input_text('date_to', $date_to, '', 10, 10, true);
|
||||
$row[] = $date_inputs;
|
||||
|
||||
$table->data[] = $row;
|
||||
|
||||
$row = array();
|
||||
|
||||
// Execution type
|
||||
$execution_type_fields = array('once' => __('Once'), 'periodically' => __('Periodically'));
|
||||
$row[] = __('Execution type') . ' ' . html_print_select($execution_type_fields, 'execution_type', $execution_type, '', __('Any'), '', true, false, false);
|
||||
// Show past downtimes
|
||||
$row[] = __('Show past downtimes') . ' ' . html_print_checkbox ("archived", 1, $show_archived, true);
|
||||
|
||||
$table->data[] = $row;
|
||||
|
||||
$row = array();
|
||||
|
||||
// Agent
|
||||
$params = array();
|
||||
$params['show_helptip'] = true;
|
||||
$params['input_name'] = 'agent_name';
|
||||
$params['value'] = $agent_name;
|
||||
$params['return'] = true;
|
||||
$params['print_hidden_input_idagent'] = true;
|
||||
$params['hidden_input_idagent_name'] = 'agent_id';
|
||||
$params['hidden_input_idagent_value'] = $agent_id;
|
||||
$agent_input = __('Agent') . ' ' . ui_print_agent_autocomplete_input($params);
|
||||
$row[] = $agent_input;
|
||||
|
||||
// Module
|
||||
$module_input = __('Module') . ' ' . html_print_autocomplete_modules('module_name', $module_name, false, true, '', array(), true);
|
||||
$row[] = $module_input;
|
||||
|
||||
$row[] = html_print_submit_button('Search', 'search', false, 'class="sub search"', true);
|
||||
|
||||
$table->data[] = $row;
|
||||
|
||||
echo "<form method='post' action='index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list'>";
|
||||
html_print_table($table);
|
||||
echo "</form>";
|
||||
|
||||
// View available downtimes present in database (if any of them)
|
||||
$table = new StdClass();
|
||||
$table->class = 'databox';
|
||||
//Start Overview of existing planned downtime
|
||||
$table->width = '98%';
|
||||
|
@ -194,10 +280,10 @@ $table->head[2] = __('Group');
|
|||
$table->head[3] = __('Type');
|
||||
$table->head[4] = __('Execution');
|
||||
$table->head[5] = __('Configuration');
|
||||
$table->head[6] = __('Delete');
|
||||
$table->head[7] = __('Update');
|
||||
$table->head[8] = __('Running');
|
||||
$table->head[9] = __('Stop downtime');
|
||||
$table->head[6] = __('Running');
|
||||
$table->head[7] = __('Stop downtime');
|
||||
$table->head[8] = __('Edit');
|
||||
$table->head[9] = __('Delete');
|
||||
$table->align[2] = "center";
|
||||
//$table->align[5] = "center";
|
||||
$table->align[6] = "center";
|
||||
|
@ -205,11 +291,85 @@ $table->align[7] = "center";
|
|||
$table->align[8] = "center";
|
||||
$table->align[9] = "center";
|
||||
|
||||
$groups = users_get_groups ();
|
||||
if(!empty($groups)) {
|
||||
$where_values = "1=1";
|
||||
|
||||
$groups_string = implode (",", array_keys ($groups));
|
||||
$where_values .= " AND id_group IN ($groups_string)";
|
||||
|
||||
if (!empty($search_text)) {
|
||||
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
|
||||
}
|
||||
|
||||
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_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;
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
$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 id_group IN (" . implode (",", array_keys ($groups)) . ")";
|
||||
FROM tplanned_downtime
|
||||
WHERE $where_values
|
||||
ORDER BY type_execution DESC, date_from DESC
|
||||
LIMIT ".$config["block_size"]."
|
||||
OFFSET $offset";
|
||||
$sql_count = "SELECT COUNT(id) AS num
|
||||
FROM tplanned_downtime
|
||||
WHERE $where_values";
|
||||
$downtimes = db_get_all_rows_sql ($sql);
|
||||
$downtimes_number_res = db_get_all_rows_sql($sql_count);
|
||||
$downtimes_number = $downtimes_number_res != false ? $downtimes_number_res[0]['num'] : 0;
|
||||
}
|
||||
else {
|
||||
$downtimes = array();
|
||||
|
@ -219,6 +379,8 @@ if (!$downtimes) {
|
|||
echo '<div class="nf">'.__('No planned downtime').'</div>';
|
||||
}
|
||||
else {
|
||||
ui_pagination($downtimes_number, "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&$filter_params_str", $offset);
|
||||
|
||||
foreach ($downtimes as $downtime) {
|
||||
$data = array();
|
||||
$total = db_get_sql ("SELECT COUNT(id_agent)
|
||||
|
@ -295,44 +457,71 @@ else {
|
|||
}
|
||||
|
||||
if ($downtime["executed"] == 0) {
|
||||
$data[6] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list&'.
|
||||
'delete_downtime=1&id_downtime='.$downtime['id'].'">' .
|
||||
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete')));
|
||||
$data[7] = '<a
|
||||
href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">' .
|
||||
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '</a>';
|
||||
}
|
||||
else {
|
||||
$data[6]= "N/A";
|
||||
$data[7]= "N/A";
|
||||
|
||||
}
|
||||
if ($downtime["executed"] == 0) {
|
||||
$data[8] = html_print_image ("images/pixel_red.png", true,
|
||||
$data[6] = html_print_image ("images/pixel_red.png", true,
|
||||
array ('width' => 20, 'height' => 20, 'alt' => __('Executed')));
|
||||
}
|
||||
else {
|
||||
$data[8] = html_print_image ("images/pixel_green.png", true,
|
||||
$data[6] = html_print_image ("images/pixel_green.png", true,
|
||||
array ('width' => 20, 'height' => 20, 'alt' => __('Not executed')));
|
||||
}
|
||||
|
||||
|
||||
if (($downtime['type_execution'] == 'once')
|
||||
&& ($downtime["executed"] == 1)) {
|
||||
if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) {
|
||||
|
||||
$data[9] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list&' .
|
||||
$data[7] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list&' .
|
||||
'stop_downtime=1&' .
|
||||
'id_downtime=' . $downtime['id'] . '">' .
|
||||
html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime')));
|
||||
}
|
||||
else {
|
||||
$data[7] = "";
|
||||
}
|
||||
|
||||
if ($downtime["executed"] == 0) {
|
||||
$data[8] = '<a
|
||||
href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&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'].'">' .
|
||||
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete')));
|
||||
}
|
||||
else {
|
||||
$data[8]= "N/A";
|
||||
$data[9]= "N/A";
|
||||
|
||||
}
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
html_print_table ($table);
|
||||
}
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
|
||||
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.editor">';
|
||||
echo '<br>';
|
||||
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 ' ';
|
||||
echo '<form method="post" action="index.php?sec=gagente&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/");
|
||||
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
$("input[name=module_name_hidden]").val(<?php echo (int)$module_id; ?>);
|
||||
|
||||
$(document).ready (function () {
|
||||
$("#text-date_from, #text-date_to").datepicker({dateFormat: "<?php echo DATE_FORMAT_JS; ?>"});
|
||||
$.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]);
|
||||
|
||||
$("a#delete_downtime").click(function (e) {
|
||||
if (!confirm("<?php echo __('WARNING: If you delete this planned downtime, it will not be taken into account in future SLA reports'); ?>")) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
|
@ -263,6 +263,12 @@ $table->data['tutorial_mode'][1] =
|
|||
html_print_select($modes_tutorial, 'tutorial_mode',
|
||||
$config["tutorial_mode"], '', '', 0, true);
|
||||
|
||||
$config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $config["past_planned_downtimes"] : 1;
|
||||
$table->data[33][0] = __('Allow create planned downtimes in the past') .
|
||||
ui_print_help_tip(__('The planned downtimes created in the past will affect the SLA reports'), true);
|
||||
$table->data[33][1] = __('Yes').' '.html_print_radio_button ('past_planned_downtimes', 1, '', $config["past_planned_downtimes"], true).' ';
|
||||
$table->data[33][1] .= __('No').' '.html_print_radio_button ('past_planned_downtimes', 0, '', $config["past_planned_downtimes"], true);
|
||||
|
||||
echo '<form id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&section=general&pure='.$config['pure'].'">';
|
||||
|
||||
echo "<fieldset>";
|
||||
|
|
|
@ -48,7 +48,7 @@ if ($get_plugin_macros) {
|
|||
|
||||
if ($search_modules) {
|
||||
$id_agents = json_decode(io_safe_output(get_parameter('id_agents')));
|
||||
$filter = get_parameter('q', '') . '%';
|
||||
$filter = '%' . get_parameter('q', '') . '%';
|
||||
$other_filter = json_decode(io_safe_output(get_parameter('other_filter')), true);
|
||||
|
||||
$modules = agents_get_modules($id_agents, false,
|
||||
|
|
|
@ -184,6 +184,8 @@ function config_update_config () {
|
|||
$error_update[] = __('Server logs directory');
|
||||
if (!config_update_value ('tutorial_mode', get_parameter('tutorial_mode')))
|
||||
$error_update[] = __('Tutorial mode');
|
||||
if (!config_update_value ('past_planned_downtimes', get_parameter('past_planned_downtimes')))
|
||||
$error_update[] = __('Allow create planned downtimes in the past');
|
||||
break;
|
||||
case 'enterprise':
|
||||
if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) {
|
||||
|
|
|
@ -2015,6 +2015,12 @@ function html_print_autocomplete_modules($name = 'module',
|
|||
}
|
||||
});
|
||||
},
|
||||
change: function( event, ui ) {
|
||||
if (!ui.item)
|
||||
$("input[name='<?php echo $name; ?>_hidden']")
|
||||
.val(0);
|
||||
return false;
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
$("input[name='<?php echo $name; ?>_hidden']")
|
||||
.val(ui.item.value);
|
||||
|
|
|
@ -470,27 +470,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu
|
|||
$interval_data = array ();
|
||||
}
|
||||
|
||||
//calculate planned downtime dates
|
||||
$id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agent_module);
|
||||
$sql_downtime = "SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent=$id_agent";
|
||||
$downtimes = db_get_all_rows_sql($sql_downtime);
|
||||
if ($downtimes == false) {
|
||||
$downtimes = array();
|
||||
}
|
||||
$i = 0;
|
||||
$downtime_dates = array();
|
||||
foreach ($downtimes as $downtime) {
|
||||
$id_downtime = $downtime['id_downtime'];
|
||||
$sql_date = "SELECT date_from, date_to FROM tplanned_downtime WHERE id=$id_downtime";
|
||||
$date_downtime = db_get_row_sql($sql_date);
|
||||
|
||||
if ($date_downtime != false) {
|
||||
$downtime_dates[$i]['date_from'] = $date_downtime['date_from'];
|
||||
$downtime_dates[$i]['date_to'] = $date_downtime['date_to'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
/////
|
||||
// Calculate planned downtime dates
|
||||
$downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date, true);
|
||||
|
||||
// Get previous data
|
||||
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
|
||||
|
@ -761,43 +742,27 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
|
|||
//------------------------------------------------------------------
|
||||
|
||||
//--------Calculate planned downtime dates--------------------------
|
||||
$id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agent_module);
|
||||
$sql_downtime = "SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent=$id_agent";
|
||||
$downtimes = db_get_all_rows_sql($sql_downtime);
|
||||
if ($downtimes == false) {
|
||||
$downtimes = array();
|
||||
}
|
||||
$i = 0;
|
||||
$downtime_dates = array();
|
||||
|
||||
foreach ($downtimes as $downtime) {
|
||||
$id_downtime = $downtime['id_downtime'];
|
||||
$sql_date = "SELECT date_from, date_to FROM tplanned_downtime WHERE id=$id_downtime";
|
||||
$date_downtime = db_get_row_sql($sql_date);
|
||||
$downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date, true);
|
||||
|
||||
foreach ($downtime_dates as $downtime_date) {
|
||||
// Delete data of the planned downtime and put the last data on the upper limit
|
||||
$interval_data_indexed[$downtime_date['date_from']]['data'] = 0;
|
||||
$interval_data_indexed[$downtime_date['date_from']]['status'] = 5;
|
||||
$interval_data_indexed[$downtime_date['date_to']]['data'] = 0;
|
||||
$interval_data_indexed[$downtime_date['date_to']]['status'] = 4;
|
||||
|
||||
if ($date_downtime != false) {
|
||||
// Delete data of the planned downtime and put the last data on the upper limit
|
||||
$interval_data_indexed[$date_downtime['date_from']]['data'] = 0;
|
||||
$interval_data_indexed[$date_downtime['date_from']]['status'] = 5;
|
||||
|
||||
$last_downtime_data = false;
|
||||
foreach ($interval_data_indexed as $idi_timestamp => $idi) {
|
||||
if ($idi_timestamp != $date_downtime['date_from'] && $idi_timestamp != $date_downtime['date_to'] &&
|
||||
$idi_timestamp >= $date_downtime['date_from'] && $idi_timestamp <= $date_downtime['date_to']) {
|
||||
$last_downtime_data = $idi['data'];
|
||||
unset($interval_data_indexed[$idi_timestamp]);
|
||||
}
|
||||
$last_downtime_data = false;
|
||||
foreach ($interval_data_indexed as $idi_timestamp => $idi) {
|
||||
if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] &&
|
||||
$idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) {
|
||||
$last_downtime_data = $idi['data'];
|
||||
unset($interval_data_indexed[$idi_timestamp]);
|
||||
}
|
||||
|
||||
// Set the last data of the interval as limit
|
||||
if ($last_downtime_data !== false) {
|
||||
$interval_data_indexed[$date_downtime['date_to']]['data'] = $last_downtime_data;
|
||||
}// If there arent data into the downtime, set unknown
|
||||
else {
|
||||
$interval_data_indexed[$date_downtime['date_to']]['data'] = 0;
|
||||
$interval_data_indexed[$date_downtime['date_to']]['status'] = 4;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Set the last data of the interval as limit
|
||||
if ($last_downtime_data !== false) {
|
||||
$interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
|
@ -895,6 +860,337 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
|
|||
return $data_colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time intervals where an agentmodule is affected by the planned downtimes.
|
||||
*
|
||||
* @param int Agent module to calculate planned downtimes intervals.
|
||||
* @param int Start date in utimestamp.
|
||||
* @param int End date in utimestamp.
|
||||
* @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule.
|
||||
*
|
||||
* @return Array with time intervals.
|
||||
*/
|
||||
function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) {
|
||||
$sql_downtime = "SELECT DISTINCT(tpd.id), tpd.*
|
||||
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tplanned_downtime_modules tpdm, tagente_modulo tam
|
||||
WHERE (tpd.id = tpda.id_downtime
|
||||
AND tpda.all_modules = 1
|
||||
AND tpda.id_agent = tam.id_agente
|
||||
AND tam.id_agente_modulo = $id_agent_module)
|
||||
OR (tpd.id = tpdm.id_downtime
|
||||
AND tpdm.id_agent_module = $id_agent_module)";
|
||||
$downtimes = db_get_all_rows_sql($sql_downtime);
|
||||
if ($downtimes == false) {
|
||||
$downtimes = array();
|
||||
}
|
||||
$downtime_dates = array();
|
||||
foreach ($downtimes as $downtime) {
|
||||
$downtime_id = $downtime['id'];
|
||||
$downtime_type = $downtime['type_execution'];
|
||||
$downtime_periodicity = $downtime['type_periodicity'];
|
||||
|
||||
if ($downtime_type == 'once') {
|
||||
$dates = array();
|
||||
$dates['date_from'] = $downtime['date_from'];
|
||||
$dates['date_to'] = $downtime['date_to'];
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
else if ($downtime_type == 'periodically') {
|
||||
$downtime_time_from = $downtime['periodically_time_from'];
|
||||
$downtime_time_to = $downtime['periodically_time_to'];
|
||||
|
||||
$downtime_hour_from = date("H", strtotime($downtime_time_from));
|
||||
$downtime_minute_from = date("i", strtotime($downtime_time_from));
|
||||
$downtime_second_from = date("s", strtotime($downtime_time_from));
|
||||
$downtime_hour_to = date("H", strtotime($downtime_time_to));
|
||||
$downtime_minute_to = date("i", strtotime($downtime_time_to));
|
||||
$downtime_second_to = date("s", strtotime($downtime_time_to));
|
||||
|
||||
if ($downtime_periodicity == "monthly") {
|
||||
$downtime_day_from = $downtime['periodically_day_from'];
|
||||
$downtime_day_to = $downtime['periodically_day_to'];
|
||||
|
||||
$date_aux = strtotime(date("Y-m-01", $start_date));
|
||||
$year_aux = date("Y", $date_aux);
|
||||
$month_aux = date("m", $date_aux);
|
||||
|
||||
$end_year = date("Y", $end_date);
|
||||
$end_month = date("m", $end_date);
|
||||
|
||||
while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) {
|
||||
|
||||
if ($downtime_day_from > $downtime_day_to) {
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59")));
|
||||
$downtime_dates[] = $dates;
|
||||
|
||||
$dates = array();
|
||||
if ($month_aux + 1 <= 12) {
|
||||
$dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00");
|
||||
$dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
else {
|
||||
$dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00");
|
||||
$dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
else {
|
||||
if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) {
|
||||
$date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$max_day_num = date('t', $date_aux);
|
||||
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59");
|
||||
$downtime_dates[] = $dates;
|
||||
|
||||
if ($downtime_day_to + 1 > $max_day_num) {
|
||||
|
||||
$dates = array();
|
||||
if ($month_aux + 1 <= 12) {
|
||||
$dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00");
|
||||
$dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
else {
|
||||
$dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00");
|
||||
$dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
else {
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00");
|
||||
$dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
}
|
||||
|
||||
$month_aux++;
|
||||
if ($month_aux > 12) {
|
||||
$month_aux = 1;
|
||||
$year_aux++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($downtime_periodicity == "weekly") {
|
||||
$date_aux = $start_date;
|
||||
$active_days = array();
|
||||
$active_days[0] = ($downtime['sunday'] == 1) ? true : false;
|
||||
$active_days[1] = ($downtime['monday'] == 1) ? true : false;
|
||||
$active_days[2] = ($downtime['tuesday'] == 1) ? true : false;
|
||||
$active_days[3] = ($downtime['wednesday'] == 1) ? true : false;
|
||||
$active_days[4] = ($downtime['thursday'] == 1) ? true : false;
|
||||
$active_days[5] = ($downtime['friday'] == 1) ? true : false;
|
||||
$active_days[6] = ($downtime['saturday'] == 1) ? true : false;
|
||||
|
||||
while ($date_aux <= $end_date) {
|
||||
$weekday_num = date('w', $date_aux);
|
||||
|
||||
if ($active_days[$weekday_num]) {
|
||||
$day_num = date('d', $date_aux);
|
||||
$month_num = date('m', $date_aux);
|
||||
$year_num = date('Y', $date_aux);
|
||||
|
||||
$max_day_num = date('t', $date_aux);
|
||||
|
||||
if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) {
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59");
|
||||
$downtime_dates[] = $dates;
|
||||
|
||||
$dates = array();
|
||||
if ($day_num + 1 > $max_day_num) {
|
||||
if ($month_num + 1 > 12) {
|
||||
$dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00");
|
||||
$dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
else {
|
||||
$dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00");
|
||||
$dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00");
|
||||
$dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
}
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
else {
|
||||
$dates = array();
|
||||
$dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from");
|
||||
$dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to");
|
||||
$downtime_dates[] = $dates;
|
||||
}
|
||||
}
|
||||
|
||||
$date_aux += SECONDS_1DAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($check_services) {
|
||||
enterprise_include_once("include/functions_services.php");
|
||||
if (function_exists("services_get_planned_downtimes_intervals")) {
|
||||
services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module);
|
||||
}
|
||||
}
|
||||
|
||||
return $downtime_dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the planned downtimes that affect the passed modules on an specific datetime range.
|
||||
*
|
||||
* @param int Start date in utimestamp.
|
||||
* @param int End date in utimestamp.
|
||||
* @param array The agent modules ids.
|
||||
*
|
||||
* @return Array with the planned downtimes that are executed in any moment of the range selected and affect the
|
||||
* agent modules selected.
|
||||
*/
|
||||
function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) {
|
||||
$start_time = date("H:i:s", $start_date);
|
||||
$end_time = date("H:i:s", $end_date);
|
||||
|
||||
$start_day = date("d", $start_date);
|
||||
$end_day = date("d", $end_date);
|
||||
|
||||
$start_month = date("m", $start_date);
|
||||
$end_month = date("m", $end_date);
|
||||
|
||||
if ($start_date > $end_date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($end_date - $start_date >= SECONDS_1MONTH) {
|
||||
// If the date range is larger than 1 month, every monthly planned downtime will be inside
|
||||
$periodically_monthly_w = "type_periodicity = 'monthly'";
|
||||
}
|
||||
else {
|
||||
// Check if the range is larger than the planned downtime execution, or if its start or end
|
||||
// is inside the planned downtime execution.
|
||||
// The start and end time is very important.
|
||||
$periodically_monthly_w = "type_periodicity = 'monthly'
|
||||
AND (((periodically_day_from > '$start_day'
|
||||
OR (periodically_day_from = '$start_day'
|
||||
AND periodically_time_from >= '$start_time'))
|
||||
AND (periodically_day_to < '$end_day'
|
||||
OR (periodically_day_to = '$end_day'
|
||||
AND periodically_time_to <= '$end_time')))
|
||||
OR ((periodically_day_from < '$start_day'
|
||||
OR (periodically_day_from = '$start_day'
|
||||
AND periodically_time_from <= '$start_time'))
|
||||
AND (periodically_day_to > '$start_day'
|
||||
OR (periodically_day_to = '$start_day'
|
||||
AND periodically_time_to >= '$start_time')))
|
||||
OR ((periodically_day_from < '$end_day'
|
||||
OR (periodically_day_from = '$end_day'
|
||||
AND periodically_time_from <= '$end_time'))
|
||||
AND (periodically_day_to > '$end_day'
|
||||
OR (periodically_day_to = '$end_day'
|
||||
AND periodically_time_to >= '$end_time'))))";
|
||||
}
|
||||
|
||||
$periodically_weekly_days = array();
|
||||
$date_aux = $start_date;
|
||||
$i = 0;
|
||||
|
||||
if (($end_date - $start_date) >= SECONDS_1WEEK) {
|
||||
// If the date range is larger than 7 days, every weekly planned downtime will be inside.
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$weekday_actual = strtolower(date('l', $date_aux));
|
||||
$periodically_weekly_days[] = "($weekday_actual = 1)";
|
||||
$date_aux += SECONDS_1DAY;
|
||||
}
|
||||
}
|
||||
else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) {
|
||||
// If the date range is smaller than 1 day, the start and end days can be equal or consecutive.
|
||||
// If they are equal, the execution times have to be contained in the date range times or contain
|
||||
// the start or end time of the date range.
|
||||
$weekday_actual = strtolower(date('l', $start_date));
|
||||
$periodically_weekly_days[] = "($weekday_actual = 1
|
||||
AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time')
|
||||
OR (periodically_time_from = '$start_time'
|
||||
OR (periodically_time_from < '$start_time'
|
||||
AND periodically_time_to >= '$start_time'))
|
||||
OR (periodically_time_from = '$end_time'
|
||||
OR (periodically_time_from < '$end_time'
|
||||
AND periodically_time_to >= '$end_time'))))";
|
||||
}
|
||||
else {
|
||||
while ($date_aux <= $end_date && $i < 7) {
|
||||
|
||||
$weekday_actual = strtolower(date('l', $date_aux));
|
||||
$day_num_actual = date('d', $date_aux);
|
||||
|
||||
if ($date_aux == $start_date) {
|
||||
$periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')";
|
||||
}
|
||||
else if ($day_num_actual == $end_day) {
|
||||
$periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')";
|
||||
}
|
||||
else {
|
||||
$periodically_weekly_days[] = "($weekday_actual = 1)";
|
||||
}
|
||||
|
||||
$date_aux += SECONDS_1DAY;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($periodically_weekly_days)) {
|
||||
$periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")";
|
||||
$periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))";
|
||||
}
|
||||
else {
|
||||
$periodically_condition = "($periodically_monthly_w)";
|
||||
}
|
||||
|
||||
if (!empty($id_agent_modules)) {
|
||||
$id_agent_modules_str = implode(",", $id_agent_modules);
|
||||
$agent_modules_condition_tpda = "AND tam.id_agente_modulo IN ($id_agent_modules_str)";
|
||||
$agent_modules_condition_tpdm = "AND tpdm.id_agent_module IN ($id_agent_modules_str)";
|
||||
}
|
||||
else {
|
||||
$agent_modules_condition_tpda = "";
|
||||
$agent_modules_condition_tpdm = "";
|
||||
}
|
||||
|
||||
$sql_downtime = "SELECT DISTINCT(tpd.id), tpd.*
|
||||
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tplanned_downtime_modules tpdm, tagente_modulo tam
|
||||
WHERE ((tpd.id = tpda.id_downtime
|
||||
AND tpda.all_modules = 1
|
||||
AND tpda.id_agent = tam.id_agente
|
||||
$agent_modules_condition_tpda)
|
||||
OR (tpd.id = tpdm.id_downtime
|
||||
$agent_modules_condition_tpdm))
|
||||
AND ((type_execution = 'periodically'
|
||||
AND $periodically_condition)
|
||||
OR (type_execution = 'once'
|
||||
AND ((date_from >= '$start_date' AND date_to <= '$end_date')
|
||||
OR (date_from <= '$start_date' AND date_to >= '$end_date')
|
||||
OR (date_from <= '$start_date' AND date_to >= '$start_date')
|
||||
OR (date_from <= '$end_date' AND date_to >= '$end_date'))))";
|
||||
|
||||
$downtimes = db_get_all_rows_sql($sql_downtime);
|
||||
if ($downtimes == false) {
|
||||
$downtimes = array();
|
||||
}
|
||||
|
||||
return $downtimes;
|
||||
}
|
||||
|
||||
function reporting_get_stats_servers($tiny = true) {
|
||||
global $config;
|
||||
|
||||
|
@ -3331,10 +3627,12 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
|
|||
|
||||
break;
|
||||
case 'SLA_monthly':
|
||||
reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title);
|
||||
if (function_exists("reporting_enterprise_sla_monthly"))
|
||||
reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title);
|
||||
break;
|
||||
case 'SLA_services':
|
||||
reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title);
|
||||
if (function_exists("reporting_enterprise_sla_services"))
|
||||
reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title);
|
||||
break;
|
||||
case 3:
|
||||
case 'SLA':
|
||||
|
@ -3622,10 +3920,115 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
|
|||
array_push ($table->data, $data);
|
||||
|
||||
$table->colspan[$next_row][0] = 3;
|
||||
$next_row++;
|
||||
$data = array();
|
||||
$data[0] = html_print_table($tableslice, true);
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
|
||||
// Table Planned Downtimes
|
||||
$id_agent_modules = array();
|
||||
foreach ($slas as $sla) {
|
||||
if (!empty($sla['id_agent_module']))
|
||||
$id_agent_modules[] = $sla['id_agent_module'];
|
||||
}
|
||||
$planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules);
|
||||
|
||||
if (!empty($planned_downtimes)) {
|
||||
|
||||
$table_planned_downtimes = new StdClass();
|
||||
$table_planned_downtimes->width = '100%';
|
||||
$table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes');
|
||||
$table_planned_downtimes->head = array();
|
||||
$table_planned_downtimes->head[0] = __('Name');
|
||||
$table_planned_downtimes->head[1] = __('Description');
|
||||
$table_planned_downtimes->head[2] = __('Execution');
|
||||
$table_planned_downtimes->head[3] = __('Dates');
|
||||
$table_planned_downtimes->headstyle = array();
|
||||
$table_planned_downtimes->style = array();
|
||||
$table_planned_downtimes->data = array();
|
||||
|
||||
if ($for_pdf) {
|
||||
$table_planned_downtimes->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey';
|
||||
$table_planned_downtimes->class = 'table_sla table_beauty';
|
||||
|
||||
for ($i = 0; $i < count($table_planned_downtimes->head); $i++) {
|
||||
$table_planned_downtimes->headstyle[$i] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
|
||||
}
|
||||
for ($i = 0; $i < count($table_planned_downtimes->head); $i++) {
|
||||
$table_planned_downtimes->style[$i] = 'display: table-cell; font-size: 10px;';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($planned_downtimes as $planned_downtime) {
|
||||
$data = array();
|
||||
$data[0] = $planned_downtime['name'];
|
||||
$data[1] = $planned_downtime['description'];
|
||||
$data[2] = ucfirst($planned_downtime['type_execution']);
|
||||
|
||||
switch ($planned_downtime['type_execution']) {
|
||||
case 'once':
|
||||
$data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) .
|
||||
" " . __('to') . " ".
|
||||
date ("Y-m-d H:i", $planned_downtime['date_to']);
|
||||
break;
|
||||
case 'periodically':
|
||||
switch ($planned_downtime['type_periodicity']) {
|
||||
case 'weekly':
|
||||
$data[3] = __('Weekly:');
|
||||
$data[3] .= " ";
|
||||
if ($planned_downtime['monday']) {
|
||||
$data[3] .= __('Mon');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['tuesday']) {
|
||||
$data[3] .= __('Tue');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['wednesday']) {
|
||||
$data[3] .= __('Wed');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['thursday']) {
|
||||
$data[3] .= __('Thu');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['friday']) {
|
||||
$data[3] .= __('Fri');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['saturday']) {
|
||||
$data[3] .= __('Sat');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
if ($planned_downtime['sunday']) {
|
||||
$data[3] .= __('Sun');
|
||||
$data[3] .= " ";
|
||||
}
|
||||
$data[3] .= " (" . $planned_downtime['periodically_time_from'];
|
||||
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
case 'monthly':
|
||||
$data[3] = __('Monthly:') . " ";
|
||||
$data[3] .= __('From day') . " " . $planned_downtime['periodically_day_from'];
|
||||
$data[3] .= " " . strtolower(__('To day')) . " ";
|
||||
$data[3] .= $planned_downtime['periodically_day_to'];
|
||||
$data[3] .= " (" . $planned_downtime['periodically_time_from'];
|
||||
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$table_planned_downtimes->data[] = $data;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data[0] = html_print_table($table_planned_downtimes, true);
|
||||
$table->colspan[$next_row][0] = 3;
|
||||
$next_row++;
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
case 'monitor_report':
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Include/help/en
|
||||
*/
|
||||
?>
|
||||
<h1>Scheduled downtimes. Time and date configuration</h1>
|
||||
|
||||
<h2>Once execution</h2>
|
||||
|
||||
<p>
|
||||
The date format must be year/month/day and the time format must be hour:minute:second.
|
||||
It's possible to create a scheduled downtime with a past date, if that option aren't disabled by the admin of Pandora FMS.
|
||||
</p>
|
||||
|
||||
<h2>Periodically execution</h2>
|
||||
|
||||
<h3>Monthly</h3>
|
||||
|
||||
<p>
|
||||
The downtime will be executed every month, from the start day at the start time, to the end date at the end time selected.
|
||||
The time format must be hour:minute:second and the start day can't be lower than the end day.
|
||||
To reflect a downtime which ends away than the last day of the month, it's necessary to create two scheduled downtimes, the first should ends the day 31 at 23:59:59 and the other should start the day 1 at 00:00:00.
|
||||
</p>
|
||||
|
||||
<h3>Weekly</h3>
|
||||
|
||||
<p>
|
||||
The downtime will be executed every selected day, from the start time, to the end time selected.
|
||||
The start time can't be lower than the end time.
|
||||
To reflect a downtime which ends away than the last day time, it's necessary to create two scheduled downtimes, the first should end at 23:59:59 and the other should start at 00:00:00 on the next day.
|
||||
</p>
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Include/help/es
|
||||
*/
|
||||
?>
|
||||
<h1>Desconexiones programadas. Configuración de tiempo y fecha</h1>
|
||||
|
||||
<h2>Ejecución única</h2>
|
||||
|
||||
<p>
|
||||
El formato de la fecha debe ser año/mes/día y el del tiempo hora:minuto:segundo.
|
||||
Se pueden crear paradas planificadas en fechas pasadas, siempre que el administrador de Pandora FMS no haya deshabilitado esa opción.
|
||||
</p>
|
||||
|
||||
<h2>Ejecución periódica</h2>
|
||||
|
||||
<h3>Mensual</h3>
|
||||
|
||||
<p>
|
||||
La parada se ejecutará cada mes, desde el día de inicio a la hora de inicio, hasta el día final a la hora final indicados.
|
||||
El formato del tiempo debe ser hora:minuto:segundo y el día de inicio no puede ser menor al día final.
|
||||
Para reflejar una parada que va más allá del último día del mes, habría que crear dos paradas, una que terminase el día 31 a las 23:59:59 y otra que empezase el día 1 a las 00:00:00.
|
||||
</p>
|
||||
|
||||
<h3>Semanal</h3>
|
||||
|
||||
<p>
|
||||
La parada se ejecutará cada día seleccionado, desde la hora de inicio a la hora final indicadas.
|
||||
La hora de inicio no puede ser superior a la hora final.
|
||||
Para reflejar una parada que va más allá de la última hora del día, habría que crear dos paradas, una que terminase a las 23:59:59 y otra que empezase a las 00:00:00 del día siguiente.
|
||||
</p>
|
Loading…
Reference in New Issue