2013-03-20 18:41:35 +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.
class Alerts {
private $correct_acl = false ;
2013-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions_groups.php:
changes for to use in the calls in mobile version.
* mobile/index.php, mobile/operation/events.php,
mobile/operation/modules.php, mobile/operation/events,
mobile/operation/events/events.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/alerts.php,
mobile/include/style/main.css, mobile/include/ui.class.php,
mobile/include/user.class.php: changes and improves in the code
of mobile.
* mobile/operation/agents/*, mobile/operation/servers/*: removed
the old files from version pandora mobile 4.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-26 18:24:10 +01:00
private $acl = " LM " ;
2013-03-20 18:41:35 +01:00
private $default = true ;
2013-07-08 12:15:49 +02:00
private $default_filters = array ();
2013-03-20 18:41:35 +01:00
private $free_search = '' ;
private $group = 0 ;
private $status = 'all' ;
private $standby = - 1 ;
2013-04-09 11:29:03 +02:00
private $id_agent = 0 ;
private $all_alerts = false ;
2013-03-20 18:41:35 +01:00
private $alert_status_items = null ;
private $alert_standby_items = null ;
2013-04-09 11:29:03 +02:00
private $columns = null ;
2013-03-20 18:41:35 +01:00
function __construct () {
$this -> alert_status_items = array (
'all_enabled' => __ ( 'All (Enabled)' ),
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
'all' => __ ( 'All' ),
2013-03-20 18:41:35 +01:00
'fired' => __ ( 'Fired' ),
'notfired' => __ ( 'Not fired' ),
'disabled' => __ ( 'Disabled' ));
$this -> alert_standby_items = array (
'-1' => __ ( 'All' ),
'1' => __ ( 'Standby on' ),
'0' => __ ( 'Standby off' ));
2013-04-09 11:29:03 +02:00
$this -> columns = array ( 'agent' => 1 );
2013-03-20 18:41:35 +01:00
$system = System :: getInstance ();
2013-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions_groups.php:
changes for to use in the calls in mobile version.
* mobile/index.php, mobile/operation/events.php,
mobile/operation/modules.php, mobile/operation/events,
mobile/operation/events/events.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/alerts.php,
mobile/include/style/main.css, mobile/include/ui.class.php,
mobile/include/user.class.php: changes and improves in the code
of mobile.
* mobile/operation/agents/*, mobile/operation/servers/*: removed
the old files from version pandora mobile 4.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-26 18:24:10 +01:00
if ( $system -> checkACL ( $this -> acl )) {
2013-03-20 18:41:35 +01:00
$this -> correct_acl = true ;
}
else {
$this -> correct_acl = false ;
}
}
private function alertsGetFilters () {
$system = System :: getInstance ();
2013-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions_groups.php:
changes for to use in the calls in mobile version.
* mobile/index.php, mobile/operation/events.php,
mobile/operation/modules.php, mobile/operation/events,
mobile/operation/events/events.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/alerts.php,
mobile/include/style/main.css, mobile/include/ui.class.php,
mobile/include/user.class.php: changes and improves in the code
of mobile.
* mobile/operation/agents/*, mobile/operation/servers/*: removed
the old files from version pandora mobile 4.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-26 18:24:10 +01:00
$user = User :: getInstance ();
2013-03-20 18:41:35 +01:00
2013-07-08 12:15:49 +02:00
$this -> default_filters [ 'standby' ] = true ;
$this -> default_filters [ 'group' ] = true ;
$this -> default_filters [ 'status' ] = true ;
$this -> default_filters [ 'free_search' ] = true ;
2013-03-20 18:41:35 +01:00
$this -> free_search = $system -> getRequest ( 'free_search' , '' );
if ( $this -> free_search != '' ) {
$this -> default = false ;
2013-07-08 12:15:49 +02:00
$this -> default_filters [ 'free_search' ] = false ;
2013-03-20 18:41:35 +01:00
}
$this -> status = $system -> getRequest ( 'status' , __ ( " Status " ));
2013-07-08 12:15:49 +02:00
if (( $this -> status === __ ( " Status " )) || ( $this -> status == 'all' )) {
2013-03-20 18:41:35 +01:00
$this -> status = 'all' ;
}
else {
$this -> default = false ;
2013-07-08 12:15:49 +02:00
$this -> default_filters [ 'status' ] = false ;
2013-03-20 18:41:35 +01:00
}
$this -> group = $system -> getRequest ( 'group' , __ ( " Group " ));
2013-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions_groups.php:
changes for to use in the calls in mobile version.
* mobile/index.php, mobile/operation/events.php,
mobile/operation/modules.php, mobile/operation/events,
mobile/operation/events/events.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/alerts.php,
mobile/include/style/main.css, mobile/include/ui.class.php,
mobile/include/user.class.php: changes and improves in the code
of mobile.
* mobile/operation/agents/*, mobile/operation/servers/*: removed
the old files from version pandora mobile 4.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-26 18:24:10 +01:00
if ( ! $user -> isInGroup ( $this -> acl , $this -> group )) {
$this -> group = 0 ;
}
if (( $this -> group === __ ( " Group " )) || ( $this -> group == 0 )) {
2013-03-20 18:41:35 +01:00
$this -> group = 0 ;
}
else {
$this -> default = false ;
2013-07-08 12:15:49 +02:00
$this -> default_filters [ 'group' ] = false ;
2013-03-20 18:41:35 +01:00
}
$this -> standby = $system -> getRequest ( 'standby' , __ ( 'Stand by' ));
2013-07-08 12:15:49 +02:00
if (( $this -> standby === __ ( 'Stand by' )) || ( $this -> standby == - 1 )) {
2013-03-20 18:41:35 +01:00
$this -> standby = - 1 ;
}
else {
$this -> default = false ;
2013-07-08 12:15:49 +02:00
$this -> default_filters [ 'standby' ] = false ;
2013-03-20 18:41:35 +01:00
}
}
2013-04-09 11:29:03 +02:00
public function setFilters ( $filters ) {
if ( isset ( $filters [ 'id_agent' ])) {
$this -> id_agent = $filters [ 'id_agent' ];
}
if ( isset ( $filters [ 'all_alerts' ])) {
$this -> all_alerts = $filters [ 'all_alerts' ];
}
}
2013-03-20 18:41:35 +01:00
public function ajax ( $parameter2 = false ) {
$system = System :: getInstance ();
if ( ! $this -> correct_acl ) {
return ;
}
else {
switch ( $parameter2 ) {
case 'xxxx' :
break ;
}
}
}
public function show () {
if ( ! $this -> correct_acl ) {
$this -> show_fail_acl ();
}
else {
$this -> alertsGetFilters ();
$this -> show_alerts ();
}
}
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-20 18:41:35 +01:00
}
private function show_alerts () {
$ui = Ui :: getInstance ();
$ui -> createPage ();
2013-11-28 17:54:18 +01:00
$ui -> createDefaultHeader ( __ ( " Alerts " ),
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
$ui -> createHeaderButton (
array ( 'icon' => 'back' ,
'pos' => 'left' ,
'text' => __ ( 'Back' ),
2013-11-28 17:54:18 +01:00
'href' => 'index.php?page=home' )));
2013-03-20 18:41:35 +01:00
$ui -> showFooter ( false );
$ui -> beginContent ();
$filter_title = sprintf ( __ ( 'Filter Alerts by %s' ),
$this -> filterAlertsGetString ());
$ui -> contentBeginCollapsible ( $filter_title );
$ui -> beginForm ();
$options = array (
'name' => 'page' ,
'type' => 'hidden' ,
'value' => 'alerts'
);
$ui -> formAddInput ( $options );
$system = System :: getInstance ();
$groups = users_get_groups_for_select (
$system -> getConfig ( 'id_user' ), " ER " , true , true , false , 'id_grupo' );
$options = array (
'name' => 'group' ,
'title' => __ ( 'Group' ),
'label' => __ ( 'Group' ),
'items' => $groups ,
'selected' => $this -> group
);
$ui -> formAddSelectBox ( $options );
$options = array (
'name' => 'free_search' ,
'value' => $this -> free_search ,
'placeholder' => __ ( 'Free search' )
);
$ui -> formAddInputSearch ( $options );
$options = array (
'name' => 'status' ,
'title' => __ ( 'Status' ),
'label' => __ ( 'Status' ),
'items' => $this -> alert_status_items ,
'selected' => $this -> status
);
$ui -> formAddSelectBox ( $options );
$options = array (
'name' => 'standby' ,
'title' => __ ( 'Stand by' ),
'label' => __ ( 'Stand by' ),
'items' => $this -> alert_standby_items ,
'selected' => $this -> standby
);
$ui -> formAddSelectBox ( $options );
$options = array (
'icon' => 'refresh' ,
'icon_pos' => 'right' ,
'text' => __ ( 'Apply Filter' )
);
$ui -> formAddSubmitButton ( $options );
$html = $ui -> getEndForm ();
$ui -> contentCollapsibleAddItem ( $html );
$ui -> contentEndCollapsible ();
$this -> listAlertsHtml ();
$ui -> endContent ();
$ui -> showPage ();
}
2013-04-09 11:29:03 +02:00
public function disabledColumns ( $columns = null ) {
if ( ! empty ( $columns )) {
foreach ( $columns as $column ) {
unset ( $this -> columns [ $column ]);
}
}
}
2013-03-20 18:41:35 +01:00
2013-04-09 11:29:03 +02:00
public function listAlertsHtml ( $return = false ) {
2013-03-20 18:41:35 +01:00
$countAlerts = alerts_get_alerts ( $this -> group ,
2013-04-24 14:36:32 +02:00
$this -> free_search , $this -> status , $this -> standby , " AR " , true , $this -> id_agent );
2013-03-20 18:41:35 +01:00
$alerts = alerts_get_alerts ( $this -> group ,
2013-04-24 14:36:32 +02:00
$this -> free_search , $this -> status , $this -> standby , " AR " , false , $this -> id_agent );
2013-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions_groups.php:
changes for to use in the calls in mobile version.
* mobile/index.php, mobile/operation/events.php,
mobile/operation/modules.php, mobile/operation/events,
mobile/operation/events/events.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/alerts.php,
mobile/include/style/main.css, mobile/include/ui.class.php,
mobile/include/user.class.php: changes and improves in the code
of mobile.
* mobile/operation/agents/*, mobile/operation/servers/*: removed
the old files from version pandora mobile 4.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-26 18:24:10 +01:00
if ( empty ( $alerts ))
$alerts = array ();
2013-03-20 18:41:35 +01:00
$table = array ();
foreach ( $alerts as $alert ) {
if ( $alert [ 'alert_disabled' ]) {
$disabled_style = " <i style='color: grey;'>%s</i> " ;
}
else {
$disabled_style = " %s " ;
}
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' );
}
$row = array ();
2014-01-31 11:50:55 +01:00
if ( isset ( $this -> columns [ 'agent' ]) && $this -> columns [ 'agent' ]) {
2014-02-05 17:38:05 +01:00
$row [ __ ( 'Agent' )] = sprintf ( $disabled_style , io_safe_output ( $alert [ 'agent_name' ]));
2013-04-09 11:29:03 +02:00
}
2013-03-20 18:41:35 +01:00
$row [ __ ( 'Module' )] = sprintf ( $disabled_style ,
io_safe_output ( $alert [ 'module_name' ]));
$row [ __ ( 'Template' )] = sprintf ( $disabled_style ,
io_safe_output ( $alert [ 'template_name' ]));
$row [ __ ( 'Last Fired' )] = sprintf ( $disabled_style ,
ui_print_timestamp ( $alert [ " last_fired " ], true ));
$row [ __ ( 'Status' )] = ui_print_status_image ( $status , $title , true );
$table [] = $row ;
}
$ui = UI :: getInstance ();
if ( empty ( $table )) {
2014-02-11 11:37:30 +01:00
$html = '<p class="empty_advice">' . __ ( 'No alerts' ) . '</p>' ;
2013-04-09 11:29:03 +02:00
if ( ! $return ) {
$ui -> contentAddHtml ( $html );
}
else {
return $html ;
}
2013-03-20 18:41:35 +01:00
}
else {
$tableHTML = new Table ();
2013-11-28 17:54:18 +01:00
$tableHTML -> id = 'list_alerts' ;
2013-03-20 18:41:35 +01:00
$tableHTML -> importFromHash ( $table );
2013-04-09 11:29:03 +02:00
if ( ! $return ) {
$ui -> contentAddHtml ( $tableHTML -> getHTML ());
}
else {
return $tableHTML -> getHTML ();
}
2013-03-20 18:41:35 +01:00
}
}
private function filterAlertsGetString () {
if ( $this -> default ) {
return __ ( " (Default) " );
}
else {
2013-07-08 12:15:49 +02:00
$filters_to_serialize = array ();
if ( ! $this -> default_filters [ 'standby' ]) {
$filters_to_serialize [] = sprintf ( __ ( " Standby: %s " ),
$this -> alert_standby_items [ $this -> standby ]);
}
if ( ! $this -> default_filters [ 'group' ]) {
$filters_to_serialize [] = sprintf ( __ ( " Group: %s " ),
groups_get_name ( $this -> group , true ));
}
if ( ! $this -> default_filters [ 'status' ]) {
$filters_to_serialize [] = sprintf ( __ ( " Status: %s " ),
$this -> alert_status_items [ $this -> status ]);
}
if ( ! $this -> default_filters [ 'free_search' ]) {
$filters_to_serialize [] = sprintf ( __ ( " Free Search: %s " ),
$this -> free_search );
}
$string = '(' . implode ( ' - ' , $filters_to_serialize ) . ')' ;
return $string ;
//~ $status_text = $this->alert_status_items[$this->status];
//~ $standby_text = $this->alert_standby_items[$this->standby];
//~ $group_text = groups_get_name($this->group, true);
2013-03-20 18:41:35 +01:00
2013-07-08 12:15:49 +02:00
//~ return sprintf(__('(Status: %s - Standby: %s - Group: %s - Free Search: %s)'),
//~ $status_text, $standby_text, $group_text, $this->free_search);
2013-03-20 18:41:35 +01:00
}
}
}
2013-11-28 17:54:18 +01:00
?>