From 0f64af2274bdd5630a87f289d4329f55a9acb319 Mon Sep 17 00:00:00 2001 From: guruevi Date: Fri, 11 Jul 2008 20:20:43 +0000 Subject: [PATCH] 2008-07-11 Evi Vanoost * 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 --- pandora_console/ChangeLog | 6 + .../operation/agentes/estado_grupo.php | 22 ++-- .../operation/agentes/networkmap.php | 48 ++++++-- pandora_server/ChangeLog | 7 ++ pandora_server/bin/pandora_network | 111 +++++++++--------- pandora_server/bin/pandora_plugin | 94 ++++++++------- pandora_server/bin/pandora_prediction | 89 +++++++------- pandora_server/bin/pandora_recon | 7 +- 8 files changed, 223 insertions(+), 161 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 50dc3ebd26..33cfa0a31f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2008-07-11 Evi Vanoost + + * 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 * pandora_console/operation/agentes/estado_grupo.php: Fixed some extra spaces that made the URL look ugly diff --git a/pandora_console/operation/agentes/estado_grupo.php b/pandora_console/operation/agentes/estado_grupo.php index cfbfd316fd..3d88089b84 100644 --- a/pandora_console/operation/agentes/estado_grupo.php +++ b/pandora_console/operation/agentes/estado_grupo.php @@ -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); } diff --git a/pandora_console/operation/agentes/networkmap.php b/pandora_console/operation/agentes/networkmap.php index e0edabd5e5..26e42c52fe 100644 --- a/pandora_console/operation/agentes/networkmap.php +++ b/pandora_console/operation/agentes/networkmap.php @@ -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 '' . lang_string('Simple') . '  '; print_checkbox ('simple', '1', $simple); echo ''; +echo '' . lang_string('Regenerate') . '  '; +print_checkbox ('regen', '1', $regen); +echo ''; + 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 '

'.lang_string ('Map could not be generated').'

'; echo $result; - return; + echo "
Apparently something went wrong reading the output.
Is ".$filter." (usually part of GraphViz) installed and able to be executed by the webserver?"; + echo "
Is ".$config["attachment_store"]." writeable by the webserver?"; + return; } - echo ''; - include $config["attachment_store"]."/networkmap.map"; + echo ''; + include $filename_map; } else { echo '

'.lang_string ('Map could not be generated').'

'; echo $result; + echo "
Apparently something went wrong executing the command."; + echo "
Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver?"; + echo "
Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)"; return; } ?> diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 55ac7df906..22b2f25c19 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2008-07-11 Evi Vanoost + + * 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 * pandora_server_installer: Some typos diff --git a/pandora_server/bin/pandora_network b/pandora_server/bin/pandora_network index a191c255c8..553ed2e702 100755 --- a/pandora_server/bin/pandora_network +++ b/pandora_server/bin/pandora_network @@ -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()) { diff --git a/pandora_server/bin/pandora_plugin b/pandora_server/bin/pandora_plugin index 465fc1d3be..eb9dfc656f 100755 --- a/pandora_server/bin/pandora_plugin +++ b/pandora_server/bin/pandora_plugin @@ -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; diff --git a/pandora_server/bin/pandora_prediction b/pandora_server/bin/pandora_prediction index 206ed44b21..63c9e0e6e6 100755 --- a/pandora_server/bin/pandora_prediction +++ b/pandora_server/bin/pandora_prediction @@ -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; diff --git a/pandora_server/bin/pandora_recon b/pandora_server/bin/pandora_recon index ead8489ea7..dd228f52a1 100755 --- a/pandora_server/bin/pandora_recon +++ b/pandora_server/bin/pandora_recon @@ -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; -} \ No newline at end of file +}