2013-02-12 Miguel de Dios <miguel.dedios@artica.es>

* godmode/agentes/planned_downtime.list.php,
	godmode/agentes/planned_downtime.editor.php: fixed the planned
	downtime.
	
	Fixes: #3602365




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7638 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-02-12 18:25:34 +00:00
parent 83c40c5a7d
commit d1aa73cd79
3 changed files with 207 additions and 61 deletions

View File

@ -1,3 +1,11 @@
2013-02-12 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/planned_downtime.list.php,
godmode/agentes/planned_downtime.editor.php: fixed the planned
downtime.
Fixes: #3602365
2013-02-12 Sergio Martin <sergio.martin@artica.es>
* include/functions_config.php: Fixed the update of the

View File

@ -59,7 +59,7 @@ $first_create = (int) get_parameter ('first_create', 0);
$create_downtime = (int) get_parameter ('create_downtime');
$stop_downtime = (int) get_parameter ('stop_downtime');
$edit_downtime = (int) get_parameter ('edit_downtime');
$update_downtime = (int) get_parameter ('update_downtime');
$id_downtime = (int) get_parameter ('id_downtime',0);
@ -81,32 +81,7 @@ $friday = (bool) get_parameter ('friday');
$saturday = (bool) get_parameter ('saturday');
$sunday = (bool) get_parameter ('sunday');
// STOP DOWNTIME
if ($stop_downtime == 1) {
$sql = "SELECT * FROM tplanned_downtime where id=$id_downtime";
$result = db_get_row_sql($sql);
$name = $result['name'];
$description = $result['description'];
$date_from = $result['date_from'];
$executed = $result['executed'];
$id_group = $result['id_group'];
$only_alerts = $result['only_alerts'];
$date_stop = date ("Y-m-j",get_system_time ());
$time_stop = date ("h:iA",get_system_time ());
$date_time_stop = strtotime ($date_stop . ' ' . $time_stop);
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $date_from,
'date_to' => $date_time_stop,
'executed' => $executed,
'id_group' => $id_group,
'only_alerts' => $only_alerts
);
$result = db_process_sql_update('tplanned_downtime', $values, array ('id' => $id_downtime));
}
// INSERT A NEW DOWNTIME_AGENT ASSOCIATION
if ($insert_downtime_agent == 1) {
@ -121,7 +96,7 @@ if ($insert_downtime_agent == 1) {
$all_modules = true;
}
for ($a=0;$a <count($agents); $a++) {
for ($a=0; $a < count($agents); $a++) {
$id_agente_dt = $agents[$a];
@ -168,11 +143,13 @@ if ($delete_downtime_agent == 1) {
if ($create_downtime || $update_downtime) {
$check = db_get_value ('name', 'tplanned_downtime', 'name', $name);
$datetime_from = strtotime ($once_date_from.' '.$once_time_from);
$datetime_to = strtotime ($once_date_to.' '.$once_time_to);
$datetime_from = strtotime ($once_date_from . ' ' . $once_time_from);
$datetime_to = strtotime ($once_date_to . ' ' . $once_time_to);
if ($datetime_from > $datetime_to) {
echo '<h3 class="error">'.__('Not created. Error inserting data').': START &gt; END</h3>';
if (($type_periodicity == 'once') &&
($datetime_from >= $datetime_to)) {
ui_print_error_message(__('Not created. Error inserting data' ).
': START &gt;= END');
}
else {
$sql = '';
@ -206,13 +183,13 @@ if ($create_downtime || $update_downtime) {
'tplanned_downtime', $values);
}
else {
echo "<h3 class='error'>" .
__('Each planned downtime must have a different name')."</h3>";
ui_print_error_message(
__('Each planned downtime must have a different name'));
}
}
else {
echo '<h3 class="error">' .
__('Planned downtime must have a name').'</h3>';
ui_print_error_message(
__('Planned downtime must have a name'));
}
}
else if ($update_downtime) {
@ -243,25 +220,26 @@ if ($create_downtime || $update_downtime) {
$result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime));
}
else {
echo '<h3 class="error">'.__('Planned downtime must have a name').'</h3>';
ui_print_error_message(
__('Planned downtime must have a name'));
}
}
if ($result === false) {
if ($create_downtime) {
echo '<h3 class="error">'.__('Could not be created').'</h3>';
ui_print_error_message(__('Could not be created'));
}
else {
echo '<h3 class="error">'.__('Could not be updated').'</h3>';
ui_print_error_message(__('Could not be updated'));
}
}
else {
if ($create_downtime && $name && !$check) {
$id_downtime = $result;
echo '<h3 class="suc">' . __('Successfully created') . '</h3>';
ui_print_success_message(__('Successfully created'));
}
else if ($update_downtime && $name) {
echo '<h3 class="suc">'.__('Successfully updated').'</h3>';
ui_print_success_message(__('Successfully updated'));
}
}
}
@ -327,7 +305,7 @@ $table->data[3][0] = __('Type');
$table->data[3][1] = html_print_select(array('quiet' => __('Quiet'),
'disable_agents' => __('Disabled Agents'),
'disable_agents_alerts' => __('Disabled only Alerts')),
'type_downtime', $type_downtime, '', '', 0, true, false, true,
'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'),
@ -398,12 +376,12 @@ $table->data[5][1] = "
<td>" . __('From day:') . "</td>
<td>".
html_print_select($days,
'periodically_day_from', $periodically_day_from, '', '', 0, true) .
'periodically_day_from', $periodically_day_from, '', '', 0, true) .
"</td>
<td>" . __('To day:') . "</td>
<td>".
html_print_select($days,
'periodically_day_to', $periodically_day_to, '', '', 0, true) .
'periodically_day_to', $periodically_day_to, '', '', 0, true) .
"</td>
</tr>
</table>
@ -503,7 +481,9 @@ if ($id_downtime > 0) {
ui_print_help_tip (__('Only for type Quiet for downtimes.'), true) . '</h4>';
if ($type_downtime != 'quiet')
echo '<div style="display: none;">';
echo '<div id="available_modules" style="display: none;">';
else
echo '<div id="available_modules" style="">';
echo html_print_select (array(), "module[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
echo "</div>";
echo "<br /><br /><br />";
@ -519,7 +499,7 @@ if ($id_downtime > 0) {
tagente.ultimo_contacto, tplanned_downtime_agents.all_modules
FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d ",$id_downtime);
AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime);
$downtimes = db_get_all_rows_sql ($sql);
if ($downtimes === false) {
@ -553,18 +533,34 @@ if ($id_downtime > 0) {
$data[3] = $downtime["ultimo_contacto"];
if ($downtime["all_modules"]) {
$data['count_modules'] = __("All modules");
if ($type_downtime == 'disable_agents_alerts') {
$data['count_modules'] = __("All alerts");
}
elseif ($type_downtime == 'disable_agents') {
$data['count_modules'] = __("Entire agent");
}
else {
$data['count_modules'] = __("Some modules");
if ($downtime["all_modules"]) {
$data['count_modules'] = __("All modules");
}
else {
$data['count_modules'] = __("Some modules");
}
}
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
$data[5] = '';
if (($type_downtime != 'disable_agents_alerts')
&& ($type_downtime != 'disable_agents')) {
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
}
$data[5] .= '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/planned_downtime.editor'.
'&amp;id_agent=' . $downtime["id_agente"] .
'&amp;delete_downtime_agent=1&amp;id_downtime_agent='.$downtime["id"].'&amp;id_downtime='.$id_downtime.'">' .
'&amp;delete_downtime_agent=1' .
'&amp;id_downtime_agent='.$downtime["id"] .
'&amp;id_downtime='.$id_downtime.'">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
$table->data['agent_' . $downtime["id_agente"]] = $data;
@ -623,7 +619,7 @@ $table->data['module'][1] = "
. '<div id="add_button_div">'
. '<a class="add_button" href="">'
. html_print_image("images/add.png", true,
array("border" => '0', "alt" => __('Add'))) . "</a>"
array("border" => '0', "alt" => __('Add'))) . "</a>"
. '</div>'
. "<div id='spinner_add' style='display: none;'>"
. html_print_image("images/spinner.gif", true)
@ -661,6 +657,18 @@ ui_require_jquery_file ("ui-timepicker-addon");
var id_downtime = <?php echo $id_downtime?>;
var action_in_progress = false;
function change_type_downtime() {
switch ($("#type_downtime").val()) {
case 'disable_agents_alerts':
case 'disable_agents':
$("#available_modules").hide();
break;
case 'quiet':
$("#available_modules").show();
break;
}
}
function change_type_execution() {
switch ($("#type_execution").val()) {
case 'once':
@ -898,6 +906,7 @@ ui_require_jquery_file ("ui-timepicker-addon");
$(document).ready (function () {
$("#id_agents").change(agent_changed_by_multiple_agents);
change_type_downtime();
change_type_execution();
change_type_periodicity();

View File

@ -39,6 +39,126 @@ ui_print_page_header(
$delete_downtime = (int) get_parameter ('delete_downtime');
$id_downtime = (int) get_parameter ('id_downtime', 0);
$stop_downtime = (bool) get_parameter ('stop_downtime');
// STOP DOWNTIME
if ($stop_downtime) {
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_execution']) {
case 'once':
$date_stop = date ("Y-m-j", get_system_time ());
$time_stop = date ("h:iA", get_system_time ());
$values = array(
'executed' => 0,
'date_to' => strtotime($date_stop . ' ' . $time_stop)
);
$result = db_process_sql_update('tplanned_downtime',
$values, array ('id' => $id_downtime));
break;
case 'periodically':
break;
}
ui_print_result_message($result,
__('Succesful stopped the Downtime'),
__('Unsuccesful stopped the Downtime'));
if ($result) {
//Reenabled the Agents or Modules or alerts...depends of type
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_downtime']) {
case 'quiet':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
if ($agent['all_modules']) {
$result = db_process_sql_update('tagente',
array('quiet' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
else {
$modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
array('id_agent' => $agent['id_agent'],
'id_downtime' => $id_downtime));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'tagente_modulo',
array('quiet' => 0),
array('id_agente_modulo' =>
$module['id_agent_module']));
if ($result)
$count++;
}
}
}
break;
case 'disable_agents':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$result = db_process_sql_update('tagente',
array('disabled' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
break;
case 'disable_agents_alerts':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$modules = db_get_all_rows_filter(
'tagente_modulo',
array('id_agente' => $agent['id_agent']));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'talert_template_modules',
array('disabled' => 0),
array('id_agent_module' =>
$module['id_agente_modulo']));
if ($result)
$count++;
}
}
break;
}
ui_print_info_message(
sprintf(__('Enabled %s elements from the downtime'), $count));
}
}
// DELETE WHOLE DOWNTIME!
if ($delete_downtime) {
$result = db_process_sql_delete('tplanned_downtime', array('id' => $id_downtime));
@ -46,10 +166,10 @@ if ($delete_downtime) {
$result2 = db_process_sql_delete('tplanned_downtime_agents', array('id' => $id_downtime));
if (($result === false) OR ($result2 === false)) {
echo '<h3 class="error">'.__('Not deleted. Error deleting data').'</h3>';
ui_print_error_message(__('Not deleted. Error deleting data'));
}
else {
echo '<h3 class="suc">'.__('Successfully deleted').'</h3>';
ui_print_success_message(__('Successfully deleted'));
}
}
@ -180,13 +300,22 @@ else {
$data[7]= "N/A";
}
if ($downtime["executed"] == 0)
$data[8] = html_print_image ("images/pixel_green.png", true, array ('width' => 20, 'height' => 20, 'alt' => __('Executed')));
else
$data[8] = html_print_image ("images/pixel_red.png", true, array ('width' => 20, 'height' => 20, 'alt' => __('Not executed')));
if ($downtime["executed"] == 0) {
$data[8] = 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,
array ('width' => 20, 'height' => 20, 'alt' => __('Not executed')));
}
if ($downtime["executed"] != 0) {
$data[9] = '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/planned_downtime.list&amp;stop_downtime=1&amp;id_downtime='.$downtime['id'].'">' .
if (($downtime['type_execution'] == 'once')
&& ($downtime["executed"] == 1)) {
$data[9] = '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/planned_downtime.list&amp;' .
'stop_downtime=1&amp;' .
'id_downtime=' . $downtime['id'] . '">' .
html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime')));
}