// Additions to code for Pandora FMS 1.2 graph code and new XML reporting template managemement
// Copyright (c) 2005-2007 Artica Soluciones Tecnologicas, info@artica.es
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars
require("include/config.php");
check_login();
if (! give_acl ($config['id_user'], 0, "AR") && ! give_acl ($config['id_user'], 0, "AW")) {
require ("general/noaccess.php");
return;
}
function give_average_from_module ($id_agente, $id_agente_modulo, $hour, $day, $start_date, $end_date){
// Return average value from an agentmodule, for a specific hour of specific day of week,
// Only valid for non-string kind of data.
require ("include/config.php");
$query1 = "SELECT AVG(datos)
FROM tagente_datos
WHERE id_agente_modulo = ". $id_agente_modulo."
AND HOUR(timestamp) = ".$hour."
AND WEEKDAY(timestamp) = ".$day."
AND timestamp >= '$start_date'
AND timestamp <= '$end_date'";
if (($resq1 = mysql_query($query1)) AND ($row=mysql_fetch_array($resq1)))
return $row[0];
else
return 0;
}
function generate_average_table ($id_de_mi_agente, $id_agente_modulo, $fecha_inicio, $fecha_fin){
// Genera una tabla con los promedios de los datos de un módulo no-string
require ("include/config.php");
$dias_de_la_semana = array (__('Sunday'),__('Monday'), __('Tuesday'), __('Wednesday'), __('Thurdsday'), __('Friday'), __('Saturday'));
$nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo);
// Table header
echo "
";
echo "
".__('One hour')." | ";
echo "".__('day')." |
";
echo "";
for ($dia=0;$dia<7;++$dia)
echo "".$dias_de_la_semana[$dia]." | ";
echo "
";
$color = 0;
for ($hora=0;$hora<24;++$hora){
if ($color == 1){
$tdcolor = "datos";
$color = 0;
} else {
$tdcolor = "datos2";
$color = 1;
}
echo " $hora ".__('Hr')." | ";
for ($dia=0; $dia<7; ++$dia){
echo "";
echo format_numeric (give_average_from_module ($id_de_mi_agente, $id_agente_modulo, $hora, $dia, $fecha_inicio, $fecha_fin));
echo " | ";
}
echo "
";
}
echo "
";
}
if ((isset($_POST["export"])) AND (! isset($_POST["update_agent"]))){
if (isset($_POST["export_type"]))
$export_type = $_POST["export_type"];
else
$export_type = 3; // Standard table;
// Header
echo "".__('Pandora Agents')." > ";
echo __('Database export results')."
";
if ($export_type == 1) { // CSV
if (isset ($_POST["origen_modulo"])){
$origen = $_POST["origen"];
if (! give_acl ($config['id_user'], dame_id_grupo ($origen), "AR")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Agent Export Data");
require ("general/noaccess.php");
}
$origen_modulo = $_POST["origen_modulo"];
$id_agentemodulo = $origen_modulo[0];
$start_date =$_POST["start_date"];
$end_date=$_POST["end_date"];
$start_time =$_POST["start_time"];
$end_time=$_POST["end_time"];
$from_date = $start_date." ".$start_time;
$to_date = $end_date." ".$end_time;
$agentmodule_name = dame_nombre_modulo_agentemodulo($origen_modulo[0]);
echo __('Data from agent '). "" . dame_nombre_agente($origen). "- $agentmodule_name ". __('from'). " ". $from_date. " ". __('to'). " ". $to_date. "
";
echo " ".__('Download file')." pandora_export_$agentmodule_name.txt";
} else
echo "".__('No module has been selected')."";
}
if ($export_type == 2){ // Avarage day/hour matrix
if (isset ($_POST["origen_modulo"])){
$origen = $_POST["origen"];
$origen_modulo = $_POST["origen_modulo"];
$start_date =$_POST["start_date"];
$end_date=$_POST["end_date"];
$start_time =$_POST["start_time"];
$end_time=$_POST["end_time"];
$agentmodule_name = dame_nombre_modulo_agentemodulo($origen_modulo[0]);
$from_date = $start_date." ".$start_time;
$to_date = $end_date." ".$end_time;
echo __('Data from agent '). "" . dame_nombre_agente ($origen). "- $agentmodule_name ". __('from'). " ". $from_date. " ". __('to'). " ". $to_date. "
";
echo "
";
// For each module
for ($a=0;$a ". generate_average_table ($origen,$id_modulo,$from_date,$to_date);
}
}
}
if ($export_type == 3) { // Standard table
if (isset ($_POST["origen_modulo"])){
$origen = $_POST["origen"];
if (! give_acl ($config['id_user'], dame_id_grupo ($origen), "AR")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Agent Export Data");
require ("general/noaccess.php");
}
$origen_modulo = $_POST["origen_modulo"];
$agentmodule_name = dame_nombre_modulo_agentemodulo($origen_modulo[0]);
$start_date =$_POST["start_date"];
$end_date=$_POST["end_date"];
$start_time =$_POST["start_time"];
$end_time=$_POST["end_time"];
$from_date = $start_date." ".$start_time;
$to_date = $end_date." ".$end_time;
echo __('Data from agent '). "" . dame_nombre_agente($origen). "- $agentmodule_name". __(' from '). "". $from_date. "". __(' to '). "". $to_date. "
";
echo "
";
echo "
".__('Module')." |
".__('Data')." |
Timestamp | ";
// Begin the render !
for ($a=0; $a "'.$from_date.'" AND timestamp < "'.$to_date.'" AND id_agente_modulo ='.$id_modulo.' ORDER BY timestamp DESC';
else
$sql1 = 'SELECT * FROM tagente_datos WHERE timestamp > "'.$from_date.'" AND timestamp < "'.$to_date.'" AND id_agente_modulo ='.$id_modulo.' ORDER BY timestamp DESC';
$result1 = mysql_query ($sql1);
$color=1;
while ($row = mysql_fetch_array ($result1)){
if ($color == 1){
$tdcolor = "datos";
$color = 0;
} else {
$tdcolor = "datos2";
$color = 1;
}
echo "";
echo $agentmodule_name;
echo " | ";
echo $row["datos"];
echo " | ";
echo $row["timestamp"];
echo " |
";
}
}
echo "
";
} else
echo "".__('No module has been selected')."";
}
} else {
// Option B: Print Form
// Form view
$ahora=date("Y/m/d H:i:s");
$ahora_s = date("U");
$ayer = date ("Y/m/d H:i:s", $ahora_s - 86400);
if (isset($_GET["date_from"]))
$date_from=$_GET["date_from"];
else
if (isset($_POST["from_date"]))
$date_from = $_POST["from_date"];
else
$date_from = $ayer;
if (isset($_GET["date_to"]))
$date_to = $_GET["date_to"];
else
if (isset($_POST["to_date"]))
$date_to = $_POST["to_date"];
else
$date_to = $ahora;
echo "";
echo "".__('Pandora Agents')." > ";
echo __('Export data')."
";
echo '";
}
?>