mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 15:54:29 +02:00
2009-03-04 Evi Vanoost <vanooste@rcbi.rochester.edu>
* include/functions_reporting.php, operation/reporting/reporting_viewer.php: Function renaming, small fixes in some code and documentation. * include/functions_db.php: Better checks on get_agent_events * operation/reporting/reporting_xml.php: Sancho sent me this solution since people apparently use this and run out of memory. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1506 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
6dea8586df
commit
42e82b8ae5
@ -1,3 +1,14 @@
|
|||||||
|
2009-03-04 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
||||||
|
|
||||||
|
* include/functions_reporting.php,
|
||||||
|
operation/reporting/reporting_viewer.php: Function renaming, small fixes
|
||||||
|
in some code and documentation.
|
||||||
|
|
||||||
|
* include/functions_db.php: Better checks on get_agent_events
|
||||||
|
|
||||||
|
* operation/reporting/reporting_xml.php: Sancho sent me this solution
|
||||||
|
since people apparently use this and run out of memory.
|
||||||
|
|
||||||
2009-03-04 Esteban Sanchez <estebans@artica.es>
|
2009-03-04 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
* godmode/agentes/configurar_agente.php: Fixed module interval update.
|
* godmode/agentes/configurar_agente.php: Fixed module interval update.
|
||||||
|
@ -732,13 +732,19 @@ function get_group_events ($id_group, $period, $date) {
|
|||||||
*
|
*
|
||||||
* @return array An array with all the events happened.
|
* @return array An array with all the events happened.
|
||||||
*/
|
*/
|
||||||
function get_agent_events ($id_agent, $period, $date) {
|
function get_agent_events ($id_agent, $period, $date = 0) {
|
||||||
|
if (!is_numeric ($date)) {
|
||||||
|
$date = strtotime ($date);
|
||||||
|
}
|
||||||
|
if (empty ($date)) {
|
||||||
|
$date = get_system_time ();
|
||||||
|
}
|
||||||
|
|
||||||
$datelimit = $date - $period;
|
$datelimit = $date - $period;
|
||||||
|
|
||||||
$sql = sprintf ('SELECT evento,event_type,criticity, count(*) as count_rep, max(timestamp) AS time2
|
$sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2
|
||||||
FROM tevento WHERE id_agente = %d AND utimestamp > %d AND utimestamp <=%d
|
FROM tevento WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d
|
||||||
GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent,
|
GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent, $datelimit, $date);
|
||||||
$datelimit, $date);
|
|
||||||
|
|
||||||
return get_db_all_rows_sql ($sql);
|
return get_db_all_rows_sql ($sql);
|
||||||
}
|
}
|
||||||
|
@ -650,14 +650,14 @@ function get_agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $retur
|
|||||||
/**
|
/**
|
||||||
* Get a detailed report of agents in a group.
|
* Get a detailed report of agents in a group.
|
||||||
*
|
*
|
||||||
* @param int Group to get the report
|
* @param mixed Group(s) to get the report
|
||||||
* @param int Period
|
* @param int Period
|
||||||
* @param int Timestamp to start from
|
* @param int Timestamp to start from
|
||||||
* @param bool Flag to return or echo the report (by default).
|
* @param bool Flag to return or echo the report (by default).
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) {
|
function get_group_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) {
|
||||||
$agents = get_group_agents ($id_group, false, "none");
|
$agents = get_group_agents ($id_group, false, "none");
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
@ -678,18 +678,25 @@ function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $retu
|
|||||||
* It construct a table object with all the grouped events happened in an agent
|
* It construct a table object with all the grouped events happened in an agent
|
||||||
* during a period of time.
|
* during a period of time.
|
||||||
*
|
*
|
||||||
* @param int Agent id to get the report.
|
* @param mixed Agent id(s) to get the report from.
|
||||||
* @param int Period of time to get the report.
|
* @param int Period of time (in seconds) to get the report.
|
||||||
* @param int Beginning date of the report
|
* @param int Beginning date (unixtime) of the report
|
||||||
* @param int Flag to return or echo the report table (echo by default).
|
* @param bool Flag to return or echo the report table (echo by default).
|
||||||
*
|
*
|
||||||
* @return object A table object
|
* @return A table object (XHTML)
|
||||||
*/
|
*/
|
||||||
function get_agents_detailed_event_reporting ($id_agent, $period, $date = 0) {
|
function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0, $return = false) {
|
||||||
|
$id_agents = safe_int ($id_agents, 1);
|
||||||
|
|
||||||
|
if (!is_numeric ($date)) {
|
||||||
|
$date = strtotime ($date);
|
||||||
|
}
|
||||||
if (empty ($date)) {
|
if (empty ($date)) {
|
||||||
$date = get_system_time ();
|
$date = get_system_time ();
|
||||||
} elseif (!is_numeric ($date)) {
|
}
|
||||||
$date = strtotime ($date);
|
if (empty ($period)) {
|
||||||
|
global $config;
|
||||||
|
$period = $config["sla_period"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->width = '99%';
|
$table->width = '99%';
|
||||||
@ -701,24 +708,25 @@ function get_agents_detailed_event_reporting ($id_agent, $period, $date = 0) {
|
|||||||
$table->head[3] = __('Count');
|
$table->head[3] = __('Count');
|
||||||
$table->head[4] = __('Timestamp');
|
$table->head[4] = __('Timestamp');
|
||||||
|
|
||||||
$events = get_agent_events ($id_agent, $period, $date);
|
|
||||||
if (empty ($events)) {
|
|
||||||
$events = array ();
|
$events = array ();
|
||||||
|
foreach ($id_agents as $id_agent) {
|
||||||
|
$event = get_agent_events ($id_agent, (int) $period, (int) $date);
|
||||||
|
if (!empty ($event)) {
|
||||||
|
array_push ($events, $event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
$data = array ();
|
$data = array ();
|
||||||
$data[0] = $event['evento'];
|
$data[0] = $event['evento'];
|
||||||
$data[1] = $event['event_type'];
|
$data[1] = $event['event_type'];
|
||||||
$data[2] = get_priority_name($event['criticity']);
|
$data[2] = get_priority_name ($event['criticity']);
|
||||||
$data[3] = $event['count_rep'];
|
$data[3] = $event['count_rep'];
|
||||||
$data[4] = $event['time2'];
|
$data[4] = $event['time2'];
|
||||||
array_push ($table->data, $data);
|
array_push ($table->data, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = print_table ($table, true);
|
return print_table ($table, $return);
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -487,7 +487,7 @@ foreach ($contents as $content) {
|
|||||||
$table->colspan[0][0] = 2;
|
$table->colspan[0][0] = 2;
|
||||||
$data = array ();
|
$data = array ();
|
||||||
$table->colspan[1][0] = 3;
|
$table->colspan[1][0] = 3;
|
||||||
$data[0] = get_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
|
$data[0] = get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
|
||||||
array_push ($table->data, $data);
|
array_push ($table->data, $data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// Pandora FMS - the Flexible Monitoring System
|
// Pandora FMS - the Flexible Monitoring System
|
||||||
// ============================================
|
// ============================================
|
||||||
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
|
// Copyright (c) 2008-2009 Artica Soluciones Tecnologicas, http://www.artica.es
|
||||||
// Please see http://pandora.sourceforge.net for full contribution list
|
// Please see http://pandora.sourceforge.net for full contribution list
|
||||||
|
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
@ -16,6 +16,25 @@
|
|||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
function xml_array ($array) {
|
||||||
|
foreach ($array as $name => $value) {
|
||||||
|
if (is_int ($name)) {
|
||||||
|
echo "<object id=\"".$name."\">";
|
||||||
|
$name = "object";
|
||||||
|
} else {
|
||||||
|
echo "<".$name.">";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array ($value)) {
|
||||||
|
xml_array ($value);
|
||||||
|
} else {
|
||||||
|
echo $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</".$name.">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Login check
|
// Login check
|
||||||
if (isset ($_GET["direct"])) {
|
if (isset ($_GET["direct"])) {
|
||||||
/*
|
/*
|
||||||
@ -28,7 +47,7 @@ if (isset ($_GET["direct"])) {
|
|||||||
in a GET request (append &nick=<yourlogin>&password=<password>).
|
in a GET request (append &nick=<yourlogin>&password=<password>).
|
||||||
|
|
||||||
You SHOULD put it in a POST but some programs
|
You SHOULD put it in a POST but some programs
|
||||||
might not be able to handle it without extensive re-programming.
|
might not be able to handle it without extensive re-programming
|
||||||
Either way, you should have a read-only user for getting reports
|
Either way, you should have a read-only user for getting reports
|
||||||
|
|
||||||
XMLHttpRequest can do it (example):
|
XMLHttpRequest can do it (example):
|
||||||
@ -55,9 +74,9 @@ if (isset ($_GET["direct"])) {
|
|||||||
require_once ("../../include/functions_reporting.php");
|
require_once ("../../include/functions_reporting.php");
|
||||||
|
|
||||||
if (!isset ($config["auth"])) {
|
if (!isset ($config["auth"])) {
|
||||||
require_once ("../../include/auth/mysql.php");
|
require_once ("include/auth/mysql.php");
|
||||||
} else {
|
} else {
|
||||||
require_once ("../../include/auth/".$config["auth"]["scheme"].".php");
|
require_once ("include/auth/".$config["auth"]["scheme"].".php");
|
||||||
}
|
}
|
||||||
|
|
||||||
$nick = get_parameter ("nick");
|
$nick = get_parameter ("nick");
|
||||||
@ -76,12 +95,12 @@ if (isset ($_GET["direct"])) {
|
|||||||
} else {
|
} else {
|
||||||
// User not known
|
// User not known
|
||||||
$login_failed = true;
|
$login_failed = true;
|
||||||
require_once ($config['homedir'].'/general/login_page.php');
|
require_once ('general/login_page.php');
|
||||||
audit_db ($nick, $REMOTE_ADDR, "Logon Failed", "Invalid login: ".$nick);
|
audit_db ($nick, $REMOTE_ADDR, "Logon Failed", "Invalid login: ".$nick);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@require_once ("include/config.php");
|
require_once ("include/config.php");
|
||||||
require_once ("include/functions_reporting.php");
|
require_once ("include/functions_reporting.php");
|
||||||
|
|
||||||
if (!isset ($config["auth"])) {
|
if (!isset ($config["auth"])) {
|
||||||
@ -99,7 +118,7 @@ if (! $id_report) {
|
|||||||
audit_db ($config['id_user'], $REMOTE_ADDR, "HACK Attempt",
|
audit_db ($config['id_user'], $REMOTE_ADDR, "HACK Attempt",
|
||||||
"Trying to access graph viewer without valid ID");
|
"Trying to access graph viewer without valid ID");
|
||||||
require ("general/noaccess.php");
|
require ("general/noaccess.php");
|
||||||
return;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$report = get_db_row ('treport', 'id_report', $id_report);
|
$report = get_db_row ('treport', 'id_report', $id_report);
|
||||||
@ -107,17 +126,17 @@ $report = get_db_row ('treport', 'id_report', $id_report);
|
|||||||
if (! give_acl ($config['id_user'], $report['id_group'], "AR")) {
|
if (! give_acl ($config['id_user'], $report['id_group'], "AR")) {
|
||||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph reader");
|
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph reader");
|
||||||
include ("general/noaccess.php");
|
include ("general/noaccess.php");
|
||||||
return;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the user can see the graph */
|
/* Check if the user can see the graph */
|
||||||
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! is_user_admin ($config['id_user']))) {
|
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! dame_admin ($config['id_user']))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
header ('Content-type: application/xml; charset="utf-8"', true);
|
header ('Content-type: application/xml; charset="utf-8"', true);
|
||||||
|
|
||||||
echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
echo '<?xml version="1.0" encoding="UTF-8" ?>'; //' - this is to mislead highlighters giving crap about the PHP closing tag
|
||||||
|
|
||||||
$date = (string) get_parameter ('date', date ('Y-m-j'));
|
$date = (string) get_parameter ('date', date ('Y-m-j'));
|
||||||
$time = (string) get_parameter ('time', date ('h:iA'));
|
$time = (string) get_parameter ('time', date ('h:iA'));
|
||||||
@ -128,15 +147,14 @@ if ($datetime === false || $datetime == -1) {
|
|||||||
echo "<error>Invalid date selected</error>"; //Not translatable because this is an error message and might have to be used on the other end
|
echo "<error>Invalid date selected</error>"; //Not translatable because this is an error message and might have to be used on the other end
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
/* Date must not be older than now */
|
|
||||||
if ($datetime > get_system_time ()) {
|
|
||||||
echo "<error>Date is larger than current time</error>"; //Not translatable because this is an error message
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$group_name = get_group_name ($report['id_group']);
|
$group_name = get_group_name ($report['id_group']);
|
||||||
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`');
|
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`');
|
||||||
|
|
||||||
|
$time = get_system_time ();
|
||||||
|
echo '<report>';
|
||||||
|
echo '<generated><unix>'.$time.'</unix>';
|
||||||
|
echo '<rfc2822>'.date ("r",$time).'</rfc2822></generated>';
|
||||||
|
|
||||||
$xml["id"] = $id_report;
|
$xml["id"] = $id_report;
|
||||||
$xml["name"] = $report['name'];
|
$xml["name"] = $report['name'];
|
||||||
@ -148,9 +166,13 @@ if ($contents === false) {
|
|||||||
$contents = array ();
|
$contents = array ();
|
||||||
};
|
};
|
||||||
|
|
||||||
$xml["reports"] = array ();
|
xml_array ($xml);
|
||||||
|
|
||||||
|
echo '<reports>';
|
||||||
|
$counter = 0;
|
||||||
|
|
||||||
foreach ($contents as $content) {
|
foreach ($contents as $content) {
|
||||||
|
echo '<object id="'.$counter.'">';
|
||||||
$data = array ();
|
$data = array ();
|
||||||
$data["module"] = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']);
|
$data["module"] = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']);
|
||||||
$data["agent"] = get_agentmodule_agent_name ($content['id_agent_module']);
|
$data["agent"] = get_agentmodule_agent_name ($content['id_agent_module']);
|
||||||
@ -173,8 +195,10 @@ foreach ($contents as $content) {
|
|||||||
$result = get_db_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']);
|
$result = get_db_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']);
|
||||||
$modules = array ();
|
$modules = array ();
|
||||||
$weights = array ();
|
$weights = array ();
|
||||||
if ($result === false)
|
|
||||||
|
if ($result === false) {
|
||||||
$result = array();
|
$result = array();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($result as $content2) {
|
foreach ($result as $content2) {
|
||||||
array_push ($modules, $content2['id_agent_module']);
|
array_push ($modules, $content2['id_agent_module']);
|
||||||
@ -187,7 +211,7 @@ foreach ($contents as $content) {
|
|||||||
case 'SLA':
|
case 'SLA':
|
||||||
$data["title"] = __('S.L.A.');
|
$data["title"] = __('S.L.A.');
|
||||||
|
|
||||||
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined', 'id_report_content', $content['id_rc']);
|
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined','id_report_content', $content['id_rc']);
|
||||||
if ($slas === false) {
|
if ($slas === false) {
|
||||||
$data["objdata"]["error"] = __('There are no SLAs defined');
|
$data["objdata"]["error"] = __('There are no SLAs defined');
|
||||||
$slas = array ();
|
$slas = array ();
|
||||||
@ -201,7 +225,6 @@ foreach ($contents as $content) {
|
|||||||
$sla_data["module"] = get_agentmodule_name ($sla['id_agent_module']);
|
$sla_data["module"] = get_agentmodule_name ($sla['id_agent_module']);
|
||||||
$sla_data["max"] = $sla['sla_max'];
|
$sla_data["max"] = $sla['sla_max'];
|
||||||
$sla_data["min"] = $sla['sla_min'];
|
$sla_data["min"] = $sla['sla_min'];
|
||||||
|
|
||||||
$sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime);
|
$sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime);
|
||||||
if ($sla_value === false) {
|
if ($sla_value === false) {
|
||||||
$sla_data["error"] = __('Unknown');
|
$sla_data["error"] = __('Unknown');
|
||||||
@ -213,7 +236,6 @@ foreach ($contents as $content) {
|
|||||||
}
|
}
|
||||||
array_push ($data["objdata"]["sla"], $sla_data);
|
array_push ($data["objdata"]["sla"], $sla_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 'event_report':
|
case 'event_report':
|
||||||
@ -275,37 +297,14 @@ foreach ($contents as $content) {
|
|||||||
case 'agents_detailed':
|
case 'agents_detailed':
|
||||||
$data["title"] = __('Agents detailed view');
|
$data["title"] = __('Agents detailed view');
|
||||||
$data["objdata"] = "<![CDATA[";
|
$data["objdata"] = "<![CDATA[";
|
||||||
$data["objdata"] .= get_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
|
$data["objdata"] .= get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
|
||||||
$data["objdata"] .= "]]>";
|
$data["objdata"] .= "]]>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
array_push ($xml["reports"], $data);
|
xml_array ($data);
|
||||||
|
echo '</object>';
|
||||||
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xml_array ($array) {
|
echo '</reports></report>';
|
||||||
foreach ($array as $name => $value) {
|
|
||||||
if (is_int ($name)) {
|
|
||||||
echo "<object id=\"".$name."\">";
|
|
||||||
$name = "object";
|
|
||||||
} else {
|
|
||||||
echo "<".$name.">";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array ($value)) {
|
|
||||||
xml_array ($value);
|
|
||||||
} else {
|
|
||||||
echo $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "</".$name.">";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$time = get_system_time ();
|
|
||||||
echo '<report>';
|
|
||||||
echo '<generated><unix>'.$time.'</unix>';
|
|
||||||
echo '<rfc2822>'.date ("r",$time).'</rfc2822></generated>';
|
|
||||||
xml_array ($xml);
|
|
||||||
echo '</report>';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user