$name) { if ($i == 0) { $str_user_groups .= $id; } else { $str_user_groups .= ',' . $id; } $i++; } $url = "index.php?sec=estado&" . "sec2=operation/snmpconsole/snmp_view&" . "filter_severity=" . $filter_severity . "&" . "filter_fired=" . $filter_fired . "&" . "free_search_string=" . $free_search_string . "&" . "pagination=" . $pagination . "&" . "offset=" . $offset . "&" . "trap_type=" . $trap_type . "&" . "group_by=" .$group_by; $statistics['text'] = '' . html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .''; $list['text'] = '' . html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .''; $list['active'] = true; if ($config["pure"]) { $fullscreen['text'] = '' . html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen'))) . ''; } else { // Fullscreen $fullscreen['text'] = '' . html_print_image("images/full_screen.png", true, array("title" => __('Full screen'))) . ''; } // Header ui_print_page_header(__("SNMP Console"), "images/op_snmp.png", false, "", false, array($fullscreen, $list, $statistics)); // OPERATIONS // Delete SNMP Trap entry Event (only incident management access). if (isset ($_GET["delete"])) { $id_trap = (int) get_parameter_get ("delete", 0); if ($id_trap > 0 && check_acl ($config['id_user'], 0, "IM")) { $result = db_process_sql_delete('ttrap', array('id_trap' => $id_trap)); ui_print_result_message ($result, __('Successfully deleted'), __('Could not be deleted')); } else { db_pandora_audit("ACL Violation", "Trying to delete SNMP event ID #".$id_trap); } } // Check Event (only incident write access). if (isset ($_GET["check"])) { $id_trap = (int) get_parameter_get ("check", 0); if (check_acl ($config['id_user'], 0, "IW")) { $values = array( 'status' => 1, 'id_usuario' => $config["id_user"]); $result = db_process_sql_update('ttrap', $values, array('id_trap' => $id_trap)); ui_print_result_message ($result, __('Successfully updated'), __('Could not be updated')); } else { db_pandora_audit("ACL Violation", "Trying to checkout SNMP Trap ID".$id_trap); } } // Mass-process DELETE if (isset ($_POST["deletebt"])) { $trap_ids = get_parameter_post ("snmptrapid", array ()); if (is_array ($trap_ids) && check_acl ($config['id_user'], 0, "IW")) { foreach ($trap_ids as $id_trap) { db_process_sql_delete('ttrap', array('id_trap' => $id_trap)); } } else { db_pandora_audit("ACL Violation", "Trying to mass-delete SNMP Trap ID"); } } // Mass-process UPDATE if (isset ($_POST["updatebt"])) { $trap_ids = get_parameter_post ("snmptrapid", array ()); if (is_array ($trap_ids) && check_acl ($config['id_user'], 0, "IW")) { foreach ($trap_ids as $id_trap) { $sql = sprintf ("UPDATE ttrap SET status = 1, id_usuario = '%s' WHERE id_trap = %d", $config["id_user"], $id_trap); db_process_sql ($sql); } } else { db_pandora_audit("ACL Violation", "Trying to mass-delete SNMP Trap ID"); } } // All traps $all_traps = db_get_all_rows_sql ("SELECT DISTINCT source FROM ttrap"); if (empty($all_traps)) $all_traps = array(); // Set filters $agents = array (); $oids = array (); $severities = get_priorities (); $alerted = array (__('Not fired'), __('Fired')); foreach ($all_traps as $trap) { $agent = agents_get_agent_with_ip ($trap['source']); $agents[$trap["source"]] = $agent !== false ? $agent["nombre"] : $trap["source"]; $oid = enterprise_hook ('get_oid', array ($trap)); if ($oid === ENTERPRISE_NOT_HOOK) { $oid = $trap["oid"]; } $oids[$oid] = $oid; } //Make query to extract traps of DB. switch ($config["dbtype"]) { case "mysql": $sql = "SELECT * FROM ttrap WHERE (`source` IN ( SELECT direccion FROM tagente WHERE id_grupo IN ($str_user_groups) ) OR `source`='' OR `source` NOT IN (SELECT direccion FROM tagente)) %s ORDER BY timestamp DESC LIMIT %d,%d"; break; case "postgresql": case "oracle": $sql = "SELECT * FROM ttrap WHERE (source IN ( SELECT direccion FROM tagente WHERE id_grupo IN ($str_user_groups) ) OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s ORDER BY timestamp DESC LIMIT %d OFFSET %d"; break; } $sql_all = "SELECT * FROM ttrap WHERE (source IN ( SELECT direccion FROM tagente WHERE id_grupo IN ($str_user_groups) ) OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s ORDER BY timestamp DESC"; $sql_count = "SELECT COUNT(id_trap) FROM ttrap WHERE (source IN ( SELECT direccion FROM tagente WHERE id_grupo IN ($str_user_groups) ) OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s"; //$whereSubquery = 'WHERE 1=1'; $whereSubquery = ''; if ($filter_fired != -1) $whereSubquery .= ' AND alerted = ' . $filter_fired; if ($free_search_string != '') { switch ($config["dbtype"]) { case "mysql": $whereSubquery .= ' AND (source LIKE "%' . $free_search_string . '%" OR oid LIKE "%' . $free_search_string . '%" OR oid_custom LIKE "%' . $free_search_string . '%" OR type_custom LIKE "%' . $free_search_string . '%" OR value LIKE "%' . $free_search_string . '%" OR value_custom LIKE "%' . $free_search_string . '%" OR id_usuario LIKE "%' . $free_search_string . '%" OR text LIKE "%' . $free_search_string . '%" OR description LIKE "%' . $free_search_string . '%")'; break; case "postgresql": case "oracle": $whereSubquery .= ' AND (source LIKE \'%' . $free_search_string . '%\' OR oid LIKE \'%' . $free_search_string . '%\' OR oid_custom LIKE \'%' . $free_search_string . '%\' OR type_custom LIKE \'%' . $free_search_string . '%\' OR value LIKE \'%' . $free_search_string . '%\' OR value_custom LIKE \'%' . $free_search_string . '%\' OR id_usuario LIKE \'%' . $free_search_string . '%\' OR text LIKE \'%' . $free_search_string . '%\' OR description LIKE \'%' . $free_search_string . '%\')'; break; } } if ($filter_severity != -1) { //Test if install the enterprise to search oid in text or oid field in ttrap. if ($config['enterprise_installed']) $whereSubquery .= ' AND ( (alerted = 0 AND severity = ' . $filter_severity . ') OR (alerted = 1 AND priority = ' . $filter_severity . '))'; else $whereSubquery .= ' AND ( (alerted = 0 AND 1 = ' . $filter_severity . ') OR (alerted = 1 AND priority = ' . $filter_severity . '))'; } if ($filter_status != -1) $whereSubquery .= ' AND status = ' . $filter_status; if ($trap_type == 5) { $whereSubquery .= ' AND type NOT IN (0, 1, 2, 3, 4)'; } else if ($trap_type != -1){ $whereSubquery .= ' AND type = ' . $trap_type; } if ($group_by) { $where_without_group = $whereSubquery; $whereSubquery .= ' GROUP BY source,oid'; } switch ($config["dbtype"]) { case "mysql": $sql = sprintf($sql, $whereSubquery, $offset, $pagination); break; case "postgresql": $sql = sprintf($sql, $whereSubquery, $pagination, $offset); break; case "oracle": $set = array(); $set['limit'] = $pagination; $set['offset'] = $offset; $sql = oracle_recode_query ($sql, $set); break; } $sql_all = sprintf($sql_all, $whereSubquery); $sql_count = sprintf($sql_count, $whereSubquery); $table->width = '90%'; $table->size = array (); $table->size[0] = '120px'; $table->data = array (); // Alert status select $table->data[1][0] = ''.__('Alert').''; $table->data[1][1] = html_print_select ($alerted, "filter_fired", $filter_fired, 'javascript:this.form.submit();', __('All'), '-1', true); // Block size for pagination select $table->data[2][0] = ''.__('Block size for pagination').''; $paginations[25] = 25; $paginations[50] = 50; $paginations[100] = 100; $paginations[200] = 200; $paginations[500] = 500; $table->data[2][1] = html_print_select ($paginations, "pagination", $pagination, 'this.form.submit();', __('Default'), $config["block_size"], true); // Severity select $table->data[1][2] = ''.__('Severity').''; $table->data[1][3] = html_print_select ($severities, 'filter_severity', $filter_severity, 'this.form.submit();', __('All'), -1, true); // Status $table->data[3][0] = ''.__('Status').''; $status_array[-1] = __('All'); $status_array[0] = __('Not validated'); $status_array[1] = __('Validated'); $table->data[3][1] = html_print_select ($status_array, 'filter_status', $filter_status, 'this.form.submit();', '', '', true); // Free search (search by all alphanumeric fields) $table->data[2][3] = ''.__('Free search').'' . ui_print_help_tip(__('Search by any alphanumeric field in the trap'), true); $table->data[2][4] = html_print_input_text ('free_search_string', $free_search_string, '', 40, 0, true); // Type filter (ColdStart, WarmStart, LinkDown, LinkUp, authenticationFailure, Other) $table->data[4][1] = ''.__('Trap type').'' . ui_print_help_tip(__('Search by trap type'), true); $trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other')); $table->data[4][2] = html_print_select ($trap_types, 'trap_type', $trap_type, 'this.form.submit();', '', '', true, false, false); $table->data[3][3] = ''.__('Group by Enterprise String/IP').''; $table->data[3][4] = __('Yes') . ' '. html_print_radio_button ('group_by', 1, '', $group_by, true) . ' '; $table->data[3][4] .= __('No') . ' ' . html_print_radio_button ('group_by', 0, '', $group_by, true); $filter = '
'; ui_toggle($filter, __('Toggle filter(s)')); unset ($table); $traps = db_get_all_rows_sql($sql); $trapcount = (int) db_get_value_sql($sql_count); // No traps if (empty ($traps)) { echo '