Fix commit for adding LOG4X support

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2361 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
eric_ross_c 2010-02-15 13:07:52 +00:00
parent fbcd36d182
commit f445bdf12c
13 changed files with 370 additions and 139 deletions

View File

@ -808,6 +808,8 @@ function print_table (&$table, $return = false) {
echo $output; echo $output;
} }
/** /**
* Render a radio button input. Extended version, use print_radio_button() to simplify. * Render a radio button input. Extended version, use print_radio_button() to simplify.
* *

View File

@ -21,9 +21,8 @@ require_once ("include/config.php");
check_login(); check_login();
$module_id = get_parameter_get ("id", 0); $module_id = get_parameter_get ("id", 0);
$period = get_parameter ("period", 86400); $period = get_parameter_get ("period", 86400);
$group = get_agentmodule_group ($module_id); $group = get_agentmodule_group ($module_id);
$agentId = get_parameter('id_agente');
if (! give_acl ($config['id_user'], $group, "AR") || $module_id == 0) { if (! give_acl ($config['id_user'], $group, "AR") || $module_id == 0) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
@ -36,117 +35,191 @@ if (isset ($_GET["delete"])) {
$delete = get_parameter_get ("delete", 0); $delete = get_parameter_get ("delete", 0);
$sql = sprintf ("DELETE FROM tagente_datos WHERE id_agente_datos = %d", $delete); $sql = sprintf ("DELETE FROM tagente_datos WHERE id_agente_datos = %d", $delete);
process_sql ($sql); process_sql ($sql);
} elseif (isset($_GET["delete_text"])) { } elseif (isset($_GET["delete_log4x"])) {
$delete = get_parameter_get ("delete_log4x", 0);
$sql = sprintf ("DELETE FROM tagente_datos_log4x WHERE id_tagente_datos_log4x = %d", $delete);
process_sql ($sql);
} elseif (isset($_GET["delete_string"])) {
$delete = get_parameter_get ("delete_string", 0); $delete = get_parameter_get ("delete_string", 0);
$sql = sprintf ("DELETE FROM tagente_datos_string WHERE id_tagente_datos_string = %d", $delete); $sql = sprintf ("DELETE FROM tagente_datos_string WHERE id_tagente_datos_string = %d", $delete);
process_sql ($sql); process_sql ($sql);
} }
// Different query for string data type $table->cellpadding = 3;
if (preg_match ("/string/", get_moduletype_name (get_agentmodule_type ($module_id)))) { $table->cellspacing = 3;
$sql = sprintf ("SELECT * $table->width = 600;
FROM tagente_datos_string $table->class = "databox";
WHERE id_agente_modulo = %d AND utimestamp > %d $table->head = array ();
ORDER BY utimestamp DESC $table->data = array ();
LIMIT %d OFFSET %d", $module_id, get_system_time () - $period, $config['block_size'], get_parameter ('offset')); $table->align = array ();
$sqlCount = sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $module_id, get_system_time () - $period); $table->size = array ();
$string_type = 1;
$moduletype_name = get_moduletype_name (get_agentmodule_type ($module_id));
$offset = (int) get_parameter("offset");
$block_size = (int) $config["block_size"];
// The "columns" array is the number(and definition) of columns in the report:
// $columns = array(
// "COLUMN1" => array(ROW_FROM_DB_TABLE, FUNCTION_NAME_TO_FORMAT_THE_DATA, "align"=>COLUMN_ALIGNMENT, "width"=>COLUMN_WIDTH)
// "COLUMN2" => array(ROW_FROM_DB_TABLE, FUNCTION_NAME_TO_FORMAT_THE_DATA, "align"=>COLUMN_ALIGNMENT, "width"=>COLUMN_WIDTH)
// ....
// )
//
// For each row from the query, and for each column, we'll call the FUNCTION passing as argument
// the value of the ROW.
//
$columns = array ();
if ($moduletype_name == "log4x") {
$table->width = 1100;
$sql_body = sprintf ("FROM tagente_datos_log4x WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $module_id, get_system_time () - $period);
$columns = array(
"Delete" => array("id_tagente_datos_log4x", "format_delete_log4x", "align" => "center", "width" => "10px"),
"Timestamp" => array("utimestamp", "format_timestamp", "align" => "center", "width" => "200px"),
"Sev" => array("severity", "format_data", "align" => "center", "width" => "70px"),
"Message" => array("message", "format_verbatim", "align" => "left", "width" => "400px"),
"ST" => array("stacktrace", "format_data", "align" => "left", "width" => "400px")
);
} else if (preg_match ("/string/", $moduletype_name)) {
$sql_body = sprintf (" FROM tagente_datos_string WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $module_id, get_system_time () - $period);
$columns = array(
"Delete" => array("id_agente_datos", "format_delete_string", "align" => "center"),
"Timestamp" => array("utimestamp", "format_timestamp", "align" => "center"),
"Data" => array("datos", "format_data", "align" => "center"),
"Time" => array("utimestamp", "format_time", "align" => "center")
);
} else { } else {
$sql = sprintf ("SELECT * $sql_body = sprintf (" FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $module_id, get_system_time () - $period);
FROM tagente_datos
WHERE id_agente_modulo = %d AND utimestamp > %d $columns = array(
ORDER BY utimestamp DESC "Delete" => array("id_agente_datos", "format_delete", "align" => "center"),
LIMIT %d OFFSET %d", $module_id, get_system_time () - $period, $config['block_size'], get_parameter ('offset')); "Timestamp" => array("utimestamp", "format_timestamp", "align" => "center"),
$sqlCount = sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $module_id, get_system_time () - $period); "Data" => array("datos", "format_data", "align" => "center"),
$string_type = 0; "Time" => array("utimestamp", "format_time", "align" => "center")
);
} }
$countData = get_db_value_sql($sqlCount); $sql = "SELECT * " . $sql_body;
$result = get_db_all_rows_sql ($sql, true); $sql_count = "SELECT count(*) " . $sql_body;
$count = get_db_value_sql($sql_count);
$sql .= " LIMIT " . $offset . "," . $block_size;
$result = get_db_all_rows_sql ($sql);
if ($result === false) { if ($result === false) {
$result = array (); $result = array ();
} }
echo "<h2>".__('Received data from')." ".get_agentmodule_agent_name ($module_id)." / ".get_agentmodule_name ($module_id)." </h2>"; echo "<h2>".__('Received data from')." ".get_agentmodule_agent_name ($module_id)." / ".get_agentmodule_name ($module_id)." </h2>";
echo "<h3>" . __("From the last") . " " . human_time_description ($period) ."</h3>"; echo "<h3>".human_time_description ($period) ."</h3>";
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=" . $agentId . "&tab=data_view&id=" . $module_id . "'>"; $index = 0;
echo __("Choose a time from now") . ": "; foreach($columns as $col => $attr){
$intervals = array (); $table->head[$index] = $col;
$intervals[3600] = human_time_description_raw (3600); // 1 hour
$intervals[86400] = human_time_description_raw (86400); // 1 day
$intervals[604800] = human_time_description_raw (604800); // 1 week
$intervals[2592000] = human_time_description_raw (2592000); // 1 month
echo print_extended_select_for_time ($intervals, 'period', $period, 'this.form.submit();', '', '0', 10) . __(" seconds.");
echo "</form><br />";
if ($result === false) { if (isset($attr["align"]))
echo '<h3 class="error">'.__('There was a problem locating the source of the graph').'</h3>'; $table->align[$index] = $attr["align"];
if (isset($attr["width"]))
$table->size[$index] = $attr["width"];
$index++;
} }
else {
pagination ($countData, false) ;
echo ' foreach ($result as $row) {
<table width="600" cellpadding="3" cellspacing="3" border="0" class="databox" id="table1"> $data = array ();
<thead>
<tr>
<th class="header c0" scope="col">' . __('Delete') . '</th>
<th class="header c1" scope="col">' . __('Timestamp') . '</th>
<th class="header c2" scope="col">' . __('Data') . '</th></tr>
</thead>
';
$count = 0;
foreach ($result as $row) {
if (($count % 2) == 0) foreach($columns as $col => $attr){
$classPairOdd = 'rowPair'; $data[] = $attr[1] ($row[$attr[0]]);
else
$classPairOdd = 'rowOdd';
if ($count > 100) break;
$count++;
echo('<tr id="table1-3" style="" class="datos ' . $classPairOdd . '">');
if (give_acl ($config['id_user'], $group, "AW") ==1) {
if ($string_type == 0) {
echo('<td id="table1-' . $count . '-0" style="text-align: center;" class="datos">
<a href="index.php?sec=estado&sec2=operation/agentes/datos_agente&period='.$period.'&id='.$module_id.'&delete='.$row["id_agente_datos"].'&offset=' . get_parameter ('offset') . '"><img src="images/cross.png" border="0" /></a>
</td>');
} }
else {
echo('<td id="table1-' . $count . '-0" style="text-align: center;" class="datos"> array_push ($table->data, $data);
<a href="index.php?sec=estado&sec2=operation/agentes/datos_agente&period='.$period.'&id='.$module_id.'&delete_string='.$row["id_tagente_datos_string"].'&offset=' . get_parameter ('offset') . '"><img src="images/cross.png" border="0" /></a> if (count($table->data) > 200) break;
</td>'); }
}
} if (empty ($table->data)) {
else { echo '<h3 class="error">'.__('There was a problem locating the source of the graph').'</h3>';
echo('<td id="table1-' . $count . '-0" style="text-align: center;" class="datos"></td>'); } else {
pagination($count);
print_table ($table);
unset ($table);
}
//
// This are functions to format the data
//
function format_time($ts)
{
return print_timestamp ($ts, true, array("prominent" => "comparation"));
}
function format_data($data)
{
if (is_numeric ($data)) {
$data = format_numeric($data, 2);
} else {
$data = safe_input ($data);
} }
return $data;
}
function format_verbatim($data)
{
return "<pre style='font-size:8px;'>" . $data . "</pre>";
}
function format_timestamp($ts)
{
global $config;
// This returns data with absolute user-defined timestamp format // This returns data with absolute user-defined timestamp format
// and numeric by data managed with 2 decimals, and not using Graph format // and numeric by data managed with 2 decimals, and not using Graph format
// (replacing 1000 by K and 1000000 by G, like version 2.x // (replacing 1000 by K and 1000000 by G, like version 2.x
return date ($config["date_format"], $ts);
}
echo('<td id="table1-' . $count . '-1" style="text-align: center;" class="datos">' . function format_delete($id)
date ($config["date_format"], $row["utimestamp"]) . {
'</td>'); global $period, $module_id, $config, $group;
if (is_numeric ($row["datos"])) {
echo('<td id="table1-' . $count . '-2" style="text-align: center;" class="datos">' .
format_numeric($row["datos"],2) .
'</td>');
}
else {
echo('<td id="table1-' . $count . '-2" style="text-align: center;" class="datos">' .
safe_input ($row["datos"]) .
'</td>');
}
echo('</tr>');
}
echo '</table>';
pagination ($countData, false) ; $txt = "";
echo "<h3>" . __('Total') . ' ' . $countData . ' ' . __('Data') . "</h3>";
if (give_acl ($config['id_user'], $group, "AW") ==1) {
$txt = '<a href="index.php?sec=estado&sec2=operation/agentes/datos_agente&period='.$period.'&id='.$module_id.'&delete='.$id.'"><img src="images/cross.png" border="0" /></a>';
}
return $txt;
}
function format_delete_string($id)
{
global $period, $module_id, $config, $group;
$txt = "";
if (give_acl ($config['id_user'], $group, "AW") ==1) {
$txt = '<a href="index.php?sec=estado&sec2=operation/agentes/datos_agente&period='.$period.'&id='.$module_id.'&delete_string='.$id.'"><img src="images/cross.png" border="0" /></a>';
}
return $txt;
}
function format_delete_log4x($id)
{
global $period, $module_id, $config, $group;
$txt = "";
if (give_acl ($config['id_user'], $group, "AW") ==1) {
$txt = '<a href="index.php?sec=estado&sec2=operation/agentes/datos_agente&period='.$period.'&id='.$module_id.'&delete_log4x='.$id.'"><img src="images/cross.png" border="0" /></a>';
}
return $txt;
} }
?> ?>

View File

@ -135,7 +135,9 @@ foreach ($modules as $module) {
$link ="winopeng('operation/agentes/stat_win.php?type=$graph_type&period=86400&id=".$module["id_agente_modulo"]."&label=".$module["nombre"]."&refresh=600','day_".$win_handle."')"; $link ="winopeng('operation/agentes/stat_win.php?type=$graph_type&period=86400&id=".$module["id_agente_modulo"]."&label=".$module["nombre"]."&refresh=600','day_".$win_handle."')";
$data[6] = '<a href="javascript:'.$link.'"><img src="images/chart_curve.png" border=0></a>'; $data[6] = "";
if ($nombre_tipo_modulo != "log4x")
$data[6] .= '<a href="javascript:'.$link.'"><img src="images/chart_curve.png" border=0></a>';
$data[6] .= "&nbsp;<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=$id_agente&tab=data_view&period=86400&id=".$module["id_agente_modulo"]."'><img border=0 src='images/binary.png'></a>"; $data[6] .= "&nbsp;<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=$id_agente&tab=data_view&period=86400&id=".$module["id_agente_modulo"]."'><img border=0 src='images/binary.png'></a>";
} }

View File

@ -143,7 +143,11 @@ foreach ($modules as $module) {
} }
echo "</td>"; echo "</td>";
} }
if (($module["id_tipo_modulo"] == 100) OR ($module['history_data'] == 0)) {
if ($module["id_tipo_modulo"] == 30) {
echo "<td class='".$tdcolor."f9' colspan='2'>&nbsp;</td>";
} else if (($module["id_tipo_modulo"] == 100) OR ($module['history_data'] == 0)) {
echo "<td class='".$tdcolor."f9' colspan='2' title='".$module["datos"]."'>"; echo "<td class='".$tdcolor."f9' colspan='2' title='".$module["datos"]."'>";
echo substr(safe_output($module["datos"]),0,12); echo substr(safe_output($module["datos"]),0,12);
} else { } else {

View File

@ -95,6 +95,19 @@ CREATE TABLE IF NOT EXISTS `tagente_datos_string` (
KEY `idx_utimestamp` (`utimestamp`) KEY `idx_utimestamp` (`utimestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tagente_datos_log4x` (
`id_tagente_datos_log4x` bigint(20) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`severity` text NOT NULL,
`message` text NOT NULL,
`stacktrace` text NOT NULL,
`utimestamp` int(20) unsigned NOT NULL default 0,
PRIMARY KEY (`id_tagente_datos_log4x`),
KEY `data_log4x_index_1` (`id_agente_modulo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- delete "cambio" not used anymore -- delete "cambio" not used anymore
CREATE TABLE `tagente_estado` ( CREATE TABLE `tagente_estado` (
`id_agente_estado` int(10) unsigned NOT NULL auto_increment, `id_agente_estado` int(10) unsigned NOT NULL auto_increment,

View File

@ -223,6 +223,9 @@ INSERT INTO `ttipo_modulo` VALUES
(21,'async_proc', 7, 'Asyncronous proc data', 'mod_async_proc.png'), (21,'async_proc', 7, 'Asyncronous proc data', 'mod_async_proc.png'),
(22,'async_data', 6, 'Asyncronous numeric data', 'mod_async_data.png'), (22,'async_data', 6, 'Asyncronous numeric data', 'mod_async_data.png'),
(23,'async_string', 8, 'Asyncronous string data', 'mod_async_string.png'), (23,'async_string', 8, 'Asyncronous string data', 'mod_async_string.png'),
(30,'log4x',0,'Log4x','mod_log4x.png'),
(100,'keep_alive',-1,'KeepAlive','mod_keepalive.png'); (100,'keep_alive',-1,'KeepAlive','mod_keepalive.png');
-- Not yet implemented -- Not yet implemented
-- (19,'image_jpg',9,'Image JPG data', 'mod_image_jpg.png'), -- (19,'image_jpg',9,'Image JPG data', 'mod_image_jpg.png'),

View File

@ -73,8 +73,8 @@ our @AlertStatus = ('Execute the alert', 'Do not execute the alert', 'Do not exe
########################################################################## ##########################################################################
# Generate alerts for a given module. # Generate alerts for a given module.
########################################################################## ##########################################################################
sub pandora_generate_alerts ($$$$$$$) { sub pandora_generate_alerts ($$$$$$$;$) {
my ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh) = @_; my ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros) = @_;
# Do not generate alerts for disabled groups # Do not generate alerts for disabled groups
if (is_group_disabled ($dbh, $agent->{'id_grupo'})) { if (is_group_disabled ($dbh, $agent->{'id_grupo'})) {
@ -93,7 +93,7 @@ sub pandora_generate_alerts ($$$$$$$) {
$utimestamp, $dbh); $utimestamp, $dbh);
pandora_process_alert ($pa_config, $data, $agent, $module, pandora_process_alert ($pa_config, $data, $agent, $module,
$alert, $rc, $dbh); $alert, $rc, $dbh, $extraMacros);
# Evaluate compound alerts even if the alert status did not change in # Evaluate compound alerts even if the alert status did not change in
# case the compound alert does not recover # case the compound alert does not recover
@ -196,8 +196,8 @@ sub pandora_evaluate_alert ($$$$$$$) {
########################################################################## ##########################################################################
# Process an alert given the status returned by pandora_evaluate_alert. # Process an alert given the status returned by pandora_evaluate_alert.
########################################################################## ##########################################################################
sub pandora_process_alert ($$$$$$$) { sub pandora_process_alert ($$$$$$$;$) {
my ($pa_config, $data, $agent, $module, $alert, $rc, $dbh) = @_; my ($pa_config, $data, $agent, $module, $alert, $rc, $dbh, $extraMacros) = @_;
logger ($pa_config, "Processing alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10); logger ($pa_config, "Processing alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10);
@ -231,7 +231,7 @@ sub pandora_process_alert ($$$$$$$) {
db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = 0, db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = 0,
internal_counter = 0 WHERE id = ?', $id); internal_counter = 0 WHERE id = ?', $id);
pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 0, $dbh); pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 0, $dbh, $extraMacros);
return; return;
} }
@ -272,7 +272,7 @@ sub pandora_process_alert ($$$$$$$) {
db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = ?, db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = ?,
last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?', last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?',
$alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id); $alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id);
pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 1, $dbh); pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 1, $dbh, $extraMacros);
return; return;
} }
} }
@ -362,9 +362,9 @@ sub pandora_generate_compound_alerts ($$$$$$$$) {
########################################################################## ##########################################################################
# Execute the given alert. # Execute the given alert.
########################################################################## ##########################################################################
sub pandora_execute_alert ($$$$$$$) { sub pandora_execute_alert ($$$$$$$;$) {
my ($pa_config, $data, $agent, $module, my ($pa_config, $data, $agent, $module,
$alert, $alert_mode, $dbh) = @_; $alert, $alert_mode, $dbh, $extraMacros) = @_;
logger ($pa_config, "Executing alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "'.", 10); logger ($pa_config, "Executing alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "'.", 10);
@ -408,7 +408,7 @@ sub pandora_execute_alert ($$$$$$$) {
# Execute actions # Execute actions
foreach my $action (@actions) { foreach my $action (@actions) {
pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh); pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh, $extraMacros);
} }
# Generate an event # Generate an event
@ -422,9 +422,9 @@ sub pandora_execute_alert ($$$$$$$) {
########################################################################## ##########################################################################
# Execute the given action. # Execute the given action.
########################################################################## ##########################################################################
sub pandora_execute_action ($$$$$$$$) { sub pandora_execute_action ($$$$$$$$;$) {
my ($pa_config, $data, $agent, $alert, my ($pa_config, $data, $agent, $alert,
$alert_mode, $action, $module, $dbh) = @_; $alert_mode, $action, $module, $dbh, $extraMacros) = @_;
logger($pa_config, "Executing action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 10); logger($pa_config, "Executing action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 10);
@ -466,6 +466,11 @@ sub pandora_execute_action ($$$$$$$$) {
_id_alert_ => $alert->{'id'} _id_alert_ => $alert->{'id'}
); );
if (defined ($extraMacros)){
while ((my $macro, my $value) = each (%{$extraMacros})) {
$macros{$macro} = $value;
}
}
# User defined alerts # User defined alerts
if ($action->{'internal'} == 0) { if ($action->{'internal'} == 0) {
@ -523,9 +528,9 @@ sub pandora_access_update ($$$) {
########################################################################## ##########################################################################
# Process Pandora module. # Process Pandora module.
########################################################################## ##########################################################################
sub pandora_process_module ($$$$$$$$$) { sub pandora_process_module ($$$$$$$$$;$) {
my ($pa_config, $data, $agent, $module, $module_type, my ($pa_config, $dataObject, $agent, $module, $module_type,
$timestamp, $utimestamp, $server_id, $dbh) = @_; $timestamp, $utimestamp, $server_id, $dbh, $extraMacros) = @_;
logger($pa_config, "Processing module '" . $module->{'nombre'} . "' for agent " . (defined ($agent) && $agent ne '' ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10); logger($pa_config, "Processing module '" . $module->{'nombre'} . "' for agent " . (defined ($agent) && $agent ne '' ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10);
@ -550,9 +555,9 @@ sub pandora_process_module ($$$$$$$$$) {
} }
# Process data # Process data
my $processed_data = process_data ($data, $module, $module_type, $utimestamp, $dbh); my $processed_data = process_data ($dataObject, $module, $module_type, $utimestamp, $dbh);
if (! defined ($processed_data)) { if (! defined ($processed_data)) {
logger($pa_config, "Received invalid data '" . $data . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3); logger($pa_config, "Received invalid data '" . $dataObject . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
return; return;
} }
@ -575,7 +580,7 @@ sub pandora_process_module ($$$$$$$$$) {
# Generate alerts # Generate alerts
if (pandora_inhibit_alerts ($pa_config, $agent, $dbh) == 0) { if (pandora_inhibit_alerts ($pa_config, $agent, $dbh) == 0) {
pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh); pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros);
} }
#Update module status #Update module status
@ -609,8 +614,8 @@ sub pandora_process_module ($$$$$$$$$) {
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'}); $utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'});
# Save module data # Save module data
if ($save == 1) { if ($module_type eq "log4x" || $save == 1) {
save_module_data ($processed_data, $module, $module_type, $utimestamp, $dbh); save_module_data ($dataObject, $module, $module_type, $utimestamp, $dbh);
} }
} }
@ -750,7 +755,7 @@ sub pandora_update_agent ($$$$$$$;$$$$) {
# if the the flag update_gis_data is 0 the positional data is ignored. # if the the flag update_gis_data is 0 the positional data is ignored.
if ($last_agent_info->{'update_gis_data'} == 0){ if ($last_agent_info->{'update_gis_data'} == 0){
logger($pa_config, "Agent id $agent_id positional data ignored",10); logger($pa_config, "Agent id $agent_id positional data ignored",10);
db_do($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, WHERE id_agente = ?', db_do($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ? WHERE id_agente = ?',
$agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id);
return; return;
} }
@ -828,7 +833,8 @@ sub pandora_module_keep_alive ($$$$$) {
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND id_tipo_modulo = 100', $id_agent); my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND id_tipo_modulo = 100', $id_agent);
return unless defined ($module); return unless defined ($module);
pandora_process_module ($pa_config, 1, '', $module, 'keep_alive', '', time(), $server_id, $dbh); my %data = ('data' => 1);
pandora_process_module ($pa_config, \%data, '', $module, 'keep_alive', '', time(), $server_id, $dbh);
} }
########################################################################## ##########################################################################
@ -923,7 +929,7 @@ sub pandora_create_agent ($$$$$$$$$$$;$$$$) {
########################################################################## ##########################################################################
# Generate an event. # Generate an event.
########################################################################## ##########################################################################
sub pandora_event (%$$$$$$$$) { sub pandora_event ($$$$$$$$$) {
my ($pa_config, $evento, $id_grupo, $id_agente, $severity, my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
$id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh) = @_; $id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh) = @_;
@ -1000,9 +1006,10 @@ sub pandora_module_keep_alive_nd {
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())'); AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())');
my %data = ('data' => 0);
foreach my $module (@modules) { foreach my $module (@modules) {
logger($pa_config, "Updating keep_alive module for module '" . $module->{'nombre'} . "' agent ID " . $module->{'id_agente'} . " (agent without data).", 10); logger($pa_config, "Updating keep_alive module for module '" . $module->{'nombre'} . "' agent ID " . $module->{'id_agente'} . " (agent without data).", 10);
pandora_process_module ($pa_config, 0, '', $module, 'keep_alive', '', time (), 0, $dbh); pandora_process_module ($pa_config, \%data, '', $module, 'keep_alive', '', time (), 0, $dbh);
} }
} }
@ -1167,7 +1174,13 @@ sub subst_alert_macros ($$) {
# Process module data. # Process module data.
########################################################################## ##########################################################################
sub process_data ($$$$$) { sub process_data ($$$$$) {
my ($data, $module, $module_type, $utimestamp, $dbh) = @_; my ($dataObject, $module, $module_type, $utimestamp, $dbh) = @_;
if ($module_type eq "log4x") {
return log4x_get_severity_num($dataObject);
}
my $data = $dataObject->{'data'};
# String data # String data
if ($module_type =~ m/_string$/) { if ($module_type =~ m/_string$/) {
@ -1195,7 +1208,11 @@ sub process_data ($$$$$) {
$data = process_inc_data ($data, $module, $utimestamp, $dbh); $data = process_inc_data ($data, $module, $utimestamp, $dbh);
# Not an error, no previous data # Not an error, no previous data
return 0 unless defined ($data); if (!defined($data)){
$dataObject->{'data'} = 0;
return 0;
}
#return 0 unless defined ($data);
} }
# Post process # Post process
@ -1208,6 +1225,7 @@ sub process_data ($$$$$) {
# Format data # Format data
$data = sprintf("%.2f", $data); $data = sprintf("%.2f", $data);
$dataObject->{'data'} = $data;
return $data; return $data;
} }
@ -1245,6 +1263,30 @@ sub process_inc_data ($$$$) {
return ($data - $data_inc->{'datos'}) / ($utimestamp - $data_inc->{'utimestamp'}); return ($data - $data_inc->{'datos'}) / ($utimestamp - $data_inc->{'utimestamp'});
} }
sub log4x_get_severity_num($) {
my ($dataObject) = @_;
my $data = $dataObject->{'severity'};
# The severity is a word, so we need to translate to numbers
if ($data =~ m/^trace$/i) {
$data = 10;
} elsif ($data =~ m/^debug$/i) {
$data = 20;
} elsif ($data =~ m/^info$/i) {
$data = 30;
} elsif ($data =~ m/^warn$/i) {
$data = 40;
} elsif ($data =~ m/^error$/i) {
$data = 50;
} elsif ($data =~ m/^fatal$/i) {
$data = 60;
} else {
$data = 10;
}
return $data;
}
########################################################################## ##########################################################################
# Returns the status of the module: 0 (NORMAL), 1 (CRITICAL), 2 (WARNING). # Returns the status of the module: 0 (NORMAL), 1 (CRITICAL), 2 (WARNING).
########################################################################## ##########################################################################
@ -1262,6 +1304,15 @@ sub get_module_status ($$) {
($critical_min, $critical_max) = (0, 1); ($critical_min, $critical_max) = (0, 1);
} }
if ($module_type eq "log4x") {
if ($critical_min eq $critical_max) {
($critical_min, $critical_max) = (50, 61); # ERROR - FATAL
}
if ($warning_min eq $warning_max) {
($warning_min, $warning_max) = (40, 41); # WARN - WARN
}
}
# Critical # Critical
if ($critical_min ne $critical_max) { if ($critical_min ne $critical_max) {
return 1 if ($data >= $critical_min && $data < $critical_max); return 1 if ($data >= $critical_min && $data < $critical_max);
@ -1352,12 +1403,36 @@ sub generate_status_event ($$$$$$$) {
# Saves module data to the DB. # Saves module data to the DB.
########################################################################## ##########################################################################
sub save_module_data ($$$$$) { sub save_module_data ($$$$$) {
my ($data, $module, $module_type, $utimestamp, $dbh) = @_; my ($dataObject, $module, $module_type, $utimestamp, $dbh) = @_;
if ($module_type eq "log4x") {
#<module>
# <name></name>
# <type>log4x</type>
#
# <severity></severity>
# <message></message>
#
# <stacktrace></stacktrace>
#</module>
print "saving log4x data: " . $dataObject->{'message'} . "\n";
my $sql = "INSERT INTO tagente_datos_log4x(id_agente_modulo, utimestamp, severity, message, stacktrace) values (?, ?, ?, ?, ?)";
db_do($dbh, $sql,
$module->{'id_agente_modulo'}, $utimestamp,
$dataObject->{'severity'},
$dataObject->{'message'},
$dataObject->{'stacktrace'}
);
} else {
my $data = $dataObject->{'data'};
my $table = ($module_type =~ m/_string/) ? 'tagente_datos_string' : 'tagente_datos'; my $table = ($module_type =~ m/_string/) ? 'tagente_datos_string' : 'tagente_datos';
db_do($dbh, 'INSERT INTO ' . $table . ' (id_agente_modulo, datos, utimestamp) db_do($dbh, 'INSERT INTO ' . $table . ' (id_agente_modulo, datos, utimestamp)
VALUES (?, ?, ?)', $module->{'id_agente_modulo'}, $data, $utimestamp); VALUES (?, ?, ?)', $module->{'id_agente_modulo'}, $data, $utimestamp);
}
} }
########################################################################## ##########################################################################
@ -1366,6 +1441,9 @@ sub save_module_data ($$$$$) {
sub export_module_data ($$$$$$$) { sub export_module_data ($$$$$$$) {
my ($pa_config, $data, $agent, $module, $module_type, $timestamp, $dbh) = @_; my ($pa_config, $data, $agent, $module, $module_type, $timestamp, $dbh) = @_;
# TODO: If module is log4x we hope for the best :P
#return if ($module_type == "log4x");
# Data export is disabled # Data export is disabled
return if ($module->{'id_export'} < 1); return if ($module->{'id_export'} < 1);

View File

@ -33,6 +33,7 @@ our @EXPORT = qw(
db_insert db_insert
get_agent_id get_agent_id
get_agent_name get_agent_name
get_module_name
get_db_rows get_db_rows
get_db_single_row get_db_single_row
get_db_value get_db_value
@ -105,6 +106,16 @@ sub get_agent_name ($$) {
return get_db_value ($dbh, "SELECT nombre FROM tagente WHERE id_agente = ?", $agent_id); return get_db_value ($dbh, "SELECT nombre FROM tagente WHERE id_agente = ?", $agent_id);
} }
##########################################################################
## SUB get_module_name(module_id)
## Return the module name, given "module_id"
##########################################################################
sub get_module_name ($$) {
my ($dbh, $module_id) = @_;
return get_db_value ($dbh, "SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ?", $module_id);
}
########################################################################## ##########################################################################
## Returns true if the given group is disabled, false otherwise. ## Returns true if the given group is disabled, false otherwise.
########################################################################## ##########################################################################
@ -223,6 +234,8 @@ sub db_insert ($$;@) {
sub db_do ($$;@) { sub db_do ($$;@) {
my ($dbh, $query, @values) = @_; my ($dbh, $query, @values) = @_;
#DBI->trace( 3, '/tmp/dbitrace.log' );
$dbh->do($query, undef, @values); $dbh->do($query, undef, @values);
} }

View File

@ -321,7 +321,6 @@ sub process_module_data ($$$$$$$$$) {
$ModuleSem->down (); $ModuleSem->down ();
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name); my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name);
if (! defined ($module)) { if (! defined ($module)) {
# Do not auto create modules # Do not auto create modules
if ($pa_config->{'autocreate'} ne '1') { if ($pa_config->{'autocreate'} ne '1') {
logger($pa_config, "Module '$module_name' not found for agent '$agent_name' and module auto-creation disabled.", 10); logger($pa_config, "Module '$module_name' not found for agent '$agent_name' and module auto-creation disabled.", 10);
@ -379,8 +378,46 @@ sub process_module_data ($$$$$$$$$) {
} }
my $utimestamp = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); my $utimestamp = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
#my $value = get_tag_value ($data, 'data', '');
my $dataObject = get_module_data($data, $agent_name, $module_name, $module_type);
my $extraMacros = get_macros_for_data($data, $agent_name, $module_name, $module_type);
pandora_process_module ($pa_config, $dataObject, $agent, $module, $module_type, $timestamp, $utimestamp, $server_id, $dbh, $extraMacros);
}
sub get_module_data($$){
my ($data, $agent_name, $module_name, $module_type) = @_;
my %dataObject;
if ($module_type eq "log4x") {
foreach my $attr ('severity','message', 'stacktrace'){
$dataObject{$attr} = get_tag_value ($data, $attr, '');
}
} else {
# Default case
my $value = get_tag_value ($data, 'data', ''); my $value = get_tag_value ($data, 'data', '');
pandora_process_module ($pa_config, $value, $agent, $module, $module_type, $timestamp, $utimestamp, $server_id, $dbh); $dataObject{'data'} = $value;
}
#return $value;
return \%dataObject;
}
sub get_macros_for_data($$){
my ($data, $agent_name, $module_name, $module_type) = @_;
my %macros;
if ($module_type eq "log4x") {
foreach my $attr ('severity','message', 'stacktrace'){
my $macro = "_" . $attr . "_";
$macros{$macro} = get_tag_value ($data, $attr, '');
}
} else {
}
return \%macros;
} }
1; 1;

View File

@ -277,7 +277,7 @@ sub pandora_query_snmp (%$) {
# SNMP v1, v2 and v2c call # SNMP v1, v2 and v2c call
if ($snmp_version ne '3'){ if ($snmp_version ne '3'){
$output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid 2>/dev/null`; $output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c '$snmp_community' $snmp_target $snmp_oid 2>/dev/null`;
if ($output ne ""){ if ($output ne ""){
$module_result = 0; $module_result = 0;
$module_data = $output; $module_data = $output;
@ -420,7 +420,8 @@ sub exec_network_module ($$$$) {
# Is everything goes ok # Is everything goes ok
if ($module_result == 0) { if ($module_result == 0) {
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $server_id, $dbh); my %data = ("data" => $module_data);
pandora_process_module ($pa_config, \%data, '', $module, '', $timestamp, $utimestamp, $server_id, $dbh);
# Update agent last contact using Pandora version as agent version # Update agent last contact using Pandora version as agent version
pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, $dbh); pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, $dbh);

View File

@ -166,9 +166,11 @@ sub data_consumer ($$) {
# Execute command # Execute command
$command = $pa_config->{'plugin_exec'} . ' ' . $timeout . ' ' . $command; $command = $pa_config->{'plugin_exec'} . ' ' . $timeout . ' ' . $command;
my $module_data = `$command`; my $module_data = `$command`;
my $ReturnCode = ($? >> 8) & 0xff; my $ReturnCode = ($? >> 8) & 0xff;
if ($plugin->{'plugin_type'} == 1) { if ($plugin->{'plugin_type'} == 1) {
# Get the errorlevel if is a Nagios plugin type (parsing the errorlevel) # Get the errorlevel if is a Nagios plugin type (parsing the errorlevel)
@ -206,7 +208,8 @@ sub data_consumer ($$) {
my $utimestamp = time (); my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh); my %data = ("data" => $module_data);
pandora_process_module ($pa_config, \%data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, $dbh); pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, $dbh);
} }

View File

@ -235,7 +235,8 @@ sub exec_prediction_module ($$$$) {
$module_data = $average; $module_data = $average;
} }
pandora_process_module ($pa_config, $module_data, undef, $agent_module, undef, $timestamp, $utimestamp, $server_id, $dbh); my %data = ("data" => $module_data);
pandora_process_module ($pa_config, \%data, '', $agent_module, '', $timestamp, $utimestamp, $server_id, $dbh);
pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, $dbh); pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, $dbh);
} }

View File

@ -192,7 +192,8 @@ sub data_consumer ($$) {
my $utimestamp = time (); my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh); my %data = ("data" => $module_data);
pandora_process_module ($pa_config, \%data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, $dbh); pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, $dbh);
} }