'; if (defined('METACONSOLE')) { $sec = 'advanced'; } else { $sec = 'galertas'; } $pure = get_parameter('pure', 0); /* Step 1 */ if ($step == 1) echo '
  • '; elseif ($step > 1) echo '
  • '; else echo '
  • '; if ($id) { echo ''; echo __('Step') . ' 1 » '; echo '' . __('Conditions') . ''; echo ''; } else { echo __('Step') . ' 1 » '; echo '' . __('Conditions') . ''; } echo '
  • '; /* Step 2 */ if ($step == 2) echo '
  • '; elseif ($step > 2) echo '
  • '; else echo '
  • '; if ($id) { echo ''; echo __('Step').' 2 » '; echo ''.__('Firing').''; echo ''; } else { echo __('Step').' 2 » '; echo ''.__('Firing').''; } echo '
  • '; /* Step 3 */ if ($step == 3) echo '
  • '; elseif ($step > 3) echo '
  • '; else echo '
  • '; if ($id) { echo ''; echo __('Step').' 3 » '; echo ''.__('Recovery').''; echo ''; } else { echo __('Step').' 3 » '; echo ''.__('Recovery').''; } echo ''; echo '
    '; } function update_template ($step) { global $config; $id = (int) get_parameter ('id'); if (empty ($id)) return false; if (defined('METACONSOLE')) { $sec = 'advanced'; } else { $sec = 'galertas'; } if ($step == 1) { $name = (string) get_parameter ('name'); $description = (string) get_parameter ('description'); $type = (string) get_parameter ('type'); $value = (string) html_entity_decode (get_parameter ('value')); $max = (float) get_parameter ('max'); $min = (float) get_parameter ('min'); $matches = (bool) get_parameter ('matches_value'); $wizard_level = (string) get_parameter ('wizard_level'); $priority = (int) get_parameter ('priority'); $id_group = get_parameter ("id_group"); $name_check = db_get_value ('name', 'talert_templates', 'name', $name); $values = array ('name' => $name, 'type' => $type, 'description' => $description, 'value' => $value, 'max_value' => $max, 'min_value' => $min, 'id_group' => $id_group, 'matches_value' => $matches, 'priority' => $priority, 'wizard_level' => $wizard_level); $result = alerts_update_alert_template ($id,$values); } 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'); $special_day = (bool) get_parameter ('special_day'); $time_from = (string) get_parameter ('time_from'); $time_from = date ("H:i:00", strtotime ($time_from)); $time_to = (string) get_parameter ('time_to'); $time_to = date ("H:i:00", strtotime ($time_to)); $threshold = (int) get_parameter ('threshold'); $max_alerts = (int) get_parameter ('max_alerts'); $min_alerts = (int) get_parameter ('min_alerts'); $default_action = (int) get_parameter ('default_action'); if (empty ($default_action)) { $default_action = NULL; } $values = array ( 'monday' => $monday, 'tuesday' => $tuesday, 'wednesday' => $wednesday, 'thursday' => $thursday, 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, 'special_day' => $special_day, 'time_threshold' => $threshold, 'id_alert_action' => $default_action, 'max_alerts' => $max_alerts, 'min_alerts' => $min_alerts); $fields = array(); for($i=1;$i<=10;$i++) { $values['field'.$i] = $fields[$i] = (string) get_parameter ('field'.$i); } // Different datetimes format for oracle switch ($config['dbtype']){ case "mysql": case "postgresql": $values['time_from'] = $time_from; $values['time_to'] = $time_to; break; case "oracle": $values['time_from'] = "#to_date('" . $time_from . "','hh24:mi:ss')"; $values['time_to'] = "#to_date('" . $time_to . "','hh24:mi:ss')"; break; } $result = alerts_update_alert_template ($id, $values); } elseif ($step == 3) { $recovery_notify = (bool) get_parameter ('recovery_notify'); $fields_recovery = array(); for($i=2;$i<=10;$i++) { $fields_recovery['field'.$i] = (string) get_parameter ('field'.$i); } $values = $fields_recovery; $values['recovery_notify'] = $recovery_notify; $result = alerts_update_alert_template ($id, $values); } else { return false; } if ($result) { db_pandora_audit("Template alert management", "Update alert template #" . $id, false, false, json_encode($values)); } else { db_pandora_audit("Template alert management", "Fail try to update alert template #" . $id, false, false, json_encode($values)); } return $result; } /* We set here the number of steps */ define ('LAST_STEP', 3); $step = (int) get_parameter ('step', 1); $create_alert = (bool) get_parameter ('create_alert'); $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; $special_day = false; $default_action = 0; $fields = array(); for ($i = 1; $i <= 10; $i++) { $fields[$i] = ''; } $priority = 1; $min_alerts = 0; $max_alerts = 1; $threshold = SECONDS_1DAY; $recovery_notify = false; $field2_recovery = ''; $field3_recovery = ''; $matches = true; $id_group = 0; $wizard_level = 'nowizard'; 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'); $priority = (int) get_parameter ('priority'); $wizard_level = (string) get_parameter ('wizard_level'); $id_group = get_parameter ("id_group"); $name_check = db_get_value ('name', 'talert_templates', 'name', $name); $values = array ('description' => $description, 'value' => $value, 'max_value' => $max, 'min_value' => $min, 'id_group' => $id_group, 'matches_value' => $matches, 'priority' => $priority, 'wizard_level' => $wizard_level); if ($config['dbtype'] == "oracle") { $values['field3'] = ' '; $values['field3_recovery'] = ' '; } if (!$name_check) { $result = alerts_create_alert_template ($name, $type, $values); } else { $result = ''; } if ($result) { //db_pandora_audit("Command management", "Create alert command " . $result, false, false, json_encode($values)); db_pandora_audit("Template alert management", "Create alert template #" . $result, false, false, json_encode($values)); } else { //db_pandora_audit("Command management", "Fail try to create alert command", false, false, json_encode($values)); db_pandora_audit("Template alert management", "Fail try to create alert template", false, false, json_encode($values)); } ui_print_result_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); ui_print_result_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 = alerts_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']; $special_day = (bool) $template['special_day']; $max_alerts = $template['max_alerts']; $min_alerts = $template['min_alerts']; $threshold = $template['time_threshold']; $fields = array(); for ($i = 1; $i <= 10; $i++) { $fields[$i] = $template['field'.$i]; } $recovery_notify = $template['recovery_notify']; $fields_recovery = array(); for ($i = 2; $i <= 10; $i++) { $fields_recovery[$i] = $template['field'.$i.'_recovery']; } $default_action = $template['id_alert_action']; $priority = $template['priority']; $id_group = $template['id_group']; $wizard_level = $template['wizard_level']; } print_alert_template_steps ($step, $id); $table->id = 'template'; $table->width = '98%'; $table->style = array (); $table->style[0] = 'font-weight: bold; vertical-align: top'; $table->style[2] = 'font-weight: bold; vertical-align: top'; $table->size = array (); $table->size[0] = '20%'; $table->size[2] = '20%'; if ($step == 2) { /* Firing conditions and events */ $table->colspan = array (); $table->colspan[4][1] = 3; $table->data[0][0] = __('Days of week'); $table->data[0][1] = __('Mon'); $table->data[0][1] .= html_print_checkbox ('monday', 1, $monday, true); $table->data[0][1] .= __('Tue'); $table->data[0][1] .= html_print_checkbox ('tuesday', 1, $tuesday, true); $table->data[0][1] .= __('Wed'); $table->data[0][1] .= html_print_checkbox ('wednesday', 1, $wednesday, true); $table->data[0][1] .= __('Thu'); $table->data[0][1] .= html_print_checkbox ('thursday', 1, $thursday, true); $table->data[0][1] .= __('Fri'); $table->data[0][1] .= html_print_checkbox ('friday', 1, $friday, true); $table->data[0][1] .= __('Sat'); $table->data[0][1] .= html_print_checkbox ('saturday', 1, $saturday, true); $table->data[0][1] .= __('Sun'); $table->data[0][1] .= html_print_checkbox ('sunday', 1, $sunday, true); $table->data[0][2] = __('Use special days list'); $table->data[0][3] = html_print_checkbox ('special_day', 1, $special_day, true); $table->data[1][0] = __('Time from'); $table->data[1][1] = html_print_input_text ('time_from', $time_from, '', 7, 7, true); $table->data[1][2] = __('Time to'); $table->data[1][3] = html_print_input_text ('time_to', $time_to, '', 7, 7, true); $table->colspan['threshold'][1] = 3; $table->data['threshold'][0] = __('Time threshold'); $table->data['threshold'][1] = html_print_extended_select_for_time ('threshold', $threshold, '', '', '', false, true); $table->data[3][0] = __('Min. number of alerts'); $table->data[3][1] = html_print_input_text ('min_alerts', $min_alerts, '', 5, 7, true); $table->data[3][2] = __('Max. number of alerts'); $table->data[3][3] = html_print_input_text ('max_alerts', $max_alerts, '', 5, 7, true); $table->colspan['fields_switch'][0] = 4; $table->data['fields_switch'][0] = ''.__('Advanced fields management').' '.html_print_image('images/down.png',true).''; for ($i = 1; $i <= 10; $i++) { if (isset($template[$name])) { $value = $template[$name]; } else { $value = ''; } $table->colspan['field'.$i][1] = 3; $table->rowclass['field'.$i] = 'row_field'; $table->data['field'.$i][0] = sprintf(__('Field %s'), $i) . ui_print_help_icon ('alert_macros', true); $table->data['field'.$i][1] = html_print_textarea ('field'.$i, 1, 1, isset($fields[$i]) ? $fields[$i] : '', 'style="min-height:40px;" class="fields"', true); } $table->data[4][0] = __('Default action'); $usr_groups = implode(',', array_keys(users_get_groups($config['id_user'], 'LM', true))); switch ($config['dbtype']){ case "mysql": case "postgresql": $sql_query = sprintf('SELECT id, name FROM talert_actions WHERE id_group IN (%s) ORDER BY name', $usr_groups); break; case "oracle": $sql_query = sprintf('SELECT id, dbms_lob.substr(name,4000,1) as nombre FROM talert_actions WHERE id_group IN (%s) ORDER BY dbms_lob.substr(name,4000,1)', $usr_groups); break; } $table->data[4][1] = html_print_select_from_sql ($sql_query, 'default_action', $default_action, '', __('None'), 0, true, false, false).ui_print_help_tip (__('In case you fill any Field 1, Field 2 or Field 3 above, those will replace the corresponding fields of this associated "Default action".'), true); } else if ($step == 3) { /* Alert recover */ if (! $recovery_notify) { $table->rowstyle = array (); $table->rowstyle['field2'] = 'display:none;'; $table->rowstyle['field3'] = 'display:none'; $table->rowstyle['field4'] = 'display:none'; $table->rowstyle['field5'] = 'display:none'; $table->rowstyle['field6'] = 'display:none'; $table->rowstyle['field7'] = 'display:none'; $table->rowstyle['field8'] = 'display:none'; $table->rowstyle['field9'] = 'display:none'; $table->rowstyle['field10'] = 'display:none'; } $table->data[0][0] = __('Alert recovery'); $values = array (false => __('Disabled'), true => __('Enabled')); $table->data[0][1] = html_print_select ($values, 'recovery_notify', $recovery_notify, '', '', '', true, false, false); for($i=2;$i<=10;$i++) { $table->data['field'.$i][0] = sprintf(__('Field %s'), $i); $table->data['field'.$i][1] = html_print_textarea ('field'.$i, 1, 1, isset($fields_recovery[$i]) ? $fields_recovery[$i] : '', 'style="min-height:40px" class="fields"', 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'; $show_matches = false; switch ($type) { case "equal": case "not_equal": 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; case "onchange": $show_matches = true; break; } $table->data[0][0] = __('Name'); $table->data[0][1] = html_print_input_text ('name', $name, '', 35, 255, true); $table->data[0][1] .= "  ". __("Group"); $groups = users_get_groups (); $own_info = get_user_info($config['id_user']); // Only display group "All" if user is administrator or has "PM" privileges if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) $display_all_group = true; else $display_all_group = false; $table->data[0][1] .= " " . html_print_select_groups(false, "AR", $display_all_group, 'id_group', $id_group, '', '', 0, true); $table->data[1][0] = __('Description'); $table->data[1][1] = html_print_textarea ('description', 10, 30, $description, '', true); $table->data[2][0] = __('Priority'); $table->data[2][1] = html_print_select (get_priorities (), 'priority', $priority, '', 0, 0, true, false, false); if(defined('METACONSOLE')) { $table->data[3][0] = __('Wizard level'); $wizard_levels = array( 'basic' => __('Basic'), 'advanced' => __('Advanced')); $table->data[3][1] = html_print_select($wizard_levels,'wizard_level',$wizard_level,'','',-1,true, false, false); } else { $table->data[2][1] .= html_print_input_hidden('wizard_level',$wizard_level,true); } $table->data[4][0] = __('Condition type'); $table->data[4][1] = html_print_select (alerts_get_alert_templates_types (), 'type', $type, '', __('Select'), 0, true, false, false); $table->data[4][1] .= ''; $table->data[4][1] .= ' '.html_print_checkbox ('matches_value', 1, $matches, true); $table->data[4][1] .= html_print_label (__('Trigger when matches the value'), 'checkbox-matches_value', true); $table->data[4][1] .= ''; $table->data['value'][0] = __('Value'); $table->data['value'][1] = html_print_input_text ('value', $value, '', 35, 255, true); $table->data['value'][1] .= ' '; $table->data['value'][1] .= html_print_image ('images/suc.png', true, array ('style' => 'display:none', 'id' => 'regex_good', 'title' => __('The regular expression is valid'))); $table->data['value'][1] .= html_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] = html_print_input_text ('min', $min, '', 5, 255, true); $table->data['max'][0] = __('Max.'); $table->data['max'][1] = html_print_input_text ('max', $max, '', 5, 255, true); $table->data['example'][1] = ui_print_alert_template_example ($id, true, false); $table->colspan['example'][1] = 2; } /* If it's the last step it will redirect to template lists */ if ($step >= LAST_STEP) { echo '
    '; } else { echo ''; } html_print_table ($table); echo '
    '; if ($id) { html_print_input_hidden ('id', $id); html_print_input_hidden ('update_template', 1); } else { html_print_input_hidden ('create_template', 1); } $disabled = false; if (!$create_alert && !$create_template) { if ($a_template['id_group'] == 0) { // then must have "PM" access privileges if (! check_acl ($config['id_user'], 0, "PM")) { $disabled = true; } } } if (!$disabled) { if ($step >= LAST_STEP) { html_print_submit_button (__('Finish'), 'finish', false, 'class="sub upd"'); } else { html_print_input_hidden ('step', $step + 1); html_print_submit_button (__('Next'), 'next', false, 'class="sub next"'); } } echo '
    '; echo '
    '; enterprise_hook('close_meta_frame'); ui_require_javascript_file ('pandora_alerts'); ui_require_jquery_file ("ui-timepicker-addon"); ui_require_javascript_file("i18n/jquery-ui-timepicker-" . get_user_language()); ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); ?>