2008-11-14 16:37:32 +01:00
< ? php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Evi Vanoost, <vanooste@rcbi.rochester.edu>
// Please see http://pandora.sourceforge.net 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.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2009-01-08 16:52:13 +01:00
/**
* Delete events in a transaction
*
* @ param mixed $id_event Event ID or array of events
*
* @ return bool Whether or not it was successful
*/
2008-11-14 16:37:32 +01:00
function delete_event ( $id_event ) {
global $config ;
$id_event = ( array ) safe_int ( $id_event , 1 ); //Cleans up the selection for all unwanted values also casts any single values as an array
process_sql ( " SET AUTOCOMMIT = 0; " );
process_sql ( " START TRANSACTION; " );
$errors = 0 ;
foreach ( $id_event as $event ) {
$sql = sprintf ( " DELETE FROM tevento WHERE id_evento = %d " , $event );
$ret = process_sql ( $sql );
if ( give_acl ( $config [ " id_user " ], get_event_group ( $event ), " IM " ) == 0 ) {
//Check ACL
audit_db ( $config [ " id_user " ], $config [ " remote_addr " ], " ACL Violation " , " Attempted deleting event # " . $event );
} elseif ( $ret !== false ) {
//ACL didn't fail nor did return
continue ;
}
$errors ++ ;
}
if ( $errors > 1 ) {
process_sql ( " ROLLBACK; " );
process_sql ( " SET AUTOCOMMIT = 1; " );
return false ;
} else {
foreach ( $id_event as $event ) {
audit_db ( $config [ " id_user " ], $config [ " remote_addr " ], " Event deleted " , " Deleted event # " . $event );
}
process_sql ( " COMMIT; " );
process_sql ( " SET AUTOCOMMIT = 1; " );
return true ;
}
}
2009-01-08 16:52:13 +01:00
/**
* Validate events in a transaction
*
* @ param mixed $id_event Event ID or array of events
*
* @ return bool Whether or not it was successful
*/
2008-11-14 16:37:32 +01:00
function process_event_validate ( $id_event ) {
global $config ;
$id_event = ( array ) safe_int ( $id_event , 1 ); //Cleans up the selection for all unwanted values also casts any single values as an array
process_sql ( " SET AUTOCOMMIT = 0; " );
process_sql ( " START TRANSACTION; " );
$errors = 0 ;
foreach ( $id_event as $event ) {
$sql = sprintf ( " UPDATE tevento SET estado = 1, id_usuario = '%s' WHERE id_evento = %d " , $config [ 'id_user' ], $event );
$ret = process_sql ( $sql );
if ( give_acl ( $config [ " id_user " ], get_event_group ( $event ), " IW " ) == 0 ) {
//Check ACL
audit_db ( $config [ " id_user " ], $config [ " remote_addr " ], " ACL Violation " , " Attempted updating event # " . $event );
} elseif ( $ret !== false ) {
//ACL didn't fail nor did return
continue ;
}
$errors ++ ;
}
if ( $errors > 1 ) {
process_sql ( " ROLLBACK; " );
process_sql ( " SET AUTOCOMMIT = 1; " );
return false ;
} else {
foreach ( $id_event as $event ) {
audit_db ( $config [ " id_user " ], $config [ " remote_addr " ], " Event validated " , " Validated event # " . $event );
}
process_sql ( " COMMIT; " );
process_sql ( " SET AUTOCOMMIT = 1; " );
return true ;
}
}
/**
* Get group id of an event .
*
2009-01-08 16:52:13 +01:00
* @ param int $id_event Event id
2008-11-14 16:37:32 +01:00
*
2009-01-08 16:52:13 +01:00
* @ return int Group id of the given event .
2008-11-14 16:37:32 +01:00
*/
function get_event_group ( $id_event ) {
return ( int ) get_db_value ( 'id_grupo' , 'tevento' , 'id_evento' , ( int ) $id_event );
}
2008-12-10 21:15:38 +01:00
/**
* Get description of an event .
*
2009-01-08 16:52:13 +01:00
* @ param int $id_event Event id .
2008-12-10 21:15:38 +01:00
*
2009-01-08 16:52:13 +01:00
* @ return string Description of the given event .
2008-12-10 21:15:38 +01:00
*/
function get_event_description ( $id_event ) {
return ( string ) get_db_value ( 'evento' , 'tevento' , 'id_evento' , ( int ) $id_event );
}
/**
* Insert a event in the event log system .
*
2009-01-08 16:52:13 +01:00
* @ param int $event
* @ param int $id_group
* @ param int $id_agent
* @ param int $status
* @ param string $id_user
* @ param string $event_type
* @ param int $priority
* @ param int $id_agent_module
* @ param int $id_aam
2008-12-10 21:15:38 +01:00
*
2009-01-08 16:52:13 +01:00
* @ return int event id
2008-12-10 21:15:38 +01:00
*/
function create_event ( $event , $id_group , $id_agent , $status = 0 , $id_user = " " , $event_type = " unknown " , $priority = 0 , $id_agent_module = 0 , $id_aam = 0 ) {
$sql = sprintf ( ' INSERT INTO tevento ( id_agente , id_grupo , evento , timestamp ,
estado , utimestamp , id_usuario , event_type , criticity ,
id_agentmodule , id_alert_am )
VALUES ( % d , % d , " %s " , NOW (), % d , NOW (), " %s " , " %s " , % d , % d , % d ) ' ,
$id_agent , $id_group , $event , $status , $id_user , $event_type ,
$priority , $id_agent_module , $id_aam );
return ( int ) process_sql ( $sql , " insert_id " );
}
2008-12-16 Evi Vanoost <vanooste@rcbi.rochester.edu>
* general/logon_ok.php, godmode/agentes/modificar_agente.php,
godmode/agentes/planned_downtime.php,
godmode/agentes/manage_recontask.php, godmode/setup/news.php,
operation/agentes/datos_agente.php, operation/agentes/estado_agente.php,
operation/agentes/status_events.php, operation/agentes/tactical.php,
operation/events/events.php, operation/incidents/incidents.php,
operation/incidents/incident_detail.php, operation/messages/message.php:
Function updates and new function definitions
* include/functions.php: safe_input used utf_decode which gives problems
with foreign chars since everything else is (or should be UTF-8) fixed.
format_datetime is no longer necessary - use print_timestamp for output.
Extended multibyte wrapper functions.
* include/functions_db.php: give_server_name is now get_server_name;
dame_so_name is now get_os_name; dame_so_icon is now print_os_icon;
show_icon_group is now print_group_icon; give_network_profile_name is now
get_networkprofile_name; smal_event_table is now print_events_table
* include/functions_events.php: print_events_table was moved here and
fixed. Now calculates the cutoff of event and agent text.
* include/functions_html.php: Added title to print_table function and
updated documentation. print_timestamp now uses the new function
definitions (array) and handles 0-dates better. print_group_icon and
print_os_icon added and extended. Added print_agent_name. This function
fixes issues that show up when cutting off agent names with multibyte char
* operation/servers/view_server.php: Rewrite with new functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1295 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-12-17 15:26:42 +01:00
/**
* Prints a small event table
*
* @ param string $filter SQL WHERE clause
* @ param int $limit How many events to show
* @ param int $width How wide the table should be
* @ param bool $return Prints out HTML if false
*
* @ return string HTML with table element
*/
function print_events_table ( $filter = " " , $limit = 10 , $width = 440 , $return = false ) {
global $config ;
$sql = sprintf ( " SELECT * FROM tevento %s ORDER BY timestamp DESC LIMIT %d " , $filter , $limit );
$result = get_db_all_rows_sql ( $sql );
if ( $result === false ) {
$return = '<div class="nf">' . __ ( 'No events' ) . '</div>' ;
if ( $return === false ) {
echo $return ;
}
return $return ;
} else {
$table -> cellpadding = 4 ;
$table -> cellspacing = 4 ;
$table -> width = $width ;
$table -> class = " databox " ;
$table -> title = __ ( 'Latest events' );
$table -> titlestyle = " background-color:#799E48; " ;
$table -> headclass = array ();
$table -> head = array ();
$table -> rowclass = array ();
$table -> data = array ();
$table -> align = array ();
$table -> head [ 0 ] = __ ( 'St' );
$table -> align [ 0 ] = " center " ;
$table -> head [ 1 ] = __ ( 'Type' );
$table -> headclass [ 1 ] = " datos3 f9 " ;
$table -> align [ 1 ] = " center " ;
$table -> head [ 2 ] = __ ( 'Event name' );
$table -> head [ 3 ] = __ ( 'Agent name' );
$table -> head [ 4 ] = __ ( 'User ID' );
$table -> headclass [ 4 ] = " datos3 f9 " ;
$table -> align [ 4 ] = " center " ;
$table -> head [ 5 ] = __ ( 'Timestamp' );
$table -> headclass [ 5 ] = " datos3 f9 " ;
$table -> align [ 5 ] = " right " ;
foreach ( $result as $event ) {
if ( ! give_acl ( $config [ " id_user " ], $event [ " id_grupo " ], " AR " )) {
continue ;
}
$data = array ();
/* Colored box */
if ( $event [ " estado " ] == 0 ) {
$data [ 0 ] = '<img src="images/pixel_red.png" width="20" height="20" title="' . get_priority_name ( $event [ " criticity " ]) . '" />' ;
} else {
$data [ 0 ] = '<img src="images/pixel_green.png" width="20" height="20" title="' . get_priority_name ( $event [ " criticity " ]) . '" />' ;
}
/* Event type */
switch ( $event [ " event_type " ]) {
case " alert_recovered " :
$data [ 1 ] = '<img src="images/error.png" title="' . __ ( 'Alert recovered' ) . '" />' ;
break ;
case " alert_manual_validation " :
$data [ 1 ] = '<img src="images/eye.png" title="' . __ ( 'Alert manually validated' ) . '" />' ;
break ;
case " monitor_up " :
$data [ 1 ] = '<img src="images/lightbulb.png" title="' . __ ( 'Monitor up' ) . '" />' ;
break ;
case " monitor_down " :
$data [ 1 ] = '<img src="images/lightbulb_off.png" title="' . __ ( 'Monitor down' ) . '" />' ;
break ;
case " alert_fired " :
$data [ 1 ] = '<img src="images/bell.png" title="' . __ ( 'Alert fired' ) . '" />' ;
break ;
case " system " ;
$data [ 1 ] = '<img src="images/cog.png" title="' . __ ( 'System' ) . '" />' ;
break ;
case " recon_host_detected " ;
$data [ 1 ] = '<img src="images/network.png" title="' . __ ( 'Host detected by recon server' ) . '" />' ;
break ;
default :
$data [ 1 ] = '<img src="images/err.png" title="' . $event [ " event_type " ] . '" />' ;
break ;
}
// Event description wrap around by default at 44 or ~3 lines (10 seems to be a good ratio to wrap around for most sizes. Smaller number gets longer strings)
$data [ 2 ] = '<span class="' . get_priority_class ( $event [ " criticity " ]) . 'f9" title="' . safe_input ( $event [ " evento " ]) . '">' . safe_input ( substr ( $event [ " evento " ], 0 , floor ( $width / 10 )));
if ( strlen ( $event [ " evento " ]) > floor ( $width / 10 )) {
$data [ 2 ] .= " ... " ;
}
$data [ 2 ] .= '</span>' ;
if ( $event [ " id_agente " ] > 0 ) {
// Agent name
$data [ 3 ] = print_agent_name ( $event [ " id_agente " ], true , floor ( $width / 20 )); //At 440 this would be be 22
// for System or SNMP generated alerts
} elseif ( $event [ " event_type " ] == " system " ) {
$data [ 3 ] = __ ( 'System' );
} else {
$data [ 3 ] = __ ( 'Alert' ) . " SNMP " ;
}
// User who validated event
if ( $event [ " estado " ] != 0 ) {
$data [ 4 ] = print_username ( $event [ " id_usuario " ], true );
} else {
$data [ 4 ] = '' ;
}
// Timestamp
$data [ 5 ] = print_timestamp ( $event [ " timestamp " ], true );
array_push ( $table -> rowclass , get_priority_class ( $event [ " criticity " ]));
array_push ( $table -> data , $data );
}
$return = print_table ( $table , $return );
unset ( $table );
return $return ;
}
}
2008-11-14 16:37:32 +01:00
?>