2013-03-15 15:50:47 +01:00
< ? 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.
include_once ( " ../include/functions_users.php " );
2016-09-28 16:56:05 +02:00
include_once ( " ../include/functions_groupview.php " );
2013-03-15 15:50:47 +01:00
class Groups {
private $correct_acl = false ;
2016-09-28 16:56:05 +02:00
private $acl = 'AR' ;
2013-03-15 15:50:47 +01:00
private $groups = array ();
private $status = array ();
function __construct () {
$system = System :: getInstance ();
2016-09-28 16:56:05 +02:00
if ( $system -> checkACL ( $this -> acl )) {
2013-03-15 15:50:47 +01:00
$this -> correct_acl = true ;
$this -> groups = $this -> getListGroups ();
2013-04-02 15:44:48 +02:00
//~ foreach ($this->groups as $key => $group) {
//~ $this->status[$key] = $group['status'];
//~ unset($this->groups[$key]['status']);
//~ }
2013-03-15 15:50:47 +01:00
}
else {
$this -> correct_acl = false ;
}
}
public function show () {
if ( ! $this -> correct_acl ) {
$this -> show_fail_acl ();
}
else {
$this -> show_group ();
}
}
private function show_fail_acl () {
2014-10-15 18:12:51 +02:00
$error [ 'type' ] = 'onStart' ;
2013-04-24 14:36:32 +02:00
$error [ 'title_text' ] = __ ( 'You don\'t have access to this page' );
$error [ 'content_text' ] = __ ( 'Access to this page is restricted to authorized users only, please contact system administrator if you need assistance. <br><br>Please know that all attempts to access this page are recorded in security logs of Pandora System Database' );
2014-10-15 18:12:51 +02:00
if ( class_exists ( " HomeEnterprise " ))
$home = new HomeEnterprise ();
else
$home = new Home ();
2013-04-24 14:36:32 +02:00
$home -> show ( $error );
2013-03-15 15:50:47 +01:00
}
private function show_group () {
$ui = Ui :: getInstance ();
$ui -> createPage ();
2013-11-28 17:54:18 +01:00
$ui -> createDefaultHeader ( __ ( " Groups " ), $ui -> createHeaderButton (
2013-07-03 Miguel de Dios <miguel.dedios@artica.es>
* mobile/operation/events.php, mobile/operation/module_graph.php,
mobile/operation/modules.php, mobile/operation/networkmaps.php,
mobile/operation/groups.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/networkmap.php,
mobile/operation/alerts.php, mobile/operation/agent.php,
mobile/include/ui.class.php: added the back button in the head and
impoved the source code style to make more easy the merges with
the last branch.
* include/functions_graph.php: fixed PHP notices.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8468 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-07-03 15:59:38 +02:00
array ( 'icon' => 'back' ,
'pos' => 'left' ,
'text' => __ ( 'Back' ),
2013-11-28 17:54:18 +01:00
'href' => 'index.php?page=home' )));
2013-03-15 15:50:47 +01:00
$ui -> showFooter ( false );
$ui -> beginContent ();
2013-04-09 11:29:03 +02:00
$ui -> contentAddHtml ( '<div class="list_groups" data-role="collapsible-set" data-theme="a" data-content-theme="d">' );
2013-04-02 15:44:48 +02:00
$count = 0 ;
2016-09-28 16:56:05 +02:00
$url_agent = 'index.php?page=agents&group=%s&status=%s' ;
$url_modules = 'index.php?page=modules&group=%s&status=%s' ;
2013-04-02 15:44:48 +02:00
foreach ( $this -> groups as $group ) {
2016-09-28 16:56:05 +02:00
// Calculate entire row color
if ( $group [ " _monitors_alerts_fired_ " ] > 0 ) {
$color_class = 'group_view_alrm' ;
$status_image = ui_print_status_image ( 'agent_alertsfired_ball.png' , " " , true );
}
elseif ( $group [ " _monitors_critical_ " ] > 0 ) {
$color_class = 'group_view_crit' ;
$status_image = ui_print_status_image ( 'agent_critical_ball.png' , " " , true );
}
elseif ( $group [ " _monitors_warning_ " ] > 0 ) {
$color_class = 'group_view_warn' ;
$status_image = ui_print_status_image ( 'agent_warning_ball.png' , " " , true );
}
elseif ( $group [ " _monitors_ok_ " ] > 0 ) {
$color_class = 'group_view_ok' ;
$status_image = ui_print_status_image ( 'agent_ok_ball.png' , " " , true );
}
elseif (( $group [ " _monitors_unknown_ " ] > 0 ) || ( $group [ " _agents_unknown_ " ] > 0 )) {
$color_class = 'group_view_unk' ;
$status_image = ui_print_status_image ( 'agent_no_monitors_ball.png' , " " , true );
}
else {
$color_class = '' ;
$status_image = ui_print_status_image ( 'agent_no_data_ball.png' , " " , true );
}
$group [ 'icon' ] = ( $group [ 'icon' ] == '' ) ? 'world' : $group [ 'icon' ];
2013-04-02 15:44:48 +02:00
$ui -> contentAddHtml ( '
< style type = " text/css " >
. ui - icon - group_ ' . $count . ' {
2016-09-28 16:56:05 +02:00
background : url ( " ../images/groups_small/'. $group['icon'] .'.png " ) no - repeat scroll 0 0 #F3F3F3 !important;
2014-01-30 11:44:54 +01:00
width : 24 px ;
height : 24 px ;
margin - top : - 12 px ! important ;
2013-04-02 15:44:48 +02:00
}
</ style >
' );
$ui -> contentAddHtml ( '<div data-collapsed-icon="group_' . $count . '" ' .
'data-expanded-icon="group_' . $count . '" ' .
'data-iconpos="right" data-role="collapsible" ' .
2016-09-28 16:56:05 +02:00
'data-collapsed="true" data-theme="' . $color_class . '" data-content-theme="d">' );
$ui -> contentAddHtml ( '<h4>' . $group [ '_name_' ] . '</h4>' );
2014-02-04 17:22:12 +01:00
$ui -> contentAddHtml ( '<ul data-role="listview" class="groups_sublist">' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_agent , $group [ '_id_' ], AGENT_STATUS_ALL ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/agent.png' , true , false , false , false , false , true ) . __ ( 'Total agents' ) . '</span>' .
'<span class="number_count">' . $group [ '_total_agents_' ] . '</span>' .
'</a></li>' );
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_agent , $group [ '_id_' ], AGENT_STATUS_NOT_INIT ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/agent_notinit.png' , true , false , false , false , false , true ) . __ ( 'Agents not init' ) . '</span>' .
'<span class="number_count">' . $group [ '_agents_not_init_' ] . '</span>' .
'</a></li>' );
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_agent , $group [ '_id_' ], AGENT_STATUS_CRITICAL ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/agent_critical.png' , true , false , false , false , false , true ) . __ ( 'Agents critical' ) . '</span>' .
'<span class="number_count">' . $group [ '_agents_critical_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_agent , $group [ '_id_' ], AGENT_STATUS_UNKNOWN ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/agent_unknown.png' , true , false , false , false , false , true ) . __ ( 'Agents unknown' ) . '</span>' .
'<span class="number_count">' . $group [ '_agents_unknown_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_modules , $group [ '_id_' ], AGENT_MODULE_STATUS_UNKNOWN ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/module_unknown.png' , true , false , false , false , false , true ) . __ ( 'Unknown modules' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_unknown_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_modules , $group [ '_id_' ], AGENT_MODULE_STATUS_NOT_INIT ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/module_notinit.png' , true , false , false , false , false , true ) . __ ( 'Not init modules' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_not_init_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_modules , $group [ '_id_' ], AGENT_MODULE_STATUS_NORMAL ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/module_ok.png' , true , false , false , false , false , true ) . __ ( 'Normal modules' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_ok_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_modules , $group [ '_id_' ], AGENT_MODULE_STATUS_WARNING ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/module_warning.png' , true , false , false , false , false , true ) . __ ( 'Warning modules' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_warning_' ] . '</span>' .
2016-09-28 16:04:13 +02:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="' . sprintf ( $url_modules , $group [ '_id_' ], AGENT_MODULE_STATUS_CRITICAL_BAD ) . '">' .
'<span class="name_count">' . html_print_image ( 'images/module_critical.png' , true , false , false , false , false , true ) . __ ( 'Critical modules' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_critical_' ] . '</span>' .
2016-09-28 16:04:13 +02:00
'</a></li>' );
2016-09-28 16:56:05 +02:00
$ui -> contentAddHtml ( '<li data-icon="false"><a href="">' .
'<span class="name_count">' . html_print_image ( 'images/bell_error.png' , true , false , false , false , false , true ) . __ ( 'Alerts fired' ) . '</span>' .
'<span class="number_count">' . $group [ '_monitors_alerts_fired_' ] . '</span>' .
2014-02-04 17:22:12 +01:00
'</a></li>' );
2013-04-02 15:44:48 +02:00
$ui -> contentAddHtml ( '</ul>' );
$ui -> contentAddHtml ( '</div>' );
$count ++ ;
}
$ui -> contentAddHtml ( '</div>' );
//$ui->contentAddHtml(ob_get_clean());
//~ $table = new Table();
//~ $table->setId('list_groups');
//~ $table->setClass('group_view');
//~ $table->importFromHash($this->groups);
//~ $table->setRowClass($this->status);
//~ $ui->contentAddHtml($table->getHTML());
2013-03-15 15:50:47 +01:00
$ui -> endContent ();
$ui -> showPage ();
}
private function getListGroups () {
$return = array ();
2016-09-30 10:32:48 +02:00
$system = System :: getInstance ();
2013-03-15 15:50:47 +01:00
$user = User :: getInstance ();
2016-09-30 10:32:48 +02:00
$all_data = groupview_status_modules_agents ( $system -> getConfig ( 'id_user' ), false , 'AR' , false );
$result_groups = groupview_get_groups_list ( $system -> getConfig ( 'id_user' ), false , 'AR' , true , true );
2013-03-15 15:50:47 +01:00
2016-09-30 10:32:48 +02:00
foreach ( $all_data as $group_all_data ) {
$result_groups [ 0 ][ '_total_agents_' ] += $group_all_data [ " _total_agents_ " ];
$result_groups [ 0 ][ '_monitors_ok_' ] += $group_all_data [ " _monitors_ok_ " ];
$result_groups [ 0 ][ '_monitors_warning_' ] += $group_all_data [ " _monitors_warning_ " ];
$result_groups [ 0 ][ '_monitors_critical_' ] += $group_all_data [ " _monitors_critical_ " ];
$result_groups [ 0 ][ '_monitors_unknown_' ] += $group_all_data [ " _monitors_unknown_ " ];
$result_groups [ 0 ][ '_monitors_not_init_' ] += $group_all_data [ " _monitors_not_init_ " ];
$result_groups [ 0 ][ '_agents_unknown_' ] += $group_all_data [ " _agents_unknown_ " ];
$result_groups [ 0 ][ '_agents_not_init_' ] += $group_all_data [ " _agents_not_init_ " ];
$result_groups [ 0 ][ '_agents_critical_' ] += $group_all_data [ " _agents_critical_ " ];
$result_groups [ 0 ][ '_monitors_alerts_fired_' ] += $group_all_data [ " _monitors_alerts_fired_ " ];
2013-03-15 15:50:47 +01:00
}
2016-09-30 10:32:48 +02:00
return $result_groups ;
2013-03-15 15:50:47 +01:00
}
2013-11-28 17:54:18 +01:00
}