'; /* Step 1 */ if ($step == 1) echo ''; if ($id) { echo ''; echo __('Step').' 1 : '.__('Conditions'); echo ''; } else { echo __('Step').' 1 : '.__('Conditions'); } if ($step == 1) echo ''; /* Step 2 */ echo ' » '; if ($step == 2) echo ''; if ($id) { echo ''; echo __('Step').' 2 : '.__('Firing'); echo ''; } else { echo __('Step').' 2 : '.__('Firing'); } if ($step == 2) echo ''; /* Step 3 */ echo ' » '; if ($step == 3) echo ''; if ($id) { echo ''; echo __('Step').' 3 : '.__('Recovery'); echo ''; } else { echo __('Step').' 3 : '.__('Recovery'); } if ($step == 3) echo ''; echo ''; } function update_template ($step) { $id = (int) get_parameter ('id'); if (empty ($id)) return false; if ($step == 1) { $type = (string) get_parameter ('type'); $name = (string) get_parameter ('name'); $description = (string) get_parameter ('description'); $type = (string) get_parameter ('type'); $value = (string) get_parameter ('value'); $max = (float) get_parameter ('max'); $min = (float) get_parameter ('min'); $matches = (bool) get_parameter ('matches_value'); $result = update_alert_template ($id, array ('type' => $type, 'description' => $description, 'value' => $value, 'max_value' => $max, 'min_value' => $min, 'matches_value' => $matches)); } elseif ($step == 2) { $monday = (bool) get_parameter ('monday'); $tuesday = (bool) get_parameter ('tuesday'); $wednesday = (bool) get_parameter ('wednesday'); $thursday = (bool) get_parameter ('thursday'); $friday = (bool) get_parameter ('friday'); $saturday = (bool) get_parameter ('saturday'); $sunday = (bool) get_parameter ('sunday'); $time_from = (string) get_parameter ('time_from'); $time_from = date ("H:s:00", strtotime ($time_from)); $time_to = (string) get_parameter ('time_to'); $time_to = date ("H:s:00", strtotime ($time_to)); $threshold = (int) get_parameter ('threshold'); $max_alerts = (int) get_parameter ('max_alerts'); $min_alerts = (int) get_parameter ('min_alerts'); if ($threshold == -1) $threshold = (int) get_parameter ('other_threshold'); $field1 = (string) get_parameter ('field1'); $field2 = (string) get_parameter ('field2'); $field3 = (string) get_parameter ('field3'); $default_action = (int) get_parameter ('default_action'); if (empty ($default_action)) { $default_action = NULL; $field1 = ''; $field2 = ''; $field3 = ''; } $values = array ('monday' => $monday, 'tuesday' => $tuesday, 'wednesday' => $wednesday, 'thursday' => $thursday, 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, 'time_from' => $time_from, 'time_to' => $time_to, 'time_threshold' => $threshold, 'default_action' => $default_action, 'field1' => $field1, 'field2' => $field2, 'field3' => $field3, 'max_alerts' => $max_alerts, 'min_alerts' => $min_alerts ); if ($default_action) { $values['id_alert_action'] = $default_action; $values['field1'] = $field1; $values['field2'] = $field2; $values['field3'] = $field3; } $result = update_alert_template ($id, $values); } elseif ($step == 3) { $recovery_notify = (bool) get_parameter ('recovery_notify'); $field2_recovery = (bool) get_parameter ('field2_recovery'); $field3_recovery = (bool) get_parameter ('field3_recovery'); $result = update_alert_template ($id, array ('recovery_notify' => $recovery_notify, 'field2_recovery' => $field2_recovery, 'field3_recovery' => $field3_recovery)); } else { return false; } return $result; } $id = (int) get_parameter ('id'); /* We set here the number of steps */ define ('LAST_STEP', 3); $step = (int) get_parameter ('step', 1); $create_template = (bool) get_parameter ('create_template'); $update_template = (bool) get_parameter ('update_template'); $name = ''; $description = ''; $type = ''; $value = ''; $max = ''; $min = ''; $time_from = '12:00'; $time_to = '12:00'; $monday = true; $tuesday = true; $wednesday = true; $thursday = true; $friday = true; $saturday = true; $sunday = true; $default_action = 0; $field1 = ''; $field2 = ''; $field3 = ''; $min_alerts = 0; $max_alerts = 1; $threshold = 300; $recovery_notify = false; $field2_recovery = ''; $field3_recovery = ''; $matches = true; if ($create_template) { $name = (string) get_parameter ('name'); $description = (string) get_parameter ('description'); $type = (string) get_parameter ('type'); $value = (string) get_parameter ('value'); $max = (float) get_parameter ('max'); $min = (float) get_parameter ('min'); $matches = (bool) get_parameter ('matches_value'); $result = create_alert_template ($name, $type, array ('description' => $description, 'value' => $value, 'max_value' => $max, 'min_value' => $min, 'matches_value' => $matches)); print_error_message ($result, __('Successfully created'), __('Could not be created')); /* Go to previous step in case of error */ if ($result === false) $step = $step - 1; else $id = $result; } if ($update_template) { $result = update_template ($step - 1); print_error_message ($result, __('Successfully updated'), __('Could not be updated')); /* Go to previous step in case of error */ if ($result === false) { $step = $step - 1; } } if ($id && ! $create_template) { $template = get_alert_template ($id); $name = $template['name']; $description = $template['description']; $type = $template['type']; $value = $template['value']; $max = $template['max_value']; $min = $template['min_value']; $matches = $template['matches_value']; $time_from = $template['time_from']; $time_to = $template['time_to']; $monday = (bool) $template['monday']; $tuesday = (bool) $template['tuesday']; $wednesday = (bool) $template['wednesday']; $thursday = (bool) $template['thursday']; $friday = (bool) $template['friday']; $saturday = (bool) $template['saturday']; $sunday = (bool) $template['sunday']; $max_alerts = $template['max_alerts']; $min_alerts = $template['min_alerts']; $threshold = $template['time_threshold']; $recovery_notify = $template['recovery_notify']; $field2_recovery = $template['field2_recovery']; $field3_recovery = $template['field3_recovery']; $default_action = $template['id_alert_action']; $field1 = $template['field1']; $field2 = $template['field2']; $field3 = $template['field3']; } echo '

'.__('Configure alert template').'

'; print_alert_template_steps ($step, $id); $table->id = 'template'; $table->width = '90%'; $table->style = array (); $table->style[0] = 'font-weight: bold'; $table->style[2] = 'font-weight: bold'; $table->size = array (); $table->size[0] = '20%'; $table->size[2] = '20%'; if ($step == 2) { /* Firing conditions and events */ $threshold_values = get_alert_template_threshold_values (); if (in_array ($threshold, array_keys ($threshold_values))) { $table->style['other_label'] = 'display:none; font-weight: bold'; $table->style['other_input'] = 'display:none'; $threshold_selected = $threshold; } else { $table->style['other_label'] = 'font-weight: bold'; $threshold_selected = -1; } if ($default_action == 0) { $table->rowstyle = array (); $table->rowstyle['field1'] = 'display: none'; $table->rowstyle['field2'] = 'display: none'; $table->rowstyle['field3'] = 'display: none'; $table->rowstyle['preview'] = 'display: none'; } $table->colspan = array (); $table->colspan[0][1] = 3; $table->colspan[4][1] = 3; $table->colspan['field1'][1] = 3; $table->colspan['field2'][1] = 3; $table->colspan['field3'][1] = 3; $table->colspan['preview'][1] = 3; $table->data[0][0] = __('Days of week'); $table->data[0][1] = __('Mon'); $table->data[0][1] .= print_checkbox ('monday', 1, $monday, true); $table->data[0][1] .= __('Tue'); $table->data[0][1] .= print_checkbox ('tuesday', 1, $tuesday, true); $table->data[0][1] .= __('Wed'); $table->data[0][1] .= print_checkbox ('wednesday', 1, $wednesday, true); $table->data[0][1] .= __('Thu'); $table->data[0][1] .= print_checkbox ('thursday', 1, $thursday, true); $table->data[0][1] .= __('Fri'); $table->data[0][1] .= print_checkbox ('friday', 1, $friday, true); $table->data[0][1] .= __('Sat'); $table->data[0][1] .= print_checkbox ('saturday', 1, $saturday, true); $table->data[0][1] .= __('Sun'); $table->data[0][1] .= print_checkbox ('sunday', 1, $sunday, true); $table->data[1][0] = __('Time from'); $table->data[1][1] = print_input_text ('time_from', $time_from, '', 7, 7, true); $table->data[1][2] = __('Time to'); $table->data[1][3] = print_input_text ('time_to', $time_to, '', 7, 7, true); $table->data['threshold'][0] = __('Time threshold'); $table->data['threshold'][1] = print_select ($threshold_values, 'threshold', $threshold_selected, '', '', '', true, false, false); $table->data['threshold']['other_label'] = __('Other value'); $table->data['threshold']['other_input'] = print_input_text ('other_threshold', $threshold, '', 5, 7, true); $table->data['threshold']['other_input'] .= ' '.__('seconds'); $table->data[3][0] = __('Min. number of alerts'); $table->data[3][1] = print_input_text ('min_alerts', $min_alerts, '', 5, 7, true); $table->data[3][2] = __('Max. number of alerts'); $table->data[3][3] = print_input_text ('max_alerts', $max_alerts, '', 5, 7, true); $table->data[4][0] = __('Default action'); $table->data[4][1] = print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', 'default_action', $default_action, '', __('None'), 0, true, false, false); $table->data['field1'][0] = __('Field 1'); $table->data['field1'][1] = print_input_text ('field1', $field1, '', 35, 255, true); $table->data['field2'][0] = __('Field 2'); $table->data['field2'][1] = print_input_text ('field2', $field2, '', 35, 255, true); $table->data['field3'][0] = __('Field 3'); $table->data['field3'][1] = print_textarea ('field3', 30, 30, $field3, '', true); $table->data['preview'][0] = __('Command preview'); $table->data['preview'][1] = print_textarea ('command_preview', 30, 30, '', 'disabled="disabled"', true); } else if ($step == 3) { /* Alert recover */ if (! $recovery_notify) { $table->rowstyle = array (); $table->rowstyle['field2'] = 'display:none;'; $table->rowstyle['field3'] = 'display:none'; } $table->data[0][0] = __('Alert recovery'); $values = array (false => __('Disabled'), true => __('Enabled')); $table->data[0][1] = print_select ($values, 'recovery_notify', $recovery_notify, '', '', '', true, false, false); $table->data['field2'][0] = __('Field 2'); $table->data['field2'][1] = print_input_text ('field2_recovery', $field2_recovery, '', 35, 255, true); $table->data['field3'][0] = __('Field 3'); $table->data['field3'][1] = print_textarea ('field3_recovery', 30, 30, $field3_recovery, '', true); } else { /* Step 1 by default */ $table->size = array (); $table->size[0] = '20%'; $table->data = array (); $table->rowstyle = array (); $table->rowstyle['value'] = 'display: none'; $table->rowstyle['max'] = 'display: none'; $table->rowstyle['min'] = 'display: none'; $table->rowstyle['example'] = 'display: none'; $show_matches = false; if ($id) { $table->rowstyle['example'] = ''; switch ($type) { case "regex": $show_matches = true; $table->rowstyle['value'] = ''; break; case "max_min": $show_matches = true; case "max": $table->rowstyle['max'] = ''; if ($type == 'max') break; case "min": $table->rowstyle['min'] = ''; break; } } $table->data[0][0] = __('Name'); $table->data[0][1] = print_input_text ('name', $name, '', 35, 255, true); $table->data[1][0] = __('Description'); $table->data[1][1] = print_textarea ('description', 30, 30, $description, '', true); $table->data[2][0] = __('Condition type'); $table->data[2][1] = print_select (get_alert_templates_types (), 'type', $type, '', __('Select'), 0, true, false, false); $table->data[2][1] .= ''; $table->data[2][1] .= ' '.print_checkbox ('matches_value', 1, $matches, true); $table->data[2][1] .= print_label (__('Trigger when matches the value'), 'checkbox-matches_value', true); $table->data[2][1] .= ''; $table->data['value'][0] = __('Value'); $table->data['value'][1] = print_input_text ('value', $value, '', 35, 255, true); $table->data['value'][1] .= ' '; $table->data['value'][1] .= print_image ('images/suc.png', true, array ('style' => 'display:none', 'id' => 'regex_good', 'title' => __('The regular expression is valid'))); $table->data['value'][1] .= print_image ('images/err.png', true, array ('style' => 'display:none', 'id' => 'regex_bad', 'title' => __('The regular expression is not valid'))); $table->data['value'][1] .= ''; //Min first, then max, that's more logical $table->data['min'][0] = __('Min.'); $table->data['min'][1] = print_input_text ('min', $min, '', 5, 255, true); $table->data['max'][0] = __('Max.'); $table->data['max'][1] = print_input_text ('max', $max, '', 5, 255, true); $table->data['example'][1] = print_alert_template_example ($id, true); $table->colspan['example'][1] = 2; } /* If it's the last step it will redirect to template lists */ if ($step >= LAST_STEP) { echo '
'; } else { echo ''; } print_table ($table); echo '
'; if ($id) { print_input_hidden ('id', $id); print_input_hidden ('update_template', 1); } else { print_input_hidden ('create_template', 1); } if ($step >= LAST_STEP) { print_submit_button (__('Finish'), 'finish', false, 'class="sub upd"'); } else { print_input_hidden ('step', $step + 1); print_submit_button (__('Next'), 'next', false, 'class="sub next"'); } echo '
'; echo '
'; ?>