2010-09-15 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_reporting.php: in function "get_agent_module_info" added
	the return "status" and "alert_value".
	
	* include/auth/mysql.php: in function "process_user_login" cleaned the
	source code style.

	* include/functions_ui.php: in function "print_timestamp" added in the
	parameter $option the check of units ('large' and 'tiny' at the moment).
	Added the function "print_group_icon2" that it is the same of
	"print_group_icon" but it has a new parameter $path for to set the images
	path.
	
	* include/functions.php: in function "human_time_comparation" added the
	parameter $units to set the type return text for time unit (at the moment
	only "large" and "tiny"). And in the function "human_time_description_raw"
	added the paramter $units for to set the type of return text for units, at
	the moment only "large" and "tiny".
	
	* include/functions_db.php, operation/agentes/ver_agente.php: cleaned source
	code.
	
	* mobile/index.php, mobile/operation/agents,
	mobile/operation/agents/view_agents.php, mobile/include/db.class.php,
	mobile/include/style, mobile/include/style/main.css,
	mobile/include/user.class.php, mobile/include/functions_web.php,
	mobile/include/system.class.php, mobile/images/bricks.png,
	mobile/images/up.png, mobile/images/zoom.png, mobile/images/down.png: added
	first version of file for Pandora Mobile version.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3246 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2010-09-15 15:54:59 +00:00
parent 91c34be254
commit 481ff650b3
18 changed files with 954 additions and 30 deletions

View File

@ -1,3 +1,34 @@
2010-09-15 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php: in function "get_agent_module_info" added
the return "status" and "alert_value".
* include/auth/mysql.php: in function "process_user_login" cleaned the
source code style.
* include/functions_ui.php: in function "print_timestamp" added in the
parameter $option the check of units ('large' and 'tiny' at the moment).
Added the function "print_group_icon2" that it is the same of
"print_group_icon" but it has a new parameter $path for to set the images
path.
* include/functions.php: in function "human_time_comparation" added the
parameter $units to set the type return text for time unit (at the moment
only "large" and "tiny"). And in the function "human_time_description_raw"
added the paramter $units for to set the type of return text for units, at
the moment only "large" and "tiny".
* include/functions_db.php, operation/agentes/ver_agente.php: cleaned source
code.
* mobile/index.php, mobile/operation/agents,
mobile/operation/agents/view_agents.php, mobile/include/db.class.php,
mobile/include/style, mobile/include/style/main.css,
mobile/include/user.class.php, mobile/include/functions_web.php,
mobile/include/system.class.php, mobile/images/bricks.png,
mobile/images/up.png, mobile/images/zoom.png, mobile/images/down.png: added
first version of file for Pandora Mobile version.
2010-09-15 Ramon Novoa <rnovoa@artica.es>
* pandoradb.sql: Fixed a typo.

View File

@ -90,14 +90,16 @@ function process_user_login ($login, $pass) {
// to avoid problems with case-sensitive usernames.
// Thanks to David Muñiz for Bug discovery :)
return $row["id_user"];
} else {
}
else {
$mysql_cache["auth_error"] = "User not found in database or incorrect password";
}
return false;
// Remote authentication
} else {
}
else {
switch ($config["auth"]) {

View File

@ -276,11 +276,12 @@ function format_integer_round ($number, $rounder = 5) {
* TODO: Make sense out of all these time functions and stick with 2 or 3
*
* @param int $timestamp Unixtimestamp to compare with current time.
* @param string $units The type of unit, by default 'large'.
*
* @return string A human readable string of the diference between current
* time and a given timestamp.
*/
function human_time_comparation ($timestamp) {
function human_time_comparation ($timestamp, $units = 'large') {
global $config;
if (!is_numeric ($timestamp)) {
@ -289,7 +290,7 @@ function human_time_comparation ($timestamp) {
$seconds = get_system_time () - $timestamp;
return human_time_description_raw ($seconds);
return human_time_description_raw($seconds, false, $units);
}
/**
@ -321,13 +322,33 @@ function get_system_time () {
*
* @param int $seconds Seconds elapsed time
* @param int $exactly If it's true, return the exactly human time
* @param string $units The type of unit, by default 'large'.
*
* @return string A human readable translation of minutes.
*/
function human_time_description_raw ($seconds, $exactly = false) {
function human_time_description_raw ($seconds, $exactly = false, $units = 'large') {
switch ($units) {
case 'large':
$secondsString = __('seconds');
$daysString = __('days');
$monthsString = __('months');
$minutesString = __('minutes');
$hoursString = __('hours');
$nowString = __('Now');
break;
case 'tiny':
$secondsString = __('s');
$daysString = __('d');
$monthsString = __('M');
$minutesString = __('m');
$hoursString = __('h');
$nowString = __('N');
break;
}
if (empty ($seconds)) {
return __('Now');
return $nowString;
// slerena 25/03/09
// Most times $seconds is empty is because last contact is current date
// Put here "uknown" or N/A or something similar is not a good idea
@ -341,39 +362,39 @@ function human_time_description_raw ($seconds, $exactly = false) {
$months = format_numeric ($seconds / 2592000, 0);
if (($mins == 0) && ($hours == 0) && ($days == 0) && ($months == 0))
return format_numeric ($secs, 0).' '.__('seconds');
return format_numeric ($secs, 0).' '. $secondsString;
else if (($hours == 0) && ($days == 0) && ($months == 0))
return sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
else if (($days == 0) && ($months == 0))
return sprintf("%02d",$hours).':'.sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
else if (($months == 0))
return $days.' '.__('days').' '.sprintf("%02d",$hours).':'.sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
return $days.' ' . $daysString . ' '.sprintf("%02d",$hours).':'.sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
else
return $months.' '.__('months').' '.$days.' '.__('days').' '.sprintf("%02d",$hours).':'.sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
return $months.' '. $monthsString .' '.$days.' ' . $daysString . ' '.sprintf("%02d",$hours).':'.sprintf("%02d",$mins).':'.sprintf("%02d",$secs);
}
if ($seconds < 60)
return format_numeric ($seconds, 0)." ".__('seconds');
return format_numeric ($seconds, 0)." " . $secondsString;
if ($seconds < 3600) {
$minutes = floor($seconds / 60);
$seconds = $seconds % 60;
if ($seconds == 0)
return $minutes.' '.__('minutes');
return $minutes.' ' . $minutesString;
$seconds = sprintf ("%02d", $seconds);
return $minutes.':'.$seconds.' '.__('minutes');
return $minutes.':'.$seconds.' ' . $minutesString;
}
if ($seconds < 86400)
return format_numeric ($seconds / 3600, 0)." ".__('hours');
return format_numeric ($seconds / 3600, 0)." " . $hoursString;
if ($seconds < 2592000)
return format_numeric ($seconds / 86400, 0)." ".__('days');
return format_numeric ($seconds / 86400, 0) . " " . $daysString;
if ($seconds < 15552000)
return format_numeric ($seconds / 2592000, 0)." ".__('months');
return format_numeric ($seconds / 2592000, 0)." ". $monthsString;
return "+6 ".__('months');
return "+6 " . $monthsString;
}
/**

View File

@ -520,13 +520,6 @@ function get_group_agents ($id_group = 0, $search = false, $case = "lower", $noA
$sql = sprintf ("SELECT id_agente, nombre FROM tagente %s ORDER BY nombre", $search_sql);
$result = get_db_all_rows_sql ($sql);
////////////////LOG AJAX///////////////////////
///////////////////////////////////////////////
//$log = fopen ( "/tmp/log_sql", "a");
//fwrite ($log, $sql."\n\n");
//fclose($log);
///////////////////////////////////////////////
if ($result === false)
return array (); //Return an empty array

View File

@ -1498,9 +1498,11 @@ function get_agent_module_info ($id_agent, $filter = false) {
$return["monitor_critical"] = 0; //Number of 'critical' monitors
$return["monitor_unknown"] = 0; //Number of 'unknown' monitors
$return["monitor_alertsfired"] = 0; //Number of monitors with fired alerts
$return["last_contact"] = 0; //Last agent contact
$return["last_contact"] = 0; //Last agent contact
$return["status"] = STATUS_AGENT_NO_DATA;
$return["status_img"] = print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true);
$return["alert_status"] = "notfired";
$return["alert_value"] = STATUS_ALERT_NOT_FIRED;
$return["alert_img"] = print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true);
$return["agent_group"] = get_agent_group ($id_agent);
@ -1550,15 +1552,19 @@ function get_agent_module_info ($id_agent, $filter = false) {
if ($return["modules"] > 0) {
if ($return["monitor_critical"] > 0) {
$return["status"] = STATUS_AGENT_CRITICAL;
$return["status_img"] = print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true);
}
else if ($return["monitor_warning"] > 0) {
$return["status"] = STATUS_AGENT_WARNING;
$return["status_img"] = print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true);
}
else if ($return["monitor_unknown"] > 0) {
$return["status"] = STATUS_AGENT_DOWN;
$return["status_img"] = print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true);
}
else {
$return["status"] = STATUS_AGENT_OK;
$return["status_img"] = print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true);
}
}
@ -1567,8 +1573,10 @@ function get_agent_module_info ($id_agent, $filter = false) {
if ($return["monitor_alertsfired"] > 0) {
$return["alert_status"] = "fired";
$return["alert_img"] = print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true);
$return["alert_value"] = STATUS_ALERT_FIRED;
} elseif (give_disabled_group ($return["agent_group"])) {
$return["alert_status"] = "disabled";
$return["alert_value"] = STATUS_ALERT_DISABLED;
$return["alert_img"] = print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true);
}

View File

@ -141,6 +141,7 @@ function print_result_message ($result, $good = '', $bad = '', $attributes = '',
* Key html_attr: which html attributes to add (defaults to none)
* Key tag: Which html tag to use (defaults to span)
* Key prominent: Overrides user preference and display "comparation" or "timestamp"
* key units: The type of units.
*
* @return string HTML code if return parameter is true.
*/
@ -181,12 +182,18 @@ function print_timestamp ($unixtime, $return = false, $option = array ()) {
if ($unixtime <= 0) {
$title = __('Unknown').'/'.__('Never');
$data = __('Unknown');
} elseif ($prominent == "timestamp") {
}
elseif ($prominent == "timestamp") {
$title = human_time_comparation ($unixtime);
$data = date ($config["date_format"], $unixtime);
} else {
}
else {
$title = date ($config["date_format"], $unixtime);
$data = human_time_comparation ($unixtime);
$units = 'large';
if (isset($option['units'])) {
$units = $option['units'];
}
$data = human_time_comparation ($unixtime, $units);
}
$output = '<'.$tag;
@ -247,7 +254,7 @@ function print_group_icon ($id_group, $return = false, $path = "groups_small", $
$output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">';
if (empty ($icon))
$output .= '<span title="'.get_group_name ($id_group, true).'">&nbsp;-&nbsp</span>';
$output .= '<span title="'. get_group_name($id_group, true).'">&nbsp;-&nbsp</span>';
else
$output .= '<img style="' . $style . '" class="bot" src="images/'.$path.'/'.$icon.'.png" alt="'.get_group_name ($id_group, true).'" title="'.get_group_name ($id_group, true).'" />';
@ -260,6 +267,42 @@ function print_group_icon ($id_group, $return = false, $path = "groups_small", $
return $output;
}
/**
* Print group icon within a link. Other version.
*
* @param int Group id
* @param bool Whether to return or print
* @param string What path to use (relative to images/). Defaults to groups_small
*
* @return string HTML code if return parameter is true.
*/
function print_group_icon2($id_group, $return = false, $path = "images/groups_small", $style='', $link = true) {
if($id_group > 0)
$icon = (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group);
else
$icon = "world";
if($style == '')
$style = 'width: 16px; height: 16px;';
$output = '';
if ($link)
$output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">';
if (empty ($icon))
$output .= '<span title="'. get_group_name($id_group, true).'">&nbsp;-&nbsp</span>';
else
$output .= '<img style="' . $style . '" class="bot" src="'.$path.'/'.$icon.'.png" alt="'.get_group_name ($id_group, true).'" title="'.get_group_name ($id_group, true).'" />';
if ($link)
$output .= '</a>';
if (!$return)
echo $output;
return $output;
}
/**
* Get the icon of an operating system.
*

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

View File

@ -0,0 +1,32 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
require_once("system.class.php");
class DB {
private $system;
private $engine;
public function __construct($system, $engine = 'mysql') {
$this->system = &$system;
$this->engine = $engine;
switch ($engine) {
case 'mysql':
//NONE
break;
}
}
}
?>

View File

@ -0,0 +1,41 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
function menu() {
?>
<div id="top_menu">
<div id="menu">
<a href="index.php?page=dashboard"><img class="icon_menu" alt="<?php echo __('Dashboard');?>" title="<?php echo __('Dashboard');?>" src="../images/house.png" /></a>
<a href="index.php?page=agents"><img class="icon_menu" alt="<?php echo __('Agents');?>" title="<?php echo __('Agents');?>" src="../images/bricks.png" /></a>
<a href=""><img class="icon_menu" alt="<?php echo __('Events');?>" title="<?php echo __('Events');?>" src="../images/lightning_go.png" /></a>
<a href=""><img class="icon_menu" alt="<?php echo __('Groups');?>" title="<?php echo __('Groups');?>" src="../images/world.png" /></a>
<a href="index.php?page=servers"><img class="icon_menu" alt="<?php echo __('Servers');?>" title="<?php echo __('Servers');?>" src="../images/god5.png" /></a>
<a href=""><img class="icon_menu" alt="<?php echo __('Reports');?>" title="<?php echo __('Reports');?>" src="../images/reporting.png" /></a>
<a href="index.php?action=logout"><img class="icon_menu" alt="<?php echo __('Logout');?>" title="<?php echo __('Logout');?>" src="../images/log-out.png" /></a>
</div>
<div id="down_button">
<a class="button_menu" id="button_menu_down" href="javascript: toggleMenu();"><img src="images/down.png" /></a>
<a class="button_menu" id="button_menu_up" href="javascript: toggleMenu();"><img src="images/up.png" /></a>
</div>
</div>
<div id="margin_bottom_menu"></div>
<script type="text/javascript">
function toggleMenu() {
$("#top_menu #menu").slideToggle("normal");
$(".button_menu").toggle();
}
</script>
<?php
}
?>

View File

@ -0,0 +1,101 @@
* {
margin: 0;
padding: 0;
border: 0;
font-size: 12px;
}
body {
}
input {
border: 1px solid;
}
.icon_menu {
width: 50px;
height: 50px;
}
.orange {
color: #ffa300;
}
.green {
color: #5a8629;
}
.yellow {
color: #F3C500;
}
.greenb {
color: #00aa00;
}
.grey {
color: #808080;
font-weight: bold;
}
select {
border: #CCCCCC 1px solid;
}
.button_filter {
background: url("../../images/zoom.png") no-repeat scroll center center;
margin-left: 5px;
width: 20px;
height: 20px;
}
input {
border: #CCCCCC 1px solid;
}
.title_h3 {
border-top: 1px solid #CCCCCC;
margin: 5px;
color: #3F4E2F;
}
/*----------------INI-MENU----------------------------------------------------*/
#top_menu {
background: #3F4E2F;
overflow: hidden;
position: absolute;
z-index: 2;
}
#margin_bottom_menu {
margin-bottom: 17px;
}
#menu {
display: none;
}
#down_button {
height: 15px;
background: #fff;
}
#down_button img {
background: #3F4E2F;
padding-left: 10px;
padding-right: 10px;
}
#button_menu_up {
display: none;
}
/*----------------END-MENU----------------------------------------------------*/
/*----------------INI-TABLE---------------------------------------------------*/
th {
background-color:#9EAC8B;
color:#FFFFFF;
text-align:center;
}
.databox {
border: 1px solid #f2f2f2;
background-color: #fafafa;
}
/*----------------END-TABLE---------------------------------------------------*/

View File

@ -0,0 +1,94 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
require_once('../include/config.php');
require_once('db.class.php');
class System {
private $session;
private $config;
private $db;
function __construct() {
$this->loadConfig();
$this->db = new DB($this, $this->getConfig('db_engine', 'mysql'));
session_start();
$this->session = $_SESSION;
session_write_close();
}
private function loadConfig() {
global $config;
$this->config = &$config;
}
public function getRequest($name, $default = null) {
$return = $default;
if (isset($_POST[$name])) {
$return = $_POST[$name];
}
else {
if (isset($_GET[$name])) {
$return = $_GET[$name];
}
}
return $return;
}
private function getConfig($name, $default = null) {
if (!isset($this->config[$name])) {
return $default;
}
else {
return $this->config[$name];
}
}
public function setSession($name, $value) {
$this->session[$name] = $value;
session_start();
$_SESSION = $this->session;
session_write_close();
}
public function getSession($name, $default = null) {
if (!isset($this->session[$name])) {
return $default;
}
else {
return $this->session[$name];
}
}
public function debug($var) {
echo "<pre>";
var_dump($var);
echo "</pre>";
}
public function sessionDestroy() {
session_start();
session_destroy();
}
public function getPageSize() {
return 10;
}
}
?>

View File

@ -0,0 +1,85 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
require_once("system.class.php");
class User {
private $user;
private $logged;
private $system;
public function __construct($user = null, $password = null) {
global $system;
$this->user = $user;
$this->system = &$system;
//$this->system->debug($this->system);
if (process_user_login($this->user, $password)) {
$this->logged = true;
}
else {
$this->logged = false;
}
}
public function hackinjectConfig() {
if ($this->logged) {
//hack to compatibility with pandora
global $config;
$config['id_user'] = $this->user;
}
}
public function isLogged() {
return $this->logged;
}
public function checkLogin($user = null, $password = null) {
if (($user == null) && ($password == null)) {
$user = $this->system->getRequest('user', null);
$password = $this->system->getRequest('password', null);
}
if (process_user_login($user, $password)) {
$this->logged = true;
$this->user = $user;
}
else {
$this->logged = false;
}
return true;
}
public function logout() {
$this->user = null;
$this->logged = false;
}
public function login() {
echo "<form method='post'>";
print_input_hidden('action', 'login');
print_input_text('user', $this->user, __('User'), 10, 20);
print_input_password('password', '', __('Password'), 10, 20);
print_submit_button(__('Login'), 'login', false, 'class="sub next"');
echo "</form>";
}
public function getIdUser() {
return $this->user;
}
}
?>

View File

@ -0,0 +1,86 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
ob_start ();
require_once("include/system.class.php");
require_once("include/user.class.php");
require_once("include/functions_web.php");
require_once('operation/agents/view_agents.php');
$system = new System();
$user = $system->getSession('user', null);
if ($user == null) {
$user = new User();
}
$user->hackinjectConfig();
?>
<html>
<head>
<title>XXX</title>
<link rel="stylesheet" href="include/style/main.css" type="text/css" />
<link rel="stylesheet" href="../include/styles/tip.css" type="text/css" />
<script type="text/javascript" src="../include/javascript/jquery.js"></script>
</head>
<body>
<!--<div style="width: 100%; height: 100%; border: 2px solid red; overflow: hidden;">-->
<!--<div style="width: 240px; height: 320px; border: 2px solid red; overflow: hidden;">-->
<div style="width: 240px; height: 640px; border: 2px solid red; overflow: hidden;">
<?php
$action = $system->getRequest('action');
switch ($action) {
case 'login':
if (!$user->checkLogin()) {
$user->login();
}
menu();
break;
case 'logout':
$user->logout();
break;
default:
if (!$user->isLogged()) {
$user->login();
}
else {
menu();
$page = $system->getRequest('page', 'dashboard');
switch ($page) {
default:
case 'dashboard':
break;
case 'agents':
$viewAgents = new ViewAgents();
$viewAgents->show();
break;
case 'agent':
$viewAgent = new ViewAgent();
$viewAgent->show();
break;
case 'servers':
break;
}
}
break;
}
?>
</div>
</body>
</html>
<?php
$system->setSession('user', $user);
//$system->sessionDestroy();
ob_end_flush();
?>

View File

@ -0,0 +1,385 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for 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.
require_once("../include/functions_agents.php");
require_once("../include/functions_reporting.php");
require_once("../include/functions_alerts.php");
class ViewAgents {
private $user;
private $system;
private $filter;
private $filterGroup;
public function __construct() {
global $system;
global $user;
$this->user = $user;
$this->system = $system;
$this->filterText = $this->system->getRequest('filter_text', '');
$this->filterGroup = $this->system->getRequest('filter_group', 0);;
}
private function showForm() {
echo "<form>";
print_input_hidden('page', 'agents');
print_select_groups($this->user->getIdUser(), "AR", true, 'filter_group', $this->filterGroup);
print_input_text('filter_text', $this->filterText, __('Free text search'), 10, 20);
echo "<input type='submit' class='button_filter' name='submit_button' value='' alt='" . __('Filter') . "' title='" . __('Filter') . "' />";
echo "<form>";
}
public function show() {
$this->showForm();
// Show only selected groups
if ($this->filterGroup > 0) {
$groups = $this->filterGroup;
$agent_names = get_group_agents ($this->filterGroup, array('string' => $this->filterText), "upper");
// Not selected any specific group
}
else {
$user_group = get_user_groups ($this->user->getIdUser(), "AR");
$groups = array_keys ($user_group);
$agent_names = get_group_agents (array_keys ($user_group), array('string' => $this->filterText), "upper");
}
$total_agents = get_agents (array('id_agente' => array_keys ($agent_names),
'order' => 'nombre ASC',
'disabled' => 0,
'id_grupo' => $groups),
array ('COUNT(*) as total'));
$total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0;
$agents = get_agents(array('id_agente' => array_keys ($agent_names),
'order' => 'nombre ASC',
'id_grupo' => $groups,
'offset' => (int) get_parameter ('offset'),
'limit' => (int) $this->system->getPageSize()), array('id_agente', 'nombre', 'id_grupo'));
$table = null;
$table->width = '100%';
$table->align = array();
$table->align[0] = 'center';
$table->align[2] = 'center';
$table->align[3] = 'center';
$table->align[4] = 'center';
$table->head = array();
$table->head[0] = '<span title="' . __('Group') . '" alt="' . __('Group') . '">' . __('G') . '</span>';
$table->head[1] = __('Name');
$table->head[2] = '<span title="' . __('Modules') . '" alt="' . __('Modules') . '">' . __('M') . '</span>';
$table->head[3] = '<span title="' . __('Status') . '" alt="' . __('Status') . '">' . __('S') . '</span>';
$table->head[4] = '<span title="' . __('Alert') . '" alt="' . __('Alert') . '">' . __('A') . '</span>';
$table->data = array();
if ($agents === false) $agents = array();
$iterator = 0;
$rowPair = false;
foreach ($agents as $agent) {
if ($rowPair)
$table->rowclass[$iterator] = 'rowPair';
else
$table->rowclass[$iterator] = 'rowOdd';
$rowPair = !$rowPair;
$agent_info = get_agent_module_info ($agent["id_agente"]); //$this->system->debug($agent_info);
$data = array();
$truncName = printTruncateText($agent['nombre'], 10, true, true);
$data[] = print_group_icon2($agent["id_grupo"], true, "../images/groups_small", '', false);
$data[] = '<a href="index.php?page=agent&id=' . $agent['id_agente'] . '">' . $truncName . '</a>';
$moduleInfo = '<b>';
$moduleInfo .= $agent_info["modules"];
if ($agent_info["monitor_alertsfired"] > 0)
$moduleInfo .= ' : <span class="orange">'.$agent_info["monitor_alertsfired"].'</span>';
if ($agent_info["monitor_critical"] > 0)
$moduleInfo .= ' : <span class="red">'.$agent_info["monitor_critical"].'</span>';
if ($agent_info["monitor_warning"] > 0)
$moduleInfo .= ' : <span class="yellow">'.$agent_info["monitor_warning"].'</span>';
if ($agent_info["monitor_unknown"] > 0)
$moduleInfo .= ' : <span class="grey">'.$agent_info["monitor_unknown"].'</span>';
if ($agent_info["monitor_normal"] > 0)
$moduleInfo .= ' : <span class="green">'.$agent_info["monitor_normal"].'</span>';
$moduleInfo .= '</b>';
$data[] = $moduleInfo;
$data[] = '<img src="../images/status_sets/default/' . str_replace('.png', '_ball.png', $agent_info['status']) . '" />';
$data[] = '<img src="../images/status_sets/default/' . str_replace('.png', '_ball.png', $agent_info['alert_value']) . '" />';
$table->data[] = $data;
}
print_table($table);
$pagination = pagination ($total_agents,
get_url_refresh (array ('filter_group' => $this->filterGroup, 'filter_group' => $this->filterGroup)),
0, 0, true);
$pagination = str_replace('images/go_first.png', '../images/go_first.png', $pagination);
$pagination = str_replace('images/go_previous.png', '../images/go_previous.png', $pagination);
$pagination = str_replace('images/go_next.png', '../images/go_next.png', $pagination);
$pagination = str_replace('images/go_last.png', '../images/go_last.png', $pagination);
echo $pagination;
}
}
class ViewAgent {
private $idAgent;
private $sytem;
private $agent;
private $name;
private $os;
private $ips;
private $modules;
public function __construct() {
global $system;
$this->system = $system;
$this->idAgent = $this->system->getRequest('id', 0);
$this->agent = get_db_row_filter('tagente', array('id_agente' => $this->idAgent));
$this->ips = get_agent_addresses($this->idAgent);
}
public function show() {
$table = null;
$table->width = '100%';
$table->style[0] = 'font-weight: bolder;';
$table->data[0][0] = __('Name:');
$table->data[0][1] = $this->agent['nombre'];
$table->data[1][0] = __('IP:');
$table->data[1][1] = implode(',', $this->ips);
$table->data[2][0] = __('OS:');
$table->data[2][1] = str_replace('images/os_icons/', '../images/os_icons/', print_os_icon($this->agent['id_os']));
$table->data[3][0] = __('Last contact');
$table->data[3][1] = $this->agent['ultimo_contacto'];
print_table($table);
$sql = sprintf ("
SELECT *
FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.disabled = 0
AND tagente_modulo.delete_pending = 0
AND tagente_estado.utimestamp != 0
ORDER BY tagente_modulo.id_module_group , tagente_modulo.nombre ASC
", $this->idAgent);
$modules = get_db_all_rows_sql ($sql);
if (empty ($modules)) {
$modules = array ();
}
echo "<h3 class='title_h3'>" . __('Modules') . "</h3>";
$table = null;
$table->width = '100%';
$table->head = array();
$table->head[0] = __('Module');
$table->head[1] = '<span title="' . __('Status') . '" alt="' . __('Status') . '">' . __('S') . '</span>';
$table->head[2] = __('Data');
$table->head[3] = '<span title="' . __('Last contact') . '" alt="' . __('Last contact') . '">' . __('L') . '</span>';
$table->data = array();
$iterator = 0;
$rowPair = false;
foreach ($modules as $module) {
if ($rowPair)
$table->rowclass[$iterator] = 'rowPair';
else
$table->rowclass[$iterator] = 'rowOdd';
$rowPair = !$rowPair;
$data = array();
$data[] = printTruncateText($module["nombre"], 10, true, true);
$status = STATUS_MODULE_WARNING;
$title = "";
if ($module["estado"] == 1) {
$status = STATUS_MODULE_CRITICAL;
$title = __('CRITICAL');
} elseif ($module["estado"] == 2) {
$status = STATUS_MODULE_WARNING;
$title = __('WARNING');
} elseif ($module["estado"] == 0) {
$status = STATUS_MODULE_OK;
$title = __('NORMAL');
} elseif ($module["estado"] == 3) {
$last_status = get_agentmodule_last_status($module['id_agente_modulo']);
switch($last_status) {
case 0:
$status = STATUS_MODULE_OK;
$title = __('UNKNOWN')." - ".__('Last status')." ".__('NORMAL');
break;
case 1:
$status = STATUS_MODULE_CRITICAL;
$title = __('UNKNOWN')." - ".__('Last status')." ".__('CRITICAL');
break;
case 2:
$status = STATUS_MODULE_WARNING;
$title = __('UNKNOWN')." - ".__('Last status')." ".__('WARNING');
break;
}
}
if (is_numeric($module["datos"])) {
$title .= ": " . format_for_graph($module["datos"]);
}
else {
$title .= ": " . substr(safe_output($module["datos"]),0,42);
}
$data[] = str_replace('.png', '_ball.png', str_replace('images/status_sets',
'../images/status_sets', print_status_image($status, $title, true)));
if ($module["id_tipo_modulo"] == 24) { // log4x
switch($module["datos"]) {
case 10: $salida = "TRACE"; $style="font-weight:bold; color:darkgreen;"; break;
case 20: $salida = "DEBUG"; $style="font-weight:bold; color:darkgreen;"; break;
case 30: $salida = "INFO"; $style="font-weight:bold; color:darkgreen;"; break;
case 40: $salida = "WARN"; $style="font-weight:bold; color:darkorange;"; break;
case 50: $salida = "ERROR"; $style="font-weight:bold; color:red;"; break;
case 60: $salida = "FATAL"; $style="font-weight:bold; color:red;"; break;
}
$salida = "<span style='$style'>$salida</span>";
} else {
if (is_numeric($module["datos"])){
$salida = format_numeric($module["datos"]);
} else {
$salida = "<span title='".$module['datos']."' style='white-space: nowrap;'>".substr(safe_output($module["datos"]),0,12)."</span>";
}
}
$data[] = $salida;
if ($module['estado'] == 3) {
$lastTime = '<span class="redb">';
} else {
$lastTime = '<span>';
}
$lastTime .= print_timestamp ($module["utimestamp"], true, array('units' => 'tiny'));
$lastTime .= '</span>';
$data[] = $lastTime;
$table->data[] = $data;
}
print_table($table);
$table->head = array();
$table->head[0] = __('Module');
$table->head[1] = __('Template');
// $table->head[2] = __('Action');
$table->head[2] = '<span title="' . __('Last fired') . '" alt="' . __('Last fired') . '">' . __('Last') . '</span>';
$table->head[3] = '<span title="' . __('Status') . '" alt="' . __('Status') . '">' . __('S') . '</span>';
$table->align = array();
$table->align[3] = 'right';
$table->align[2] = 'center';
$table->data = array();
$table->rowclass = array();
echo "<h3 class='title_h3'>" . __('Alerts') . "</h3>";
$alertsSimple = get_agent_alerts_simple (array($this->idAgent));
foreach ($alertsSimple as $alert) {
if ($rowPair)
$table->rowclass[$iterator] = 'rowPair';
else
$table->rowclass[$iterator] = 'rowOdd';
$rowPair = !$rowPair;
$data = array();
$data[] = printTruncateText(get_agentmodule_name($alert["id_agent_module"]), 10, true, true);
$template = safe_output(get_alert_template ($alert['id_alert_template']));
$data[] = printTruncateText(safe_output($template['name']), 10, true, true);
// $actions = get_alert_agent_module_actions ($alert['id'], false, false);
// if (!empty($actions)){
// $actionText = '<ul class="action_list">';
// foreach ($actions as $action) {
// $actionText .= '<li><div><span class="action_name">' . $action['name'];
// if ($action["fires_min"] != $action["fires_max"]){
// $actionText .= " (".$action["fires_min"] . " / ". $action["fires_max"] . ")";
// }
// $actionText .= '</li></span><br></div>';
// }
// $actionText .= '</div></ul>';
// }
// else {
// if ($actionDefault != "")
// $actionText = get_db_sql ("SELECT name FROM talert_actions WHERE id = $actionDefault"). " <i>(".__("Default") . ")</i>";
// }
//
// $data[] = $actionText;
$data[] = print_timestamp ($alert["last_fired"], true, array('units' => 'tiny'));
$status = STATUS_ALERT_NOT_FIRED;
$title = "";
if ($alert["times_fired"] > 0) {
$status = STATUS_ALERT_FIRED;
$title = __('Alert fired').' '.$alert["times_fired"].' '.__('times');
} elseif ($alert["disabled"] > 0) {
$status = STATUS_ALERT_DISABLED;
$title = __('Alert disabled');
} else {
$status = STATUS_ALERT_NOT_FIRED;
$title = __('Alert not fired');
}
$data[] = str_replace('.png', '_ball.png', str_replace('images/status_sets',
'../images/status_sets', print_status_image($status, $title, true)));
$table->data[] = $data;
}
print_table($table);
// echo "<h3 class='title_h3'>" . __('Alerts compound') . "</h3>";
//
// $alertsCombined = get_agent_alerts_compound(array($this->idAgent));
//
// $table->data = array();
// foreach ($alertsCombined as $alert) {
// $data = array();
//
// $table->data[] = $data;
// }
}
}
?>

View File

@ -389,7 +389,8 @@ $custom_fields['text']= '<a href="index.php?sec=estado&sec2=operation/agentes/ve
if ($tab == 'custom_fields') {
$custom_fields['active'] = true;
} else {
}
else {
$custom_fields['active'] = false;
}
@ -398,7 +399,8 @@ $graphs['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agen
. '</a>';
if ($tab == 'graphs') {
$graphs['active'] = true;
} else {
}
else {
$graphs['active'] = false;
}