Merge branch 'develop' of https://github.com/pandorafms/pandorafms into develop

This commit is contained in:
Sancho Lerena 2014-09-25 18:50:04 +02:00
commit 1184306533
9 changed files with 202 additions and 162 deletions

View File

@ -71,6 +71,11 @@ echo "<div id='background_grid'
//Print the layout datas from the DB.
foreach ($layoutDatas as $layoutData) {
$layoutData['status_calculated'] =
visual_map_get_status_element($layoutData);
// Pending delete and disable modules must be ignored
$delete_pending_module = db_get_value ("delete_pending",
"tagente_modulo", "id_agente_modulo", $layoutData["id_agente_modulo"]);
@ -80,8 +85,12 @@ foreach ($layoutDatas as $layoutData) {
if ($delete_pending_module == 1 || $disabled_module == 1)
continue;
visual_map_print_item($layoutData);
html_print_input_hidden('status_' . $layoutData['id'], visual_map_get_status_element($layoutData));
html_print_input_hidden('status_' . $layoutData['id'], $layoutData['status_calculated']);
}
echo "<img style='position: absolute; top: 0px; left: 0px;' id='background_img' src='" . $metaconsole_hack . "images/console/background/" . $background . "' width='100%' height='100%' />";

View File

@ -299,19 +299,19 @@ define('PASSSWORD_POLICIES_FIRST_CHANGE', 1);
define('PASSSWORD_POLICIES_EXPIRED', 2);
/* SERVER TYPES */
define ('SERVER_TYPE_DATA', 0);
define ('SERVER_TYPE_NETWORK', 1);
define ('SERVER_TYPE_SNMP', 2);
define ('SERVER_TYPE_RECON', 3);
define ('SERVER_TYPE_PLUGIN', 4);
define ('SERVER_TYPE_PREDICTION', 5);
define ('SERVER_TYPE_WMI', 6);
define ('SERVER_TYPE_EXPORT', 7);
define ('SERVER_TYPE_INVENTORY', 8);
define ('SERVER_TYPE_WEB', 9);
define ('SERVER_TYPE_EVENT', 10);
define ('SERVER_TYPE_ENTERPRISE_ICMP', 11);
define ('SERVER_TYPE_ENTERPRISE_SNMP', 12);
define('SERVER_TYPE_DATA', 0);
define('SERVER_TYPE_NETWORK', 1);
define('SERVER_TYPE_SNMP', 2);
define('SERVER_TYPE_RECON', 3);
define('SERVER_TYPE_PLUGIN', 4);
define('SERVER_TYPE_PREDICTION', 5);
define('SERVER_TYPE_WMI', 6);
define('SERVER_TYPE_EXPORT', 7);
define('SERVER_TYPE_INVENTORY', 8);
define('SERVER_TYPE_WEB', 9);
define('SERVER_TYPE_EVENT', 10);
define('SERVER_TYPE_ENTERPRISE_ICMP', 11);
define('SERVER_TYPE_ENTERPRISE_SNMP', 12);
/* REPORTS */
define ('REPORT_TOP_N_MAX', 1);

View File

@ -15,6 +15,7 @@
// GNU General Public License for more details.
require_once ($config['homedir'].'/include/functions_users.php');
require_once ($config['homedir'].'/include/functions_reporting.php');
/**
* Check if the group is in use in the Pandora DB.
@ -531,30 +532,18 @@ function groups_get_groups_tree_recursive($groups, $trash = 0, $trash2 = 0) {
* @return int Status of the agents.
*/
function groups_get_status ($id_group = 0) {
$agents = agents_get_group_agents($id_group);
$data = reporting_get_group_stats($id_group);
$agents_status = array();
foreach ($agents as $key => $agent) {
$agents_status[] = agents_get_status($key);
}
$childrens = groups_get_childrens($id_group);
foreach ($childrens as $key => $child) {
$agents_status[] = groups_get_status($key);
}
// Status is 0 for normal, 1 for critical, 2 for warning and 3/-1 for unknown. 4 for fired alerts
if (is_int(array_search(AGENT_STATUS_ALERT_FIRED, $agents_status))) {
if ($data['monitor_alerts_fired'] > 0) {
return AGENT_STATUS_ALERT_FIRED;
}
elseif (is_int(array_search(AGENT_STATUS_CRITICAL, $agents_status))) {
elseif ($data['agent_critical'] > 0) {
return AGENT_STATUS_CRITICAL;
}
elseif (is_int(array_search(AGENT_STATUS_WARNING, $agents_status))) {
elseif ($data['agent_warning'] > 0) {
return AGENT_STATUS_WARNING;
}
elseif (is_int(array_search(AGENT_STATUS_UNKNOWN, $agents_status))) {
elseif ($data['agent_unknown'] > 0) {
return AGENT_STATUS_UNKNOWN;
}
else {
@ -869,11 +858,12 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
// Get stats for this group
$data = reporting_get_group_stats($id_group);
if ($data["total_agents"] == 0) {
if (!empty($group['childs'])) {
$group_childrens = groups_get_childrens($id_group, null, true);
$group_childrens_agents = groups_total_agents(array_keys($group_childrens));
if (empty($group_childrens_agents)) {
return; // Skip empty groups
}

View File

@ -70,7 +70,7 @@ function visual_map_print_item($layoutData) {
$text = '<span id="text_' . $id . '" class="text">' . $label . '</span>';
$status = visual_map_get_status_element($layoutData);
$status = $layoutData['status_calculated'];
switch ($status) {
case VISUAL_MAP_STATUS_CRITICAL_BAD:
@ -100,7 +100,8 @@ function visual_map_print_item($layoutData) {
switch ($type) {
case STATIC_GRAPH:
if ($layoutData['image'] != null) {
$img = visual_map_get_image_status_element($layoutData);
$img = visual_map_get_image_status_element($layoutData,
$layoutData['status_calculated']);
if (substr($img,0,1) == '4') {
$borderStyle ='border: 2px solid ' . COL_ALERTFIRED . ';';
$img = substr_replace($img, '', 0,1);
@ -127,7 +128,8 @@ function visual_map_print_item($layoutData) {
case GROUP_ITEM:
if ($layoutData['image'] != null) {
$img = visual_map_get_image_status_element($layoutData);
$img = visual_map_get_image_status_element($layoutData,
$layoutData['status_calculated']);
if (substr($img,0,1) == '4') {
$borderStyle ='border: 2px solid ' . COL_ALERTFIRED . ';';
$img = substr_replace($img, '', 0,1);
@ -294,7 +296,8 @@ function visual_map_print_item($layoutData) {
break;
case ICON:
if ($layoutData['image'] != null) {
$img = visual_map_get_image_status_element($layoutData);
$img = visual_map_get_image_status_element($layoutData,
$layoutData['status_calculated']);
}
if (($width != 0) && ($height != 0)) {
@ -869,7 +872,7 @@ function visual_map_get_color_line_status($layoutData) {
*
* @return string The image with the relative path to pandora console directory.
*/
function visual_map_get_image_status_element($layoutData) {
function visual_map_get_image_status_element($layoutData, $status = false) {
$img = "images/console/icons/" . $layoutData["image"];
if ($layoutData['type'] == 5) {
@ -877,7 +880,11 @@ function visual_map_get_image_status_element($layoutData) {
$img .= ".png";
}
else {
switch (visual_map_get_status_element($layoutData)) {
if ($status === false) {
$status = visual_map_get_status_element($layoutData);
}
switch ($status) {
case 1:
//Critical (BAD)
$img .= "_bad.png";

View File

@ -377,116 +377,133 @@ $columns = array(
);
$filter = array(
"id_agente" => $id_agente,
"id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc")
"id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc"),
"disabled" => 0
);
$modules = agents_get_modules($id_agente, $columns, $filter);
$modules = agents_get_modules($id_agente, $columns, $filter, true, false);
$interfaces = array();
if (! empty($modules)) {
$table_interface = new stdClass();
$table_interface->id = 'agent_interface_info';
$table_interface->class = 'databox';
$table_interface->width = '100%';
$table_interface->style = array();
$table_interface->style['interface_status'] = 'width: 30px;';
$table_interface->style['interface_graph'] = 'width: 20px;';
$table_interface->head = array();
$options = array(
"class" => "closed",
"style" => "vertical-align:middle; cursor:pointer;"
);
$table_interface->head[0] = html_print_image("images/go.png", true, $options) . "&nbsp;&nbsp;";
$table_interface->head[0] .= '<span style="vertical-align: middle;">' . __('Interface information') .' (SNMP)</span>';
$table_interface->head_colspan = array();
$table_interface->head_colspan[0] = 5;
$table_interface->data = array();
if (!empty($modules)) {
foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
$interface_name_escaped = str_replace("/", "\/", $interface_name);
$module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status = ui_print_status_image($status, $title, true);
$ip_target = "--";
// Trying to get something like an IP from the description
if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", (string)$module['descripcion'], $matches) ||
preg_match ("/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:?)|\2))(?4){5}((?4){2}|(25[0-5]|
(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})/i", (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$ip_target = $matches[0];
}
}
$description = "--";
// Trying to get something like a mac from the description
if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i", (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$description = $matches[0];
}
if (!isset($interfaces[$interface_name])
|| (isset($interfaces[$interface_name])
&& preg_match ("/^ifOperStatus_$interface_name_escaped$/i", (string)$module['nombre'], $matches))) {
$interfaces[$interface_name] = $module;
}
// Get the ifInOctets and ifOutOctets modules of the interface
$columns = array(
"id_agente_modulo",
"nombre"
);
$interface_traffic_modules = agents_get_modules($id_agente, $columns, "nombre LIKE 'if%Octets_$interface_name'");
if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) {
$interface_traffic_modules_aux = array('in' => '', 'out' => '');
foreach ($interface_traffic_modules as $interface_traffic_module) {
if (preg_match ("/if(.+)Octets_$interface_name$/i", (string)$interface_traffic_module['nombre'], $matches)) {
if (strtolower($matches[1]) == 'in') {
$interface_traffic_modules_aux['in'] = $interface_traffic_module['id_agente_modulo'];
}
elseif (strtolower($matches[1]) == 'out') {
$interface_traffic_modules_aux['out'] = $interface_traffic_module['id_agente_modulo'];
}
}
}
if (!empty($interface_traffic_modules_aux['in']) && !empty($interface_traffic_modules_aux['out'])) {
$interface_traffic_modules = $interface_traffic_modules_aux;
}
else {
$interface_traffic_modules = false;
}
}
else {
$interface_traffic_modules = false;
}
if ($interface_traffic_modules != false) {
$params = array(
'interface_name' => $interface_name,
'agent_id' => $id_agente,
'traffic_module_in' => $interface_traffic_modules_aux['in'],
'traffic_module_out' => $interface_traffic_modules_aux['out']
);
$params_json = json_encode($params);
$params_encoded = base64_encode($params_json);
$win_handle = dechex(crc32($module_id.$interface_name));
$graph_link = "<a href=\"javascript:winopeng('operation/agentes/interface_traffic_graph_win.php?params=$params_encoded','$win_handle')\">" .
html_print_image("images/chart_curve.png", true, array("title" => __('Interface traffic'))) . "</a>";
}
else {
$graph_link = "";
}
$data = array();
$data['interface_name'] = "<strong>" . $interface_name . "</strong>";
$data['interface_status'] = $status;
$data['interface_graph'] = $graph_link;
$data['interface_ip'] = $ip_target;
$data['interface_mac'] = $description;
$table_interface->data[] = $data;
}
}
}
unset($modules);
if (!empty($interfaces)) {
$table_interface = new stdClass();
$table_interface->id = 'agent_interface_info';
$table_interface->class = 'databox';
$table_interface->width = '100%';
$table_interface->style = array();
$table_interface->style['interface_status'] = 'width: 30px;';
$table_interface->style['interface_graph'] = 'width: 20px;';
$table_interface->head = array();
$options = array(
"class" => "closed",
"style" => "vertical-align:middle; cursor:pointer;"
);
$table_interface->head[0] = html_print_image("images/go.png", true, $options) . "&nbsp;&nbsp;";
$table_interface->head[0] .= '<span style="vertical-align: middle;">' . __('Interface information') .' (SNMP)</span>';
$table_interface->head_colspan = array();
$table_interface->head_colspan[0] = 5;
$table_interface->data = array();
foreach ($interfaces as $interface_name => $module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
$module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status = ui_print_status_image($status, $title, true);
$ip_target = "--";
// Trying to get something like an IP from the description
if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", (string)$module['descripcion'], $matches) ||
preg_match ("/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:?)|\2))(?4){5}((?4){2}|(25[0-5]|
(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})/i", (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$ip_target = $matches[0];
}
}
$mac = "--";
// Trying to get something like a mac from the description
if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i", (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$mac = $matches[0];
}
}
// Get the ifInOctets and ifOutOctets modules of the interface
$columns = array(
"id_agente_modulo",
"nombre"
);
$interface_traffic_modules = agents_get_modules($id_agente, $columns, "nombre LIKE 'if%Octets_$interface_name'");
if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) {
$interface_traffic_modules_aux = array('in' => '', 'out' => '');
foreach ($interface_traffic_modules as $interface_traffic_module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
if (preg_match ("/^if(.+)Octets_$interface_name_escaped$/i", $interface_traffic_module['nombre'], $matches)) {
if (strtolower($matches[1]) == 'in') {
$interface_traffic_modules_aux['in'] = $interface_traffic_module['id_agente_modulo'];
}
elseif (strtolower($matches[1]) == 'out') {
$interface_traffic_modules_aux['out'] = $interface_traffic_module['id_agente_modulo'];
}
}
}
if (!empty($interface_traffic_modules_aux['in']) && !empty($interface_traffic_modules_aux['out'])) {
$interface_traffic_modules = $interface_traffic_modules_aux;
}
else {
$interface_traffic_modules = false;
}
}
else {
$interface_traffic_modules = false;
}
if ($interface_traffic_modules != false) {
$params = array(
'interface_name' => $interface_name,
'agent_id' => $id_agente,
'traffic_module_in' => $interface_traffic_modules_aux['in'],
'traffic_module_out' => $interface_traffic_modules_aux['out']
);
$params_json = json_encode($params);
$params_encoded = base64_encode($params_json);
$win_handle = dechex(crc32($module_id.$interface_name));
$graph_link = "<a href=\"javascript:winopeng('operation/agentes/interface_traffic_graph_win.php?params=$params_encoded','$win_handle')\">" .
html_print_image("images/chart_curve.png", true, array("title" => __('Interface traffic'))) . "</a>";
}
else {
$graph_link = "";
}
$data = array();
$data['interface_name'] = "<strong>" . $interface_name . "</strong>";
$data['interface_status'] = $status;
$data['interface_graph'] = $graph_link;
$data['interface_ip'] = $ip_target;
$data['interface_mac'] = $mac;
$table_interface->data[] = $data;
}
}
// This javascript piece of code is used to make expandible the body of the table
?>

View File

@ -844,7 +844,7 @@ else {
$result = array();
$count_modules = 0;
foreach($servers as $server) {
foreach ($servers as $server) {
// If connection was good then retrieve all data server
if (metaconsole_connect($server) == NOERR) {
$connection = true;
@ -1068,18 +1068,39 @@ foreach ($result as $row) {
}
$data[2] = html_print_image("images/" . modules_show_icon_type ($row["module_type"]), true);
if (check_acl ($config['id_user'], $row['id_group'], "AW"))
$data[2] .= '<a href="' .
'index.php?' .
if (check_acl ($config['id_user'], $row['id_group'], "AW")) {
$show_edit_icon = true;
if (defined('METACONSOLE')) {
if (!can_user_access_node ()) {
$show_edit_icon = false;
}
$url_edit_module = $row["server_url"] . 'index.php?' .
'sec=gagente&amp;' .
'sec2=godmode/agentes/configurar_agente&amp;' .
'id_agente=' . $row['id_agent'] . '&amp;' .
'tab=module&amp;' .
'id_agent_module=' . $row["id_agente_modulo"] . '&amp;' .
'edit_module=1">' .
'edit_module=1' .
'&amp;loginhash=auto&amp;loginhash_data=' . $row["hashdata"] . '&amp;loginhash_user=' . $row["user"];
}
else {
$url_edit_module = 'index.php?' .
'sec=gagente&amp;' .
'sec2=godmode/agentes/configurar_agente&amp;' .
'id_agente=' . $row['id_agent'] . '&amp;' .
'tab=module&amp;' .
'id_agent_module=' . $row["id_agente_modulo"] . '&amp;' .
'edit_module=1';
}
if ($show_edit_icon) {
$data[2] .= '<a href="' . $url_edit_module . '">' .
html_print_image("images/config.png", true,
array("alt" => '0', "border" => "", "title" => __('Edit'))) .
'</a>';
'</a>';
}
}
$data[3] = ui_print_truncate_text($row["module_name"], 'agent_small', false, true, true);
if ($row["extended_info"] != "") {
@ -1322,14 +1343,14 @@ ui_require_javascript_file('pandora_modules');
}
function refresh_pagination_callback (module_id, id_agent, server_name) {
$(".binary_dialog").click( function() {
var classes = $(this).attr('class');
classes = classes.split(' ');
var offset_class = classes[2];
offset_class = offset_class.split('_');
var offset = offset_class[1];
var period = $('#period').val();
show_module_detail_dialog(module_id, id_agent, server_name, offset, period);

View File

@ -51,7 +51,7 @@ $layout = db_get_row ('tlayout', 'id', $id_layout);
if (! $layout) {
db_pandora_audit("ACL Violation","Trying to access visual console without id layout");
include ("../../general/noaccess.php");
include ($config['homedir'] . "/general/noaccess.php");
exit;
}

View File

@ -1146,15 +1146,10 @@ sub pandora_process_module ($$$$$$$$$;$) {
$min_ff_event = $module->{'min_ff_event_warning'} if ($new_status == 2);
}
# replace $new_status with $last_known_status when recovering from 'unknown'
if ($status == 3) {
$new_status = $last_known_status;
}
if ($last_status == $new_status) {
# Avoid overflows
$status_changes = $min_ff_event if ($status_changes > $module->{'min_ff_event'});
$status_changes = $min_ff_event if ($status_changes > $min_ff_event);
$status_changes++;
if ($module_type =~ m/async/ && $min_ff_event != 0 && $ff_timeout != 0 && ($utimestamp - $ff_start_utimestamp) > $ff_timeout) {
@ -1173,9 +1168,10 @@ sub pandora_process_module ($$$$$$$$$;$) {
}
# Change status
if ($status_changes == $min_ff_event && $status != $new_status) {
if ($status_changes >= $min_ff_event && $status != $new_status) {
generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $last_known_status, $dbh);
$status = $new_status;
$last_status = $new_status;
# Update module status count
pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'});
@ -1185,20 +1181,23 @@ sub pandora_process_module ($$$$$$$$$;$) {
elsif ($status == 4) {
generate_status_event ($pa_config, $processed_data, $agent, $module, 0, $status, $last_known_status, $dbh);
$status = 0;
$last_status = $new_status;
# Update module status count
pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'});
}
# If unknown modules receive data, restore status even if min_ff_event is not matched.
elsif ($status == 3) {
$last_status = $new_status; # Set last_status before forcing the module's new status to its last known status.
$new_status = $last_known_status; # Set the module to its last known status.
generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $last_known_status, $dbh);
$status = $new_status;
# Update module status count
pandora_mark_agent_for_module_update ($dbh, $agent->{'id_agente'});
} else {
$last_status = $new_status;
}
$last_status = $new_status;
# tagente_estado.last_try defaults to NULL, should default to '1970-01-01 00:00:00'
$agent_status->{'last_try'} = '1970-01-01 00:00:00' unless defined ($agent_status->{'last_try'});
@ -3563,18 +3562,15 @@ sub generate_status_event ($$$$$$$$) {
# Warning
} elsif ($status == 2) {
# From normal
if ($last_known_status == 0 || $last_known_status == 4) {
($event_type, $severity) = ('going_up_warning', 3);
$description = $pa_config->{"text_going_up_warning"};
# From critical
} elsif ($last_known_status == 1) {
if ($last_known_status == 1) {
($event_type, $severity) = ('going_down_warning', 3);
$description = $pa_config->{"text_going_down_warning"};
} else {
# Unknown last_status
return;
}
# From normal or warning (after becoming unknown)
else {
($event_type, $severity) = ('going_up_warning', 3);
$description = $pa_config->{"text_going_up_warning"};
}
} else {
# Unknown status

View File

@ -219,7 +219,7 @@ sub pandora_snmptrapd {
if (!defined($oid)) {
logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv2 trap?)", 1);
next;
return;
}
$oid =~ s/.* = OID: //;
$data = join("\t", @data);