From bcd04b213083e4fd474cc56c927d3064d743b227 Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Wed, 2 Jul 2008 12:30:56 +0000 Subject: [PATCH] 2008-07-02 Esteban Sanchez * general/logon_ok.php: Style correction. * include/languages/language_en.php: Added a couple of strings. * include/styles/pandora.css: Container div has now variable width, so Pandora console is wider now. * include/config.php: Replaced default values from last commit. Change homeurl variable, which now points to base url directory. * include/config_process.php: Style correction. Use pandora functions and indent the code properly. * reporting/fgraph.php, include/functions.php, ajax.php: Use require_once instead of require which speeds up the code parsing. * index.php: Use require_once instead of require which speeds up the code parsing. Add all GET and POST variables when refreshing a page. Style corrections. Use $_SERVER instead getenv. * include/functions_db.php: Avoid including config.php and use global instead. Replaced some id_user with the respective variable holds in config array. Replaced SQL syntax, removed an undeclared variable and renamed to english in event_insert(). Renamed return_moduledata_*_value() to get_agent_module_value_*(). Fixed an error in the sumatory when the module is incremental. * include/functions_reporting.php: Renamed return_module_SLA() to get_agent_module_sla(). * include/functions_reporting_pdf.php: Tabs and blankspaces correction. Style correction. Added new reports rendering, and fixed images references. Removed old and deprecated functions. * operation/agentes/networkmap.php: Style correction. * operation/agentes/sla_view.php, reporting/stat_win.php: Use renamed functions. * operation/reporting/reporting_viewer.php: Table reports width are now wider. Fixed some colspan problems. Generate custom graph ids better. Added agent and module name to SLAs. Style correction in the use of rowclass structure since now each content has its own table. * operation/reporting/custom_reporting.php: Removed unused variable for PDF reporting generation link. * operation/reporting/reporting_viewer_pdf.php: Rewrite the code to make style corrections and use pandora functions. * operation/menu.php: Tabs and blankspaces correction. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@916 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 54 ++ pandora_console/ajax.php | 10 +- pandora_console/general/logon_ok.php | 2 +- pandora_console/include/config.php | 6 +- pandora_console/include/config_process.php | 184 +++--- pandora_console/include/functions.php | 2 +- pandora_console/include/functions_db.php | 57 +- .../include/functions_reporting.php | 487 ++++++++------ .../include/functions_reporting_pdf.php | 599 +++++++++--------- .../include/languages/language_en.php | 2 + pandora_console/include/styles/pandora.css | 16 +- pandora_console/index.php | 88 +-- .../operation/agentes/networkmap.php | 8 +- .../operation/agentes/sla_view.php | 4 +- pandora_console/operation/menu.php | 22 +- .../operation/reporting/custom_reporting.php | 4 +- .../operation/reporting/reporting_viewer.php | 157 ++--- .../reporting/reporting_viewer_pdf.php | 44 +- pandora_console/reporting/fgraph.php | 234 +++---- pandora_console/reporting/stat_win.php | 6 +- 20 files changed, 1059 insertions(+), 927 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5b2e3b7c5e..e2a055c6c5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,57 @@ +2008-07-02 Esteban Sanchez + + * general/logon_ok.php: Style correction. + + * include/languages/language_en.php: Added a couple of strings. + + * include/styles/pandora.css: Container div has now variable width, so + Pandora console is wider now. + + * include/config.php: Replaced default values from last commit. Change + homeurl variable, which now points to base url directory. + + * include/config_process.php: Style correction. Use pandora functions + and indent the code properly. + + * reporting/fgraph.php, include/functions.php, ajax.php: Use + require_once instead of require which speeds up the code parsing. + + * index.php: Use require_once instead of require which speeds up the + code parsing. Add all GET and POST variables when refreshing a page. + Style corrections. Use $_SERVER instead getenv. + + * include/functions_db.php: Avoid including config.php and use global + instead. Replaced some id_user with the respective variable holds in + config array. Replaced SQL syntax, removed an undeclared variable and + renamed to english in event_insert(). Renamed + return_moduledata_*_value() to get_agent_module_value_*(). Fixed an + error in the sumatory when the module is incremental. + + * include/functions_reporting.php: Renamed return_module_SLA() to + get_agent_module_sla(). + + * include/functions_reporting_pdf.php: Tabs and blankspaces + correction. Style correction. Added new reports rendering, and fixed + images references. Removed old and deprecated functions. + + * operation/agentes/networkmap.php: Style correction. + + * operation/agentes/sla_view.php, reporting/stat_win.php: Use renamed + functions. + + * operation/reporting/reporting_viewer.php: Table reports width are + now wider. Fixed some colspan problems. Generate custom graph ids + better. Added agent and module name to SLAs. Style correction in the + use of rowclass structure since now each content has its own table. + + * operation/reporting/custom_reporting.php: Removed unused variable + for PDF reporting generation link. + + * operation/reporting/reporting_viewer_pdf.php: Rewrite the code to + make style corrections and use pandora functions. + + * operation/menu.php: Tabs and blankspaces correction. + 2008-07-01 Sancho Lerena * include/config_process.php: Default back to 1 week. diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php index 679da88676..021a3d9221 100644 --- a/pandora_console/ajax.php +++ b/pandora_console/ajax.php @@ -22,10 +22,10 @@ if ((! file_exists("include/config.php")) || (! is_readable("include/config.php"))) { - exit; + exit; } -require ('include/config.php'); +require_once ('include/config.php'); // Check for correct language file presence if (file_exists ('include/languages/language_'.$config['language'].'.php')) { @@ -34,8 +34,8 @@ if (file_exists ('include/languages/language_'.$config['language'].'.php')) { include "include/languages/language_en.php"; } -require ('include/functions.php'); -require ('include/functions_db.php'); +require_once ('include/functions.php'); +require_once ('include/functions_db.php'); // Real start session_start(); @@ -51,7 +51,7 @@ $config["id_user"] = $_SESSION["id_usuario"]; session_write_close (); if (file_exists ($page)) { $id_user = $_SESSION["id_usuario"]; - require ($page); + require_once ($page); } else { echo "
Sorry! I can't find the page $page!"; } diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index c7a5dac04e..43f593b596 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -17,7 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require("include/functions_reporting.php"); +require ("include/functions_reporting.php"); echo "
"; $nick = $_SESSION['id_usuario']; diff --git a/pandora_console/include/config.php b/pandora_console/include/config.php index 62f1a2f504..bfd277ea52 100644 --- a/pandora_console/include/config.php +++ b/pandora_console/include/config.php @@ -2,10 +2,10 @@ // Begin of automatic config file $config["dbname"]="pandora"; // MySQL DataBase name $config["dbuser"]="pandora"; // DB User -$config["dbpass"]="dstxhvec"; // DB Password +$config["dbpass"]="pandora"; // DB Password $config["dbhost"]="localhost"; // DB Host -$config["homedir"]="/var/www/pandora/"; // Config homedir -$config["homeurl"]="http://192.168.50.1/pandora"; // Base URL +$config["homedir"]="/var/www/pandora_console/"; // Config homedir +$config["homeurl"]="/pandora_console"; // Base URL (all in URL after http://example.com) // End of automatic config file ?>Pandora FMS Error - -
-
-
- -
-
-

Pandora Console Error DB-001

- Cannot connect with Database, please check your database setup in the - ./include/config.php file and read documentation.

- Probably any of your user/database/hostname values are incorrect or - database is not running.


- MySQL ERROR: '. mysql_error().' -
  -
-
'); + //Non-persistent connection. If you want persistent conn change it to mysql_pconnect() + exit ('Pandora FMS Error + +
+
+
+ +
+
+

Pandora Console Error DB-001

+ Cannot connect with Database, please check your database setup in the + ./include/config.php file and read documentation.

+ Probably any of your user/database/hostname values are incorrect or + database is not running.


+ MySQL ERROR: '. mysql_error().' +
  +
+
'); } -mysql_select_db($config["dbname"]); -if($result2=mysql_query("SELECT * FROM tconfig")){ - while ($row2=mysql_fetch_array($result2)){ - switch ($row2["token"]) { - case "language_code": $config["language"]=$row2["value"]; - break; - case "block_size": $config["block_size"]=$row2["value"]; - break; - case "days_purge": $config["days_purge"]=$row2["value"]; - break; - case "days_compact": $config["days_compact"]=$row2["value"]; - break; - case "graph_res": $config["graph_res"]=$row2["value"]; - break; - case "step_compact": $config["step_compact"]=$row2["value"]; - break; - case "style": $config["style"]=$row2["value"]; - break; - case "show_unknown": $config["show_unknown"] = $row2["value"]; - break; - case "show_lastalerts": $config["show_lastalerts"] = $row2["value"]; - break; - case "remote_config": $config["remote_config"] = $row2["value"]; - break; - case "sla_period": $config["sla_period"] = $row2["value"]; - break; - case "graph_color1": - $config["graph_color1"] = $row2["value"]; - break; - case "graph_color2": - $config["graph_color2"] = $row2["value"]; - break; - case "graph_color3": - $config["graph_color3"] = $row2["value"]; - break; - } - } -} else { - exit ('Pandora FMS Error - -
-
-
- -
-
-

Pandora Console Error DB-002

- Cannot load configuration variables. Please check your database setup in the - ./include/config.php file and read documentation.

- Probably database schema is created but there are no data inside it or you have a problem with DB access credentials. -

-
-
'); -} +mysql_select_db ($config["dbname"]); +require_once ('functions_db.php'); +$configs = get_db_all_rows_in_table ('tconfig'); + +if (sizeof ($configs) == 0) { + exit ('Pandora FMS Error + +
+
+
+ +
+
+

Pandora Console Error DB-002

+ Cannot load configuration variables. Please check your database setup in the + ./include/config.php file and read documentation.

+ Probably database schema is created but there are no data inside it or you have a problem with DB access credentials. +

+
+
'); +} +foreach ($configs as $c) { + switch ($c["token"]) { + case "language_code": + $config["language"] = $c["value"]; + + break; + case "block_size": + $config["block_size"] = $c["value"]; + + break; + case "days_purge": + $config["days_purge"] = $c["value"]; + + break; + case "days_compact": + $config["days_compact"] = $c["value"]; + + break; + case "graph_res": + $config["graph_res"] = $c["value"]; + + break; + case "step_compact": + $config["step_compact"] = $c["value"]; + + break; + case "style": + $config["style"] = $c["value"]; + + break; + case "show_unknown": + $config["show_unknown"] = $c["value"]; + + break; + case "show_lastalerts": + $config["show_lastalerts"] = $c["value"]; + + break; + case "remote_config": + $config["remote_config"] = $c["value"]; + + break; + case "graph_color1": + $config["graph_color1"] = $c["value"]; + + break; + case "graph_color2": + $config["graph_color2"] = $c["value"]; + + break; + case "graph_color3": + $config["graph_color3"] = $c["value"]; + + break; + case "sla_period": + $config["sla_period"] = $c["value"]; + + break; + } +} if ($config["language"] == 'ast_es') { - $help_code='ast'; - } -else $help_code = substr($config["language"],0,2); + $help_code = 'ast'; +} else { + $help_code = substr ($config["language"], 0, 2); +} ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 3c1e365394..725c5e1296 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require ('functions_html.php'); +require_once ('functions_html.php'); /** * Prints a help tip icon. diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index e3683f373a..d39da6f412 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -80,8 +80,8 @@ function give_acl ($id_user, $id_group, $access) { PM - Pandora Management */ - // Conexion con la base Datos - require("config.php"); + global $config; + $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id_user."'"; $res=mysql_query($query1); $row=mysql_fetch_array($res); @@ -157,7 +157,6 @@ function give_acl ($id_user, $id_group, $access) { * @param descripcion Long action description */ function audit_db ($id, $ip, $accion, $descripcion){ - require("config.php"); $today=date('Y-m-d H:i:s'); $utimestamp = time(); $sql1='INSERT INTO tsesion (ID_usuario, accion, fecha, IP_origen,descripcion, utimestamp) VALUES ("'.$id.'","'.$accion.'","'.$today.'","'.$ip.'","'.$descripcion.'", '.$utimestamp.')'; @@ -171,10 +170,11 @@ function audit_db ($id, $ip, $accion, $descripcion){ * @param ip Client user IP address. */ function logon_db ($id_user, $ip) { - require ("config.php"); - audit_db ($id_user, $ip, "Logon", "Logged in"); + global $config; + + audit_db ($config['id_user'], $ip, "Logon", "Logged in"); // Update last registry of user to get last logon - $sql = 'UPDATE tusuario fecha_registro = $today WHERE id_usuario = "$id_user"'; + $sql = sprintf ('UPDATE tusuario fecha_registro = $today WHERE id_usuario = "%s"', $id_user); $result = mysql_query ($sql); } @@ -185,8 +185,8 @@ function logon_db ($id_user, $ip) { * @param ip Client user IP address. */ function logoff_db ($id_user, $ip) { - require ("config.php"); - audit_db ($id_user, $ip, "Logoff", "Logged out"); + global $config; + audit_db ($config['id_user'], $ip, "Logoff", "Logged out"); } /** @@ -683,7 +683,8 @@ function dame_generic_string_data ($id) { * @param id_inc Incident id */ function borrar_incidencia ($id_inc) { - require ("config.php"); + global $config; + $sql = "DELETE FROM tincidencia WHERE id_incidencia = ".$id_inc; mysql_query ($sql); $sql = "SELECT * FROM tnota_inc WHERE id_incidencia = ".$id_inc; @@ -810,24 +811,25 @@ function existe ($id_user) { /** * Insert a event in the event log system. * - * @param evento - * @param id_grupo - * @param id_agente + * @param event + * @param id_group + * @param id_agent * @param status - * @param id_usuario + * @param id_user * @param event_type * @param priority * @param id_agent_module * @param id_aam */ -function event_insert ($evento, $id_grupo, $id_agente, $status = 0, - $id_usuario = '', $event_type = "unknown", $priority = 0, +function event_insert ($event, $id_group, $id_agent, $status = 0, + $id_user = '', $event_type = "unknown", $priority = 0, $id_agent_module = 0, $id_aam = 0) { - $sql = 'INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, - estado, utimestamp, id_usuario, event_type, criticity, id_agentmodule, id_alert_am) - VALUES ('.$id_agente.','.$id_grupo.',"'.$evento.'",NOW(),'.$status. - ', '.$utimestamp.', "'.$id_usuario.'", "'.$event_type.'", '.$priority. - ', '.$id_agent_module.', '.$id_aam.')'; + $sql = sprint ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, + estado, utimestamp, id_usuario, event_type, criticity, + id_agentmodule, id_alert_am) + VALUES (%d, %d, "%s", NOW(), %d, NOW(), "%s", "%s", %d, %d, %d)', + $id_agent, $id_group, $event, $status, $id_user, $event_type, + $priority, $id_agent_module, $id_aam); mysql_query ($sql); } @@ -1450,7 +1452,7 @@ function get_previous_data ($id_agent_module, $utimestamp) { * * @return The average module value in the interval. */ -function return_moduledata_avg_value ($id_agent_module, $period, $date = 0) { +function get_agent_module_value_average ($id_agent_module, $period, $date = 0) { if (! $date) $date = time (); $datelimit = $date - $period; @@ -1482,7 +1484,7 @@ function return_moduledata_avg_value ($id_agent_module, $period, $date = 0) { * * @return The maximum module value in the interval. */ -function return_moduledata_max_value ($id_agent_module, $period, $date = 0) { +function get_agent_module_value_max ($id_agent_module, $period, $date = 0) { if (! $date) $date = time (); $datelimit = $date - $period; @@ -1510,7 +1512,7 @@ function return_moduledata_max_value ($id_agent_module, $period, $date = 0) { * * @return The minimum module value of the module */ -function return_moduledata_min_value ($id_agent_module, $period, $date = 0) { +function get_agent_module_value_min ($id_agent_module, $period, $date = 0) { if (! $date) $date = time (); $datelimit = $date - $period; @@ -1537,7 +1539,7 @@ function return_moduledata_min_value ($id_agent_module, $period, $date = 0) { * * @return The sumatory of the module values in the interval. */ -function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) { +function get_agent_module_value_sumatory ($id_agent_module, $period, $date = 0) { if (! $date) $date = time (); $datelimit = $date - $period; // limit date @@ -1596,7 +1598,12 @@ function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) { if ($timestamp_end <= $datelimit) { $elapsed = $timestamp_end - $timestamp_begin; $times = intval ($elapsed / $module_interval); - $sum += $times * $previous_data; + if (is_module_inc ($module_name)) { + $data_value = $data['datos'] * $module_interval; + } else { + $data_value = $data['datos']; + } + $sum += $times * $data_value; } return (float) $sum; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 8e5c3bf0fb..daa66ff7c9 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -function return_module_SLA ($id_agent_module, $period, $min_value, $max_value, $date = 0) { +function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value, $date = 0) { require("config.php"); if (! $date) $date = time (); @@ -190,60 +190,110 @@ function general_stats ( $id_user, $id_group = 0) { return $data; } -function event_reporting ($id_agent, $period, $date = 0, $return = false) { - require("config.php"); - require ("include/languages/language_".$config["language"].".php"); +function event_reporting ($id_group, $period, $date = 0, $return = false) { + global $config; - $output = ''; - $id_user = $_SESSION["id_usuario"]; - global $REMOTE_ADDR; if (! $date) $date = time (); - $mytimestamp = $date - $period; + $datelimit = $date - $period; - $output .= ""; - $output .= ""; - $output .= ""; - $output .= ""; - $output .= ""; - $output .= ""; - $color = 1; - $id_evento = 0; + $table->data = array (); + $table->head = array (); + $table->head[0] = lang_string ('status'); + $table->head[1] = lang_string ('event_name'); + $table->head[2] = lang_string ('id_user'); + $table->head[3] = lang_string ('timestamp'); - $sql2="SELECT * FROM tevento WHERE id_agente = $id_agent AND utimestamp > '$mytimestamp'"; - - // Make query for data (all data, not only distinct). - $result2 = mysql_query($sql2); - while ($row2 = mysql_fetch_array($result2)) { - $id_grupo = $row2["id_grupo"]; - if (give_acl($id_user, $id_grupo, "IR") == 1) { // Only incident read access to view data ! - $id_group = $row2["id_grupo"]; - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - $output .= ""; - } + $sql = sprintf ('SELECT * FROM tevento + WHERE id_agente = %d + AND utimestamp > %d AND utimestamp <= %d + AND id_grupo = %d + ORDER BY utimestamp ASC', + $id_group, $datelimit, $date, $id_group); + $events = get_db_all_rows_sql ($sql); + foreach ($events as $event) { + $data = array (); + if ($event["estado"] == 0) + $data[0] = ''; + else + $data[0] = ''; + $data[1] = $event['evento']; + $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; + $data[3] = $event["timestamp"]; + array_push ($table->data, $data); } - $output .= "
".$lang_label["status"]."".$lang_label["event_name"]."".$lang_label["id_user"]."".$lang_label["timestamp"]."
"; - if ($row2["estado"] == 0) - $output .= ""; - else - $output .= ""; - $output .= "".$row2["evento"]; - $output .= ""; - if ($row2["estado"] <> 0) - $output .= substr($row2["id_usuario"],0,8)." ".dame_nombre_real($row2["id_usuario"]).""; - $output .= "".$row2["timestamp"]; - $output .= "
"; if (!$return) - echo $output; - return $output; + print_table ($table); + return $table; +} + +function get_alerts_in_group ($id_group) { + $alerts = array (); + $agents = get_agents_in_group ($id_group); + foreach ($agents as $agent) { + $agent_alerts = get_alerts_in_agent ($agent['id_agente']); + $alerts = array_merge ($alerts, $agent_alerts); + } + + return $alerts; +} + +function get_alerts_fired ($alerts, $period = 0, $date = 0) { + if (! $date) + $date = time (); + $datelimit = $date - $period; + + $alerts_fired = array (); + $agents = array (); + foreach ($alerts as $alert) { + $fires = get_alert_fires_in_period ($alert['id_agente_modulo'], $period, $date); + if (! $fires) { + continue; + } + $alerts_fired[$alert['id_aam']] = $fires; + } + return $alerts_fired; +} + +function get_fired_alerts_reporting_table ($alerts_fired, $return = false) { + $agents = array (); + + foreach (array_keys ($alerts_fired) as $id_alert) { + $alert = get_db_row ('talerta_agente_modulo', 'id_aam', $id_alert); + + /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ + $id_agent = $alert['id_agent']; + if (!isset ($agents[$id_agent])) { + $agents[$id_agent] = array (); + } + array_push ($agents[$id_agent], $alert); + } + + $table->data = array (); + $table->head = array (); + $table->head[0] = lang_string ('agent'); + $table->head[1] = lang_string ('alert_description'); + $table->head[2] = lang_string ('times_fired'); + $table->head[3] = lang_string ('priority'); + + foreach ($agents as $alerts) { + $data = array (); + foreach ($alerts as $alert) { + if (! isset ($data[0])) + $data[0] = dame_nombre_agente_agentemodulo ($alert['id_agente_modulo']); + else + $data[0] = ''; + $data[1] = $alert['descripcion']; + $data[2] = $alerts_fired[$alert['id_aam']]; + $data[3] = get_alert_priority ($alert['priority']); + array_push ($table->data, $data); + } + } + + if (!$return) + print_table ($table); + return $table; } /** @@ -258,73 +308,32 @@ function event_reporting ($id_agent, $period, $date = 0, $return = false) { * @param $return Flag to return or echo the report (by default). */ function alert_reporting ($id_group, $period = 0, $date = 0, $return = false) { - if (! $date) - $date = time (); - $datelimit = $date - $period; $output = ''; - $alerts = array (); + $alerts = get_alerts_in_group ($id_group); + $alerts_fired = get_alerts_fired ($alerts, $period, $date); - $agents = get_agents_in_group ($id_group); - foreach ($agents as $agent) { - $agent_alerts = get_alerts_in_agent ($agent['id_agente']); - $alerts = array_merge ($alerts, $agent_alerts); - } - if (sizeof ($alerts) == 0) - return; - - $alerts_fired = array (); - $agents = array (); - foreach ($alerts as $alert) { - $fires = get_alert_fires_in_period ($alert['id_agente_modulo'], $period, $date); - if (! $fires) { - continue; - } - $alerts_fired[$alert['id_aam']] = $fires; - $data = array (); - - /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ - $id_agent = $alert['id_agent']; - if (!isset ($agents[$id_agent])) { - $agents[$id_agent] = array (); - } - array_push ($agents[$id_agent], $alert); - } $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); $not_fired_percentage = 100 - $fired_percentage; $output .= ''; - $output .= ''.lang_string ('agents_with_fired_alerts').': '.sizeof ($agents).'
'; $output .= ''.lang_string ('fired_alerts').': '.sizeof ($alerts_fired).'
'; $output .= ''.lang_string ('total_alerts_monitored').': '.sizeof ($alerts).'
'; - if ($alerts_fired) { - $table->width = '100%'; - $table->class = 'databox'; - $table->size = array (); - $table->size[0] = '100px'; - $table->data = array (); - $table->head = array (); - $table->head[0] = lang_string ('agent'); - $table->head[1] = lang_string ('alert_description'); - $table->head[2] = lang_string ('times_fired'); - $table->head[3] = lang_string ('priority'); - - foreach ($agents as $alerts) { - $data = array (); - foreach ($alerts as $alert) { - if (! isset ($data[0])) - $data[0] = ''.dame_nombre_agente_agentemodulo ($alert['id_agente_modulo']).''; - else - $data[0] = ''; - $data[1] = $alert['descripcion']; - $data[2] = $alerts_fired[$alert['id_aam']]; - $data[3] = get_alert_priority ($alert['priority']); - array_push ($table->data, $data); - } - } - $output .= print_table ($table, true); + if (! sizeof ($alerts_fired)) { + if (!$return) + echo $output; + return $output; } + $table = get_fired_alerts_reporting_table ($alerts_fired, true); + $table->width = '100%'; + $table->class = 'databox'; + $table->size = array (); + $table->size[0] = '100px'; + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + + $output .= print_table ($table, true); if (!$return) echo $output; return $output; @@ -347,24 +356,54 @@ function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return = $datelimit = $date - $period; $output = ''; - $sql = sprintf ('SELECT * FROM tagente_modulo, ttipo_modulo, tagente - WHERE id_tipo_modulo = id_tipo - AND tagente.id_agente = tagente_modulo.id_agente - AND ttipo_modulo.nombre like "%%_proc" - AND tagente.id_grupo = %d', $id_group); - $monitors = get_db_all_rows_sql ($sql); + $monitors = get_monitors_in_group ($id_group); if (sizeof ($monitors) == 0) return; + $monitors_down = get_monitors_down ($monitors, $period, $date); + $down_percentage = round (sizeof ($monitors_down) / sizeof ($monitors) * 100, 2); + $not_down_percentage = 100 - $down_percentage; + $output .= ''; + + $output .= ''.lang_string ('total_monitors').': '.sizeof ($monitors).'
'; + $output .= ''.lang_string ('monitors_down_on_period').': '.sizeof ($monitors_down).'
'; + + $table = get_monitors_down_reporting_table ($monitors_down, true); + $table->width = '100%'; + $table->class = 'databox'; + $table->size = array (); + $table->size[0] = '100px'; + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + + $table->size = array (); + $table->size[0] = '100px'; + + $output .= print_table ($table, true); + + if (!$return) + echo $output; + return $output; +} - $monitors_down = 0; - $agents = array (); +function get_monitors_down ($monitors, $period = 0, $date = 0) { + $monitors_down = array (); foreach ($monitors as $monitor) { $down = get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); - if (! $down) { - continue; - } - $data = array (); - + if ($down) + array_push ($monitors_down, $monitor); + } + return $monitors_down; +} + +function get_monitors_down_reporting_table ($monitors_down, $return = false) { + $table->data = array (); + $table->head = array (); + $table->head[0] = lang_string ('agent'); + $table->head[1] = lang_string ('monitor'); + + $agents = array (); + foreach ($monitors_down as $monitor) { /* Add monitors fired to $agents_fired_alerts indexed by id_agent */ $id_agent = $monitor['id_agente']; if (!isset ($agents[$id_agent])) { @@ -374,39 +413,25 @@ function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return = $monitors_down++; } - $down_percentage = round ($monitors_down / sizeof ($monitors) * 100, 2); - $not_down_percentage = 100 - $down_percentage; - $output .= ''; - - $output .= ''.lang_string ('total_monitors').': '.sizeof ($monitors).'
'; - $output .= ''.lang_string ('monitors_down_on_period').': '.$monitors_down.'
'; - - $table->width = '100%'; - $table->class = 'databox'; - $table->size = array (); - $table->size[0] = '100px'; - $table->data = array (); - $table->head = array (); - $table->head[0] = lang_string ('agent'); - $table->head[1] = lang_string ('alert_description'); - - foreach ($agents as $monitors) { + foreach ($agents as $id_agent => $monitors) { $data = array (); foreach ($monitors as $monitor) { if (! isset ($data[0])) - $data[0] = ''.$monitor['nombre'].''; + $data[0] = dame_nombre_agente ($id_agent); else $data[0] = ''; - $data[1] = $monitor['descripcion']; + if ($monitor['descripcion'] != '') { + $data[1] = $monitor['descripcion']; + } else { + $data[1] = $monitor['nombre']; + } array_push ($table->data, $data); } } - $output .= print_table ($table, true); if (!$return) - echo $output; - return $output; + print_table ($table); + return $table; } /** @@ -427,42 +452,37 @@ function general_group_reporting ($id_group, $return = false) { return $output; } -/** - * Get a detailed report of an agent - * - * @param $id_agent Agent to get the report. - * @param $period Period of time of the desired report. - * @param $date Beggining date of the report (current date by default). - * @param $return Flag to return or echo the report (by default). - */ -function agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $return = false) { - $output = ''; - $n_a_string = lang_string ('N/A').'(*)'; - $monitors = array (); - $table_modules->data = array (); - $table_modules->head = array (); - $table_alerts->data = array (); +function get_monitors_in_group ($id_group) { + $sql = sprintf ('SELECT tagente_modulo.* + FROM tagente_modulo, ttipo_modulo, tagente + WHERE id_tipo_modulo = id_tipo + AND tagente.id_agente = tagente_modulo.id_agente + AND ttipo_modulo.nombre like "%%_proc" + AND tagente.id_grupo = %d', $id_group); + return get_db_all_rows_sql ($sql); +} + +function get_monitors_in_agent ($id_agent) { + $sql = sprintf ('SELECT tagente_modulo.* + FROM tagente_modulo, ttipo_modulo, tagente + WHERE id_tipo_modulo = id_tipo + AND tagente.id_agente = tagente_modulo.id_agente + AND ttipo_modulo.nombre like "%%_proc" + AND tagente.id_agente = %d', $id_agent); + return get_db_all_rows_sql ($sql); +} + +function get_agent_alerts_reporting_table ($id_agent, $period = 0, $date = 0, $return = false) { + $table->data = array (); + $table->head = array (); + $table->head[0] = lang_string ('type'); + $table->head[1] = lang_string ('description'); + $table->head[2] = lang_string ('min'); + $table->head[3] = lang_string ('max'); + $table->head[4] = lang_string ('threshold'); + $table->head[5] = lang_string ('last_fired'); + $table->head[6] = lang_string ('times_fired'); - /* Show modules in agent */ - $modules = get_modules_in_agent ($id_agent); - $output .= '
'; - $output .= '

'.lang_string ('agent').' - '.dame_nombre_agente ($id_agent).'

'; - $output .= '

'.lang_string ('modules').'

'; - $data = array (); - foreach ($modules as $module) { - if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') - $data[0] = $module['descripcion']; - else - $data[0] = $module['nombre']; - $module_name = giveme_module_type ($module['id_tipo_modulo']); - if (is_module_proc ($module_name)) { - array_push ($monitors, $module); - } - array_push ($table_modules->data, $data); - } - $output .= print_table ($table_modules, true); - - /* Show alerts in agent */ $alerts = get_alerts_in_agent ($id_agent); foreach ($alerts as $alert) { $fires = get_alert_fires_in_period ($alert['id_agente_modulo'], $period, $date); @@ -479,21 +499,21 @@ function agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $return = $data[5] = get_alert_last_fire_timestamp_in_period ($alert['id_agente_modulo'], $period, $date); $data[6] = $fires; - array_push ($table_alerts->data, $data); - } - if (sizeof ($table_alerts->data)) { - $output .= '

'.lang_string ('alerts').'

'; - $output .= print_table ($table_alerts, true); + array_push ($table->data, $data); } + if (!$return) + print_table ($table); + return $table; +} + +function get_agent_monitors_reporting_table ($id_agent, $period = 0, $date = 0, $return = false) { + $n_a_string = lang_string ('N/A').'(*)'; + $table->head = array (); + $table->head[0] = lang_string ('monitor'); + $table->head[1] = lang_string ('last_failure'); + $table->data = array (); + $monitors = get_monitors_in_agent ($id_agent); - /* Show monitor status in agent (if any) */ - if (sizeof ($monitors) == 0) { - $output .= '
'; - if (! $return) - echo $output; - return $output; - } - $table_monitors->data = array (); foreach ($monitors as $monitor) { $downs = get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); if (! $downs) { @@ -505,12 +525,75 @@ function agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $return = else $data[0] = $monitor['nombre']; $data[1] = get_monitor_last_down_timestamp_in_period ($monitor['id_agente_modulo'], $period, $date); - array_push ($table_monitors->data, $data); + array_push ($table->data, $data); } - if (sizeof ($table_monitors->data)) { - $output .= '

'.lang_string ('monitors').'

'; - $output .= print_table ($table_monitors, true); + if (!$return) + print_table ($table); + return $table; +} + +function get_agent_modules_reporting_table ($id_agent, $period = 0, $date = 0, $return = false) { + $table->data = array (); + $n_a_string = lang_string ('N/A').'(*)'; + $modules = get_modules_in_agent ($id_agent); + $data = array (); + + foreach ($modules as $module) { + if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') + $data[0] = $module['descripcion']; + else + $data[0] = $module['nombre']; + array_push ($table->data, $data); } + if (!$return) + print_table ($table); + return $table; +} + +/** + * Get a detailed report of an agent + * + * @param $id_agent Agent to get the report. + * @param $period Period of time of the desired report. + * @param $date Beggining date of the report (current date by default). + * @param $return Flag to return or echo the report (by default). + */ +function get_agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $return = false) { + $output = ''; + $n_a_string = lang_string ('N/A').'(*)'; + + /* Show modules in agent */ + $output .= '
'; + $output .= '

'.lang_string ('agent').' - '.dame_nombre_agente ($id_agent).'

'; + $output .= '

'.lang_string ('modules').'

'; + $table_modules = get_agent_modules_reporting_table ($id_agent, $period, $date, true); + $table_modules->width = '99%'; + $output .= print_table ($table_modules, true); + + /* Show alerts in agent */ + $table_alerts = get_agent_alerts_reporting_table ($id_agent, $period, $date, true); + $table_alerts->width = '99%'; + if (sizeof ($table_alerts->data)) { + $output .= '

'.lang_string ('alerts').'

'; + $output .= print_table ($table_alerts, true); + } + + /* Show monitor status in agent (if any) */ + $table_monitors = get_agent_monitors_reporting_table ($id_agent, $period, $date, true); + if (sizeof ($table_monitors->data) == 0) { + $output .= '
'; + if (! $return) + echo $output; + return $output; + } + $table_monitors->width = '99%'; + $table_monitors->align = array (); + $table_monitors->align[1] = 'right'; + $table_monitors->size = array (); + $table_monitors->align[1] = '10%'; + $output .= '

'.lang_string ('monitors').'

'; + $output .= print_table ($table_monitors, true); + $output .= '
'; if (! $return) @@ -524,30 +607,12 @@ function agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $return = * @param $id_group Group to get the report * @param $return Flag to return or echo the report (by default). */ -function agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) { +function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) { $output = ''; $agents = get_agents_in_group ($id_group); - $table_modules->width = '700px'; - $table_alerts->width = '700px'; - $table_monitors->width = '700px'; - $table_monitors->align = array (); - $table_monitors->align[1] = 'right'; - $table_monitors->head = array (); - $table_monitors->head[0] = lang_string ('monitor'); - $table_monitors->head[1] = lang_string ('last_failure'); - $table_alerts->head = array (); - $table_alerts->head[0] = lang_string ('type'); - $table_alerts->head[1] = lang_string ('description'); - $table_alerts->head[2] = lang_string ('min'); - $table_alerts->head[3] = lang_string ('max'); - $table_alerts->head[4] = lang_string ('threshold'); - $table_alerts->head[5] = lang_string ('last_fired'); - $table_alerts->head[6] = lang_string ('times_fired'); - - $agents = get_agents_in_group ($id_group); foreach ($agents as $agent) { - $output .= agent_detailed_reporting ($agent['id_agente'], $period, $date, true); + $output .= get_agent_detailed_reporting ($agent['id_agente'], $period, $date, true); if (!$return) { echo $output; $output = ''; diff --git a/pandora_console/include/functions_reporting_pdf.php b/pandora_console/include/functions_reporting_pdf.php index 7c68be5832..037ee6dab7 100644 --- a/pandora_console/include/functions_reporting_pdf.php +++ b/pandora_console/include/functions_reporting_pdf.php @@ -17,314 +17,329 @@ global $config; -$reporting_debug = 0; -if ($reporting_debug != 0){ - error_reporting(E_ALL); +$reporting_debug = false; +if ($reporting_debug) { + error_reporting (E_ALL); } else { - error_reporting(0); + error_reporting (0); } -function doTitle ($pdf, $title=""){ - $pdf->transaction('start'); - $ok=0; - while (!$ok){ - $thisPageNum = $pdf->ezPageCount; - $pdf->saveState(); - $pdf->setColor(0.9,0.9,0.9); - $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y-$pdf->getFontHeight(16)+$pdf->getFontDecender(16),$pdf->ez['pageWidth']-$pdf->ez['leftMargin']-$pdf->ez['rightMargin'],$pdf->getFontHeight(16)); - $pdf->restoreState(); - $pdf->ezText (utf8_decode($title),14,array('justification'=>'left')); - $pdf->ezText ("\n",6); - if ($pdf->ezPageCount==$thisPageNum){ - $pdf->transaction('commit'); - $ok=1; - } else { - // then we have moved onto a new page, bad bad, as the background colour will be on the old one - $pdf->transaction('rewind'); - $pdf->ezNewPage(); - } - } +function doTitle ($pdf, $title="") { + $pdf->transaction('start'); + $ok=0; + while (!$ok) { + $thisPageNum = $pdf->ezPageCount; + $pdf->saveState(); + $pdf->setColor(0.9,0.9,0.9); + $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y-$pdf->getFontHeight(16)+$pdf->getFontDecender(16),$pdf->ez['pageWidth']-$pdf->ez['leftMargin']-$pdf->ez['rightMargin'],$pdf->getFontHeight(16)); + $pdf->restoreState(); + $pdf->ezText (utf8_decode($title),14,array('justification'=>'left')); + $pdf->ezText ("\n",6); + if ($pdf->ezPageCount==$thisPageNum){ + $pdf->transaction('commit'); + $ok = 1; + } else { + // then we have moved onto a new page, bad bad, as the background colour will be on the old one + $pdf->transaction('rewind'); + $pdf->ezNewPage(); + } + } } function doPageNumbering($pdf, $x=500, $y=25, $size=9) { -// Original code by Johny Mnemonic (mnemonic23 in SF site) -// God bless Sourceforge forums ! + // Original code by Johny Mnemonic (mnemonic23 in SF site) + // God bless Sourceforge forums ! - //count pages - $pages = count($pdf->ezPages); - //iterate through pages - for($pageno = 1; $pageno <= $pages; $pageno++) { - //build footer string - $foot = 'Page '.$pageno.' of '.$pages; - //open the page again - $pdf->reopenObject($pdf->ezPages[$pageno]); - //print the footer - $pdf->addText($x, $y, $size, $foot); - //close the page - $pdf->closeObject(); - } + //count pages + $pages = count($pdf->ezPages); + //iterate through pages + for($pageno = 1; $pageno <= $pages; $pageno++) { + //build footer string + $foot = 'Page '.$pageno.' of '.$pages; + //open the page again + $pdf->reopenObject($pdf->ezPages[$pageno]); + //print the footer + $pdf->addText($x, $y, $size, $foot); + //close the page + $pdf->closeObject(); + } } function doPageHeader ($pdf, $title){ - global $config; + global $config; - $pdf->addInfo("Title", $title); - $pdf->addInfo("Author","Pandora FMS 2.0"); - $pdf->addInfo("Creator","Pandora FMS with ezPDF engine"); - $pdf->addInfo("Subject","Automated Pandora FMS report for user defined report"); - - // Add header - $all = $pdf->openObject(); - $pdf->saveState(); - $pdf->addJpegFromFile($config["homedir"]."/images/pandora_logo.jpg",20,812,25); - $pdf->setStrokeColor(0,0,0,1); - $pdf->line(20,40,578,40); - $pdf->line(20,810,578,810); - $pdf->addText(25,25,8,'Pandora FMS 2.0 - http://pandora.sourceforge.net'); - $pdf->addText(50,815,10,"Pandora FMS - Report $title"); - $pdf->restoreState(); - $pdf->closeObject(); - $pdf->addObject($all,'all'); + $pdf->addInfo("Title", $title); + $pdf->addInfo("Author","Pandora FMS 2.0"); + $pdf->addInfo("Creator","Pandora FMS with ezPDF engine"); + $pdf->addInfo("Subject","Automated Pandora FMS report for user defined report"); + + // Add header + $all = $pdf->openObject(); + $pdf->saveState(); + $pdf->addJpegFromFile($config["homedir"]."/images/pandora_logo.jpg",20,812,25); + $pdf->setStrokeColor(0,0,0,1); + $pdf->line(20,40,578,40); + $pdf->line(20,810,578,810); + $pdf->addText(25,25,8,'Pandora FMS 2.0 - http://pandora.sourceforge.net'); + $pdf->addText(50,815,10,"Pandora FMS - Report $title"); + $pdf->restoreState(); + $pdf->closeObject(); + $pdf->addObject($all,'all'); } -// =========================================================================================== -// =========================================================================================== - -function event_reporting_pdf ($id_agent, $period){ - global $config; - require ($config["homedir"]."/include/languages/language_".$config["language"].".php"); - - $id_user=$_SESSION["id_usuario"]; - global $REMOTE_ADDR; - $ahora = date("U"); - $mytimestamp = $ahora - $period; - $total_count = 0; - $table_data = array(); - $sql2="SELECT * FROM tevento WHERE id_agente = $id_agent AND utimestamp > '$mytimestamp'"; - // Make query for data (all data, not only distinct). - $result2=mysql_query($sql2); - while ($row2=mysql_fetch_array($result2)){ - $id_grupo = $row2["id_grupo"]; - if (give_acl($id_user, $id_grupo, "IR") == 1){ // Only incident read access to view data ! - $id_group = $row2["id_grupo"]; - if ($row2["estado"] == 0) - $table_data[$total_count][0] = "--"; - else - $table_data[$total_count][0] = "OK"; - $table_data[$total_count][1] = $row2["evento"]; - - if ($row2["estado"] <> 0) - $table_data[$total_count][2] = substr($row2["id_usuario"],0,8); - else - $table_data[$total_count][2] = ""; - $table_data[$total_count][3] = $row2["timestamp"]; - $total_count++; - } - } - return $table_data; -} - -function alert_reporting_pdf ($id_agent_module){ - global $config; - require ($config["homedir"]."/include/languages/language_".$config["language"].".php"); - - $query_gen='SELECT talerta_agente_modulo.alert_text, talerta_agente_modulo.id_alerta, talerta_agente_modulo.descripcion, talerta_agente_modulo.last_fired, talerta_agente_modulo.times_fired, tagente_modulo.nombre, talerta_agente_modulo.dis_max, talerta_agente_modulo.dis_min, talerta_agente_modulo.max_alerts, talerta_agente_modulo.time_threshold, talerta_agente_modulo.min_alerts, talerta_agente_modulo.id_agente_modulo, tagente_modulo.id_agente_modulo FROM tagente_modulo, talerta_agente_modulo WHERE tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo and talerta_agente_modulo.id_agente_modulo = '.$id_agent_module.' ORDER BY tagente_modulo.nombre'; - $result_gen=mysql_query($query_gen); - $total_count = 0; - $table_data = array(); - if (mysql_num_rows ($result_gen)) { - while ($data=mysql_fetch_array($result_gen)){ - if ($data["times_fired"] <> 0) - $table_data[$total_count][0] = "FIRED"; - else - $table_data[$total_count][0] = "--"; - $table_data[$total_count][1] = $data["descripcion"]; - $table_data[$total_count][2] = human_time_description($data["time_threshold"]); - - if ($data["last_fired"] == "0000-00-00 00:00:00") { - $table_data[$total_count][3] = $lang_label["never"]; - } - else { - $table_data[$total_count][3] = human_time_comparation ($data["last_fired"]); - } - $table_data[$total_count][4] = $data["times_fired"]; - $total_count++; - } - } - return $table_data; -} - -function general_report ($id_report){ - global $config; - include $config["homedir"]."/include/languages/language_".$config["language"].".php"; - include ($config["homedir"].'/include/pdf/class.ezpdf.php'); - require ($config["homedir"]."/include/functions_reporting.php"); - $session_id = session_id(); - - $report_name = html_entity_decode(get_db_value ("name", "treport", "id_report", $id_report), ENT_COMPAT, "iso-8859-15"); - $report_description = html_entity_decode (get_db_value ("description", "treport", "id_report", $id_report), ENT_COMPAT, "iso-8859-15"); - - $report_private= html_entity_decode( get_db_value ("private", "treport", "id_report", $id_report), ENT_COMPAT, "iso-8859-15"); - $report_user = html_entity_decode( get_db_value ("id_user", "treport", "id_report", $id_report), ENT_COMPAT, "iso-8859-15"); +function get_pdf_report ($report) { + global $config; + $session_id = session_id (); + $report_name = html_entity_decode ($report['name'], ENT_COMPAT, "iso-8859-15"); + $report_description = html_entity_decode ($report['description'], ENT_COMPAT, "iso-8859-15"); + $report_private= $report['private']; + $report_user = $report['id_user']; $date_today = date("Y/m/d H:i:s"); - $report_title = utf8_decode ("$report_name"); + $report_title = utf8_decode ("$report_name"); - // Start PDF - $pdf = new Cezpdf (); - $pdf->selectFont ($config["homedir"].'/include/pdf/fonts/Times-Roman.afm', array('encoding'=>'utf-8')); - doPageHeader ($pdf, $report_title); - $pdf->ezSetCmMargins(2,2,2,2); - $pdf->ezText ("$report_title ", 18); - $pdf->ezText ("Generated at $date_today", 8); - $pdf->ezText ("\n".$report_description, 10); - $pdf->ezText ("\n\n", 8); - - $sql = "SELECT * FROM treport_content WHERE id_report = $id_report ORDER by type, id_agent_module DESC"; - $res=mysql_query($sql); - while ($row = mysql_fetch_array($res)){ - $type = $row["type"]; - $sla_max = $row["sla_max"]; - $sla_min = $row["sla_min"]; - $sla_limit = $row["sla_limit"]; - $id_agent_module = $row["id_agent_module"]; - $period = $row["period"]; - $id_gs = $row["id_gs"]; - unset ($modules); - unset ($weights); - // Agent name for type 3 (event ) - - if ($type != 3) { - $module_name = utf8_decode(get_db_sql ("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ". $id_agent_module)); - $agent_name = dame_nombre_agente_agentemodulo ($id_agent_module); - } else { - $agent_name = utf8_decode(get_db_sql ("SELECT nombre FROM tagente WHERE id_agente =$id_agent_module")); - $module_name = ""; - } - - switch($type){ - case 2: // SLA - $sla_result = format_numeric(return_module_SLA ($id_agent_module, $period, $sla_min, $sla_max), 2); - doTitle($pdf, lang_string("SLA").": $agent_name - $module_name"); - //if ($sla_result < $sla_limit) - $pdf->setColor(0.9,0,0,0); // Red ink - $pdf->ezText ("".$sla_result . " %", 18); - $pdf->setColor(0,0,0,1); // Black again - $pdf->ezText ($lang_label["sla_max"]. " : ".$sla_max,8); - $pdf->ezText ($lang_label["sla_min"]. " : ".$sla_min,8); - $pdf->ezText ($lang_label["sla_limit"]. " : ".$sla_limit,8); - $pdf->ezText ("\n",8); - break; - - case 0: // Simple graph - doTitle($pdf, lang_string("Module graph").": $agent_name - $module_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $image = $config["homeurl"]."/reporting/fgraph.php?PHPSESSID=".$session_id."&tipo=sparse&id=$id_agent_module&height=180&width=780&period=$period&avg_only=1&pure=1"; - //ezImage(image,[padding],[width],[resize],[justification],[array border]) - $pdf->ezImage($image,0,470,'none','left'); - $pdf->ezText ("\n",8); - break; - - case 1: // Custom/Combined graph - $graph = get_db_row ("tgraph", "id_graph", $id_gs); - $graph_name = $graph["name"]; - $stacked = $graph["stacked"]; - $sql2="SELECT * FROM tgraph_source WHERE id_graph = $id_gs"; - $res2=mysql_query($sql2); - while ( $row2 = mysql_fetch_array($res2)){ - $weight = $row2["weight"]; - $id_agent_module = $row2["id_agent_module"]; - if (!isset($modules)){ - $modules = $id_agent_module; - $weights = $weight; - } else { - $modules = $modules.",".$id_agent_module; - $weights = $weights.",".$weight; - } - } - doTitle($pdf, lang_string("Custom graph").": $graph_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $image = $config["homeurl"]."/reporting/fgraph.php?tipo=combined&id=$modules&weight_l=$weights&height=230&width=720&stacked=$stacked&period=$period&pure=1"; - $pdf->ezImage($image,0,470,'none','left'); - $pdf->ezText ("\n",8); - break; - case 6: // AVG value - $avg_value = format_for_graph(return_moduledata_avg_value ($id_agent_module, $period),2); - doTitle($pdf, lang_string("avg_value").": $agent_name - $module_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $pdf->ezText ("".$avg_value . "", 18); - $pdf->ezText ("\n",8); - break; - - case 7: // MAX value - $max_value = format_for_graph(return_moduledata_max_value ($id_agent_module, $period),2); - doTitle($pdf, lang_string("max_value").": $agent_name - $module_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $pdf->ezText ("".$max_value . "", 18); - $pdf->ezText ("\n",8); - break; - case 8: // MIN value - $min_value = format_for_graph(return_moduledata_min_value ($id_agent_module, $period),2); - doTitle($pdf, lang_string("min_value").": $agent_name - $module_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $pdf->ezText ("".$min_value . "", 18); - $pdf->ezText ("\n",8); - break; - case 5: // Monitor report - $monitor_value = $sla_result = format_numeric(return_module_SLA ($id_agent_module, $period, 1, 1), 2); - doTitle($pdf, lang_string("monitor_report").": $agent_name - $module_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $pdf->setColor(0,0.9,0,0); // Red ink - $pdf->ezText ("UP: ".$monitor_value . " %", 18); - $pdf->setColor(0.9,0,0,1); // Black again - $monitor_value2 = format_numeric(100 - $monitor_value,2) ; - $pdf->ezText ("DOWN: ".$monitor_value2 . " %", 18); - $pdf->setColor(0,0,0,1); // Black again - $pdf->ezText ("\n",8); - break; - case 3: // Event report - doTitle($pdf, lang_string("event_report")." - $agent_name"); - $pdf->ezText (human_time_description($period)."\n",8); - $table_data = array (); - $table_label[0] = lang_string ("status"); - $table_label[1] = lang_string ("event"); - $table_label[2] = lang_string ("user"); - $table_label[3] = lang_string ("timestamp"); - $table_data = event_reporting_pdf ($id_agent_module, $period); - $pdf->ezTable( $table_data, $table_label, "", - array('width'=>450, 'fontSize'=>9, 'rowGap'=>2, - 'outerLineThickness'=>0.8, 'innerLineThickness'=>0.2, 'shaded'=>1) - ); - $pdf->ezText ("\n",8); - break; - case 4: // Alert report - $module_name = get_db_value ("nombre", "tagente_modulo", "id_agente_modulo", $id_agent_module); - $agent_name = dame_nombre_agente_agentemodulo ($id_agent_module); - $table_data = array(); - $table_label[0] = $lang_label["status"]; - $table_label[1] = $lang_label["description"]; - $table_label[2] = $lang_label["time_threshold"]; - $table_label[3] = $lang_label["last_fired"]; - $table_label[4] = $lang_label["times_fired"]; - - doTitle($pdf, lang_string("alert_report").": $agent_name - $module_name"); - $table_data = alert_reporting_pdf ($id_agent_module); - $pdf->ezTable( $table_data, $table_label, "", - array('width'=>450, 'fontSize'=>9, 'rowGap'=>2, - 'outerLineThickness'=>0.8, 'innerLineThickness'=>0.2, 'shaded'=>1) - ); - $pdf->ezText ("\n",8); - break; - } // switch - } // while row - - - - // End report - doPageNumbering($pdf); - $pdf->ezStream (); + // Start PDF + $pdf = new Cezpdf (); + $pdf->selectFont ($config["homedir"].'/include/pdf/fonts/Times-Roman.afm', array('encoding'=>'utf-8')); + doPageHeader ($pdf, $report_title); + $pdf->ezSetCmMargins (2, 2, 2, 2); + $pdf->ezText ("$report_title ", 18); + $pdf->ezText ("Generated at $date_today", 8); + $pdf->ezText ("\n".$report_description, 10); + $pdf->ezText ("\n\n", 8); + $table_options = array ('width' => 450, + 'fontSize' => 9, + 'rowGap' => 2, + 'outerLineThickness' => 0.8, + 'innerLineThickness' => 0.2, + 'shaded' => 1); + $group_name = dame_grupo ($report['id_group']); + + $agents = get_agents_in_group ($report['id_group']); + + $sql = sprintf ('SELECT * FROM treport_content WHERE id_report = %d ORDER BY `order`', $report['id_report']); + $contents = get_db_all_rows_sql ($sql); + foreach ($contents as $content) { + $module_name = utf8_decode (get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); + $agent_name = utf8_decode (dame_nombre_agente_agentemodulo ($content['id_agent_module'])); + $period = human_time_description ($content['period']); + + switch ($content["type"]) { + case 1: + case 'simple_graph': + doTitle ($pdf, lang_string ("Module graph").': '.$agent_name. + ' - '.$module_name.' - '.$period); + $image = 'http://'.$_SERVER['HTTP_HOST'].$config["homeurl"]. + '/reporting/fgraph.php?PHPSESSID='.$session_id. + '&tipo=sparse&id='.$content["id_agent_module"]. + '&height=180&width=780&period='.$content['period']. + '&avg_only=1&pure=1'; + //ezImage(image,[padding],[width],[resize],[justification],[array border] + $pdf->ezImage ($image,0,470,'none','left'); + + break; + case 2: + case 'custom_graph': + $graph = get_db_row ("tgraph", "id_graph", $content["id_gs"]); + $modules = array (); + $weights = array (); + $sql = sprintf ('SELECT * FROM tgraph_source + WHERE id_graph = %d', + $content["id_gs"]); + $result = mysql_query ($sql); + while ($content2 = mysql_fetch_array($result)) { + array_push ($modules, $content2['id_agent_module']); + array_push ($weights, $content2["weight"]); + } + doTitle ($pdf, lang_string ("Custom graph").': '.$graph["name"]. + ' - '.$period); + $image = 'http://'.$_SERVER['HTTP_HOST'].$config["homeurl"]. + '/reporting/fgraph.php?PHPSESSID='.$session_id.'&tipo=combined&id='. + implode (',', $modules).'&weight_l='.implode (',', $weights). + '&height=230&width=720&period='.$content['period'].'&stacked='. + $graph["stacked"].'&pure=1'; + $pdf->ezImage ($image, 0, 470, 'none', 'left'); + + break; + case 3: + case 'SLA': + doTitle ($pdf, lang_string ('SLA').': '.$period); + + $slas = get_db_all_rows_field_filter ('treport_content_sla_combined', + 'id_report_content', $content['id_rc']); + if (sizeof ($slas) == 0) { + $pdf->ezText ("".lang_string ('no_defined_slas') . " %", 18); + } + $table->data = array (); + $table->head = array (lang_string ('Info'), + lang_string ('sla_result')); + foreach ($slas as $sla) { + $data = array (); + + $data[0] = lang_string ('agent')." : ".dame_nombre_agente_agentemodulo ($sla['id_agent_module'])."\n"; + $data[0] .= lang_string ('module')." : ".dame_nombre_modulo_agentemodulo ($sla['id_agent_module'])."\n"; + $data[0] .= lang_string ('sla_max')." : ".$sla['sla_max']."\n"; + $data[0] .= lang_string ('sla_min')." : ".$sla['sla_min']; + + $sla_value = get_agent_module_sla ($sla['id_agent_module'], $content['period'], + $sla['sla_min'], $sla['sla_max']); + if ($sla_value === false) { + $data[1] = lang_string ('unknown'); + } else { + if ($sla_value < $sla['sla_limit']) + $pdf->setColor (0, 1, 0, 0); // Red + $data[1] = format_numeric ($sla_value). " %"; + $pdf->setColor (0, 0, 0, 1); // Black + } + array_push ($table->data, $data); + } + $pdf->ezTable ($table->data, $table->head, "", $table_options); + unset ($slas); + + break; + case 4: + case 'event_report': + doTitle ($pdf, lang_string ("event_report").' - '.$period); + $table_events = event_reporting ($report['id_group'], $content['period'], 0, true); + $pdf->ezTable ($table_events->data, $table_events->head, + "", $table_options); + + break; + case 5: + case 'alert_report': + $alerts = get_alerts_in_group ($report['id_group']); + $alerts_fired = get_alerts_fired ($alerts, $content['period']); + + doTitle ($pdf, lang_string ("alert_report").': '.$group_name. + ' - '.$period); + $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); + $not_fired_percentage = 100 - $fired_percentage; + $image = 'http://'.$_SERVER['HTTP_HOST'].$config["homeurl"]. + '/reporting/fgraph.php?PHPSESSID='.$session_id. + '&tipo=alerts_fired_pipe&height=150&width=280&fired='. + $fired_percentage.'¬_fired='.$not_fired_percentage; + $pdf->ezImage ($image, 0, 150, 'none', 'left'); + $pdf->ezText (''.lang_string ('fired_alerts').': '.sizeof ($alerts_fired).'', 8); + $pdf->ezText (''.lang_string ('total_alerts_monitored').': '.sizeof ($alerts).'', 8); + $pdf->ezText ("\n", 8); + + $table_alerts = get_fired_alerts_reporting_table ($alerts_fired, true); + $pdf->ezTable ($table_alerts->data, $table_alerts->head, + "", $table_options); + unset ($alerts); + unset ($alerts_fired); + + break; + case 6: + case 'monitor_report': + $value = get_agent_module_sla ($content["id_agent_module"], $content['period'], 1, 1); + doTitle ($pdf, lang_string ("monitor_report").': '.$agent_name.' - '.$module_name. + ' - '.$period); + $pdf->setColor (0, 0.9, 0, 0); // Red + $pdf->ezText (''.lang_string ('up').': '.format_for_graph ($value, 2) . " %", 18); + $pdf->setColor (0.9, 0, 0, 1); // Grey + $pdf->ezText (''.lang_string ('down').': '.format_numeric (100 - $value, 2) . " %", 18); + $pdf->setColor (0, 0, 0, 1); // Black + + break; + case 7: + case 'avg_value': + $value = get_agent_module_value_average ($content["id_agent_module"], $content['period']); + doTitle ($pdf, lang_string("avg_value").': '.$agent_name.' - '. + $module_name.' - '.$period); + $pdf->ezText ("".format_for_graph ($value, 2)."", 18); + + break; + case 8: + case 'max_value': + $value = get_agent_module_value_max ($content["id_agent_module"], $content['period']); + doTitle ($pdf, lang_string ("max_value").': '.$agent_name. + ' - '.$module_name.' - '.$period); + $pdf->ezText ("".format_for_graph ($value, 2)."", 18); + + break; + case 9: + case 'min_value': + $value = get_agent_module_value_min ($content["id_agent_module"], $content['period']); + doTitle ($pdf, lang_string ("min_value").': '.$agent_name. + ' - '.$module_name.' - '.$period); + $pdf->ezText ("".format_for_graph ($value, 2)."", 18); + + break; + case 10: + case 'sumatory': + $value = get_agent_module_value_sumatory ($content["id_agent_module"], $content['period']); + doTitle ($pdf, lang_string ("sumatory").': '.$agent_name. + ' - '.$module_name.' - '.$period); + $pdf->ezText ("".format_for_graph ($value, 2)."", 18); + + break; + case 11: + case 'general_group_report': + doTitle ($pdf, lang_string ("group").': '.$group_name); + $pdf->ezText ("".lang_string ('agents_in_group').': '.sizeof ($agents)."", 12); + + break; + case 12: + case 'monitor_health': + $monitors = get_monitors_in_group ($report['id_group']); + $monitors_down = get_monitors_down ($monitors, $content['period']); + + doTitle ($pdf, lang_string ("monitor_health").': '. + $group_name. ' - '.$period); + $down_percentage = round (sizeof ($monitors_down) / sizeof ($monitors) * 100, 2); + $not_down_percentage = 100 - $down_percentage; + $image = 'http://'.$_SERVER['HTTP_HOST'].$config["homeurl"]. + '/reporting/fgraph.php?PHPSESSID='.$session_id. + '&tipo=monitors_health_pipe&height=150&width=280&down='. + $down_percentage.'¬_down='.$not_down_percentage; + $pdf->ezImage ($image, 0, 150, 'none', 'left'); + $pdf->ezText ("\n", 4); + $pdf->ezText (''.lang_string ('total_monitors').': '.sizeof ($monitors).'', 8); + $pdf->ezText (''.lang_string ('monitors_down_on_period').': '.sizeof ($monitors_down).'', 8); + $pdf->ezText ("\n", 8); + + $table_monitors = get_monitors_down_reporting_table ($monitors_down, true); + $pdf->ezTable ($table_monitors->data, $table_monitors->head, + "", $table_options); + unset ($monitors); + unset ($monitors_down); + + break; + case 13: + case 'agents_detailed': + doTitle ($pdf, lang_string ("agents_detailed").': '. + $group_name.' '.lang_string ('group')); + foreach ($agents as $agent) { + $pdf->ezText ("".$agent['nombre']."", 18); + $table = get_agent_modules_reporting_table ($agent['id_agente'], $content['period'], 0, true); + $pdf->ezText ("".lang_string ('modules')."", 12); + $pdf->ezText ("\n", 3); + $pdf->ezTable ($table->data, array (lang_string ('name')), "", $table_options); + + $table = get_agent_alerts_reporting_table ($agent['id_agente'], $content['period'], 0, true); + if (sizeof ($table->data)) { + $pdf->ezText ("".lang_string ('alerts')."", 12); + $pdf->ezText ("\n", 3); + $pdf->ezTable ($table->data, $table->head, "", $table_options); + } + + $table = get_agent_monitors_reporting_table ($agent['id_agente'], $content['period'], 0, true); + if (sizeof ($table->data)) { + $pdf->ezText ("".lang_string ('monitors')."", 12); + $pdf->ezText ("\n", 3); + $pdf->ezTable ($table->data, $table->head, "", $table_options); + } + } + + break; + } + $pdf->ezText ("\n", 8); + } + + // End report + doPageNumbering ($pdf); + $pdf->ezStream (); } - -// End code ?> diff --git a/pandora_console/include/languages/language_en.php b/pandora_console/include/languages/language_en.php index a010bdef02..a3a18ff8a5 100644 --- a/pandora_console/include/languages/language_en.php +++ b/pandora_console/include/languages/language_en.php @@ -842,6 +842,7 @@ $lang_label["delete_sla_no"]="There was a problem deleting SLA"; $lang_label["sla_module_is_null"]="Module is not set"; $lang_label["no_defined_slas"]="There are no SLAs defined"; $lang_label["defined_slas"]="SLAs defined"; +$lang_label["sla_result"]="SLA result"; $lang_label["up"]="Up"; $lang_label["down"]="Down"; $lang_label["map_builder"]="Map builder"; @@ -952,6 +953,7 @@ $lang_label["Simple alerts"]="Simple alerts"; $lang_label["Combined alerts"]="Combined alerts"; $lang_label["Oper"]="Oper"; $lang_label["info"]="info"; +$lang_label["Info"]="Info"; $lang_label["Operation"]="Operation"; $lang_label["Source Agent/Alert"]="Source Agent/Alert"; diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 7c0c2d1dbd..4f48f7f55a 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -176,7 +176,7 @@ div#db_ftxt { } div#container { margin: 0 auto; - width: 960px; + width: 95%; text-align: left; border-left: solid 2px #000; border-right: solid 2px #000; @@ -184,25 +184,22 @@ div#container { margin-top: 5px; } div#page { - width: 960px; background: #fff; clear: both; border-bottom: solid 5px #786; border-top: solid 5px #786; + background: #FFF; } div#main { - width: 780px; + width: 80%; min-height: 500px; - float: right; + float: both; padding-left: 0px; padding-top: 0px; padding-bottom: 20px; - margin-bottom: 25px; + margin-left: 180px; background-color: #fefefe; - background-image: url(../../images/backgrounds/background4.jpg); - margin-top: 0px; - margin-left: 0px; - margin-right: 0px; + background-image: url(../../images/backgrounds/background4.jpg); } div#menu { @@ -226,7 +223,6 @@ div#foot { padding-bottom: 5px; text-align: center; background: #000; - width: 960px; clear: both; } #ver { diff --git a/pandora_console/index.php b/pandora_console/index.php index 6137c8774c..820d66a247 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -54,45 +54,54 @@ if ($develop_bypass != 1){ } if ((! file_exists("include/config.php")) OR (! is_readable("include/config.php"))){ - include ("general/error_noconfig.php"); - exit; + include ("general/error_noconfig.php"); + exit; } // Real start session_start(); -include "include/config.php"; -include "include/languages/language_".$config["language"].".php"; -require "include/functions.php"; // Including funcions. -require "include/functions_db.php"; +include_once ("include/config.php"); +include_once ("include/languages/language_".$config["language"].".php"); +require_once ("include/functions.php"); +require_once ("include/functions_db.php"); ?> 0){ - // Agent selection filters and refresh - $query = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': '') . '://' . $_SERVER['SERVER_NAME']; +// Auto Refresh page +$intervalo = get_parameter ("refr",0); +if ($intervalo > 0){ + // Agent selection filters and refresh + $query = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': '') . '://' . $_SERVER['SERVER_NAME']; + if ($_SERVER['SERVER_PORT'] != 80) + $query .= ":" . $_SERVER['SERVER_PORT']; + + $query .= $_SERVER['SCRIPT_NAME']; + if (isset ($_REQUEST["refr"])) { + $query .= '?'; + + foreach ($_POST as $key => $value) { + $query .= '&'.$key.'='.$value; + } + foreach ($_GET as $key => $value) { + $query .= '&'.$key.'='.$value; + } + } + if (isset ($_POST["ag_group"])) { + $ag_group = $_POST["ag_group"]; + $query = 'http://' . $_SERVER['SERVER_NAME']; if ($_SERVER['SERVER_PORT'] != 80) $query .= ":" . $_SERVER['SERVER_PORT']; - - $query .= $_SERVER['REQUEST_URI']; - if (isset ($_POST["refr"])) - $query .= '&refr=' . $intervalo; - if (isset ($_POST["ag_group"])) { - $ag_group = $_POST["ag_group"]; - $query = 'http://' . $_SERVER['SERVER_NAME']; - if ($_SERVER['SERVER_PORT'] != 80) - $query .= ":" . $_SERVER['SERVER_PORT']; - $query .= $_SERVER['REQUEST_URI'] . '&ag_group_refresh=' . $ag_group; - } else - echo ''; + $query .= $_SERVER['REQUEST_URI'] . '&ag_group_refresh=' . $ag_group; + } else { + echo ''; } +} ?> Pandora FMS - <?php echo lang_string("header_title"); ?> @@ -105,10 +114,7 @@ require "include/functions_db.php"; -'; -?> + @@ -117,11 +123,10 @@ require "include/functions_db.php"; '; + echo ''; else -echo ''; - -$REMOTE_ADDR = getenv ("REMOTE_ADDR"); + echo ''; +$REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; // Login process if ( (! isset ($_SESSION['id_usuario'])) && (isset ($_GET["login"]))) { @@ -201,9 +206,10 @@ if (isset ($_GET["sec"])){ $sec = get_parameter_get ('sec'); $sec = parameter_extra_clean ($sec); $pagina = $sec2; -} -else +} else { $sec = ""; +} + // http://es2.php.net/manual/en/ref.session.php#64525 // Session locking concurrency speedup! session_write_close(); @@ -212,12 +218,12 @@ session_write_close(); if ($config["pure"] == 0){ echo '
'; echo ''; echo '
'; - echo ' '; } else { echo '
'; } @@ -229,8 +235,8 @@ if ($config["pure"] == 0){ // Page loader / selector if ($pagina != ""){ - if (file_exists ($pagina . ".php")) { - require ($pagina . ".php"); + if (file_exists ($pagina.".php")) { + require ($pagina.".php"); } else { echo "
".lang_string("Sorry! I can't find the page!").""; } @@ -247,7 +253,7 @@ if ($config["pure"] == 0){ if ($config["pure"] == 0) { echo ''; echo '
'; } diff --git a/pandora_console/operation/agentes/networkmap.php b/pandora_console/operation/agentes/networkmap.php index 9d8e07fc44..f234399111 100644 --- a/pandora_console/operation/agentes/networkmap.php +++ b/pandora_console/operation/agentes/networkmap.php @@ -17,10 +17,6 @@ require("include/config.php"); $pandora_name = 'Pandora FMS'; -/////////////////////////////////////////////////////////////////////////////// -// DOT related functions -/////////////////////////////////////////////////////////////////////////////// - // Generate a dot graph definition for graphviz function generate_dot ($simple = 0) { global $config; @@ -167,8 +163,8 @@ function open_graph () { if ($pure == 1 && $zoom > 1 && $zoom <= 3) { - $size_x *= $zoom; - $size_y *= $zoom; + $size_x *= $zoom; + $size_y *= $zoom; } $size = $size_x . ',' . $size_y; diff --git a/pandora_console/operation/agentes/sla_view.php b/pandora_console/operation/agentes/sla_view.php index bda9f12268..92fc6dc83a 100644 --- a/pandora_console/operation/agentes/sla_view.php +++ b/pandora_console/operation/agentes/sla_view.php @@ -99,7 +99,7 @@ require ("include/functions_reporting.php"); echo "".$est_modulo.""; echo ""; - $temp = return_module_SLA ($row_t["id_agente_modulo"], $config["sla_period"], 1, 2147483647); + $temp = get_agent_module_sla ($row_t["id_agente_modulo"], $config["sla_period"], 1, 2147483647); if ($temp === false) echo lang_string("N/A"); else { @@ -182,7 +182,7 @@ require ("include/functions_reporting.php"); echo " ($sla_min/$sla_max/$sla_limit) "; echo ""; - $temp = return_module_SLA ($row_t["id_agente_modulo"], $config["sla_period"], $sla_min, $sla_max); + $temp = get_agent_module_sla ($row_t["id_agente_modulo"], $config["sla_period"], $sla_min, $sla_max); if ($temp === false){ echo lang_string("N/A"); echo ""; diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index e33bcb2aca..0d3b8986d8 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -33,7 +33,7 @@ if (! isset($_SESSION["id_usuario"])) { '; } else { @@ -187,7 +187,7 @@ if (give_acl($_SESSION["id_usuario"], 0, "AR")==1) { echo '
'; // User edit (submenu) - if (isset($_GET["sec"]) && $_GET["sec"] == "usuarios"){ + if (isset($_GET["sec"]) && $_GET["sec"] == "usuarios") { if(isset($_GET["ver"]) && $_GET["ver"] == $_SESSION["id_usuario"]) { echo "
"; } else { @@ -195,15 +195,15 @@ if (give_acl($_SESSION["id_usuario"], 0, "AR")==1) { } echo "
"; - // User statistics require UM - if (give_acl($_SESSION["id_usuario"], 0, "UM")==1) { - if(isset($_GET["sec2"]) && $_GET["sec2"] == "operation/users/user_statistics") { - echo "
"; - } else { - echo ""; - } + // User statistics require UM + if (give_acl($_SESSION["id_usuario"], 0, "UM")==1) { + if(isset($_GET["sec2"]) && $_GET["sec2"] == "operation/users/user_statistics") { + echo "
"; + } else { + echo ""; + } } // SNMP console diff --git a/pandora_console/operation/reporting/custom_reporting.php b/pandora_console/operation/reporting/custom_reporting.php index ac7241fa4c..8d8d655e80 100644 --- a/pandora_console/operation/reporting/custom_reporting.php +++ b/pandora_console/operation/reporting/custom_reporting.php @@ -57,8 +57,8 @@ foreach ($reports as $report) { $data[1] = $report['description']; $data[2] = ' '; - $data[3] = ''; + $data[3] = ''; array_push ($table->data, $data); } diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 83b7eab3b8..98f5ad8359 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -57,7 +57,7 @@ echo "

".lang_string ('reporting')." > "; echo lang_string ('custom_reporting')." - "; echo $report['name']."

"; -$table->width = '750px'; +$table->width = '99%'; $table->class = 'databox'; $table->style = array (); $table->style[0] = 'font-weight: bold'; @@ -115,15 +115,19 @@ if ($datetime > time ()) { $table->size = array (); $table->style = array (); -$table->width = '750px'; +$table->width = '99%'; $table->class = 'databox report_table'; -$table->rowclasses = array (); +$table->rowclass = array (); +$table->rowclass[0] = 'datos3'; $group_name = dame_grupo ($report['id_group']); $sql = sprintf ('SELECT * FROM treport_content WHERE id_report = %d ORDER BY `order`', $id_report); $contents = get_db_all_rows_sql ($sql); foreach ($contents as $content) { $table->data = array (); + $table->head = array (); + $table->style = array (); + $table->colspan = array (); $module_name = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); $agent_name = dame_nombre_agente_agentemodulo ($content['id_agent_module']); @@ -131,16 +135,13 @@ foreach ($contents as $content) { switch ($content["type"]) { case 1: case 'simple_graph': - $table->colspan[1][0] = 3; + $table->colspan[1][0] = 4; $data = array (); $data[0] = '

'.lang_string ('simple_graph').'

'; $data[1] = '

'.$agent_name.' - '.$module_name.'

'; $data[2] = '

'.human_time_description($content['period']).'

'; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); - // $n is the number of elements in the array, so it will be the index of the next element - $table->colspan[$n][0] = 3; $data = array (); $data[0] = ''; array_push ($table->data, $data); @@ -148,63 +149,59 @@ foreach ($contents as $content) { break; case 2: case 'custom_graph': - $graph = get_db_row ("tgraph", "id_graph", $content['id_gs']); - $sql2 = sprintf ('SELECT * FROM tgraph_source WHERE id_graph = %d', $content['id_gs']); - $res2 = mysql_query($sql2); - while ($content2 = mysql_fetch_array($res2)) { - $weight = $content2["weight"]; - $content['id_agent_module'] = $content2["id_agent_module"]; - if (!isset ($modules)) { - $modules = $content['id_agent_module']; - $weights = $weight; - } else { - $modules = $modules.",".$content['id_agent_module']; - $weights = $weights.",".$weight; - } - } - unset ($modules); - unset ($weights); $data = array (); $data[0] = '

'.lang_string ('custom_graph').'

'; $data[1] = "

".$graph["name"]."

"; - $data[2] = "

".human_time_description($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + $data[2] = "

".human_time_description ($content['period'])."

"; + array_push ($table->data, $data); - $table->colspan[$n][0] = 3; + $graph = get_db_row ("tgraph", "id_graph", $content['id_gs']); + $sql2 = sprintf ('SELECT * FROM tgraph_source WHERE id_graph = %d', $content['id_gs']); + $res2 = mysql_query($sql2); + $modules = array (); + $weights = array (); + while ($content2 = mysql_fetch_array($res2)) { + array_push ($modules, $content2['id_agent_module']); + array_push ($weights, $content2["weight"]); + } + + $table->colspan[1][0] = 4; $data = array (); - $data[0] = ''; + $data[0] = ''; array_push ($table->data, $data); break; case 3: case 'SLA': + $table->colspan[0][0] = 2; + $table->style[1] = 'text-align: right'; $data = array (); $data[0] = '

'.lang_string ('SLA').'

'; - $data[1] = '

'.$group_name.'

'; - $data[2] = '

'.human_time_description ($content['period']).'

'; + $data[1] = '

'.human_time_description ($content['period']).'

';; $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; $slas = get_db_all_rows_field_filter ('treport_content_sla_combined', 'id_report_content', $content['id_rc']); if (sizeof ($slas) == 0) { $data = array (); - $table->colspan[$n][0] = 3; + $table->colspan[1][0] = 3; $data[0] = lang_string ('no_defined_slas'); array_push ($table->data, $data); } + + $sla_failed = false; foreach ($slas as $sla) { $data = array (); $table->colspan[$n][0] = 2; $data[0] = ''; - $data[0] .= lang_string ('sla_max')." : ".$sla['sla_max']."
"; - $data[0] .= lang_string ('sla_min')." : ".$sla['sla_min']."
"; - $data[0] .= lang_string ('sla_limit')." : ".$sla['sla_limit']."
"; + $data[0] .= lang_string ('agent')." : ".dame_nombre_agente_agentemodulo ($sla['id_agent_module'])."
"; + $data[0] .= lang_string ('module')." : ".dame_nombre_modulo_agentemodulo ($sla['id_agent_module'])."
"; + $data[0] .= lang_string ('sla_max')." : ".$sla['sla_max']."
"; + $data[0] .= lang_string ('sla_min')." : ".$sla['sla_min']."
"; $data[0] .= "
"; - $sla_value = return_module_SLA ($sla['id_agent_module'], $content['period'], + $sla_value = get_agent_module_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime); if ($sla_value === false) { $data[1] = ''; @@ -212,29 +209,43 @@ foreach ($contents as $content) { } else { if ($sla_value >= $sla['sla_limit']) $data[1] = ''; - else + else { + $sla_failed = true; $data[1] = ''; + } $data[1] .= format_numeric ($sla_value). " %"; } $data[1] .= ""; $n = array_push ($table->data, $data); } + if (sizeof ($slas)) { + $data = array (); + if ($sla_failed) + $data[0] = ''.lang_string ('Ok').''; + else + $data[0] = ''.lang_string ('Fail').''; + $n = array_push ($table->data, $data); + $table->colspan[$n - 1][0] = 3; + $table->rowstyle[$n - 1] = 'text-align: right'; + } break; case 4: case 'event_report': + $table->colspan[0][0] = 2; $id_agent = dame_agente_id ($agent_name); $data = array (); $data[0] = "

".lang_string ('event_report')."

"; - $data[1] = "

$agent_name - $module_name

"; - $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + $data[1] = "

".human_time_description ($content['period'])."

"; + array_push ($table->data, $data); - $table->colspan[$n][0] = 3; + $table->colspan[1][0] = 3; $data = array (); - $data[0] = event_reporting ($id_agent, $content['period'], $datetime, true); + $table_report = event_reporting ($report['id_group'], $content['period'], $datetime, true); + $table_report->class = 'databox'; + $table_report->width = '100%'; + $data[0] = print_table ($table_report, true); array_push ($table->data, $data); break; @@ -244,11 +255,10 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('alert_report')."

"; $data[1] = "

$group_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 3; + $table->colspan[1][0] = 3; $data[0] = alert_reporting ($report['id_group'], $content['period'], $datetime, true); array_push ($table->data, $data); @@ -259,11 +269,10 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('monitor_report')."

"; $data[1] = "

$agent_name - $module_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $monitor_value = format_numeric (return_module_SLA ($content['id_agent_module'], $content['period'], 1, 1, $datetime)); + $monitor_value = format_numeric (get_agent_module_sla ($content['id_agent_module'], $content['period'], 1, 1, $datetime)); $data[0] = '

'; $data[0] .= $monitor_value.' %

'; $monitor_value2 = format_numeric (100 - $monitor_value, 2) ; @@ -278,12 +287,11 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('avg_value')."

"; $data[1] = "

$agent_name - $module_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 2; - $value = format_numeric (return_moduledata_avg_value ($content['id_agent_module'], $content['period'], $datetime)); + $table->colspan[1][0] = 2; + $value = format_numeric (get_agent_module_value_average ($content['id_agent_module'], $content['period'], $datetime)); $data[0] = '

'.$value.'

'; array_push ($table->data, $data); @@ -294,12 +302,11 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('max_value')."

"; $data[1] = "

$agent_name - $module_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 2; - $value = format_numeric (return_moduledata_max_value ($content['id_agent_module'], $content['period'], $datetime)); + $table->colspan[1][0] = 2; + $value = format_numeric (get_agent_module_value_max ($content['id_agent_module'], $content['period'], $datetime)); $data[0] = '

'.$value.'

'; array_push ($table->data, $data); @@ -310,12 +317,11 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('min_value')."

"; $data[1] = "

$agent_name - $module_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 2; - $value = format_numeric (return_moduledata_min_value ($content['id_agent_module'], $content['period'], $datetime)); + $table->colspan[1][0] = 2; + $value = format_numeric (get_agent_module_value_min ($content['id_agent_module'], $content['period'], $datetime)); $data[0] = '

'.$value.'

'; array_push ($table->data, $data); @@ -326,12 +332,11 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('sumatory')."

"; $data[1] = "

$agent_name - $module_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 2; - $value = format_numeric (return_moduledata_sum_value ($content['id_agent_module'], $content['period'], $datetime)); + $table->colspan[1][0] = 2; + $value = format_numeric (get_agent_module_value_sumatory ($content['id_agent_module'], $content['period'], $datetime)); $data[0] = '

'.$value.'

'; array_push ($table->data, $data); @@ -341,12 +346,10 @@ foreach ($contents as $content) { $data = array (); $data[0] = "

".lang_string ('group')."

"; $data[1] = "

$group_name

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 2; - $value = format_numeric (return_moduledata_sum_value ($content['id_agent_module'], $content['period'], $datetime)); + $table->colspan[1][0] = 2; $data[0] = general_group_reporting ($report['id_group'], true); array_push ($table->data, $data); @@ -357,11 +360,10 @@ foreach ($contents as $content) { $data[0] = "

".lang_string ('monitor_health')."

"; $data[1] = "

$group_name

"; $data[2] = "

".human_time_description ($content['period'])."

"; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); $data = array (); - $table->colspan[$n][0] = 3; + $table->colspan[1][0] = 4; $data[0] = monitor_health_reporting ($report['id_group'], $content['period'], $datetime, true); array_push ($table->data, $data); @@ -371,13 +373,12 @@ foreach ($contents as $content) { $data = array (); $data[0] = "

".lang_string ('agents_detailed')."

"; $data[1] = "

$group_name

"; - $data[2] = ""; - $n = array_push ($table->data, $data); - $table->rowclass[$n - 1] = 'datos3'; + array_push ($table->data, $data); + $table->colspan[0][0] = 2; $data = array (); - $table->colspan[$n][0] = 3; - $data[0] = agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true); + $table->colspan[1][0] = 3; + $data[0] = get_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true); array_push ($table->data, $data); break; diff --git a/pandora_console/operation/reporting/reporting_viewer_pdf.php b/pandora_console/operation/reporting/reporting_viewer_pdf.php index 3c9a09aa54..0badab6b95 100644 --- a/pandora_console/operation/reporting/reporting_viewer_pdf.php +++ b/pandora_console/operation/reporting/reporting_viewer_pdf.php @@ -24,9 +24,9 @@ require_once ("../../include/functions_db.php"); require_once ("../../include/languages/language_".$config["language"].".php"); require_once ("../../include/functions_reporting_pdf.php"); -if (!isset ($_SESSION["id_usuario"])) { - session_start(); - session_write_close(); +if (! isset ($_SESSION["id_usuario"])) { + session_start (); + session_write_close (); } // Session check @@ -34,44 +34,38 @@ check_login (); // Login check global $REMOTE_ADDR; +$config['id_user'] = $_SESSION["id_usuario"]; if (comprueba_login ()) { - audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access graph builder"); + audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation", "Trying to access graph builder"); include ("general/noaccess.php"); exit; } -if (! give_acl ($id_user, 0, "AR") && ! dame_admin ($id_user)) { - audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access graph builder"); +if (! give_acl ($config["id_user"], 0, "AR") && ! dame_admin ($config["id_user"])) { + audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation", "Trying to access graph builder"); include ("general/noaccess.php"); exit; } -$id_report = (int) get_parameter ('id'); +$id_report = (int) get_parameter ('id_report'); if (! $id_report) { - audit_db ($id_user, $REMOTE_ADDR, "HACK Attempt", "Trying to access graph viewer withoud ID"); + audit_db ($config["id_user"], $REMOTE_ADDR, "HACK Attempt", "Trying to access graph viewer withoud ID"); include ("general/noaccess.php"); exit; } -$report_private= get_db_value ("private", "treport", "id_report", $id_report); -$report_user = get_db_value ("id_user", "treport", "id_report", $id_report); +$report = get_db_row ("treport", "id_report", $id_report); -if ($report_user == $id_user || dame_admin ($id_user) || ! $report_private) { - $report_type = get_parameter ("rtype"); - // Without report type parameter: ABORT - if (! $report_type) { - echo "

No access without report type

"; - audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access report without specify reportype"); - exit; - } - - // Available PDF reports: - switch ($report_type) { - case "general": - general_report ($id_report); - break; - } +if ($report['id_user'] != $config["id_user"] && ! give_acl ($config["id_user"], $report['id_group'], 'AR')) { + echo "

No access without report type

"; + audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation", "Trying to access unauthorized report"); + exit; } +include ('../../include/pdf/class.ezpdf.php'); +require ('../../include/functions_reporting.php'); + +get_pdf_report ($report); + ?> diff --git a/pandora_console/reporting/fgraph.php b/pandora_console/reporting/fgraph.php index 3dfbb373f1..a98461b045 100644 --- a/pandora_console/reporting/fgraph.php +++ b/pandora_console/reporting/fgraph.php @@ -16,10 +16,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -include ('../include/config.php'); -include ($config["homedir"].'/include/functions.php'); -include ($config["homedir"].'/include/functions_db.php'); -require ($config["homedir"].'/include/languages/language_'.$config['language'].'.php'); +require_once ('../include/config.php'); +require_once ($config["homedir"].'/include/functions.php'); +require_once ($config["homedir"].'/include/functions_db.php'); +require_once ('Image/Graph.php'); global $config; @@ -27,7 +27,7 @@ if (!isset($_SESSION["id_user"])){ session_start(); session_write_close(); } -$config ["id_user"] = $_SESSION["id_usuario"]; +$config["id_user"] = $_SESSION["id_usuario"]; // Session check check_login (); @@ -92,8 +92,8 @@ function dame_fecha_grafico_timestamp ($timestamp) { function graphic_combined_module ($module_list, $weight_list, $periodo, $width, $height, $title, $unit_name, $show_event = 0, $show_alert = 0, $pure = 0, $stacked = 0, $date = 0) { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); + global $config; + require_once 'Image/Graph.php'; $resolution = $config['graph_res'] * 50; // Number of "slices" we want in graph @@ -375,7 +375,6 @@ function graphic_combined_module ($module_list, $weight_list, $periodo, $width, function grafico_modulo_sparse ($id_agente_modulo, $periodo, $show_event, $width, $height , $title, $unit_name, $show_alert, $avg_only = 0, $pure = 0, $date = 0) { include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); require_once 'Image/Graph.php'; if (! $date) @@ -661,9 +660,8 @@ function grafico_modulo_sparse ($id_agente_modulo, $periodo, $show_event, } function generic_pie_graph ($width = 300, $height = 200, $data, $legend) { - require ("../include/config.php"); - require_once 'Image/Graph.php'; - require ("../include/languages/language_".$config['language'].".php"); + global $config; + if (sizeof($data) == 0) { graphic_error (); return; @@ -723,9 +721,7 @@ function generic_pie_graph ($width = 300, $height = 200, $data, $legend) { function graphic_agentmodules($id_agent, $width, $height) { - include ("../include/config.php"); - require_once 'Image/Graph.php'; - require ("../include/languages/language_".$config['language'].".php"); + global $config; $sql1="SELECT * FROM ttipo_modulo"; $result=mysql_query($sql1); @@ -771,9 +767,8 @@ function graphic_agentmodules($id_agent, $width, $height) { } function graphic_agentaccess ($id_agent, $periodo, $width, $height) { - include ("../include/config.php"); - require_once 'Image/Graph.php'; - require ("../include/languages/language_".$config['language'].".php"); + global $config; + $color ="#437722"; // Green pandora 1.1 octopus color /* $agent_interval = give_agentinterval($id_agent); @@ -865,9 +860,8 @@ function graphic_agentaccess ($id_agent, $periodo, $width, $height) { } function graphic_string_data ($id_agent_module, $periodo, $width, $height, $pure = 0, $date = "") { - include ("../include/config.php"); - require_once 'Image/Graph.php'; - require ("../include/languages/language_".$config['language'].".php"); + global $config; + // $color = $config["color_graph1"]; //#437722"; // Green pandora 1.1 octopus color $color = "#437722"; @@ -907,44 +901,44 @@ function graphic_string_data ($id_agent_module, $periodo, $width, $height, $pure $valor_maximo = $valores[$i][0]; } - if ($valor_maximo <= 0) { + if ($valor_maximo <= 0) { graphic_error (); return; } - $nombre_agente = dame_nombre_agente_agentemodulo ($id_agent_module); + $nombre_agente = dame_nombre_agente_agentemodulo ($id_agent_module); $id_agente = dame_agente_id ($nombre_agente); $nombre_modulo = dame_nombre_modulo_agentemodulo ($id_agent_module); -if ($pure == 0){ - $Graph =& Image_Graph::factory('graph', array($width, $height)); - // add a TrueType font - $Font =& $Graph->addNew('font', $config['fontpath']); - $Font->setSize(7); - $Graph->setFont($Font); + if ($pure == 0) { + $Graph =& Image_Graph::factory('graph', array($width, $height)); + // add a TrueType font + $Font =& $Graph->addNew('font', $config['fontpath']); + $Font->setSize(7); + $Graph->setFont($Font); - $Graph->add( - Image_Graph::vertical( + $Graph->add( Image_Graph::vertical( - $Title = Image_Graph::factory('title', array(' Pandora FMS Graph - '.strtoupper($nombre_agente)." - ".give_human_time ($periodo), 10)), - $Subtitle = Image_Graph::factory('title', array(' '.lang_string("Data occurrence for module ").$nombre_modulo, 7)), - 90 - ), - Image_Graph::horizontal( - $Plotarea = Image_Graph::factory('plotarea'), - $Legend = Image_Graph::factory('legend'), - 100 - ), - 15) - ); - $Legend->setPlotarea($Plotarea); - $Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT); - $Subtitle->setAlignment(IMAGE_GRAPH_ALIGN_LEFT); + Image_Graph::vertical( + $Title = Image_Graph::factory('title', array(' Pandora FMS Graph - '.strtoupper($nombre_agente)." - ".give_human_time ($periodo), 10)), + $Subtitle = Image_Graph::factory('title', array(' '.lang_string("Data occurrence for module ").$nombre_modulo, 7)), + 90 + ), + Image_Graph::horizontal( + $Plotarea = Image_Graph::factory('plotarea'), + $Legend = Image_Graph::factory('legend'), + 100 + ), + 15) + ); + $Legend->setPlotarea($Plotarea); + $Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT); + $Subtitle->setAlignment(IMAGE_GRAPH_ALIGN_LEFT); -} else { // Pure, without title and legends - $Graph->add($Plotarea = Image_Graph::factory('plotarea')); -} + } else { // Pure, without title and legends + $Graph->add($Plotarea = Image_Graph::factory('plotarea')); + } //$Legend->setPlotarea($Plotarea); // Create the dataset @@ -968,9 +962,6 @@ if ($pure == 0){ function grafico_incidente_estados() { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - $data = array(0,0,0,0); // 0 - Abierta / Sin notas // 2 - Descartada @@ -1001,29 +992,18 @@ function grafico_incidente_estados() { } function grafico_incidente_prioridad () { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - - $data = array(0,0,0,0,0,0); + $data = array (0, 0, 0, 0, 0, 0); // 0 - Abierta / Sin notas // 2 - Descartada // 3 - Caducada // 13 - Cerrada - $sql1="SELECT * FROM tincidencia"; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ - if ($row["prioridad"] == 0) - $data[0]=$data[0]+1; - if ($row["prioridad"] == 1) - $data[1]=$data[1]+1; - if ($row["prioridad"] == 2) - $data[2]=$data[2]+1; - if ($row["prioridad"] == 3) - $data[3]=$data[3]+1; - if ($row["prioridad"] == 4) - $data[4]=$data[4]+1; - if ($row["prioridad"] == 10) - $data[5]=$data[5]+1; + $sql = "SELECT * FROM tincidencia"; + $result = mysql_query ($sql); + while ($row = mysql_fetch_array ($result)){ + if ($row["prioridad"] < 10) + $data[$row["prioridad"]] += 1; + else + $data[5] += 1; } $mayor = 0; @@ -1033,26 +1013,28 @@ function grafico_incidente_prioridad () { $mayor = $i; $mayor_data = $data[$i]; } - $legend = array ("Informative","Low","Medium","Serious", "Very serious", "Maintance"); + $legend = array (lang_string ("Informative"), + lang_string ("Low"), + lang_string ("Medium"), + lang_string ("Serious"), + lang_string ("Very serious"), + lang_string ("Maintance")); generic_pie_graph (320, 200, $data, $legend); } -function graphic_incident_group() { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - +function graphic_incident_group () { $data = array(); $legend = array(); - $sql1="SELECT distinct id_grupo FROM tincidencia "; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ - $sql1="SELECT COUNT(id_incidencia) FROM tincidencia WHERE id_grupo = ".$row[0]; - $result2=mysql_query($sql1); - $row2=mysql_fetch_array($result2); + $sql = "SELECT distinct id_grupo FROM tincidencia "; + $result = mysql_query ($sql); + while ($row = mysql_fetch_array($result)) { + $sql="SELECT COUNT(id_incidencia) FROM tincidencia WHERE id_grupo = ".$row[0]; + $result2=mysql_query ($sql); + $row2 = mysql_fetch_array($result2); $data[] = $row2[0]; $legend[] = dame_nombre_grupo($row[0])."(".$row2[0].")"; } -// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) + // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) for ($i = 0; $i < sizeof($data); $i++) { for ($j = $i; $j 10){ $height = sizeof($legend) * 20; @@ -1480,9 +1436,6 @@ function generic_bar_graph ( $width =380, $height = 200, $data, $legend) { } function grafico_db_agentes_paquetes ($width = 380, $height = 300) { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - $data = array(); $legend = array(); $sql1="SELECT distinct (id_agente) FROM tagente_datos"; @@ -1517,10 +1470,6 @@ function grafico_db_agentes_paquetes ($width = 380, $height = 300) { } function grafico_db_agentes_purge ($id_agent, $width, $height) { - include ("../include/config.php"); - require_once 'Image/Graph.php'; - require ("../include/languages/language_".$config['language'].".php"); - if ($id_agent == 0) $id_agent = -1; // All data (now) @@ -1564,8 +1513,8 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) { } function drawWarning($width,$height) { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); + global $config; + if ($width == 0) { $width = 50; } @@ -1583,7 +1532,7 @@ function drawWarning($width,$height) { ImageFilledRectangle($image,0,0,$width-1,$height-1,$back); ImageRectangle($image,0,0,$width-1,$height-1,$border); - ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $border, $config['fontpath'], $lang_label["no_data"]); + ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $border, $config['fontpath'], lang_string ("no_data")); imagePNG($image); imagedestroy($image); } @@ -1599,8 +1548,8 @@ function progress_bar ($progress, $width, $height, $mode = 1) { // With some adds from sdonie at lgc dot com // Get from official documentation PHP.net website. Thanks guys :-) function drawRating($rating, $width, $height, $mode) { - include ("../include/config.php"); - require ("../include/languages/language_".$config["language"].".php"); + global $config; + $rating = format_numeric($rating,1); if ($width == 0) { $width = 150; @@ -1672,8 +1621,7 @@ function progress_bar ($progress, $width, $height, $mode = 1) { } function odo_tactic ($value1, $value2, $value3) { - require_once 'Image/Graph.php'; - include ("../include/config.php"); + global $config; // create the graph $driver=& Image_Canvas::factory('png',array('width'=>350,'height'=>260,'antialias' => 'driver')); @@ -1773,9 +1721,7 @@ function odo_tactic ($value1, $value2, $value3) { function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, $width, $height , $title, $unit_name, $show_alert, $avg_only = 0, $pure=0 ) { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - require_once 'Image/Graph.php'; + global $config; $resolution = $config['graph_res'] * 50; // Number of "slices" we want in graph @@ -1917,12 +1863,12 @@ function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, //echo $valores[$i][6]; //echo "
"; } -//exit; + // Create graph // ************* $Graph =& Image_Graph::factory('graph', array($width, $height)); // add a TrueType font - $Font =& $Graph->addNew('font', $config['fontpath']); + $Font =& $Graph->addNew ('font', $config['fontpath']); $Font->setSize(6); $Graph->setFont($Font); @@ -2115,64 +2061,83 @@ if ($graphic_type) { switch ($graphic_type) { case 'string': graphic_string_data ($id, $period, $width, $height, $date); + + break; case 'sparse': - grafico_modulo_sparse ($id, $period, $draw_events, $width, $height , $label, $unit_name, $draw_alerts, $avg_only, $pure, $date); + grafico_modulo_sparse ($id, $period, $draw_events, $width, $height, + $label, $unit_name, $draw_alerts, $avg_only, $pure, $date); break; case "boolean": grafico_modulo_boolean ($id, $period, $draw_events, $width, $height , $label, $unit_name, $draw_alerts, 1, $pure); + break; case "estado_incidente": grafico_incidente_estados (); + break; case "prioridad_incidente": grafico_incidente_prioridad (); + break; case "db_agente_modulo": grafico_db_agentes_modulos($width, $height); + break; case "db_agente_paquetes": grafico_db_agentes_paquetes($width, $height); + break; case "db_agente_purge": grafico_db_agentes_purge($id, $width, $height); + break; case "event_module": graph_event_module ($width, $height, $id_agent); + case "group_events": grafico_eventos_grupo($width, $height); + break; case "user_events": grafico_eventos_usuario($width, $height); + break; case "total_events": grafico_eventos_total(); + break; case "group_incident": graphic_incident_group(); + break; case "user_incident": graphic_incident_user(); + break; case "source_incident": graphic_incident_source(); + break; case "user_activity": graphic_user_activity($width,$height); + break; case "agentaccess": graphic_agentaccess ($_GET["id"], $_GET["periodo"], $width, $height); + break; case "agentmodules": graphic_agentmodules($_GET["id"], $width, $height); + break; - //elseif ($_GET["tipo"] == "gdirect") -// graphic_test ($id, $period, $intervalo, $label, $width, $height); case "progress": $percent = $_GET["percent"]; progress_bar ($percent,$width,$height, $mode); + break; case "odo_tactic": odo_tactic ( $value1, $value2, $value3 ); + break; case "combined": // Split id to get all parameters @@ -2182,6 +2147,7 @@ if ($graphic_type) { $weight_list = split (",", $weight_l); graphic_combined_module ($module_list, $weight_list, $period, $width, $height, $label, $unit_name, $draw_events, $draw_alerts, $pure, $stacked, $date); + break; case "alerts_fired_pipe": $data = array (); @@ -2191,6 +2157,7 @@ if ($graphic_type) { $legends[0] = lang_string ('fired_alerts'); $legends[1] = lang_string ('not_fired_alerts'); generic_pie_graph ($width, $height, $data, $legends); + break; case 'monitors_health_pipe': $data = array (); @@ -2200,6 +2167,7 @@ if ($graphic_type) { $legends[0] = lang_string ('monitors_ok'); $legends[1] = lang_string ('monitors_bad'); generic_pie_graph ($width, $height, $data, $legends); + break; default: graphic_error (); diff --git a/pandora_console/reporting/stat_win.php b/pandora_console/reporting/stat_win.php index 556a930826..cb95a364e2 100644 --- a/pandora_console/reporting/stat_win.php +++ b/pandora_console/reporting/stat_win.php @@ -122,11 +122,11 @@ if ($start_date != $current){ echo ""; echo ""; echo "
"; - echo $lang_label["max_value"]." : ". format_for_graph(return_moduledata_max_value ($id, $period)); + echo $lang_label["max_value"]." : ". format_for_graph(get_agent_module_value_max ($id, $period)); echo ""; - echo $lang_label["avg_value"]." : ". format_for_graph(return_moduledata_avg_value ($id, $period)); + echo $lang_label["avg_value"]." : ". format_for_graph(get_agent_module_value_average ($id, $period)); echo ""; - echo $lang_label["min_value"]." : ". format_for_graph(return_moduledata_min_value ($id, $period)); + echo $lang_label["min_value"]." : ". format_for_graph(get_agent_module_value_min ($id, $period)); echo "
";