$alert_type, 'al_field1' => $al_field1, 'al_field2' => $al_field2, 'al_field3' => $al_field3, 'description' => $description, 'agent' => $source_ip, 'custom_oid' => $custom_value, 'oid' => $oid, 'time_threshold' => $time_threshold, 'max_alerts' => $max_alerts, 'min_alerts' => $min_alerts, 'priority' => $priority); $result = db_process_sql_insert('talert_snmp', $values); if ($result === false) { echo '

'.__('There was a problem creating the alert').'

'; } else { echo '

'.__('Successfully created').'

'; } } else { $sql = sprintf ("UPDATE talert_snmp SET priority = %d, id_alert = %d, al_field1 = '%s', al_field2 = '%s', al_field3 = '%s', description = '%s', agent = '%s', custom_oid = '%s', oid = '%s', time_threshold = %d, max_alerts = %d, min_alerts = %d WHERE id_as = %d", $priority, $alert_type, $al_field1, $al_field2, $al_field3, $description, $source_ip, $custom_value, $oid, $time_threshold, $max_alerts, $min_alerts, $id_as); $result = db_process_sql ($sql); if ($result === false) { echo '

'.__('There was a problem updating the alert').'

'; } else { echo '

'.__('Successfully updated').'

'; } } } else { ui_print_page_header (__('SNMP Console')." » ".__('Alert overview'), "images/computer_error.png", false, "", true); } // From variable init // ================== if ((isset ($_GET["update_alert"])) && ($_GET["update_alert"] != -1)) { $id_as = (int) get_parameter_get ("update_alert", -1); $alert = db_get_row ("talert_snmp", "id_as", $id_as); $id_as = $alert["id_as"]; $source_ip = $alert["agent"]; $alert_type = $alert["id_alert"]; $description = $alert["description"]; $oid = $alert["oid"]; $custom_value = $alert["custom_oid"]; $time_threshold = $alert["time_threshold"]; $al_field1 = $alert["al_field1"]; $al_field2 = $alert["al_field2"]; $al_field3 = $alert["al_field3"]; $max_alerts = $alert["max_alerts"]; $min_alerts = $alert["min_alerts"]; $priority = $alert["priority"]; } elseif (isset ($_GET["update_alert"])) { // Variable init $id_as = -1; $source_ip = ""; $alert_type = 1; //Event, e-mail $description = ""; $oid = ""; $custom_value = ""; $time_threshold = 300; $al_field1 = ""; $al_field2 = ""; $al_field3 = ""; $max_alerts = 1; $min_alerts = 0; $priority = 0; } // Header // Alert Delete // ============= if (isset ($_GET["delete_alert"])) { // Delete alert $alert_delete = (int) get_parameter_get ("delete_alert", 0); $result = db_process_sql_delete('talert_snmp', array('id_as' => $alert_delete)); if ($result === false) { echo '

'.__('There was a problem deleting the alert').'

'; } else { echo '

'.__('Successfully deleted').'

'; } } // Alert form if (isset ($_GET["update_alert"])) { //the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated echo '
'; echo ''; // Alert type (e-mail, event etc.) echo ''; // Description echo ''; // OID echo ''; // OID Custom echo ''; // SNMP Agent echo ''; // Alert fields echo ''; echo ''; echo ''; // Max / Min alerts echo ''; // Time Threshold echo ''; // Priority echo ''; //Button echo '
'.__('Alert action').''; $fields = array (); $result = db_get_all_rows_in_table ('talert_actions', "name"); if ($result === false) { $result = array (); } foreach ($result as $row) { $fields[$row["id"]] = $row["name"]; } html_print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', "alert_type", $alert_type, '', '', 0, false, false, false); echo '
'.__('Description').''; html_print_input_text ("description", $description, '', 60); echo '
'.__('OID').''; html_print_input_text ("oid", $oid, '', 30); echo '
'.__('Custom Value')."/".__("OID").''; html_print_input_text ("custom_value", $custom_value, '', 30); echo '
'.__('SNMP Agent').' (IP)'; html_print_input_text ("source_ip", $source_ip, '', 30); echo '
'.__('Field #1 (Alias, name)').''; html_print_input_text ("al_field1", $al_field1, '', 30); echo '
'.__('Field #2 (Single Line)').''; html_print_input_text ("al_field2", $al_field2, '', 30); echo '
'.__('Field #3 (Full Text)').''; html_print_textarea ("al_field3", $al_field3, 4, $al_field3, 'style="width:400px"'); echo '
'.__('Min. number of alerts').''; html_print_input_text ("min_alerts", $min_alerts, '', 3); echo '
'.__('Max. number of alerts').''; html_print_input_text ("max_alerts", $max_alerts, '', 3); echo '
'.__('Time threshold').''; $fields = array (); $fields[$time_threshold] = human_time_description_raw ($time_threshold); $fields[300] = human_time_description_raw (300); $fields[600] = human_time_description_raw (600); $fields[900] = human_time_description_raw (900); $fields[1800] = human_time_description_raw (1800); $fields[3600] = human_time_description_raw (3600); $fields[7200] = human_time_description_raw (7200); $fields[18000] = human_time_description_raw (18000); $fields[43200] = human_time_description_raw (43200); $fields[86400] = human_time_description_raw (86400); $fields[604800] = human_time_description_raw (604800); $fields[-1] = __('Other value'); html_print_select ($fields, "time_threshold", $time_threshold, '', '', '0', false, false, false, '" style="margin-right:60px'); echo '
'.__('Priority').''; echo html_print_select (get_priorities (), "priority", $priority, '', '', '0', false, false, false); echo '
'; if ($id_as > 0) { html_print_submit_button (__('Update'), "submit", false, 'class="sub upd"', false); } else { html_print_submit_button (__('Create'), "submit", false, 'class="sub wand"', false); } // End table echo "
"; } else { require_once ('include/functions_alerts.php'); //Overview $result = db_get_all_rows_in_table ("talert_snmp"); if ($result === false) { $result = array (); echo "
".__('There are no SNMP alerts')."
"; } $table->data = array (); $table->head = array (); $table->size = array (); $table->cellpadding = 4; $table->cellspacing = 4; $table->width = "750 px"; $table->class= "databox"; $table->align = array (); $table->head[0] = __('Alert action'); $table->head[1] = __('SNMP Agent'); $table->size[1] = "90px"; $table->align[1] = 'center'; $table->head[2] = __('OID'); $table->align[2] = 'center'; $table->head[3] = __('Custom Value/OID'); $table->align[3] = 'center'; $table->head[4] = __('Description'); $table->head[5] = __('Times fired'); $table->align[5] = 'center'; $table->head[6] = __('Last fired'); $table->align[6] = 'center'; $table->head[7] = __('Action'); $table->size[7] = "50px"; $table->align[7] = 'center'; foreach ($result as $row) { $data = array (); $data[0] = alerts_get_alert_action_name ($row["id_alert"]); $data[1] = __('SNMP Agent'); $data[1] = $row["agent"]; $data[2] = __('OID'); $data[2] = $row["oid"]; $data[3] = __('Custom Value/OID'); $data[3] = $row["custom_oid"]; $data[4] = $row["description"]; $data[5] = $row["times_fired"]; if ($row["last_fired"] != "01-01-1970 00:00:00") { $data[6] = $row["last_fired"]; } else { $data[6] = __('Never'); } $data[7] = '' . html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . '  ' . html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . ''; $idx = count ($table->data); //The current index of the table is 1 less than the count of table data so we count before adding to table->data array_push ($table->data, $data); $table->rowclass[$idx] = get_priority_class ($row["priority"]); } if (!empty ($table->data)) { html_print_table ($table); } unset ($table); echo '
'; echo ''; html_print_submit_button (__('Create'), "add_alert", false, 'class="sub next"'); echo "
"; echo '
'; echo '

'.__('Legend').'

'; foreach (get_priorities () as $num => $name) { echo ''.$name.''; echo '
'; } echo '
'; } ?>