2007-02-20 Sancho Lerena <slerena@artica.es>

* pandoradb.sql: Upgraded SQL. Improved lenght for some fields.
	
	* index.php: Better permission checks
	
	* operation/agentes/estado_ultimopaquete.php: Changed some
	parameters for agent graphics.
	
	* operation/agentes/estado_generalagente.php: Changed some
	parameters for agent graphics.
	
	* reporting/fgraph.php: MAJOR UPGRADE. Replacement for three main
	graphics from agents now using Image Graph.
	
        * reporting/stat_win.php: MAJOR UPGRADE.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@379 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2007-02-20 18:09:54 +00:00
parent 44c8e7ad16
commit 2d148cc0a5
8 changed files with 492 additions and 758 deletions

View File

@ -1,3 +1,21 @@
2007-02-20 Sancho Lerena <slerena@artica.es>
* pandoradb.sql: Upgraded SQL. Improved lenght for some fields.
* index.php: Better permission checks
* operation/agentes/estado_ultimopaquete.php: Changed some
parameters for agent graphics.
* operation/agentes/estado_generalagente.php: Changed some
parameters for agent graphics.
* reporting/fgraph.php: MAJOR UPGRADE. Replacement for three main
graphics from agents now using Image Graph.
* reporting/stat_win.php: MAJOR UPGRADE.
2007-02-19 Sancho Leren <slerena@openideas.info>
* include/styles/pandora.css: Updated to have new styles for

View File

@ -19,13 +19,13 @@
// This is the base config file
//Pandora Version
$build_version="PC080105"; //PCyymmdd
$build_version="PC070221"; //PCyymmdd
$pandora_version="v1.3 devel";
// Database configuration
$dbname="pandora"; // MySQL DataBase
$dbuser="root"; // DB User
$dbpassword=""; // Password
$dbuser="pandora"; // DB User
$dbpassword="pandora"; // Password
$dbhost="localhost"; // MySQL Host
$dbtype="mysql"; // Type of Database, now only "mysql" its supported
$attachment_store="/var/www/pandora_console"; //This is directory where placed "attachment" directory, to upload files stores. This MUST be writtable by wwwserver user, and should be in pandora root. Please append "/" to the end :-)

View File

@ -22,27 +22,40 @@
// Pandora FMS 1.x uses icons from famfamfam, licensed under CC Atr. 2.5
// Silk icon set 1.3 (cc) Mark James, http://www.famfamfam.com/lab/icons/silk/
// Pandora FMS 1.x uses Pear Image::Graph code
// Pandora FMS shares much of it's code with project Babel Enterprise, also a
// FreeSoftware Project coded by some of the people who makes Pandora FMS
// If no config file, automatically try to install
if (! file_exists("include/config.php")){
include ("install.php");
exit;
$develop_bypass = 1;
if ($develop_bypass != 1){
// If no config file, automatically try to install
if (! file_exists("include/config.php")){
include ("install.php");
exit;
}
// Check for installer presence
if (file_exists("install.php")){
include "general/error_install.php";
exit;
}
// Check perms for config.php
if ((substr(sprintf('%o', fileperms('include/config.php')), -4) != "0600") &&
(substr(sprintf('%o', fileperms('include/config.php')), -4) != "0660") &&
(substr(sprintf('%o', fileperms('include/config.php')), -4) != "0640") &&
(substr(sprintf('%o', fileperms('include/config.php')), -4) != "0600"))
{
include "general/error_perms.php";
exit;
}
}
// Check for installer presence
if (file_exists("install.php")){
include "general/error_install.php";
exit;
}
// Pandora FMS 1.x uses Pear Image::Graph code
// Real start
session_start();
include "include/config.php";
include "include/languages/language_".$language_code.".php";
require("include/functions.php"); // Including funcions.
require("include/functions_db.php");
require "include/functions.php"; // Including funcions.
require "include/functions_db.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -67,7 +67,7 @@ if (comprueba_login() == 0) {
echo "
<td rowspan=4>
<b>".$lang_label["agent_access_rate"]."</b><br><br>
<img src='reporting/fgraph.php?id=".$id_agente."&tipo=agentaccess&periodo=1440'>
<img src='reporting/fgraph.php?id=".$id_agente."&tipo=agentaccess&periodo=1440&height=70&width=280'>
</td>";
echo '</tr>';
echo '<tr>
@ -95,7 +95,7 @@ if (comprueba_login() == 0) {
<td class="datos">'.$comentarios.'</td>';
echo "<td rowspan=6><b>".$lang_label["agent_module_shareout"]."</b><br><br>
<img src='reporting/fgraph.php?id=".$id_agente."&tipo=agentmodules' >
<img src='reporting/fgraph.php?id=".$id_agente."&tipo=agentmodules&height=150&width=280' >
</td>";
echo '</tr>';
echo '<tr>

View File

@ -147,7 +147,7 @@ if (comprueba_login() == 0) {
// For types not string type (3 data_string, 9 tcp_string, 14 snmp_string)
if (($row3["id_tipo_modulo"] != 3)
AND ($row3["id_tipo_modulo"] != 10)
AND ($row3["id_tipo_modulo"] != 17)){
AND ($row3["id_tipo_modulo"] != 17)){
echo "<td class=".$tdcolor.">";
if (($row3["datos"] != 0) AND (is_numeric($row3["datos"]))){
$mytempdata = fmod($row3["datos"], $row3["datos"]);
@ -171,19 +171,17 @@ AND ($row3["id_tipo_modulo"] != 17)){
$url = 'reporting/procesos.php?agente='.$nombre_agente;
$win_handle=dechex(crc32($nombre_agente.$row3["nombre"]));
echo "<td class=".$tdcolor." width='78'>";
$graph_label = entrada_limpia($row3["nombre"]." - ".$nombre_agente);
echo "<a href='javascript:winopeng(\"reporting/stat_win.php?range=mes&id=".$row3["id_agente_modulo"]."&refresh=180000\", \"mes_".$win_handle."\")'><img src='images/grafica_m.gif' border=0></a>&nbsp;";
$link ="winopeng('reporting/stat_win.php?range=mesg&id=".$row3["id_agente_modulo"]."&refresh=6000','sem_".$win_handle."')";
echo '<a href="javascript:'.$link.'"><img src="images/b_green.gif" border=0></a>&nbsp;';
echo "<a href='javascript:winopeng(\"reporting/stat_win.php?period=2419200&id=".$row3["id_agente_modulo"]."&label=".$graph_label."refresh=180000\", \"month_".$win_handle."\")'><img src='images/grafica_m.gif' border=0></a>&nbsp;";
$link ="winopeng('reporting/stat_win.php?range=semana&id=".$row3["id_agente_modulo"]."&refresh=6000','sem_".$win_handle."')";
$link ="winopeng('reporting/stat_win.php?period=604800&id=".$row3["id_agente_modulo"]."&label=".$graph_label."&refresh=6000','week_".$win_handle."')";
echo '<a href="javascript:'.$link.'"><img src="images/grafica_w.gif" border=0></a>&nbsp;';
$link ="winopeng('reporting/stat_win.php?range=dia&id=".$row3["id_agente_modulo"]."&refresh=800','dia_".$win_handle."')";
$link ="winopeng('reporting/stat_win.php?period=86400&id=".$row3["id_agente_modulo"]."&label=".$graph_label."&refresh=600','day_".$win_handle."')";
echo '<a href="javascript:'.$link.'"><img src="images/grafica_d.gif" border=0></a>&nbsp;';
$link ="winopeng('reporting/stat_win.php?tipo=range&id=".$row3["id_agente_modulo"]."&refresh=30','hora_".$win_handle."')";
$link ="winopeng('reporting/stat_win.php?period=3600&id=".$row3["id_agente_modulo"]."&label=".$graph_label."&refresh=60','hour_".$win_handle."')";
echo '<a href="javascript:'.$link.'"><img src="images/grafica_h.gif" border=0></a>';
}
else { # Writing string data in different way :)

View File

@ -9,9 +9,9 @@ USE `pandora`;
#
CREATE TABLE `tagent_access` (
`id_ac` bigint(20) unsigned NOT NULL auto_increment,
`id_agent` int(11) NOT NULL default '0',
`id_agent` int(8) unsigned NOT NULL default '0',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`utimestamp` bigint(20) NOT NULL default '0',
`utimestamp` mediumint(12) unsigned NOT NULL default '0',
PRIMARY KEY (`id_ac`),
KEY `agent_index` (`id_agent`)
) TYPE=InnoDB;
@ -20,20 +20,20 @@ CREATE TABLE `tagent_access` (
# Table: 'tagente'
#
CREATE TABLE `tagente` (
`id_agente` bigint(4) unsigned NOT NULL auto_increment,
`id_agente` int(8) unsigned NOT NULL auto_increment,
`nombre` varchar(100) NOT NULL default '',
`direccion` varchar(100) default '',
`comentarios` varchar(255) default '',
`id_grupo` int(10) unsigned NOT NULL default '0',
`id_grupo` int(8) unsigned NOT NULL default '0',
`ultimo_contacto` datetime NOT NULL default '0000-00-00 00:00:00',
`modo` tinyint(1) NOT NULL default '0',
`intervalo` int(8) NOT NULL default '300',
`id_os` int(11) default '0',
`modo` tinyint(1) unsigned NOT NULL default '0',
`intervalo` int(8) unsigned NOT NULL default '300',
`id_os` tinyint(4) unsigned default '0',
`os_version` varchar(100) default '',
`agent_version` varchar(100) default '',
`ultimo_contacto_remoto` datetime default '0000-00-00 00:00:00',
`disabled` tinyint(2) NOT NULL default '0',
`agent_type` int(2) unsigned NOT NULL default '0',
`disabled` tinyint(2) unsigned NOT NULL default '0',
`agent_type` tinyint(2) unsigned NOT NULL default '0',
`id_server` int(4) unsigned default '0',
PRIMARY KEY (`id_agente`)
) TYPE=InnoDB;
@ -42,12 +42,12 @@ CREATE TABLE `tagente` (
# Table: 'tagente_datos'
#
CREATE TABLE `tagente_datos` (
`id_agente_datos` bigint(10) unsigned NOT NULL auto_increment,
`id_agente_modulo` bigint(4) NOT NULL default '0',
`id_agente_datos` bigint(20) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`datos` double(18,2) default NULL,
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`id_agente` bigint(4) unsigned NOT NULL default '0',
`utimestamp` bigint(20) NOT NULL default '0',
`utimestamp` mediumint(12) unsigned NOT NULL default '0',
PRIMARY KEY (`id_agente_datos`),
KEY `data_index_1` (`id_agente_modulo`),
KEY `data_index_2` (`id_agente`),
@ -59,8 +59,8 @@ CREATE TABLE `tagente_datos` (
#
CREATE TABLE `tagente_datos_inc` (
`id_adi` bigint(20) unsigned NOT NULL auto_increment,
`id_agente_modulo` bigint(20) NOT NULL default '0',
`datos` bigint(18) default NULL,
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`datos` double(18,2) default NULL,
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id_adi`),
KEY `data_inc_index_1` (`id_agente_modulo`)
@ -71,15 +71,14 @@ CREATE TABLE `tagente_datos_inc` (
#
CREATE TABLE `tagente_datos_string` (
`id_tagente_datos_string` bigint(20) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(11) NOT NULL default '0',
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`datos` tinytext NOT NULL default '',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`id_agente` bigint(4) unsigned NOT NULL default '0',
`utimestamp` bigint(20) NOT NULL default '0',
`utimestamp` mediumint(12) unsigned NOT NULL default '0',
PRIMARY KEY (`id_tagente_datos_string`),
KEY `data_string_index_1` (`id_agente_modulo`),
KEY `data_string_index_2` (`id_agente`),
KEY `data_string_index_3` (`timestamp`)
) TYPE=InnoDB;
# Database: pandora
@ -87,14 +86,14 @@ CREATE TABLE `tagente_datos_string` (
#
CREATE TABLE `tagente_estado` (
`id_agente_estado` int(10) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(20) NOT NULL default '0',
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`datos` varchar(255) NOT NULL default '',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`cambio` int(11) NOT NULL default '0',
`estado` int(11) NOT NULL default '0',
`id_agente` int(11) NOT NULL default '0',
`cambio` tinyint(2) unsigned NOT NULL default '0',
`estado` tinyint(2) unsigned NOT NULL default '0',
`id_agente` int(8) unsigned NOT NULL default '0',
`last_try` datetime default NULL,
`utimestamp` bigint(20) NOT NULL default '0',
`utimestamp` mediumint(12) unsigned NOT NULL default '0',
PRIMARY KEY (`id_agente_estado`),
KEY `status_index_2` (`id_agente_modulo`,`estado`)
) TYPE=InnoDB;
@ -103,15 +102,15 @@ CREATE TABLE `tagente_estado` (
# Table: 'tagente_modulo'
#
CREATE TABLE `tagente_modulo` (
`id_agente_modulo` bigint(100) unsigned NOT NULL auto_increment,
`id_agente` int(11) NOT NULL default '0',
`id_tipo_modulo` int(11) NOT NULL default '0',
`id_agente_modulo` int(10) unsigned NOT NULL auto_increment,
`id_agente` int(10) unsigned NOT NULL default '0',
`id_tipo_modulo` int(10) unsigned NOT NULL default '0',
`descripcion` varchar(100) NOT NULL default '',
`nombre` varchar(100) NOT NULL default '',
`max` bigint(20) default '0',
`min` bigint(20) default '0',
`module_interval` int(4) unsigned default '0',
`tcp_port` int(4) unsigned default '0',
`max` int(10) default '0',
`min` int(10) default '0',
`module_interval` int(8) unsigned default '0',
`tcp_port` int(5) unsigned default '0',
`tcp_send` varchar(150) default '',
`tcp_rcv` varchar(100) default '',
`snmp_community` varchar(100) default '',
@ -136,11 +135,11 @@ CREATE TABLE `talert_snmp` (
`agent` varchar(100) default '',
`custom_oid` varchar(200) default '',
`oid` varchar(255) NOT NULL default '',
`time_threshold` int(11) NOT NULL default '0',
`time_threshold` int(10) unsigned NOT NULL default '0',
`times_fired` int(2) unsigned NOT NULL default '0',
`last_fired` datetime NOT NULL default '0000-00-00 00:00:00',
`max_alerts` int(11) NOT NULL default '1',
`min_alerts` int(11) NOT NULL default '1',
`max_alerts` tinyint(4) unsigned NOT NULL default '1',
`min_alerts` tinyint(4) unsigned NOT NULL default '1',
`internal_counter` int(2) unsigned NOT NULL default '0',
PRIMARY KEY (`id_as`)
) TYPE=InnoDB;
@ -161,22 +160,22 @@ CREATE TABLE `talerta` (
#
CREATE TABLE `talerta_agente_modulo` (
`id_aam` int(11) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(11) NOT NULL default '0',
`id_alerta` int(11) NOT NULL default '0',
`id_aam` int(10) unsigned NOT NULL auto_increment,
`id_agente_modulo` int(10) unsigned NOT NULL default '0',
`id_alerta` int(10) unsigned NOT NULL default '0',
`al_campo1` varchar(255) default '',
`al_campo2` varchar(255) default '',
`al_campo3` mediumtext default '',
`descripcion` varchar(255) default '',
`dis_max` bigint(12) default NULL,
`dis_min` bigint(12) default NULL,
`time_threshold` int(11) NOT NULL default '0',
`dis_max` int(8) default NULL,
`dis_min` int(8) default NULL,
`time_threshold` int(8) NOT NULL default '0',
`last_fired` datetime NOT NULL default '0000-00-00 00:00:00',
`max_alerts` int(4) NOT NULL default '1',
`times_fired` int(11) NOT NULL default '0',
`module_type` int(11) NOT NULL default '0',
`min_alerts` int(4) NOT NULL default '0',
`internal_counter` int(4) default '0',
`max_alerts` tinyint(4) unsigned NOT NULL default '1',
`times_fired` tinyint(4) unsigned NOT NULL default '0',
`module_type` tinyint(4) unsigned NOT NULL default '0',
`min_alerts` tinyint(4) unsigned NOT NULL default '0',
`internal_counter` tinyint(4) unsigned default '0',
PRIMARY KEY (`id_aam`)
) TYPE=InnoDB;
@ -184,12 +183,12 @@ CREATE TABLE `talerta_agente_modulo` (
# Table: 'tattachment'
#
CREATE TABLE `tattachment` (
`id_attachment` bigint(20) unsigned NOT NULL auto_increment,
`id_incidencia` bigint(20) NOT NULL default '0',
`id_attachment` int(10) unsigned NOT NULL auto_increment,
`id_incidencia` int(10) unsigned NOT NULL default '0',
`id_usuario` varchar(60) NOT NULL default '',
`filename` varchar(255) NOT NULL default '',
`description` varchar(150) default '',
`size` bigint(20) NOT NULL default '0',
`size` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id_attachment`)
) TYPE=InnoDB;
@ -219,10 +218,10 @@ CREATE TABLE `tconfig_os` (
#
CREATE TABLE `tevento` (
`id_evento` bigint(20) unsigned NOT NULL auto_increment,
`id_agente` bigint(20) NOT NULL default '0',
`id_agente` int(10) unsigned NOT NULL default '0',
`id_usuario` varchar(60) NOT NULL default '0',
`id_grupo` bigint(20) NOT NULL default '0',
`estado` int(10) unsigned NOT NULL default '0',
`id_grupo` int(10) unsigned NOT NULL default '0',
`estado` tynyint(4) unsigned NOT NULL default '0',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`evento` varchar(255) NOT NULL default '',
PRIMARY KEY (`id_evento`),
@ -244,16 +243,16 @@ CREATE TABLE `tgrupo` (
# Table: 'tincidencia'
#
CREATE TABLE `tincidencia` (
`id_incidencia` bigint(20) unsigned NOT NULL auto_increment,
`id_incidencia` int(10) unsigned NOT NULL auto_increment,
`inicio` datetime NOT NULL default '0000-00-00 00:00:00',
`cierre` datetime NOT NULL default '0000-00-00 00:00:00',
`titulo` varchar(100) NOT NULL default '',
`descripcion` mediumtext NOT NULL,
`id_usuario` varchar(100) NOT NULL default '',
`origen` varchar(100) NOT NULL default '',
`estado` int(11) NOT NULL default '0',
`prioridad` int(11) NOT NULL default '0',
`id_grupo` mediumint(9) NOT NULL default '0',
`estado` tinyint(4) unsigned NOT NULL default '0',
`prioridad` tinyint(4) unsigned NOT NULL default '0',
`id_grupo` int(10) unsigned NOT NULL default '0',
`actualizacion` datetime NOT NULL default '0000-00-00 00:00:00',
`id_creator` varchar(60) default NULL,
PRIMARY KEY (`id_incidencia`),
@ -283,7 +282,7 @@ CREATE TABLE `tlink` (
# Table: 'tmensajes'
#
CREATE TABLE `tmensajes` (
`id_mensaje` bigint(20) unsigned NOT NULL auto_increment,
`id_mensaje` int(10) unsigned NOT NULL auto_increment,
`id_usuario_origen` varchar(100) NOT NULL default '',
`id_usuario_destino` varchar(100) NOT NULL default '',
`mensaje` tinytext NOT NULL,
@ -297,7 +296,7 @@ CREATE TABLE `tmensajes` (
# Table: 'tmodule_group'
#
CREATE TABLE `tmodule_group` (
`id_mg` bigint(20) unsigned NOT NULL auto_increment,
`id_mg` int(10) unsigned NOT NULL auto_increment,
`name` varchar(150) NOT NULL default '',
PRIMARY KEY (`id_mg`)
) TYPE=InnoDB;
@ -318,8 +317,8 @@ CREATE TABLE `tnota` (
#
CREATE TABLE `tnota_inc` (
`id_nota_inc` mediumint(8) unsigned NOT NULL auto_increment,
`id_incidencia` mediumint(9) NOT NULL default '0',
`id_nota` mediumint(9) NOT NULL default '0',
`id_incidencia` mediumint(8) unsigned NOT NULL default '0',
`id_nota` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`id_nota_inc`)
) TYPE=InnoDB;
@ -334,18 +333,18 @@ CREATE TABLE `torigen` (
# Table: 'tperfil'
#
CREATE TABLE `tperfil` (
`id_perfil` int(10) unsigned NOT NULL auto_increment,
`id_perfil` mediumint(8) unsigned NOT NULL auto_increment,
`name` varchar(60) NOT NULL default '',
`incident_edit` int(11) NOT NULL default '0',
`incident_view` int(11) NOT NULL default '0',
`incident_management` int(11) NOT NULL default '0',
`agent_view` int(11) NOT NULL default '0',
`agent_edit` int(11) NOT NULL default '0',
`alert_edit` int(11) NOT NULL default '0',
`user_management` int(11) NOT NULL default '0',
`db_management` int(11) NOT NULL default '0',
`alert_management` int(11) NOT NULL default '0',
`pandora_management` int(11) NOT NULL default '0',
`incident_edit` tinyint(3) unsigned NOT NULL default '0',
`incident_view` tinyint(3) unsigned NOT NULL default '0',
`incident_management` tinyint(3) unsigned NOT NULL default '0',
`agent_view` tinyint(3) unsigned NOT NULL default '0',
`agent_edit` tinyint(3) unsigned NOT NULL default '0',
`alert_edit` tinyint(3) unsigned NOT NULL default '0',
`user_management` tinyint(3) unsigned NOT NULL default '0',
`db_management` tinyint(3) unsigned NOT NULL default '0',
`alert_management` tinyint(3) unsigned NOT NULL default '0',
`pandora_management` tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (`id_perfil`)
) TYPE=InnoDB;
@ -356,14 +355,14 @@ CREATE TABLE `tserver` (
`id_server` int(10) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
`ip_address` varchar(100) NOT NULL default '',
`status` int(11) NOT NULL default '0',
`status` tinyint(3) unsigned NOT NULL default '0',
`laststart` datetime NOT NULL default '0000-00-00 00:00:00',
`keepalive` datetime NOT NULL default '0000-00-00 00:00:00',
`snmp_server` int(6) NOT NULL default '1',
`network_server` int(11) NOT NULL default '0',
`data_server` int(11) NOT NULL default '0',
`master` smallint(6) NOT NULL default '1',
`checksum` smallint(6) NOT NULL default '1',
`snmp_server` tinyint(3) unsigned NOT NULL default '1',
`network_server` tinyint(3) unsigned NOT NULL default '0',
`data_server` tinyint(3) unsigned NOT NULL default '0',
`master` tinyint(3) unsigned NOT NULL default '1',
`checksum` tinyint(3) unsigned NOT NULL default '1',
`description` varchar(255) NOT NULL default '',
PRIMARY KEY (`id_server`)
) TYPE=InnoDB;
@ -387,7 +386,7 @@ CREATE TABLE `tsesion` (
CREATE TABLE `ttipo_modulo` (
`id_tipo` smallint(5) unsigned NOT NULL auto_increment,
`nombre` varchar(100) NOT NULL default '',
`categoria` int(11) NOT NULL default '0',
`categoria` tinyint(3) unsigned NOT NULL default '0',
`descripcion` varchar(100) NOT NULL default '',
`icon` varchar(100) default NULL,
PRIMARY KEY (`id_tipo`)
@ -397,16 +396,16 @@ CREATE TABLE `ttipo_modulo` (
# Table: 'ttrap'
#
CREATE TABLE `ttrap` (
`id_trap` bigint(20) unsigned NOT NULL auto_increment,
`id_trap` int(10) unsigned NOT NULL auto_increment,
`source` varchar(50) NOT NULL default '',
`oid` varchar(255) NOT NULL default '',
`oid_custom` varchar(255) default '',
`type` int(11) NOT NULL default '0',
`type` tinyint(3) unsigned NOT NULL default '0',
`type_custom` varchar(100) default '',
`value` varchar(255) default '',
`value_custom` varchar(255) default '',
`alerted` smallint(6) NOT NULL default '0',
`status` smallint(6) NOT NULL default '0',
`alerted` tinyint(3) unsigned NOT NULL default '0',
`status`tinyint(3) unsigned NOT NULL default '0',
`id_usuario` varchar(150) default '',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id_trap`)
@ -430,10 +429,10 @@ CREATE TABLE `tusuario` (
# Table: 'tusuario_perfil'
#
CREATE TABLE `tusuario_perfil` (
`id_up` bigint(20) unsigned NOT NULL auto_increment,
`id_up` int(10) unsigned NOT NULL auto_increment,
`id_usuario` varchar(100) NOT NULL default '',
`id_perfil` int(20) NOT NULL default '0',
`id_grupo` int(11) NOT NULL default '0',
`id_perfil` tinyint(3) unsigned NOT NULL default '0',
`id_grupo` tinyint(3) unsigned NOT NULL default '0',
`assigned_by` varchar(100) NOT NULL default '',
PRIMARY KEY (`id_up`)
) TYPE=InnoDB;

View File

@ -25,6 +25,36 @@ include ("../include/functions.php");
include ("../include/functions_db.php");
require ("../include/languages/language_".$language_code.".php");
function graphic_error () {
Header("Content-type: image/png");
$imgPng = imageCreateFromPng("../images/image_problem.png");
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
imagePng($imgPng);
}
function dame_fecha_grafico ($mh, $format){
// Date 24x7x30 hours ago (one month)
$m_year = date("Y", time()-$mh*60);
$m_month = date("m", time()-$mh*60);
$m_month_word = date("M", time()-$mh*60);
$m_day = date ("d", time()-$mh*60);
$m_hour = date ("H", time()-$mh*60);
$m_min = date ("i", time()-$mh*60);
switch ($format) {
case 1: $m = $m_month."/".$m_day." ".$m_hour.":".$m_min;
break;
case 2: $m = $m_year."-".$m_month."-".$m_day;
break;
case 3: $m = $m_day."th -".$m_month_word."\n".$m_year;
break;
case 4: $m = $m_day."th -".$m_month_word;
break;
}
return $m;
}
function dame_fecha($mh){
// Return a MySQL timestamp date, formatted with actual date MINUS X minutes, given as parameter
$m_year = date("Y", time()-$mh*60);
@ -36,254 +66,20 @@ function dame_fecha($mh){
return $m;
}
function dame_fecha_grafico($mh){ // Devuelve fecha formateada en funcion de un numero de minustos antes de la fecha actual
// Date 24x7x30 hours ago (one month)
$m_year = date("Y", time()-$mh*60);
$m_month = date("m", time()-$mh*60);
$m_day = date ("d", time()-$mh*60);
$m_hour = date ("H", time()-$mh*60);
$m_min = date ("i", time()-$mh*60);
$m = $m_month."/".$m_day." ".$m_hour.":".$m_min;
return $m;
}
function dame_fecha_grafico_timestamp ($timestamp) { return date('d/m H:i', $timestamp); }
function grafico_modulo_sparse_ORIGINAL(
$id_agente_modulo,
$periodo, $intervalo,
$etiqueta, $color,
$zoom=1, $draw_events=0){
function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $draw_events,
$width, $height , $title, $unit_name ) {
include ("../include/config.php");
require ("../include/languages/language_".$language_code.".php");
require_once 'Image/Graph.php';
// Where periodo is lapse of time in minutes that we want to show in a
// graph, this could be a week, 1 hour, a day, etc
// 30.06.06 dervitx:
// $draw_events behaves as a boolean: 1 implies that events for that
// module in that period of time will be represented with a line in the graph
$fechatope = dame_fecha($periodo); // Max old-date limit
$resolution = $config_graph_res * 50; // Number of "slices" we want in graph
$horasint = $periodo / $intervalo; // Each intervalo is $horasint seconds length
$nombre_agente = dame_nombre_agente_agentemodulo($id_agente_modulo);
$id_agente = dame_agente_id($nombre_agente);
$nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo);
// Para crear las graficas vamos a crear un array de Ax4 elementos, donde
// A es el numero de posiciones diferentes en la grafica (30 para un mes, 7 para una semana, etc)
// y los 4 valores en el ejeY serian los detallados a continuacion:
// Rellenamos la tabla con un solo select, y los calculos se hacen todos sobre memoria
// esto acelera el tiempo de calculo al maximo, aunque complica el algoritmo :-)
// Where
// intervalo - This is the number of "rows" we are divided the time to fill data.
// more interval, more resolution, and slower.
// periodo - Gap of time, in seconds. This is now to (now-periodo) secs
// Init tables
for ($x = 0; $x <= $intervalo; $x++) {
$valores[$x][0] = 0; // [0] Value (counter)
$valores[$x][2] = dame_fecha($horasint * $x); // [2] Rango superior de fecha para ese rango
$valores[$x][3] = dame_fecha($horasint*($x+1)); // [3] Rango inferior de fecha para ese rango
$etiq_base[] = dame_fecha_grafico($horasint * $x);
$valores_min[$x]= 0; $valores_max[$x]=0;
}
// Get the last value, the last known value (more recent)
$sql1 = "SELECT * FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." ORDER BY timestamp DESC limit 1";
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$old_value=$row["datos"];
$old_date = $row["timestamp"];
} else {
$old_value=0;
}
// Get the last known date (most near to now) for lastcontact in this module
$sql1 = "SELECT * FROM tagente_estado WHERE id_agente_modulo = ".$id_agente_modulo;
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$old_date = $row["timestamp"];
}
// Get the last first date (most far to now) for lastcontact in this module
// there is no data far away, so value must be 0 before this date
$sql1 = "SELECT * FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." order by timestamp asc limit 1";
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$first_date = $row["timestamp"];
}
// Get the oldest known date just out of lower bound for global interval
$sql1 = "SELECT * FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." and timestamp < '".$fechatope."' order by timestamp desc limit 1";
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$old_date_interval = $row["timestamp"];
$old_data_interval = $row["datos"];
$old_data_used = 0;
}
for ($i = $intervalo; $i >= 0; $i--){
$sql1 = "SELECT AVG(datos),MAX(datos),MIN(datos) FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." and timestamp >= '".$valores[$i][3]."' and timestamp < '".$valores[$i][2]."'";
$sql2 = "SELECT datos FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." and timestamp >= '".$valores[$i][3]."' and timestamp < '".$valores[$i][2]."' order by timestamp desc limit 1";
$result2=mysql_query($sql2);
$result=mysql_query($sql1);
$row=mysql_fetch_array($result);
$row2=mysql_fetch_array($result2);
#echo "AVG MAX MIN (old_value) ".$valores[$i][3]."<br>";
#echo $row[0]." ".$row[1]." ".$row[2]." old-".$old_value." ".$old_date;
#echo "<br><br>";
if ($row[0] != ""){
$data_item=$row[0];
$valores_max[$i] = $row[1];
$valores_min[$i] = $row[2];
if ($data_item == ""){
$data_item = $old_value;
$valores_min[$i] = $old_value;
$valores_max[$i] = $old_value;
} else {
$old_value = $row2[0]; // Last data
#$old_date = $valores[$i][3];
}
$old_data_used =1; // Dont use "previous value for this interval" anymore // if a real value its in database.
} else {
// Interval more recent that last module -contact-
if ((strtotime($old_date) < strtotime($valores[$i][2]))){
$data_item = 0;
$valores_min[$i] = 0;
$valores_max[$i] = 0;
// Get data from lower limit of this interval
} elseif ((isset($old_date_interval)) AND (strtotime($old_date_interval) < strtotime($valores[$i][2])) AND ($old_data_used == 0)) {
$data_item = $old_data_interval;
$valores_min[$i] = $data_item;
$valores_max[$i] = $data_item;
} elseif ( strtotime($valores[$i][2]) < strtotime($first_date)){
$data_item = 0;
$valores_min[$i] = 0;
$valores_max[$i] = 0;
} else {
$data_item = $old_value;
$valores_min[$i] = $old_value;
$valores_max[$i] = $old_value;
}
}
$valores[$i][0]=$data_item;
}
$sql1 = "SELECT MAX(datos) FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." AND timestamp > '".$valores[0][2]."' AND timestamp > '".$valores[$intervalo][3]."'";
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$valor_maximo=$row[0];
if ($valor_maximo == ""){
$valor_maximo = 0;
}
} else {
$valor_maximo=0;
}
// Invert data order in graph
if ($config_graph_order == 1){
$valor_maximo=0;$valor_minimo=0;
for ($x = 0; $x <=$intervalo; $x++) {
$grafica[$x]=$valores[$x][0];
if ($valores_max[$x] > $valor_maximo){
$valor_maximo = $valores_max[$x];
}
if ($valores_min[$x] < $valor_minimo){
$valor_minimo = $valores_min[$x];
}
}
} else {
// Invert data
$valor_maximo=0;$valor_minimo=0;
for ($x = $intervalo; $x>=0; $x--) {
$grafica[$x]=$valores[$intervalo-$x][0];
$valores_max2[$x] = $valores_max[$intervalo-$x];
$valores_min2[$x] = $valores_min[$intervalo-$x];
if ($valores_max[$x] > $valor_maximo){
$valor_maximo = $valores_max[$x];
}
if ($valores_min[$x] < $valor_minimo){
$valor_minimo = $valores_min[$x] - 50;
}
$etiq_base2[$intervalo-$x]=$etiq_base[$x];
}
$valores_max = $valores_max2;
$valores_min = $valores_min2;
$etiq_base = $etiq_base2;
}
// 29.06.06 dervitx
// let's see if the module in this agent has some events associated
// if it has, let's fill $datax and $datay to scatter the events
// in the graphic
if ($draw_events) {
$initial_time = strtotime($fechatope);
$graph_duration = $periodo * 60; // in seconds
$final_time = $initial_time + $graph_duration; // now
// careful here! next sql sentence looks for the module by name in the "evento" field
// tevento database table SHOULD have module_id !!
$sql1 = "SELECT * FROM tevento WHERE id_agente = ".$id_agente." and timestamp > '".$fechatope."' and evento like '%" . $nombre_modulo . "%' ";
// we populate two arrays with validated and no validated events of the module:
// $datax[1] and $datax[0], respectively. There are $datay arrays for y values.
if ($result=mysql_query($sql1)){
while ($row=mysql_fetch_array($result)) {
if ($row["estado"]) { $estado=1; } else { $estado=0; }
$datax[$estado][count($datax[$estado])] = strtotime( $row["timestamp"] );
$datay[$estado][count($datay[$estado])] = ceil($valor_maximo / 6) + $valor_maximo;
}
}
}
// end 29.06.06 dervitx
$Graph_param = array (
'title' => " $etiqueta - $nombre_agente / $nombre_modulo",
'size_x' => intval(550 * $zoom) ,
'size_y' => intval(220 * $zoom) ,
'id_agente_modulo' => $id_agente_modulo ,
'valor_maximo' => $valor_maximo ,
'periodo' => $periodo ,
'draw_events' => 1
);
modulo_grafico_draw ( $Graph_param,
$etiq_base,
array('Maximum','Average','Minimum'),
array ( &$valores_max, &$grafica, &$valores_min ),
$datax
); // Replaced pass by reference (slerena, 11 Jul06)
/* PHP Warning:  Call-time pass-by-reference has
been deprecated - argument pass
ed by value;  If you would like to pass it by reference, modify the
declaration of [runtime function
  name]().  If you would like to enable call-time pass-by-reference,
you can set allow_call_time_pass
_reference to true in your INI file.  However, future versions may not
support this any longer.  */
}
function grafico_modulo_sparse(
$id_agente_modulo,
$periodo, $intervalo,
$etiqueta, $color,
$zoom, $draw_events,
$width, $height , $title ){
include ("../include/config.php");
require ("../include/languages/language_".$language_code.".php");
include 'Image/Graph.php';
// Where periodo is lapse of time in minutes that we want to show in a
// graph, this could be a week, 1 hour, a day, etc
// 30.06.06 dervitx:
// $draw_events behaves as a boolean: 1 implies that events for that
// module in that period of time will be represented with a line in the graph
$fechatope = time - $periodo; // limit date
$horasint = $periodo / $intervalo; // Each intervalo is $horasint seconds length
//$unix_timestamp = strtotime($mysql_timestamp) // Convert MYSQL format tio utime
$fechatope = time() - $periodo; // limit date
$horasint = $periodo / $resolution; // Each intervalo is $horasint seconds length
$nombre_agente = dame_nombre_agente_agentemodulo($id_agente_modulo);
$id_agente = dame_agente_id($nombre_agente);
$nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo);
@ -293,242 +89,172 @@ function grafico_modulo_sparse(
// periodo - Gap of time, in seconds. This is now to (now-periodo) secs
// Init tables
for ($x = 0; $x <= $intervalo; $x++) {
$valores[$x][0] = 0; // real value
$valores[$x][1] = 0; // min
$valores[$x][2] = $horasint * $x; // [2] Top limit for this range
$valores[$x][3] = $horasint*($x+1); // [3] Botom limit
$etiq_base[] = dame_fecha_grafico($horasint * $x);
$valores[$x][5] = 0; // max
for ($x = 0; $x <= $resolution; $x++) {
$valores[$x][0] = 0; // SUM of all values for this interval
$valores[$x][1] = 0; // counter
$valores[$x][2] = $fechatope + ($horasint * $x); // [2] Top limit for this range
$valores[$x][3] = $fechatope + ($horasint*($x+1)); // [3] Botom limit
$valores[$x][4] = 0; // MIN
$valores[$x][5] = 0; // MAX
}
// Init other general variables
$max_value = 0;
$min_value = 9999999999999;
// Get the last value, the last known value (the more recent or last stored)
$sql1 = "SELECT * FROM tagente_estado WHERE id_agente_modulo = ".$id_agente_modulo;
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$old_value=$row["datos"];
$old_date = $row["utimestamp"];
} else {
$old_value=0;
}
$min_value = 0;
// Get the last first date (most far to now) for lastcontact in this module
// there is no data far away, so value must be 0 before this date
$sql1 = "SELECT * FROM tagente_datos WHERE id_agente_modulo = ".$id_agente_modulo." order by timestamp asc limit 1";
if ($result=mysql_query($sql1)){
$row=mysql_fetch_array($result);
$first_date = $row["timestamp"];
}
for ($i = $intervalo; $i >= 0; $i--){
$sql1 = "SELECT AVG(datos),MAX(datos),MIN(datos) FROM tagente_datos
WHERE id_agente_modulo = ".$id_agente_modulo." AND utimestamp >= ".$valores[$i][3]."' and utimestamp < ".$valores[$i][2];
// DEBUG ONLY (to get number of items for this graph)
/*
// Make "THE" query. Very HUGE.
$sql1="SELECT COUNT(datos) FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope";
$result=mysql_query($sql1);
$row=mysql_fetch_array($result);
#echo "AVG MAX MIN (old_value) ".$valores[$i][3]."<br>";
#echo $row[0]." ".$row[1]." ".$row[2]." old-".$old_value." ".$old_date;
#echo "<br><br>";
if ($row[0] != ""){
$valores[$i][0] = $row[0];
$valores[$i][1] = $row[2];
$valores[$i][5] = $row[1];
}
// Check max. value
if ($valores[$i][5] > $max_value)
$max_value = $valores[$i][5];
// Check min. value... not needed I think..
// if ($valores[$i][1] < $min_value)
//$min_value = $valores[$i][1];
}
// 29.06.06 dervitx
// let's see if the module in this agent has some events associated
// if it has, let's fill $datax and $datay to scatter the events
// in the graphic
/*
if ($draw_events) {
$initial_time = strtotime($fechatope);
$graph_duration = $periodo * 60; // in seconds
$final_time = $initial_time + $graph_duration; // now
// careful here! next sql sentence looks for the module by name in the "evento" field
// tevento database table SHOULD have module_id !!
$sql1 = "SELECT * FROM tevento WHERE id_agente = ".$id_agente." and timestamp > '".$fechatope."' and evento like '%" . $nombre_modulo . "%' ";
// we populate two arrays with validated and no validated events of the module:
// $datax[1] and $datax[0], respectively. There are $datay arrays for y values.
if ($result=mysql_query($sql1)){
while ($row=mysql_fetch_array($result)) {
if ($row["estado"]) { $estado=1; } else { $estado=0; }
$datax[$estado][count($datax[$estado])] = strtotime( $row["timestamp"] );
$datay[$estado][count($datay[$estado])] = ceil($valor_maximo / 6) + $valor_maximo;
$title=$title." [C] ".$row[0];
*/
$previous=0;
// Get the first data outsite (to the left---more old) of the interval given
$sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope ORDER BY utimestamp DESC LIMIT 1";
$result=mysql_query($sql1);
if ($row=mysql_fetch_array($result))
$previous=$row[0];
$sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
$datos = $row[0];
$utimestamp = $row[1];
if ($datos > 0) {
for ($i=0; $i <= $resolution; $i++) {
if ( ($utimestamp <= $valores[$i][3]) && ($utimestamp >= $valores[$i][2]) ){
$valores[$i][0]=$valores[$i][0]+$datos;
$valores[$i][1]++;
// Init min value
if ($valores[$i][4] == 0)
$valores[$i][4] = $datos;
else {
// Check min value
if ($datos < $valores[$i][4])
$valores[$i][4] = $datos;
}
// Check max value
if ($datos > $valores[$i][5])
$valores[$i][5] = $datos;
$i = $resolution+1; // BREAK FOR
}
}
}
}
}
// end 29.06.06 dervitx
*/
/*
$Graph_param = array (
'title' => " $etiqueta - $nombre_agente / $nombre_modulo",
'size_x' => intval(550 * $zoom) ,
'size_y' => intval(220 * $zoom) ,
'id_agente_modulo' => $id_agente_modulo ,
'valor_maximo' => $max_value ,
'periodo' => $periodo ,
'draw_events' => 0
);
*/
/* modulo_grafico_draw ( $Graph_param,
$etiq_base,
array('Maximum','Average','Minimum'),
array ( &$valores_max, &$grafica, &$valores_min ),
$datax
); // Replaced pass by reference (slerena, 11 Jul06)
/* PHP Warning:  Call-time pass-by-reference has
been deprecated - argument pass
ed by value;  If you would like to pass it by reference, modify the
declaration of [runtime function
  name]().  If you would like to enable call-time pass-by-reference,
you can set allow_call_time_pass
_reference to true in your INI file.  However, future versions may not
support this any longer.  */
/* function modulo_grafico_draw( $MGD_param, $MGD_labels, $MGD_data_name, $MGD_data, $MGD_event_data ) {
*/
// draws the graph corresponding to the data of a module
// arguments:
// $MGD_param = array (
// 'title' => title ,
// 'size_x' => size of the graphic ,
// 'size_y' => ,
// 'id_agente_modulo' => agent-module id ,
// 'valor_maximo' => maximum value for y axis ,
// 'periodo' => interval ,
// 'draw_events' => draw events if equals to 1
// );
// Calculate Average value for $valores[][0]
for ($x =0; $x <= $resolution; $x++) {
if ($valores[$x][1] > 0)
$valores[$x][0] = $valores[$x][0]/$valores[$x][1];
else {
$valores[$x][0] = $previous;
$valores[$x][4] = $previous;
$valores[$x][5] = $previous;
}
// Get max value for all graph
if ($valores[$x][5] > $max_value)
$max_value = $valores[$x][5];
// Take prev. value
// TODO: CHeck if there are more than 24hours between
// data, if there are > 24h, module down.
$previous = $valores[$x][0];
}
// &$MGD_labels = array ( $etiq_base ) // labels
// $MGD_data_name = array ( name1, name2, ... ) // name of the datasets (for the legend only)
// $MGD_data = array ( &array(data1), &array(data2), ... ); // data to be represented
// $MGD_event_data = array ( (notvalidated) &array(data_x), (validated) => &array(data_x) );
// initializing parameters
$count_datasets = count( $MGD_data_name ); // number of datasets to represent
// creating the graph with PEAR Image_Graph
$Graph =& Image_Graph::factory('graph',
array( $width,
$height
)
);
// Create graph
// *************
$Graph =& Image_Graph::factory('graph', array($width, $height));
// add a TrueType font
$Font =& $Graph->addNew('font', $config_fontpath);
$Font->setSize(6);
$Graph->setFont($Font);
if ($periodo == 86400)
$title_period = "Last day";
elseif ($periodo == 604800)
$title_period = "Last week";
elseif ($periodo == 3600)
$title_period = "Last hour";
elseif ($periodo == 2419200)
$title_period = "Last month";
else
$title_period = "Last ".($periodo / (3600*24))." days";
$Graph->add(
Image_Graph::vertical(
Image_Graph::vertical(
$Title = Image_Graph::factory('title', array ($title , 10)),
Image_Graph::horizontal(
$Plotarea = Image_Graph::factory('plotarea','axis'),
$Legend = Image_Graph::factory('legend'),
80
),
5
)
);
$Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
$Grid =& $Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_X);
$Grid->setBackgroundColor('silver@0.6');
$Grid->setBorderColor('black');
$Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_Y);
// the next grid is only necessary for drawing the right black line of the PlotArea
$Grid_sec =& $Plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
$Grid_sec->setBorderColor('black');
$dataset[0] = Image_Graph::factory('dataset');
$dataset[0]->setName("Avg.");
$dataset[1] = Image_Graph::factory('dataset');
$dataset[1]->setName("Min.");
$dataset[2] = Image_Graph::factory('dataset');
$dataset[2]->setName("Max.");
$Title = Image_Graph::factory('title', array(' Pandora FMS Graph - '.$title_period, 10)),
$Subtitle = Image_Graph::factory('title', array(' '.$title, 7)),
90
),
Image_Graph::horizontal(
$Plotarea = Image_Graph::factory('plotarea'),
$Legend = Image_Graph::factory('legend'),
85
),
15)
);
$Legend->setPlotarea($Plotarea);
$Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
$Subtitle->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
// Create the dataset
// Merge data into a dataset object (sancho)
// $Dataset =& Image_Graph::factory('dataset');
$dataset[0] = Image_Graph::factory('dataset');
$dataset[0]->setName("Max.");
$dataset[1] = Image_Graph::factory('dataset');
$dataset[1]->setName("Avg.");
$dataset[2] = Image_Graph::factory('dataset');
$dataset[2]->setName("Min.");
// ... and populated with data ...
for ($cc=0; $cc<$intervalo; $cc++) {
$tdate = strtotime( $valores[$cc][2] );
$dataset[0]->addPoint($tdate, $valores[$cc][0]);
$dataset[1]->addPoint($tdate, $valores[$cc][1]);
$dataset[2]->addPoint($tdate, $valores[$cc][5]);
}
// ... and added to the Graph
$Plot =& $Plotarea->addNew('Image_Graph_Plot_Area', array($dataset));
// some other properties of the Graph
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$FillArray->addColor('blue');
$FillArray->addColor('orange');
$FillArray->addColor('yellow');
$Plot->setFillStyle($FillArray);
$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
$AxisX->setLabelInterval($periodo*60/10);
$AxisX->setFontAngle(45);
$AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'dame_fecha_grafico_timestamp'));
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
$AxisY->forceMaximum(ceil($max_value / 4) + $max_value);
// let's draw the alerts zones
$sql1 = "SELECT dis_min, dis_max FROM talerta_agente_modulo WHERE id_agente_modulo = ".$id_agente_modulo;
if ($result=mysql_query($sql1)){
while ($row=mysql_fetch_array($result)) {
$Marker_alertzone =& $Plotarea->addNew('Image_Graph_Axis_Marker_Area', IMAGE_GRAPH_AXIS_Y);
$Marker_alertzone->setFillColor('green@0.2');
$Marker_alertzone->setLowerBound($row["dis_min"]);
$Marker_alertzone->setUpperBound($row["dis_max"]);
}
}
for ($cc=0; $cc <= $resolution; $cc++) {
$tdate = date('d/m', $valores[$cc][2])."\n".date('H:i', $valores[$cc][2]);
$dataset[1]->addPoint($tdate, $valores[$cc][0]);
$dataset[0]->addPoint($tdate, $valores[$cc][5]);
$dataset[2]->addPoint($tdate, $valores[$cc][4]);
//echo "$cc -- $tdate - ".$valores[$cc][0]." -- ".$valores[$cc][4]."--".$valores[$cc][5]."<br>";
// if there are some events to draw let's scatter them!
/*
if ($MGD_param['draw_events']) {
for ($cc=1; $cc>=0; $cc--) {
if (isset($MGD_event_data[$cc])) {
$Dataset_events =& Image_Graph::factory('dataset');
$Dataset_events->setName($cc?'Validated events':'Not valid. events');
for ($nn=0; $nn<count($MGD_event_data[$cc]); $nn++) {
$Dataset_events->addPoint(
$MGD_event_data[$cc][$nn],
ceil($MGD_param['valor_maximo'] / 7) + $MGD_param['valor_maximo']);
}
$Plot =& $Plotarea->addNew('Plot_Impulse', array(&$Dataset_events));
$Plot->setLineColor($cc?'green@0.5':'red@0.5');
$Marker_event =& Image_Graph::factory('Image_Graph_Marker_Diamond');
$Plot->setMarker($Marker_event);
$Marker_event->setFillColor($cc?'green@0.5':'red@0.5');
$Marker_event->setLineColor('black');
}
}
}
*/
$Graph->done();
// 30.06.06 dervitx end
if ($max_value > 0){
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('area', array(&$dataset));
$Plot->setLineColor('yellow@0.1');
$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
// $AxisX->Hide();
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
$AxisY->setLabelOption("showtext",true);
$AxisY->setLabelInterval(ceil($max_value / 5));
$AxisY->showLabel(IMAGE_GRAPH_LABEL_ZERO);
if ($unit_name != "")
$AxisY->setTitle($unit_name, 'vertical');
$AxisX->setLabelInterval($resolution / 10);
//$AxisY->forceMinimum($minvalue);
$AxisY->forceMaximum($max_value+($max_value/12)) ;
$GridY2 =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
$GridY2->setLineColor('gray');
$GridY2->setFillColor('lightgray@0.05');
// set line colors
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$Plot->setFillStyle($FillArray);
$FillArray->addColor('yellow@0.5'); // MAX
$FillArray->addColor('orange@0.6'); // AVG
$FillArray->addColor('brown@0.7'); // MIN
$AxisY_Weather =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
$Graph->done();
} else
graphic_error ();
}
function graphic_agentmodules($id_agent) {
function graphic_agentmodules($id_agent, $width, $height) {
include ("../include/config.php");
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_pie.php");
include ("jpgraph/jpgraph_pie3d.php");
require_once 'Image/Graph.php';
require ("../include/languages/language_".$language_code.".php");
$sql1="SELECT * FROM ttipo_modulo";
@ -562,55 +288,85 @@ function graphic_agentmodules($id_agent) {
$mayor_data = $data[$a];
}
$bx=0;
for ($a=0;$a < sizeof($data_label); $a++)
for ($a=0;$a < sizeof($data_label); $a++){
if ($data[$a] > 0){
$data_label2[$bx] = $data_label[$a];
$data2[$bx] = $data[$a];
$bx++;
}
$graph = new PieGraph(280,120,"auto");
// $graph->SetMarginColor('white@0.2');
$graph->SetMargin(15,4,2,2);
$graph->SetMarginColor('#f5f5f5');
$graph->img->SetCanvasColor('#f5f5f5');
$graph->SetFrame(True,'#f5f5f5',0);
$graph->SetAlphaBlending();
if ($cx > 1){
$p1 = new PiePlot3D($data2);
$p1->SetLegends($data_label2);
} else {
$data_void[]="1";
$legend_void[]="N/A";
$p1 = new PiePlot3D($data_void);
$p1->SetLegends($legend_void);
}
$p1->ExplodeSlice($mayor);
$p1->SetSize(0.5);
$p1->SetCenter(0.3);
$p1->value->SetColor("#f5f5f5"); // Invisible
$graph->legend->SetAbsPos(5,5,'right','top');
$graph->Add($p1);
$graph->img->SetAntiAliasing();
$graph->Stroke();
if ($cx > 1){
// create the graph
$Graph =& Image_Graph::factory('graph', array($width, $height));
// add a TrueType font
$Font =& $Graph->addNew('font', $config_fontpath);
// set the font size to 7 pixels
$Font->setSize(7);
$Graph->setFont($Font);
// create the plotarea
$Graph->add(
Image_Graph::horizontal(
$Plotarea = Image_Graph::factory('plotarea'),
$Legend = Image_Graph::factory('legend'),
50
)
);
$Legend->setPlotarea($Plotarea);
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset1 =& Image_Graph::factory('dataset');
for ($a=0;$a < sizeof($data2); $a++){
$Dataset1->addPoint($data_label2[$a], $data2[$a]);
}
$Plot =& $Plotarea->addNew('pie', $Dataset1);
$Plotarea->hideAxis();
// create a Y data value marker
$Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL);
// create a pin-point marker type
$PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(1, &$Marker));
// and use the marker on the 1st plot
$Plot->setMarker($PointingMarker);
// format value marker labels as percentage values
$Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%'));
$Plot->Radius = 15;
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$Plot->setFillStyle($FillArray);
$FillArray->addColor('green@0.7');
$FillArray->addColor('yellow@0.7');
$FillArray->addColor('red@0.7');
$FillArray->addColor('orange@0.7');
$FillArray->addColor('blue@0.7');
$FillArray->addColor('purple@0.7');
$FillArray->addColor('lightgreen@0.7');
$FillArray->addColor('lightblue@0.7');
$FillArray->addColor('lightred@0.7');
$FillArray->addColor('grey@0.6', 'rest');
$Plot->explode(6);
$Plot->setStartingAngle(145);
// output the Graph
$Graph->done();
} else
graphic_error ();
}
function graphic_agentaccess($id_agent, $periodo){
function graphic_agentaccess($id_agent, $periodo, $width, $height){
include ("../include/config.php");
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_line.php");
require_once 'Image/Graph.php';
require ("../include/languages/language_".$language_code.".php");
$color ="#437722"; // Green pandora 1.1 octopus color
/*
$agent_interval = give_agentinterval($id_agent);
$intervalo = 30 * $config_graph_res; // Desired interval / range between dates
$intervalo_real = (86400 / $agent_interval); // 60x60x24 secs
if ($intervalo_real < $intervalo ) {
$intervalo = $intervalo_real;
}
}*/
$intervalo = 24;
$fechatope = dame_fecha($periodo);
$horasint = $periodo / $intervalo;
@ -645,58 +401,50 @@ function graphic_agentaccess($id_agent, $periodo){
$valor_maximo = 0;
for ($i = 0; $i < $intervalo; $i++) { // 30 entries in graph, one by day
$grafica[]=$valores[$i][0];
if ($valores[$i][0] > $valor_maximo)
$valor_maximo = $valores[$i][0];
}
// Create graph
$graph = new Graph(280,70);
$graph-> img-> SetImgFormat("png"); // GIF was causing odd problems in Redhat EL 4
$graph->SetMargin(25,5,3,3);
$graph->SetScale("textlin",0,0,0,0);
$graph->SetAlphaBlending(true);
// Create graph
// create the graph
$Graph =& Image_Graph::factory('graph', array($width, $height));
// add a TrueType font
$Font =& $Graph->addNew('font', $config_fontpath);
$Font->setSize(6);
$Graph->setFont($Font);
$Graph->add(
Image_Graph::vertical(
Image_Graph::factory('title', array("", 2)),
$Plotarea = Image_Graph::factory('plotarea'),
0)
);
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset =& Image_Graph::factory('dataset');
for ($a=0;$a < sizeof($grafica); $a++){
$Dataset->addPoint($a,$grafica[$a]);
}
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('area', array(&$Dataset));
// set a line color
$Plot->setLineColor('green');
// set a standard fill style
$Plot->setFillColor('green@0.5');
// $Plotarea->hideAxis();
$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
// $AxisX->Hide();
$graph->yaxis->HideTicks(false);
$graph->xaxis->HideTicks(true);
$graph->xaxis->HideLabels(true);
$graph->yaxis->HideLabels(false);
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
$AxisY->setLabelOption("showtext",true);
$AxisY->setLabelInterval($valor_maximo / 2);
$graph->SetMarginColor('#f5f5f5');
$graph->img->SetCanvasColor('#f5f5f5');
$graph->SetFrame(True,'#f5f5f5',0);
// Linea del eje Y de color
// $graph->ygrid->SetFill(true,'#EFEFEF@0.6','#BBCCFF@0.6');
// $graph->xgrid->Show();
// Titulo guay
//$graph->tabtitle->Set("Access Access");
//$graph->xaxis->SetTickLabels("Que ostias");
$graph->xaxis->SetFont(FF_FONT0);
$graph->xaxis->SetLabelAngle(90);
//$graph->xaxis->SetTextLabelInterval(ceil($intervalo / 10));
$graph->yaxis->SetFont(FF_FONT0);
// Creacion de la linea de datos
$AxisX->setLabelInterval($intervalo / 5);
$line1=new LinePlot($grafica);
$line1->SetColor($color);
$line1->SetWeight(1);
$line1->SetFillColor($color."@0.2");
//$line1->SetLegend($lang_label["med"]);
// A�dimos la linea a la imagen
$line1->SetFillColor($color."@0.2");
$graph->Add($line1);
//$graph->legend->Pos(0.01,0.2,"right","center");
// Lineas eje Y por encima del grafico
//$graph->SetGridDepth(DEPTH_BACK);
// Antialias
//$graph->img->SetAntiAliasing();
// Mostramos la imagen
$graph->Stroke();
$GridY2 =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
$GridY2->setLineColor('green');
$GridY2->setFillColor('green@0.2');
$AxisY2 =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
$Graph->done();
}
@ -1637,7 +1385,6 @@ function graphic_test ($id, $period, $interval, $label, $width, $height){
}
// **************************************************************************
// **************************************************************************
// MAIN Code - Parse get parameters
@ -1653,10 +1400,10 @@ else
$tipo = ""; // 1 day default period
if (isset($_GET["periodo"]))
$periodo = entrada_limpia($_GET["periodo"]);
if (isset($_GET["period"]))
$period = entrada_limpia($_GET["period"]);
else
$periodo = 86400; // 1 day default period
$period = 86400; // 1 day default period
if (isset($_GET["intervalo"]))
$intervalo = entrada_limpia($_GET["intervalo"]);
@ -1670,7 +1417,7 @@ else
if (isset($_GET["width"]))
$width = entrada_limpia($_GET["width"]);
else
$width = 300;
$width = 450;
if (isset($_GET["height"]))
$height = entrada_limpia ($_GET["height"]);
@ -1699,7 +1446,14 @@ if (isset($_GET['zoom']) and
$zoom = $_GET['zoom'] / 100 ;
else
$zoom = 1;
// Unit_name
if (isset($_GET["unit_name"]))
$unit_name = entrada_limpia ($_GET["unit_name"]);
else
$unit_name = "";
// Draw Events ?
if ( isset($_GET["draw_events"]) and $_GET["draw_events"]==0 )
$draw_events = 0;
@ -1709,9 +1463,10 @@ if ( isset($_GET["draw_events"]) and $_GET["draw_events"]==0 )
// Image handler
// *****************
if (isset($_GET["tipo"])){
if ($_GET["tipo"] == "sparse"){
grafico_modulo_sparse($id, $periodo, $intervalo, $label, $color, $zoom, $draw_events, $width, $height , $title );
if ($_GET["tipo"] == "sparse"){
grafico_modulo_sparse($id, $period, $draw_events, $width, $height , $label, $unit_name);
}
elseif ($_GET["tipo"] =="estado_incidente")
grafico_incidente_estados();
@ -1738,14 +1493,17 @@ if (isset($_GET["tipo"])){
elseif ($_GET["tipo"] =="user_activity")
graphic_user_activity();
elseif ($_GET["tipo"] == "agentaccess")
graphic_agentaccess($_GET["id"], $_GET["periodo"]);
graphic_agentaccess($_GET["id"], $_GET["periodo"], $width, $height);
elseif ($_GET["tipo"] == "agentmodules")
graphic_agentmodules($_GET["id"]);
graphic_agentmodules($_GET["id"], $width, $height);
elseif ($_GET["tipo"] == "gdirect")
graphic_test ($id, $periodo, $intervalo, $label, $width, $height);
graphic_test ($id, $period, $intervalo, $label, $width, $height);
elseif ( $_GET["tipo"] =="progress"){
$percent= $_GET["percent"];
progress_bar($percent,$width,$height);
}
}
else
graphic_error ();
} else
graphic_error ();
?>

View File

@ -35,109 +35,55 @@ if (comprueba_login() == 0) {
include("../include/styles/pandora.css");
echo '</style>';
if (isset($_GET["range"]) AND isset($_GET["id"])) {
$range =entrada_limpia($_GET["range"]);
$id_agente_modulo = entrada_limpia($_GET["id"]);
}
else {
// Get input parameters
if (!isset($_GET["period"]) OR (!isset($_GET["id"]))) {
echo "<h3 class='error'>".$lang_label["graf_error"]."</h3>";
exit;
}
// Nota: En los intervalos, se han aumentado por encima de los 24 del grafico diario y los 7 del semanal para
// que la grafica tenga mas resolucion. Cuanto mayor sea el intervalo mas tardara la grafica en generarse !!!.
// TODO: Crear una variable para que se pueda utilizar como factor de resolucion de graficos y parametrizarlo en un
// archivo de configuracion.
$module_interval = give_moduleinterval($id_agente_modulo);
// Interval defined for this module or agent general interval, if interval for this specific module not defined
$module_interval = $module_interval / 60; // Convert to resol / minute
// Please be caution, interval now is in MINUTES not in seconds
// interval is the number of rows that will store data. more rows, more resolution
// Testing 16Feb06
$param['tipo']='sparse';
switch ($range) {
case "mesg": $intervalo = 30 * $config_graph_res;
$intervalo_real = (43200 / $module_interval);
if ($intervalo_real < $intervalo ){
$intervalo = $intervalo_real;
}
$param['color'] = '6e90ff';
$param['periodo'] = 43200;
$param['intervalo'] = $intervalo;
$param['label'] = $lang_label["month_graph"];
$param['tipo']='gdirect';
break;
if (isset($_GET["event"]))
$draw_events = entrada_limpia($_GET["event"]);
else
$draw_events = 0;
if (isset($_GET["refresh"]))
$refresh = entrada_limpia($_GET["refresh"]);
else
$refresh = 0;
if (isset($_GET["period"]))
$period = entrada_limpia($_GET["period"]);
else
$period = 86400; // 1 day default period
case "mes": $intervalo = 30 * $config_graph_res;
$intervalo_real = (43200 / $module_interval);
if ($intervalo_real < $intervalo ){
$intervalo = $intervalo_real;
}
$param['color'] = '6e90ff';
$param['periodo'] = 43200;
$param['intervalo'] = $intervalo;
$param['label'] = $lang_label["month_graph"];
break;
case "dia": $intervalo = 24 * $config_graph_res;
$intervalo_real = (1440 / $module_interval);
if ($intervalo_real < $intervalo ){
$intervalo = $intervalo_real;
}
$param['color'] = 'f3c330';
$param['periodo'] = 1440;
$param['intervalo'] = $intervalo;
$param['label'] = $lang_label["day_graph"];
break;
case "semana": $intervalo = 28 * $config_graph_res;
$intervalo_real = (10080 / $module_interval);
if ($intervalo_real < $intervalo ) {
$intervalo = $intervalo_real;
}
$param['color'] = 'e366cd';
$param['periodo'] = 10080;
$param['intervalo'] = $intervalo;
$param['label'] = $lang_label["week_graph"];
break;
case "hora": $intervalo = 5 * $config_graph_res;
$intervalo_real = 60 / $module_interval;
if ($intervalo_real < $intervalo ) {
$intervalo = $intervalo_real;
}
$param['color'] = '40d840';
$param['periodo'] = 60;
$param['intervalo'] = $intervalo;
$param['label'] = $lang_label["hour_graph"];
break;
}
foreach ($_GET as $key => $value) {
$param[$key] = $value;
}
$param['zoom']=isset($param['zoom'])?$param['zoom']:100;
$param['draw_events']=isset($param['draw_events'])?$param['draw_events']:1;
/*if (isset($_GET['draw_events']) and $_GET['draw_events']==0) {
$param['draw_events'] = 0;
}*/
$imgtag = "<img src='fgraph.php?id=". $id_agente_modulo ;
foreach ($param as $key => $value) {
$imgtag .= "&" . $key . "=" . $value;
}
$imgtag .= "' border=0 alt=''>";
if (isset($_GET["id"]))
$id = entrada_limpia($_GET["id"]);
else
$id = 0;
echo $imgtag;
$param['id'] = $_GET['id'];
if (isset($_GET["width"]))
$width = entrada_limpia($_GET["width"]);
else
$width = 525;
if (isset($_GET["height"]))
$height = entrada_limpia ($_GET["height"]);
else
$height = 200;
if (isset($_GET["label"]))
$label = entrada_limpia ($_GET["label"]);
else
$label = "";
if (isset($_GET["zoom"])){
$zoom = entrada_limpia ($_GET["zoom"]);
$height=$height*$zoom;
$width=$width*$zoom;
}
else
$zoom = "1";
echo "<img src='fgraph.php?tipo=sparse&id=$id&zoom=$zoom&label=$label&height=$height&width=$width&period=$period' border=0 alt=''>";
}
?>
@ -222,16 +168,18 @@ if (comprueba_login() == 0) {
</tr>
<tr><td>
<?php
foreach ($param as $key => $value) {
echo "<input type='hidden' name='$key' value='$value'>";
echo "<DD>$key - $value <BR>";
}
echo "<input type='hidden' name='$id' value='$id'>";
echo "<input type='hidden' name='$refresh' value='$refresh'>";
echo "<input type='hidden' name='$zoom' value='$zoom'>";
echo "<input type='hidden' name='$events' value='$draw_events'>";
?>
</td><td>
<?php
echo "Refresh <input type='text' name='refresh' value='" . $param['refresh'] . "'> seconds <br>";
echo "Zoom <input type='text' name='zoom' value='" . $param['zoom'] . "'> % <br>";
echo "Show events <input type='text' name='draw_events' value='" . $param['draw_events'] . "'> ( 1 or 0 ) <br>";
echo "Refresh <input type='text' name='refresh' value='" . $refresh . "'> seconds <br>";
echo "Zoom <input type='text' name='zoom' value='" . $zoom . "'> % <br>";
echo "Show events <input type='text' name='draw_events' value='" . $draw_events . "'> ( 1 or 0 ) <br>";
?>
</td></tr>
</table>