Merge branch 'develop' of github.com:pandorafms/pandorafms into develop

This commit is contained in:
mdtrooper 2014-10-09 19:04:39 +02:00
commit 5224704085
5 changed files with 847 additions and 111 deletions

View File

@ -640,6 +640,7 @@ Pandora_Module_Logevent::getEventDescriptionXPATH (PEVENTLOGRECORD pevlr) {
description = strUnicodeToAnsi (pwsMessage); description = strUnicodeToAnsi (pwsMessage);
// Cleanup // Cleanup
free(pwsMessage);
free(pRenderedValues); free(pRenderedValues);
EvtCloseF(hProviderMetadata); EvtCloseF(hProviderMetadata);
EvtCloseF(hContext); EvtCloseF(hContext);

View File

@ -164,7 +164,7 @@ if ($create_downtime || $update_downtime) {
|| ($type_periodicity == 'monthly' && $periodically_day_from == $periodically_day_to && $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')); 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) { 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')); ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end day must be higher than the start day'));
} }
else { else {

View File

@ -27,6 +27,21 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
require_once ('include/functions_users.php'); require_once ('include/functions_users.php');
require_once ('include/functions_events.php'); require_once ('include/functions_events.php');
require_once ('include/functions_planned_downtimes.php');
$malformed_downtimes = planned_downtimes_get_malformed();
$malformed_downtimes_exist = !empty($malformed_downtimes) ? true : false;
$migrate_malformed = (bool) get_parameter("migrate_malformed");
if ($migrate_malformed) {
$migration_result = planned_downtimes_migrate_malformed_downtimes();
if ($migration_result['status'] == false) {
ui_print_error_message(__('An error occurred while migrating the malformed planned downtimes') . ". "
. __('Please run the migration again or contact with the administrator'));
echo "<br>";
}
}
// Header // Header
ui_print_page_header( ui_print_page_header(
@ -272,6 +287,7 @@ $table = new StdClass();
$table->class = 'databox'; $table->class = 'databox';
//Start Overview of existing planned downtime //Start Overview of existing planned downtime
$table->width = '98%'; $table->width = '98%';
$table->cellstyle = array();
$table->data = array(); $table->data = array();
$table->head = array(); $table->head = array();
$table->head[0] = __('Name #Ag.'); $table->head[0] = __('Name #Ag.');
@ -285,7 +301,6 @@ $table->head[7] = __('Stop downtime');
$table->head[8] = __('Edit'); $table->head[8] = __('Edit');
$table->head[9] = __('Delete'); $table->head[9] = __('Delete');
$table->align[2] = "center"; $table->align[2] = "center";
//$table->align[5] = "center";
$table->align[6] = "center"; $table->align[6] = "center";
$table->align[7] = "center"; $table->align[7] = "center";
$table->align[8] = "center"; $table->align[8] = "center";
@ -489,6 +504,16 @@ else {
$data[9]= "N/A"; $data[9]= "N/A";
} }
if (!empty($malformed_downtimes_exist) && isset($malformed_downtimes[$downtime['id']])) {
$next_row_num = count($table->data);
$table->cellstyle[$next_row_num][0] = 'color: red';
$table->cellstyle[$next_row_num][1] = 'color: red';
$table->cellstyle[$next_row_num][3] = 'color: red';
$table->cellstyle[$next_row_num][4] = 'color: red';
$table->cellstyle[$next_row_num][5] = 'color: red';
}
array_push ($table->data, $data); array_push ($table->data, $data);
} }
html_print_table ($table); html_print_table ($table);
@ -522,6 +547,12 @@ $(document).ready (function () {
e.preventDefault(); e.preventDefault();
} }
}); });
if (<?php echo json_encode($malformed_downtimes_exist) ?> && <?php echo json_encode($migrate_malformed == false) ?>) {
if (confirm("<?php echo __('WARNING: There are malformed planned downtimes') . '.\n' . __('Do you want to migrate automatically the malformed items?'); ?>")) {
window.location.href = "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&migrate_malformed=1";
}
}
}); });
</script> </script>

View File

@ -0,0 +1,521 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 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 Lesser General Public License
// as published by the Free Software Foundation; 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.
/**
* @package Include
* @subpackage Planned downtimes
*/
// Load global vars
global $config;
/**
* Include the usual functions
*/
// require_once($config["homedir"] . "/include/functions.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) {
global $config;
$now = time();
$result = array(
'result' => false,
'message' => ''
);
if ($type_execution == 'once' && !$config["past_planned_downtimes"] && $datetime_from < $now) {
$result['message'] = ui_print_error_message(__('Not created. Error inserting data. Start time must be higher than the current time' ), '', true);
}
else if ($type_execution == 'once' && $datetime_from >= $datetime_to) {
$result['message'] = ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end date must be higher than the start date'), '', true);
}
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))) {
$result['message'] = ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end time must be higher than the start time'), '', true);
}
else if ($type_execution == 'periodically' && $type_periodicity == 'monthly' && $periodically_day_from > $periodically_day_to) {
$result['message'] = ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end day must be higher than the start day'), '', true);
}
else {
$result['result'] = true;
}
return $result;
}
/**
* Update or create a planned downtime.
*
* @param array Values of the planned downtime.
* @param int Id of the planned downtime. Empty to create a new downtime.
*
* @return array Id of the updated/created planned downtime, result of the operation and result message.
*/
function planned_downtimes_update ($values, $downtime_id = 0, $check_dates = true) {
$result = array(
'id' => $downtime_id,
'result' => false,
'message' => ''
);
if ($check_dates) {
$dates_check = planned_downtimes_check_dates($values['type_execution'], $values['type_periodicity'],
$values['date_from'], $values['date_to'], $values['periodically_time_from'], $values['periodically_time_to'],
$values['periodically_day_from'], $values['periodically_day_to']);
if (!$dates_check['result']) {
$result['message'] = $dates_check['message'];
return $result;
}
}
$name_trimmed = trim(io_safe_output($values['name']));
if (!empty($name_trimmed)) {
$name_exists = (bool) db_get_value('id', 'tplanned_downtime', 'name', $values['name']);
if ($name_exists) {
$result['message'] = ui_print_error_message(__('Each planned downtime must have a different name'), '', true);
return $result;
}
}
else {
$result['message'] = ui_print_error_message(__('Planned downtime must have a name'), '', true);
return $result;
}
if (empty($downtime_id)) {
$res = db_process_sql_insert('tplanned_downtime', $values);
if ($res === false) {
$result['message'] = ui_print_error_message(__('Could not be created'), '', true);
}
else {
$result['message'] = ui_print_success_message(__('Successfully created'), '', true);
$result['result'] = true;
$result['id'] = $res;
}
}
else {
$res = db_process_sql_update('tplanned_downtime', $values, array('id' => $downtime_id));
if (empty($res)) {
$result['message'] = ui_print_error_message(__('Could not be updated'), '', true);
}
else {
$result['message'] = ui_print_success_message(__('Successfully updated'), '', true);
$result['result'] = true;
}
}
return $result;
}
/**
* Add new agents and modules to the planned downtime.
*
* @param int Id of the planned downtime.
* @param array IDs of the agents to add.
* @param bool Add all modules of the agents or not.
* @param array Names of the modules to add. Empty to add all the modules.
*
* @return array The status will be false id any insertion fails.
* The failed insertions will be added to bad_agents and bad_modules.
*/
function planned_downtimes_add_items ($downtime_id, $agents, $all_modules = true, $module_names = array()) {
global $config;
include_once($config['homedir'] . "/include/functions_modules.php");
$result = array(
'status' => true,
'bad_agents' => array(),
'bad_modules' => array()
);
if (empty($module_names)) {
$all_modules = true;
}
else {
//It is empty.
if ($module_names[0] == "0")
$all_modules = true;
}
if (empty($agents)) {
$agents = array();
$result['status'] = false;
}
foreach ($agents as $agent_id) {
$values = array(
'id_downtime' => $downtime_id,
'id_agent' => $agent_id,
'all_modules' => $all_modules,
'id_user' => $config['id_user']
);
$result = db_process_sql_insert('tplanned_downtime_agents', $values);
if (empty($result)) {
$result['bad_agents'][] = $agent_id;
}
else if (!$all_modules) {
foreach ($module_names as $module_name) {
$module = modules_get_agentmodule_id($module_name, $agent_id);
$module_id = $module["id_agente_modulo"];
$values = array(
'id_downtime' => $downtime_id,
'id_agent' => $agent_id,
'id_agent_module' => $module_id
);
$result = db_process_sql_insert('tplanned_downtime_modules', $values);
if (empty($result)) {
$result['bad_modules'][] = $module_id;
}
}
}
}
return $result;
}
/**
* Delete the agents and modules asociated to a planned downtime.
*
* @param int Id of the planned downtime.
* @param int ID of the agent to delete.
*
* @return bool The result of the operation.
*/
function planned_downtimes_delete_items ($downtime_id, $agent_id) {
$filter = array(
'id_downtime' => $downtime_id,
'id_agent' => $agent_id
);
$downtime_agent_row = db_get_row('tplanned_downtime_agents', $filter);
$result = db_process_sql_delete('tplanned_downtime_agents', array('id' => $downtime_agent_row['id']));
if (!empty($result) && $downtime_agent_row['all_modules'] == 0) {
//Delete modules in downtime
$filter = array(
'id_downtime' => $downtime_id,
'id_agent' => $agent_id
);
db_process_sql_delete('tplanned_downtime_modules', $filter);
}
return $result;
}
/**
* Get the planned downtimes that don't comply the actual rules of dates
*
* @return array List of planned downtimes
*/
function planned_downtimes_get_malformed () {
$sql = "SELECT *
FROM tplanned_downtime
WHERE type_execution = 'periodically'
AND ((type_periodicity = 'monthly'
AND (periodically_day_from > periodically_day_to
OR (periodically_day_from = periodically_day_to
AND periodically_time_from >= periodically_time_to)))
OR (type_periodicity = 'weekly'
AND periodically_time_from >= periodically_time_to))";
$malformed_downtimes = db_get_all_rows_sql($sql);
if ($malformed_downtimes === false) {
return false;
}
$malformed_downtimes_aux = array();
foreach ($malformed_downtimes as $malformed_downtime) {
$malformed_downtimes_aux[$malformed_downtime['id']] = $malformed_downtime;
}
$malformed_downtimes = $malformed_downtimes_aux;
return $malformed_downtimes;
}
/**
* Create new downtimes with the correct format and delete the malformed
*
* @param array List with the malformed downtimes
*
* @return bool The result of the migration
*/
function planned_downtimes_migrate_malformed_downtimes ($malformed_downtimes = array()) {
global $config;
$migration_result = array(
'status' => true,
'bad_downtimes' => array()
);
if (empty($malformed_downtimes))
$malformed_downtimes = planned_downtimes_get_malformed();
foreach ($malformed_downtimes as $key => $downtime) {
$downtime_type = $downtime['type_downtime'];
$downtime_execution = $downtime['type_execution'];
$downtime_periodicity = $downtime['type_periodicity'];
$downtime_time_from = $downtime['periodically_time_from'];
$downtime_time_to = $downtime['periodically_time_to'];
if ($downtime_execution == 'periodically') {
if ($downtime_periodicity == 'monthly') {
$downtime_day_from = $downtime['periodically_day_from'];
$downtime_day_to = $downtime['periodically_day_to'];
if (($downtime_day_from > $downtime_day_to) || ($downtime_day_from == $downtime_day_to && $downtime_time_from > $downtime_time_to)) {
$values_first = array(
'name' => $downtime['name'] . "&nbsp;[1/2]",
'description' => $downtime['description'],
'executed' => $downtime['executed'],
'id_group' => $downtime['id_group'],
'only_alerts' => $downtime['only_alerts'],
'periodically_time_from' => $downtime_time_from,
'periodically_time_to' => "23:59:59",
'periodically_day_from' => $downtime_day_from,
'periodically_day_to' => 31,
'type_downtime' => $downtime_type,
'type_execution' => $downtime_execution,
'type_periodicity' => $downtime_periodicity,
'id_user' => $config['id_user']
);
$values_second = $values_first;
$values_second['name'] = $downtime['name'] . "&nbsp;[2/2]";
$values_second['periodically_day_from'] = 1;
$values_second['periodically_time_from'] = "00:00:00";
$values_second['periodically_day_to'] = $downtime_day_to;
$values_second['periodically_time_to'] = $downtime_time_to;
$result_first = planned_downtimes_update($values_first, 0, false);
if ($result_first['result']) {
$result_second = planned_downtimes_update($values_second, 0, false);
if (!$result_second['result']) {
db_process_sql_delete('tplanned_downtime', array('id' => $result_first['id']));
}
}
if ($result_first['result'] && $result_second['result']) {
$result_copy = planned_downtimes_migrate_malformed_downtimes_copy_items($downtime['id'], $result_first['id'], $result_second['id']);
if (!$result_copy) {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
else {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
else if ($downtime_day_from == $downtime_day_to && $downtime_time_from == $downtime_time_to) {
$utimestamp = strtotime("1-1-1970 $downtime_time_to");
$time = date('H:i:s', $utimestamp + 1);
if ($time != '00:00:00') {
$values = array('periodically_time_to' => $time);
}
else {
$utimestamp = strtotime("1-1-1970 $downtime_time_from");
$time = date('H:i:s', $utimestamp - 1);
$values = array('periodically_time_from' => $time);
}
$filter = array('id' => $downtime['id']);
$result_update = db_process_sql_update('tplanned_downtime', $values, $filter);
if (!$result_update) {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
}
else if ($downtime_periodicity == 'weekly') {
if ($downtime_time_from > $downtime_time_to) {
$days = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
$values_first = array(
'name' => $downtime['name'] . "&nbsp;[1/2]",
'description' => $downtime['description'],
'executed' => $downtime['executed'],
'id_group' => $downtime['id_group'],
'only_alerts' => $downtime['only_alerts'],
'monday' => $downtime['monday'],
'tuesday' => $downtime['tuesday'],
'wednesday' => $downtime['wednesday'],
'thursday' => $downtime['thursday'],
'friday' => $downtime['friday'],
'saturday' => $downtime['saturday'],
'sunday' => $downtime['sunday'],
'periodically_time_from' => $downtime_time_from,
'periodically_time_to' => "23:59:59",
'type_downtime' => $downtime_type,
'type_execution' => $downtime_execution,
'type_periodicity' => $downtime_periodicity,
'id_user' => $config['id_user']
);
$values_second = $values_first;
$values_second['name'] = $downtime['name'] . "&nbsp;[2/2]";
$values_second['periodically_time_from'] = "00:00:00";
$values_second['periodically_time_to'] = $downtime_time_to;
$values_second['tuesday'] = $downtime['monday'] ? 1 : 0;
$values_second['wednesday'] = $downtime['tuesday'] ? 1 : 0;
$values_second['thursday'] = $downtime['wednesday'] ? 1 : 0;
$values_second['friday'] = $downtime['thursday'] ? 1 : 0;
$values_second['saturday'] = $downtime['friday'] ? 1 : 0;
$values_second['sunday'] = $downtime['saturday'] ? 1 : 0;
$values_second['monday'] = $downtime['sunday'] ? 1 : 0;
$result_first = planned_downtimes_update($values_first, 0, false);
if ($result_first['result']) {
$result_second = planned_downtimes_update($values_second, 0, false);
if (!$result_second['result']) {
db_process_sql_delete('tplanned_downtime', array('id' => $result_first['id']));
}
}
if ($result_first['result'] && $result_second['result']) {
$result_copy = planned_downtimes_migrate_malformed_downtimes_copy_items($downtime['id'], $result_first['id'], $result_second['id']);
if (!$result_copy) {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
else {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
else if ($downtime_time_from == $downtime_time_to) {
$utimestamp = strtotime("1-1-1970 $downtime_time_to");
$time = date('H:i:s', $utimestamp + 1);
if ($time != '00:00:00') {
$values = array('periodically_time_to' => $time);
}
else {
$utimestamp = strtotime("1-1-1970 $downtime_time_from");
$time = date('H:i:s', $utimestamp - 1);
$values = array('periodically_time_from' => $time);
}
$filter = array('id' => $downtime['id']);
$result_update = db_process_sql_update('tplanned_downtime', $values, $filter);
if (!$result_update) {
$migration_result['status'] = false;
$migration_result['bad_downtimes'][] = $downtime['id'];
}
}
}
}
}
return $migration_result;
}
/**
* Aux function to copy the items of the selected downtime to the new downtimes.
* Deletes the new downtimes if the items are not copied.
*/
function planned_downtimes_migrate_malformed_downtimes_copy_items ($original_downtime_id, $new_downtime_first_id, $new_downtime_second_id) {
$sql = "SELECT *
FROM tplanned_downtime_agents
WHERE id_downtime = " . $original_downtime_id;
$downtime_agents_rows = db_get_all_rows_sql($sql);
$sql = "SELECT *
FROM tplanned_downtime_modules
WHERE id_downtime = " . $original_downtime_id;
$downtime_modules_rows = db_get_all_rows_sql($sql);
if (!empty($downtime_agents_rows)) {
$result_agents = true;
foreach ($downtime_agents_rows as $downtime_agents_row) {
$values_agent = array(
'id_agent' => $downtime_agents_row['id_agent'],
'all_modules' => $downtime_agents_row['all_modules']
);
$values_agent['id_downtime'] = $new_downtime_first_id;
$result_agent_first = db_process_sql_insert('tplanned_downtime_agents', $values_agent);
$values_agent['id_downtime'] = $new_downtime_second_id;
$result_agent_second = db_process_sql_insert('tplanned_downtime_agents', $values_agent);
if (empty($result_agent_first) || empty($result_agent_second)) {
$result_agents = false;
db_process_sql_delete('tplanned_downtime', array('id' => $new_downtime_first_id));
db_process_sql_delete('tplanned_downtime', array('id' => $new_downtime_second_id));
break;
}
}
if ($result_agents) {
if (!empty($downtime_modules_rows)) {
foreach ($downtime_modules_rows as $downtime_modules_row) {
$values_module = array(
'id_agent' => $downtime_modules_row['id_agent'],
'id_agent_module' => $downtime_modules_row['id_agent_module']
);
$values_module['id_downtime'] = $new_downtime_first_id;
$result_module_first = db_process_sql_insert('tplanned_downtime_modules', $values_module);
$values_module['id_downtime'] = $new_downtime_second_id;
$result_module_second = db_process_sql_insert('tplanned_downtime_modules', $values_module);
if (empty($result_module_first) || empty($result_module_second)) {
db_process_sql_delete('tplanned_downtime', array('id' => $new_downtime_first_id));
db_process_sql_delete('tplanned_downtime', array('id' => $new_downtime_second_id));
break;
}
}
}
}
}
// The new downtimes are created
$new_planned_downtimes_exists = (bool) db_get_value('id', 'tplanned_downtime', 'id', $new_downtime_first_id)
&& (bool) db_get_value('id', 'tplanned_downtime', 'id', $new_downtime_second_id);
if ($new_planned_downtimes_exists) {
// Delete the migrated downtime and its items
db_process_sql_delete('tplanned_downtime', array('id' => $original_downtime_id));
}
return $new_planned_downtimes_exists;
}
?>

View File

@ -871,14 +871,22 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
* @return Array with time intervals. * @return Array with time intervals.
*/ */
function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) {
global $config;
require_once ($config['homedir'] . '/include/functions_planned_downtimes.php');
$malformed_planned_downtimes = planned_downtimes_get_malformed();
if (empty($malformed_planned_downtimes))
$malformed_planned_downtimes = array();
$sql_downtime = "SELECT DISTINCT(tpd.id), tpd.* $sql_downtime = "SELECT DISTINCT(tpd.id), tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tplanned_downtime_modules tpdm, tagente_modulo tam FROM tplanned_downtime_agents tpda, tagente_modulo tam, tplanned_downtime tpd
LEFT OUTER JOIN tplanned_downtime_modules tpdm ON tpd.id = tpdm.id_downtime
WHERE (tpd.id = tpda.id_downtime WHERE (tpd.id = tpda.id_downtime
AND tpda.all_modules = 1 AND tpda.all_modules = 1
AND tpda.id_agent = tam.id_agente AND tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo = $id_agent_module) AND tam.id_agente_modulo = $id_agent_module)
OR (tpd.id = tpdm.id_downtime OR (tpdm.id_agent_module = $id_agent_module)";
AND tpdm.id_agent_module = $id_agent_module)";
$downtimes = db_get_all_rows_sql($sql_downtime); $downtimes = db_get_all_rows_sql($sql_downtime);
if ($downtimes == false) { if ($downtimes == false) {
$downtimes = array(); $downtimes = array();
@ -896,6 +904,20 @@ function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_dat
$downtime_dates[] = $dates; $downtime_dates[] = $dates;
} }
else if ($downtime_type == 'periodically') { else if ($downtime_type == 'periodically') {
// If a planned downtime have malformed dates, its intervals aren't taken account
$downtime_malformed = false;
foreach ($malformed_planned_downtimes as $malformed_planned_downtime) {
if ($downtime_id == $malformed_planned_downtime['id']) {
$downtime_malformed = true;
break;
}
}
if ($downtime_malformed == true) {
continue;
}
// If a planned downtime have malformed dates, its intervals aren't taken account
$downtime_time_from = $downtime['periodically_time_from']; $downtime_time_from = $downtime['periodically_time_from'];
$downtime_time_to = $downtime['periodically_time_to']; $downtime_time_to = $downtime['periodically_time_to'];
@ -1160,21 +1182,21 @@ function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modu
if (!empty($id_agent_modules)) { if (!empty($id_agent_modules)) {
$id_agent_modules_str = implode(",", $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_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)"; $agent_modules_condition_tpdm = "tpdm.id_agent_module IN ($id_agent_modules_str)";
} }
else { else {
$agent_modules_condition_tpda = ""; $agent_modules_condition_tpda = "";
$agent_modules_condition_tpdm = ""; $agent_modules_condition_tpdm = "1=1";
} }
$sql_downtime = "SELECT DISTINCT(tpd.id), tpd.* $sql_downtime = "SELECT DISTINCT(tpd.id), tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tplanned_downtime_modules tpdm, tagente_modulo tam FROM tplanned_downtime_agents tpda, tagente_modulo tam, tplanned_downtime tpd
LEFT OUTER JOIN tplanned_downtime_modules tpdm ON tpd.id = tpdm.id_downtime
WHERE ((tpd.id = tpda.id_downtime WHERE ((tpd.id = tpda.id_downtime
AND tpda.all_modules = 1 AND tpda.all_modules = 1
AND tpda.id_agent = tam.id_agente AND tpda.id_agent = tam.id_agente
$agent_modules_condition_tpda) $agent_modules_condition_tpda)
OR (tpd.id = tpdm.id_downtime OR ($agent_modules_condition_tpdm))
$agent_modules_condition_tpdm))
AND ((type_execution = 'periodically' AND ((type_execution = 'periodically'
AND $periodically_condition) AND $periodically_condition)
OR (type_execution = 'once' OR (type_execution = 'once'
@ -3696,6 +3718,263 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$table1->style[6] = 'text-align: center'; $table1->style[6] = 'text-align: center';
} }
// Table Planned Downtimes
require_once ($config['homedir'] . '/include/functions_planned_downtimes.php');
$metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE');
$downtime_malformed = false;
$planned_downtimes_empty = true;
$malformed_planned_downtimes_empty = true;
if ($metaconsole_on) {
$id_agent_modules_by_server = array();
foreach ($slas as $sla) {
$server = $sla['server_name'];
if (empty($server))
continue;
if (!isset($id_agent_modules_by_server[$server]))
$id_agent_modules_by_server[$server] = array();
$id_agent_modules_by_server[$server][] = $sla['id_agent_module'];
}
$planned_downtimes_by_server = array();
$malformed_planned_downtimes_by_server = array();
foreach ($id_agent_modules_by_server as $server => $id_agent_modules) {
//Metaconsole connection
if ($metaconsole_on && !empty($server)) {
$connection = metaconsole_get_connection($server);
if (!metaconsole_load_external_db($connection)) {
continue;
}
$planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules);
$malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed();
if (!empty($planned_downtimes_by_server[$server]))
$planned_downtimes_empty = false;
if (!empty($malformed_planned_downtimes_by_server[$server]))
$malformed_planned_downtimes_empty = false;
}
}
if (!$planned_downtimes_empty) {
$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] = __('Server');
$table_planned_downtimes->head[1] = __('Name');
$table_planned_downtimes->head[2] = __('Description');
$table_planned_downtimes->head[3] = __('Execution');
$table_planned_downtimes->head[4] = __('Dates');
$table_planned_downtimes->headstyle = array();
$table_planned_downtimes->style = array();
$table_planned_downtimes->cellstyle = array();
$table_planned_downtimes->data = array();
foreach ($planned_downtimes_by_server as $server => $planned_downtimes) {
foreach ($planned_downtimes as $planned_downtime) {
$data = array();
$data[0] = $server;
$data[1] = $planned_downtime['name'];
$data[2] = $planned_downtime['description'];
$data[3] = ucfirst($planned_downtime['type_execution']);
$data[4] = "";
switch ($planned_downtime['type_execution']) {
case 'once':
$data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
date ("Y-m-d H:i", $planned_downtime['date_to']);
break;
case 'periodically':
switch ($planned_downtime['type_periodicity']) {
case 'weekly':
$data[4] = __('Weekly:');
$data[4] .= "&nbsp;";
if ($planned_downtime['monday']) {
$data[4] .= __('Mon');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['tuesday']) {
$data[4] .= __('Tue');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['wednesday']) {
$data[4] .= __('Wed');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['thursday']) {
$data[4] .= __('Thu');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['friday']) {
$data[4] .= __('Fri');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['saturday']) {
$data[4] .= __('Sat');
$data[4] .= "&nbsp;";
}
if ($planned_downtime['sunday']) {
$data[4] .= __('Sun');
$data[4] .= "&nbsp;";
}
$data[4] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data[4] = __('Monthly:') . "&nbsp;";
$data[4] .= __('From day') . "&nbsp;" . $planned_downtime['periodically_day_from'];
$data[4] .= "&nbsp;" . strtolower(__('To day')) . "&nbsp;";
$data[4] .= $planned_downtime['periodically_day_to'];
$data[4] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
if (!$malformed_planned_downtimes_empty
&& isset($malformed_planned_downtimes[$server])
&& isset($malformed_planned_downtimes[$server][$planned_downtime['id']])) {
$next_row_num = count($table_planned_downtimes->data);
$table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][4] = 'color: red';
if (!$downtime_malformed)
$downtime_malformed = true;
}
$table_planned_downtimes->data[] = $data;
}
}
}
}
else {
$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);
$malformed_planned_downtimes = planned_downtimes_get_malformed();
if (!empty($planned_downtimes))
$planned_downtimes_empty = false;
if (!empty($malformed_planned_downtimes))
$malformed_planned_downtimes_empty = false;
if (!$planned_downtimes_empty) {
$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->cellstyle = array();
$table_planned_downtimes->data = array();
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']);
$data[3] = "";
switch ($planned_downtime['type_execution']) {
case 'once':
$data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
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] .= "&nbsp;";
if ($planned_downtime['monday']) {
$data[3] .= __('Mon');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['tuesday']) {
$data[3] .= __('Tue');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['wednesday']) {
$data[3] .= __('Wed');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['thursday']) {
$data[3] .= __('Thu');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['friday']) {
$data[3] .= __('Fri');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['saturday']) {
$data[3] .= __('Sat');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['sunday']) {
$data[3] .= __('Sun');
$data[3] .= "&nbsp;";
}
$data[3] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data[3] = __('Monthly:') . "&nbsp;";
$data[3] .= __('From day') . "&nbsp;" . $planned_downtime['periodically_day_from'];
$data[3] .= "&nbsp;" . strtolower(__('To day')) . "&nbsp;";
$data[3] .= $planned_downtime['periodically_day_to'];
$data[3] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) {
$next_row_num = count($table_planned_downtimes->data);
$table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red';
$table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red';
if (!$downtime_malformed)
$downtime_malformed = true;
}
$table_planned_downtimes->data[] = $data;
}
}
}
if ($downtime_malformed) {
$info_malformed = ui_print_error_message(__('This item is affected by a malformed planned downtime') . ". " .
__('Go to the planned downtimes section to solve this') . ".", '', true);
$data = array();
$data[0] = $info_malformed;
$data[0] .= html_print_table($table_planned_downtimes, true);
$table->colspan[$next_row][0] = 3;
$next_row++;
array_push ($table->data, $data);
break;
}
$data_graph = array (); $data_graph = array ();
$data_horin_graph = array(); $data_horin_graph = array();
$data_graph[__('Inside limits')] = 0; $data_graph[__('Inside limits')] = 0;
@ -3818,8 +4097,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
if ($sla_value === false) { if ($sla_value === false) {
$data[4] = '<span style="font: bold '.$sizem.'em Arial, Sans-serif; color: #0000FF;">'; $data[4] = '<span style="font: bold '.$sizem.'em Arial, Sans-serif; color: #0000FF;">';
$data[5] = html_print_image('images/status_sets/default/severity_maintenance.png',true,array('title'=>__('Unknown'))); $data[5] = '<span style="font: bold '.$sizem.'em Arial, Sans-serif; color: #736F6E;">'.__('Unknown').'</span>';
$data[6] = '<span style="font: bold '.$sizem.'em Arial, Sans-serif; color: #736F6E;">'.__('Unknown').'</span>'; $data[6] = html_print_image('images/status_sets/default/severity_maintenance.png',true,array('title'=>__('Unknown')));
} }
else { else {
$data[4] = ''; $data[4] = '';
@ -3928,103 +4207,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data); array_push ($table->data, $data);
} }
// Table Planned Downtimes if (!empty($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']) .
"&nbsp;" . __('to') . "&nbsp;".
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] .= "&nbsp;";
if ($planned_downtime['monday']) {
$data[3] .= __('Mon');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['tuesday']) {
$data[3] .= __('Tue');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['wednesday']) {
$data[3] .= __('Wed');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['thursday']) {
$data[3] .= __('Thu');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['friday']) {
$data[3] .= __('Fri');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['saturday']) {
$data[3] .= __('Sat');
$data[3] .= "&nbsp;";
}
if ($planned_downtime['sunday']) {
$data[3] .= __('Sun');
$data[3] .= "&nbsp;";
}
$data[3] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data[3] = __('Monthly:') . "&nbsp;";
$data[3] .= __('From day') . "&nbsp;" . $planned_downtime['periodically_day_from'];
$data[3] .= "&nbsp;" . strtolower(__('To day')) . "&nbsp;";
$data[3] .= $planned_downtime['periodically_day_to'];
$data[3] .= "&nbsp;(" . $planned_downtime['periodically_time_from'];
$data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
$table_planned_downtimes->data[] = $data;
}
$data = array(); $data = array();
$data[0] = html_print_table($table_planned_downtimes, true); $data[0] = html_print_table($table_planned_downtimes, true);
$table->colspan[$next_row][0] = 3; $table->colspan[$next_row][0] = 3;