pandorafms/pandora_console/include/functions_events.php

142 lines
4.3 KiB
PHP
Raw Normal View History

<?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.
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;
}
}
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.
*
* @param id_event Event id
*
* @return Group id of the given event.
*/
function get_event_group ($id_event) {
return (int) get_db_value ('id_grupo', 'tevento', 'id_evento', (int) $id_event);
}
2008-12-10 Evi Vanoost <vanooste@rcbi.rochester.edu> * include/functions.php: format_for_graph is now much simpler and uses format_numeric. * include/functions_db.php: give_note_author, give_incident_author, dame_numero_notas, borrar_incidencia, event_insert and return_event_description are now in their respective functions_*.php files but under a new name. Fixed delete_agent transaction error detection * include/functions_events.php: Added get_event_description and create_event (formerly return_event_description and event_insert) * include/functions_html.php: print_timestamp attributes should be default empty, not required. Added print_username for a consistent username print * operation/agentes/ver_agente.php: Function renaming (create_event) * operation/incidents/incident.php: Partial rewrite. Uses new functions. Also added some of feature request #2264838 * operation/incidents/incident_detail.php: Partial rewrite. Uses new functions. Added some of feature request #2264838 functionality. * operation/incidents/incident_search.php, operation/incidents/incident_statistics.php: Minor style update * pandoradb.sql: New tincidencia and tnota layout. No use for tnota_inc * include/functions_incidents.php: All incidents functions. Documentation will be online soon. Also includes an upgrade mechanism for SVN users. Mechanism should be removed for a stable version and integrated into install/upgrade tool. * lib/PandoraFMS/DB.pm: New table layout doesn't require timestamp anymore git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1285 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-12-10 21:15:38 +01:00
/**
* Get description of an event.
*
* @param id_event Event id.
*
* @return Description of the given event.
*/
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.
*
* @param event
* @param id_group
* @param id_agent
* @param status
* @param id_user
* @param event_type
* @param priority
* @param id_agent_module
* @param id_aam
*
* @return event_id
*/
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");
}
?>