2008-07-11 Evi Vanoost <vanooste@rcbi.rochester.edu>

* pandora_server/pandora_network
        * pandora_server/pandora_recon
        * pandora_server/pandora_plugin
        * pandora_server/pandora_prediction: Updated the queries it performs. Made the MASTER server query a nested query, that way you don't join thousands of records (it was up to 6000 in my environment) wh
ile you only need a few records. It won't log as a slow query (indexes are used)

        * pandora_console/operation/agentes/estado_grupo.php: Fixed the issue where all data was 0-ed out. There was an if-then-else construction that wasn't working well

        * pandora_console/operation/agentes/networkmap.php: Made more extensive error messages that explains WHY it wasn't generating. Then also made it so the image is cached instead of regenerated every tim
e (currently hardcoded at 5 min.). 


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@951 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-07-11 20:20:43 +00:00
parent 4aee8792e8
commit 0f64af2274
8 changed files with 223 additions and 161 deletions

View File

@ -1,3 +1,9 @@
2008-07-11 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_console/operation/agentes/estado_grupo.php: Fixed the issue where all data was 0-ed out. There was an if-then-else construction that wasn't working well
* pandora_console/operation/agentes/networkmap.php: Made more extensive error messages that explains WHY it wasn't generating. Then also made it so the image is cached instead of regenerated every time (currently hardcoded at 5 min.).
2008-07-10 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_console/operation/agentes/estado_grupo.php: Fixed some extra spaces that made the URL look ugly

View File

@ -69,19 +69,24 @@ foreach ($groups as $id_group => $group_name) {
$sql = sprintf ("SELECT tagente_estado.datos, tagente_estado.current_interval,
tagente_estado.utimestamp
FROM tagente, tagente_estado, tagente_modulo
WHERE tagente.disabled = 0 AND tagente.id_grupo = %d
AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.estado != 100
WHERE tagente.disabled = 0
AND tagente.id_grupo = %d
AND tagente.id_agente = tagente_estado.id_agente
AND tagente_estado.estado != 100
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0
AND tagente_estado.utimestamp != 0",
$id_group);
$result = mysql_query ($sql);
while ($module = mysql_fetch_array ($result)) {
if ($config["show_unknown"] > 0) {
$seconds = $now - $module['utimestamp'];
if ($seconds >= ($module['current_interval'] * 2)) {
$group_info["down"]++;
}
while ($module = mysql_fetch_assoc ($result)) {
//if ($config["show_unknown"] > 0) {
//this needs to be filled out somehow, but this was a serious bug. If that config var is set, it would short circuit both ok++ and bad++ returning empty for everything
//}
$seconds = $now - $module['utimestamp'];
// Down = module/agent down (as in it didn't monitor in time)
// Bad = module bad (as in it did monitor but it returned 0)
if ($seconds >= ($module['current_interval'] * 2)) {
$group_info["down"]++;
} elseif ($module['datos'] != 0) {
$group_info["ok"]++;
} else {
@ -101,7 +106,6 @@ foreach ($groups as $id_group => $group_name) {
$id_group);
$group_info["alerts"] = get_db_sql ($sql);
}
array_push ($groups_info, $group_info);
}

View File

@ -30,8 +30,8 @@ function generate_dot ($simple = 0, $font_size) {
$graph = open_graph();
// Get agent data
$agents = mysql_query('SELECT * FROM tagente WHERE disabled = 0 ORDER BY id_grupo');
while ($agent = mysql_fetch_array($agents)) {
$agents = mysql_query('SELECT id_grupo, id_parent, id_agente FROM tagente WHERE disabled = 0 ORDER BY id_grupo');
while ($agent = mysql_fetch_assoc($agents)) {
if (give_acl($config["id_user"], $agent["id_grupo"], "AR") == 0)
continue;
// Save node parent information to define edges later
@ -75,7 +75,7 @@ function create_edge ($head, $tail) {
// Returns a node definition
function create_node ($agent, $simple = 0, $font_size = 10) {
$sql = sprintf ('SELECT COUNT(*) FROM tagente_estado,
$sql = sprintf ('SELECT COUNT(tagente_modulo.id_agente) FROM tagente_estado,
tagente_modulo
WHERE tagente_modulo.id_agente = %d
AND tagente_modulo.id_tipo_modulo in (2, 6, 9, 18, 21, 100)
@ -229,7 +229,8 @@ $nooverlap = (boolean) get_parameter ('nooverlap', 0);
$pure = (int) get_parameter ('pure');
$zoom = (float) get_parameter ('zoom');
$ranksep = (float) get_parameter ('ranksep', 2.5);
$simple = (int) get_parameter ('simple', 0);
$simple = (boolean) get_parameter ('simple', 0);
$regen = (boolean) get_parameter ('regen',0);
$font_size = (int) get_parameter ('font_size', 12);
// Login check
@ -279,6 +280,10 @@ echo '<td valign="top">' . lang_string('Simple') . ' &nbsp;';
print_checkbox ('simple', '1', $simple);
echo '</td>';
echo '<td valign="top">' . lang_string('Regenerate') . ' &nbsp;';
print_checkbox ('regen', '1', $regen);
echo '</td>';
if ($pure == "1") {
// Zoom
$zoom_array = array (
@ -321,22 +326,43 @@ $filter = set_filter();
$graph = generate_dot ($simple, $font_size);
// Generate image and map
$cmd = "echo " . escapeshellarg($graph) .
" | $filter -Tcmapx -o".$config["attachment_store"]."/networkmap.map -Tpng -o".$config["attachment_store"]."/networkmap.png";
// If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set
$filename_map = $config["attachment_store"]."/networkmap_".$layout;
$filename_img = "attachment/networkmap_".$layout."_".$font_size;
if($simple) {
$filename_map .= "_simple";
$filename_img .= "_simple";
}
if($nooverlap) {
$filename_map .= "_nooverlap";
$filename_img .= "_nooverlap";
}
$filename_map .= ".map";
$filename_img .= ".png";
$result = system ($cmd);
if($regen != 1 && filemtime($filename_img) > time() - 300) {
$result = true;
} else {
$cmd = "echo " . escapeshellarg($graph) . " | $filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img;
$result = system ($cmd);
}
if ($result !== false) {
if (! file_exists ($config["attachment_store"]."/networkmap.map")) {
if (! file_exists ($filename_map)) {
echo '<h2 class="err">'.lang_string ('Map could not be generated').'</h2>';
echo $result;
return;
echo "<br /> Apparently something went wrong reading the output.<br /> Is ".$filter." (usually part of GraphViz) installed and able to be executed by the webserver?";
echo "<br /> Is ".$config["attachment_store"]." writeable by the webserver?";
return;
}
echo '<img src="attachment/networkmap.png" usemap="#networkmap"/>';
include $config["attachment_store"]."/networkmap.map";
echo '<img src="'.$filename_img.'" usemap="#networkmap" />';
include $filename_map;
} else {
echo '<h2 class="err">'.lang_string ('Map could not be generated').'</h2>';
echo $result;
echo "<br /> Apparently something went wrong executing the command.";
echo "<br /> Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver?";
echo "<br /> Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)";
return;
}
?>

View File

@ -1,3 +1,10 @@
2008-07-11 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_server/pandora_network
* pandora_server/pandora_recon
* pandora_server/pandora_plugin
* pandora_server/pandora_prediction: Updated the queries it performs. Made the MASTER server query a nested query, that way you don't join thousands of records (it was up to 6000 in my environment) while you only need a few records. It won't log as a slow query (indexes are used)
2008-07-10 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_server_installer: Some typos

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
##########################################################################
# Pandora FMS Network Server
##########################################################################
@ -196,60 +199,62 @@ sub pandora_network_producer ($) {
while (1) {
if ($pa_config->{"pandora_master"} != 1) {
# Query for normal server, not MASTER server
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_network_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.id_tipo_modulo > 4
AND
tagente_modulo.id_tipo_modulo < 19
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP())
# Query for normal server, not MASTER server
$query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_network_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.id_tipo_modulo > 4
AND
tagente_modulo.id_tipo_modulo < 19
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
tagente_modulo.flag = 1
OR
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP())
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
# Apparently the MASTER SERVER takes over a SLAVE SERVER tasks' when it's down. Made a subquery of it so it doesn't do 3-4 joins
$query1 = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, tagente_estado.last_execution_try
FROM
tagente, tagente_modulo, tagente_estado
WHERE
(
(tagente.id_network_server = $server_id)
OR
(tagente.id_network_server = ANY(SELECT id_server FROM tserver WHERE status = 0 AND id_server != $server_id AND network_server = 1))
)
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.id_tipo_modulo > 4
AND
tagente_modulo.id_tipo_modulo < 19
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
tagente_modulo.flag = 1
OR
tagente_modulo.flag = 1
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, tagente_estado.last_execution_try
FROM
tagente, tagente_modulo, tagente_estado, tserver
WHERE
( (tagente.id_network_server = $server_id AND tagente_modulo.id_agente = tagente.id_agente) OR
(tagente.id_network_server != $server_id AND tagente_modulo.id_agente = tagente.id_agente AND tagente.id_network_server = tserver.id_server AND tserver.status = 0)
) AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.id_tipo_modulo > 4
AND
tagente_modulo.id_tipo_modulo < 19
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() )
OR
tagente_modulo.flag = 1
)
ORDER BY
last_execution_try ASC";
}
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() )
)
ORDER BY last_execution_try ASC";
}
$exec_sql1 = $dbh->prepare($query1);
$exec_sql1 ->execute;
while (@sql_data1 = $exec_sql1->fetchrow_array()) {

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
##########################################################################
# Pandora FMS Plugin Server
##########################################################################
@ -194,50 +197,53 @@ sub pandora_plugin_producer ($) {
while (1) {
if ($pa_config->{"pandora_master"} != 1) {
# Query for normal server, not MASTER server
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_plugin_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.id_plugin != 0
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
(tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()
OR
tagente_modulo.flag = 1
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado, tserver
WHERE
( (tagente.id_plugin_server = $server_id AND tagente_modulo.id_agente = tagente.id_agente) OR
(tagente.id_plugin_server != $server_id AND tagente_modulo.id_agente = tagente.id_agente AND tagente.id_plugin_server = tserver.id_server AND tserver.status = 0)
) AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.id_plugin != 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() OR tagente_modulo.flag = 1 )
ORDER BY last_execution_try ASC";
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_plugin_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.id_plugin != 0
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
tagente_modulo.flag = 1
OR
(tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
( (tagente.id_plugin_server = $server_id) OR
(tagente.id_plugin_server = ANY(SELECT id_server FROM tserver WHERE status = 0 AND id_server != $server_id AND plugin_server = 1))
)
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.id_plugin != 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND
(tagente_modulo.flag = 1 OR (tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() )
ORDER BY last_execution_try ASC";
}
$exec_sql1 = $dbh->prepare($query1);
$exec_sql1 ->execute;

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
##########################################################################
# Pandora FMS Prediction Server
##########################################################################
@ -189,50 +192,52 @@ sub pandora_prediction_producer ($) {
while (1) {
if ($pa_config->{"pandora_master"} != 1) {
# Query for normal server, not MASTER server
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_prediction_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
id_prediction_server = $server_id
AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.prediction_module != 0
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
(tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()
OR
tagente_modulo.flag = 1
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado, tserver
WHERE
( (tagente.id_prediction_server = $server_id AND tagente_modulo.id_agente = tagente.id_agente) OR
(tagente.id_prediction_server != $server_id AND tagente_modulo.id_agente = tagente.id_agente AND tagente.id_prediction_server = tserver.id_server AND tserver.status = 0)
) AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.prediction_module != 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() OR tagente_modulo.flag = 1 )
ORDER BY last_execution_try ASC";
AND
tagente_modulo.disabled = 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND (
tagente_modulo.flag = 1
OR
(tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()
)
ORDER BY
last_execution_try ASC ";
} else {
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado
WHERE
( (tagente.id_prediction_server = $server_id) OR
(tagente.id_prediction_server = ANY(SELECT id_server FROM tserver WHERE status = 0 AND id_server != $server_id AND prediction_server = 1) )
) AND
tagente_modulo.id_agente = tagente.id_agente
AND
tagente.disabled = 0
AND
tagente_modulo.disabled = 0
AND
tagente_modulo.prediction_module != 0
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND
(tagente_modulo.flag = 1 OR (tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP())
ORDER BY last_execution_try ASC";
}
$exec_sql1 = $dbh->prepare($query1);
$exec_sql1 ->execute;

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
##########################################################################
# Pandora FMS Recon Server
##########################################################################
@ -128,7 +131,7 @@ sub pandora_recon_producer ($) {
WHERE
id_network_server = $server_id
AND
status = -1
status = 1
AND
(utimestamp + interval_sweep) < UNIX_TIMESTAMP()
";
@ -641,4 +644,4 @@ sub pandora_shutdown {
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0, 0, 4, 0, 0, "system", $dbh);
exit;
}
}