2009-01-19 Esteban Sanchez <estebans@artica.es>

* godmode/agentes/configurar_agente.php: Removed references to old
        talerta and talerta_modulo tables.

        * godmode/agentes/alert_manager_editor.php,
        godmode/alerts/configure_alert.php: Removed from repository. It became 
        a useless file since the new alert system is implemented.

        * godmode/agentes/manage_config.php: Style correction. Copy alerts
        among agents using the new tables and structures.

        * godmode/reporting/reporting_builder.php: Do not sort report time 
        period, it was not human readable if it was alphanumeric sorted.

        * include/functions_agents.php: Fixed get_agent_alerts_simple() and
        commented get_agent_alerts_combined() code since it's not implemented 
        yet.

        * include/functions_db.php, include/functions_reporting.php: Fixed 
        function documentation format. Use structures, functions and tables of 
        the new alert system.

        * operation/reporting/reporting_viewer.php: Style correction.

        * pandoradb.sql: Removed default values on mediumtext fields because
        it was causing a SQL warning.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1356 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-01-19 14:42:34 +00:00
parent 735c2a24bd
commit 02d09bd32d
11 changed files with 337 additions and 1040 deletions

View File

@ -1,3 +1,31 @@
2009-01-19 Esteban Sanchez <estebans@artica.es>
* godmode/agentes/configurar_agente.php: Removed references to old
talerta and talerta_modulo tables.
* godmode/agentes/alert_manager_editor.php,
godmode/alerts/configure_alert.php: Removed from repository. It became
a useless file since the new alert system is implemented.
* godmode/agentes/manage_config.php: Style correction. Copy alerts
among agents using the new tables and structures.
* godmode/reporting/reporting_builder.php: Do not sort report time
period, it was not human readable if it was alphanumeric sorted.
* include/functions_agents.php: Fixed get_agent_alerts_simple() and
commented get_agent_alerts_combined() code since it's not implemented
yet.
* include/functions_db.php, include/functions_reporting.php: Fixed
function documentation format. Use structures, functions and tables of
the new alert system.
* operation/reporting/reporting_viewer.php: Style correction.
* pandoradb.sql: Removed default values on mediumtext fields because
it was causing a SQL warning.
2009-01-16 Evi Vanoost <vanooste@rcbi.rochester.edu> 2009-01-16 Evi Vanoost <vanooste@rcbi.rochester.edu>
* godmode/alerts/configure_alert_template.php: Some aesthetic fixes and * godmode/alerts/configure_alert_template.php: Some aesthetic fixes and

View File

@ -1,410 +0,0 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// 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.
if (!isset ($id_agente)) {
die ("Not Authorized");
}
$add_component = get_parameter ("add_component",0);
echo "<h3>".__('Alert association form');
pandora_help ("alerts");
echo "</h3>";
echo '<form name="agente" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$id_agente.'">';
if ($form_alerttype == "combined")
echo "<input type='hidden' name='combined' value ='1'>";
else
echo "<input type='hidden' name='combined' value ='0'>";
if (! isset($update_alert))
$update_alert = -1;
if ($update_alert != 1) {
echo '<input type="hidden" name="insert_alert" value=1>';
} else {
echo '<input type="hidden" name="update_alert" value=1>';
echo '<input type="hidden" name="id_aam" value="'.$alerta_id_aam.'">';
}
echo '<input type="hidden" name="id_agente" value="'.$id_agente.'">';
echo '<table width=600 cellpadding="4" cellspacing="4" class="databox_color" border=0>';
// AgentModule association
echo '<tr><td class="datos3">'.__('Assigned module');
echo '<td class="datos3">';
if ($form_alerttype != "combined"){
if ($update_alert != 1) {
echo '<select name="agente_modulo" style="width:210px;"> ';
$sql2 = "SELECT id_agente_modulo, id_tipo_modulo, nombre FROM tagente_modulo WHERE id_agente = $id_agente ORDER BY nombre";
$result2=mysql_query($sql2);
while ($row2=mysql_fetch_array($result2)){
if ($row2["id_tipo_modulo"] != -1) {
$sql1='SELECT nombre FROM ttipo_modulo WHERE id_tipo = '.$row2["id_tipo_modulo"];
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
echo "<option value='".$row2["id_agente_modulo"]."'>".$row2["nombre"]." ( ".$row["nombre"]." )</option>";
}
} else // for -1, is a special module, keep alive monitor !!
echo "<option value='".$row2["id_agente_modulo"]."'>".$row2["nombre"]."</option>";
}
echo "</select>";
} else {
$agentmodule_name = get_db_sql ("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = $alerta_id_agentemodulo");
echo $agentmodule_name;
}
} else {
echo __('N/A');
}
echo '<td class="datos3">';
echo __('Priority');
echo '<td class="datos3">';
if (! isset($alert_priority)) {
$alert_priority = 3; // Warning by default
}
print_select (get_priorities (), "alert_priority", $alert_priority, '', '', '');
// Alert type
echo '<tr><td class="datos">'. __('Alert type');
pandora_help ("alert_type");
echo '</td>';
echo '<td class="datos"><select name="tipo_alerta">';
if (isset($tipo_alerta)){
echo "<option value='".$tipo_alerta."'>".get_alert_type ($tipo_alerta)."</option>";
}
$sql1 = 'SELECT id_alerta, nombre FROM talerta ORDER BY nombre';
$result = mysql_query ($sql1);
while ($row = mysql_fetch_array ($result)){
echo "<option value='".$row["id_alerta"]."'>".$row["nombre"]."</option>";
}
echo "</select>";
// Alert disable / enable
echo "<td class='datos'>";
echo __('Alert status');
echo "<td class='datos'>";
echo '<select name="disable_alert">';
if ((isset($alerta_disable)) AND ($alerta_disable == "1")) {
echo "<option value='1'>".__('Disabled');
echo "<option value='0'>".__('Enabled');
} else {
echo "<option value='0'>".__('Enabled');
echo "<option value='1'>".__('Disabled');
}
echo "</select>";
// Descripcion
echo '<tr><td class="datos2">'.__('Description');
echo '<td class="datos2" colspan=4><input type="text" name="descripcion" size="60" value ="'.$alerta_descripcion.'">';
// Trigger values for alert
if ($form_alerttype != "combined"){
echo '<tr><td class="datos">'.__('Min. Value');
echo "<a href='#' class='tip'>&nbsp;<span>";echo __('Min. possible value to consider \'valid\' values, below this limit, Pandora FMS will fire the alert')."</span></a>";
echo '<td class="datos"><input type="text" name="minimo" size="5" value="'.$alerta_dis_min.'" style="margin-right: 70px;">';
echo "<td class='datos'>";
echo __('Max. Value');
echo "<a href='#' class='tip'>&nbsp;<span>";
echo __('Max. possible value to consider \'valid\' values, above this limit, Pandora FMS will fire the alert');
echo "</span></a>";
echo "<td class='datos'>";
echo "<input type='text' name='maximo' size='5' value='$alerta_dis_max'>";
// <!-- FREE TEXT ALERT -->
echo '<tr><td class="datos2">'.__('Alert text')."<a href='#' class='tip'>&nbsp;<span>NOTE: This field is for matching text on data. Regular Expression Supported </span></a>";
echo '<td class="datos2" colspan=4><input type="text" name="alert_text" size="60" value ="'.$alert_text.'">';
}
// Time Threshold (TT)
echo '<tr><td class="datos">'.__('Time threshold');
echo "<a href='#' class='tip'>&nbsp;<span>".__('This value must be al least Module Interval * (Min.Number of Alerts + 1)')."</span></a>";
echo '<td class="datos">';
echo '<select name="time_threshold" style="margin-right: 60px;">';
if ($alerta_time_threshold != ""){
echo "<option value='".$alerta_time_threshold."'>".human_time_description($alerta_time_threshold)."</option>";
}
echo '
<option value=300>5 Min.</option>
<option value=600>10 Min.</option>
<option value=900>15 Min.</option>
<option value=1800>30 Min.</option>
<option value=3600>1 Hour</option>
<option value=7200>2 Hour</option>
<option value=18000>5 Hour</option>
<option value=43200>12 Hour</option>
<option value=86400>1 Day</option>
<option value=604800>1 Week</option>
<option value=-1>Other value</option>
</select>';
// Other TT
echo '<td class="datos">';
echo __('Other');
echo '<td class="datos">';
echo '<input type="text" name="other" size="5">';
// Max / Min alerts
echo "<tr><td class='datos2'>".__('Min. number of alerts');
echo '<td class="datos2">';
echo '<input type="text" name="min_alerts" size="5" value="';
if (isset($alerta_min_alerts))
echo $alerta_min_alerts;
else
echo 0;
echo '" style="margin-right: 10px;">';
echo '<td class="datos2">';
echo __('Max. number of alerts');
echo '<td class="datos2">';
echo '<input type="text" name="max_alerts" size="5" value="';
if (isset($alerta_max_alerts))
echo $alerta_max_alerts;
else
echo 1;
echo '" style="margin-right: 10px;">';
// Field1
echo '<tr><td class="datos">'.__('Field #1 (Alias, name)');
echo '<td class="datos" colspan=4><input type="text" name="campo_1" size="39" value="'.$alerta_campo1.'">';
echo "<a href='#' class='tip'><span><b>Macros:</b><br>_agent_<br>";
echo '_timestamp_<br>_data_<br></span></a>';
// Field2
echo '<tr><td class="datos2">'.__('Field #2 (Single Line)');
echo '<td class="datos2" colspan=4>';
echo '<input type="text" name="campo_2" size="39" value="'.$alerta_campo2.'">';
echo "<a href='#' class='tip'><span>";
echo '<b>Macros:</b><br>_agent_<br>_timestamp_<br>_data_<br></span></a>';
//Field3
echo '<tr><td class="datos">'.__('Field #3 (Full Text)');
echo '<td class="datos" colspan=4>';
echo '<textarea name="campo_3" style="height:85px; width: 380px" rows="4">';
echo $alerta_campo3;
echo '</textarea><a href="#" class="tip"><span><b>Macros:</b><br>_agent_<br>';
echo '_timestamp_<br>_data_<br></span></a>';
// Time for alerting
echo "<tr><td class='datos2'>".__('Time from');
echo "<td class='datos2'><select name='time_from'>";
if ($time_from != ""){
echo "<option value='$time_from'>".substr($time_from,0,5);
}
for ($a=0; $a < 48; $a++){
echo "<option value='";
echo render_time ($a);
echo "'>";
echo render_time ($a);
}
echo "<option value='23:59'>23:59";
echo "</select>";
echo "<td class='datos2'>".__('Time to');
echo "<td class='datos2'><select name='time_to'>";
if ($time_from != ""){
echo "<option value='$time_to'>".substr($time_to,0,5);
}
for ($a=0; $a < 48; $a++){
echo "<option value='";
echo render_time ($a);
echo "'>";
echo render_time ($a);
}
echo "<option value='23:59'>23:59";
echo "</select>";
// Days of week
echo "<tr><td class='datos'>".__('Days of week');
echo "<td class='datos' colspan=4>";
echo __('Mon');
print_checkbox ("alert_d1", 1, $alert_d1);
echo "&nbsp;&nbsp;";
echo __('Tue');
print_checkbox ("alert_d2", 1, $alert_d2);
echo "&nbsp;&nbsp;";
echo __('Wed');
print_checkbox ("alert_d3", 1, $alert_d3);
echo "&nbsp;&nbsp;";
echo __('Thu');
print_checkbox ("alert_d4", 1, $alert_d4);
echo "&nbsp;&nbsp;";
echo __('Fri');
print_checkbox ("alert_d5", 1, $alert_d5);
echo "&nbsp;&nbsp;";
echo __('Sat');
print_checkbox ("alert_d6", 1, $alert_d6);
echo "&nbsp;&nbsp;";
echo __('Sun');
print_checkbox ("alert_d7", 1, $alert_d7);
// Field2 Recovery
echo '<tr><td class="datos2">'.__('Field #2 (Rec)');
echo '<td class="datos2">';
echo '<input type="text" name="campo_2_rec" size="20" value="'.$alerta_campo2_rec.'">';
// Alert recovery disable / enable
echo '<td class="datos2">'. __('Alert recovery');
pandora_help ("alert_recovery");
echo '</td>';
echo "<td class='datos2'>";
echo '<select name="alert_recovery">';
if ((isset($alert_recovery)) AND ($alert_recovery == "1")) {
echo "<option value='1'>".__('Enabled');
echo "<option value='0'>".__('Disabled');
} else {
echo "<option value='0'>".__('Disabled');
echo "<option value='1'>".__('Enabled');
}
echo "</select>";
//Field3 - Recovery
echo '<tr><td class="datos">'.__('Field #3 (Rec)');
echo '<td class="datos" colspan=4>';
echo '<input type="text" name="campo_3_rec" size="60" value="'.$alerta_campo3_rec.'">';
// End block only if $creacion_agente != 1;
echo "</td></tr></table>";
echo '<table width=605>';
echo '<tr><td align="right">';
if ($update_alert== "1"){
echo '<input name="updbutton" type="submit" class="sub upd" value="'.__('Update').'">';
} else {
echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Add').'">';
}
echo '</form>';
echo '</td></tr></table>';
if (($form_alerttype == "combined") AND ($update_alert != -1)){
echo "<h3>".__('Combined alert components')."</h3>";
echo '<table width=605 class="databox" border=0 cellpadding=4 cellspacing=4>';
echo '<form method=POST action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$id_agente.'&update_alert='.$alerta_id_aam.'&add_component=1&form_alerttype=combined">';
if ($form_alerttype == "combined")
echo "<input type='hidden' name='combined' value ='1'>";
else
echo "<input type='hidden' name='combined' value ='0'>";
echo '<input type="hidden" name="add_alert_combined" value="1">';
echo '<input type="hidden" name="id_agente" value="'.$id_agente.'">';
echo "<tr><td>";
echo __('Source Agent/Alert');
echo "<td>";
echo "<select name='component_item'>";
// Add to combo single alerts
$result_alert = mysql_query("SELECT tagente_modulo.id_agente_modulo, tagente.nombre, tagente_modulo.nombre, id_aam, tagente.id_grupo FROM talerta_agente_modulo, tagente_modulo, tagente WHERE talerta_agente_modulo.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_agente = tagente.id_agente");
while ($alertrow = mysql_fetch_array($result_alert)){
if (give_acl ($config["id_user"], $alertrow[4], "AR") == 1)
echo "<option value='".$alertrow[3]."'>(S) ".$alertrow[1]." - ".$alertrow[2];
}
// Add to combo combined alerts
$result_alert = mysql_query("SELECT tagente.id_grupo, tagente.nombre, talerta_agente_modulo.id_aam, talerta_agente_modulo.descripcion FROM talerta_agente_modulo, tagente WHERE talerta_agente_modulo.id_agent = tagente.id_agente AND tagente.id_agente != '' AND tagente.id_agente > 0");
while ($alertrow = mysql_fetch_array($result_alert)){
if (give_acl ($config["id_user"], $alertrow[0], "AR"))
echo "<option value='".$alertrow[2]."'>(C) ".$alertrow[1]." - ".$alertrow[3];
}
echo "</select>";
// there is any component already in this alert ?
$result = mysql_query ("SELECT COUNT(*) FROM tcompound_alert, talerta_agente_modulo WHERE tcompound_alert.id = $id_aam AND talerta_agente_modulo.id_aam = tcompound_alert.id_aam");
$row=mysql_fetch_array($result);
if ($row[0] > 0){
echo "<td>";
echo __('Operation');
echo "<td>";
echo "<select name='component_operation'>";
echo "<option>OR";
echo "<option>AND";
echo "<option>XOR";
echo "<option>NOR";
echo "<option>NAND";
echo "<option>NXOR";
echo "</select>";
} else {
echo "<input type=hidden name='component_operation' value='NOP'>";
}
echo "<td>";
echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Add').'">';
echo "</form>";
echo "</table>";
echo '<table width=750 cellpadding="4" cellspacing="4" class="databox" border=0>';
echo '<tr>';
echo '<th>'.__('Agent');
echo '<th>'.__('Module');
echo "<th>".__('Type')."</th>
<th>".__('Oper')."</th>
<th>".__('Threshold')."</th>
<th>".__('Min.')."</th>
<th>".__('Max.')."</th>
<th>".__('Time')."</th>
<th>".__('Description')."</th>
<th>".__('info')."</th>
<th width='50'>".__('Action')."</th></tr>";
$id_aam = $alerta_id_aam;
$sql2 = "SELECT * FROM tcompound_alert, talerta_agente_modulo WHERE tcompound_alert.id = $id_aam AND talerta_agente_modulo.id_aam = tcompound_alert.id_aam";
$result2=mysql_query($sql2);
$string = "";
$color = 1;
while ($row2=mysql_fetch_array($result2)) {
// Show data for each component of this combined alert
if ($color == 1){
$tdcolor="datos";
$color =0;
} else {
$tdcolor="datos2";
$color =1;
}
$module = get_db_row ("tagente_modulo", "id_agente_modulo", $row2["id_agente_modulo"]);
$description = $row2["descripcion"];
$alert_mode = $row2["operation"];
$id_agente_name = get_db_value ("nombre", "tagente", "id_agente", $module["id_agente"]);
echo "<tr>";
echo "<td class='$tdcolor'>".$id_agente_name;
echo "<td class='$tdcolor'>".$module["nombre"];
echo show_alert_row_edit ($row2, $tdcolor, $module["id_tipo_modulo"],1);
echo "</td><td class='$tdcolor'>";
$id_grupo = dame_id_grupo($id_agente);
if (give_acl ($config['id_user'], $id_grupo, "LW")) {
echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente=".$id_agente."&delete_alert_comp=".$row2["id_aam"]."'> <img src='images/cross.png' border=0 alt='".__('Delete')."'></a> &nbsp; ";
echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente=".$id_agente."&update_alert=".$row2["id_aam"]."'>
<img src='images/config.png' border=0 alt='".__('Update')."'></a>";
}
echo "</td>";
}
echo "</table>";
}
?>

View File

@ -273,22 +273,6 @@ if (isset($_GET["fix_module"])){
} }
} }
// Delete Alert
// =============
if (isset($_GET["delete_alert"])){ // if modified some parameter
$id_borrar_modulo = get_parameter_get ("delete_alert",0);
// get info about agent
$sql = sprintf ("DELETE FROM talerta_agente_modulo WHERE id_aam = %d", $id_borrar_modulo);
$result = process_sql ($sql);
if ($result === false) {
echo '<h3 class="error">'.__('There was a problem deleting the alert').'</h3>';
} else {
echo '<h3 class="suc">'.__('Alert successfully deleted').'</h3>';
}
}
// Delete Alert component (from a combined) // Delete Alert component (from a combined)
// ========================================== // ==========================================
if (isset($_GET["delete_alert_comp"])) { // if modified some parameter if (isset($_GET["delete_alert_comp"])) { // if modified some parameter
@ -304,88 +288,6 @@ if (isset($_GET["delete_alert_comp"])) { // if modified some parameter
} }
} }
// Create alert
// =============
if (isset($_POST["insert_alert"])){ // if created alert
$combined = get_parameter ("combined",0);
$id_agente_modulo = get_parameter ("agente_modulo",0);
$maximo = get_parameter ("maximo",0);
$minimo = get_parameter ("minimo",0);
$descripcion= get_parameter ('descripcion', '');
$campo_1 = get_parameter ('campo_1', '');
$campo_2 = get_parameter ('campo_2', '');
$campo_3 = get_parameter ('campo_3', '');
$tipo_alerta = get_parameter ("tipo_alerta",3);
$alert_text = get_parameter ("alert_text",'');
$time_threshold = get_parameter ("time_threshold",900);
$max_alerts = get_parameter ("max_alerts",1);
$min_alerts = get_parameter ("min_alerts",0);
$time_from = get_parameter ("time_from");
$time_to= get_parameter ("time_to");
$other = get_parameter ("other",0);
$disable_alert = get_parameter ("disable_alert");
$alert_d1 = get_parameter("alert_d1",0);
$alert_d2 = get_parameter("alert_d2",0);
$alert_d3 = get_parameter("alert_d3",0);
$alert_d4 = get_parameter("alert_d4",0);
$alert_d5 = get_parameter("alert_d5",0);
$alert_d6 = get_parameter("alert_d6",0);
$alert_d7 = get_parameter("alert_d7",0);
$alert_recovery = get_parameter("alert_recovery", 1);
$alert_priority = get_parameter("alert_priority", 0);
$campo2_rec = get_parameter ("campo_2_rec","");
$campo3_rec = get_parameter ("campo_3_rec","");
if ($combined == 1) {
$alert_id_agent = $id_agente;
} else {
$alert_id_agent = 0;
}
if ($time_threshold == -1) {
$time_threshold = $other;
}
$sql = sprintf ("INSERT INTO talerta_agente_modulo
(id_agente_modulo,
id_alerta,
al_campo1,
al_campo2,
al_campo3,
descripcion,
dis_max,
dis_min,
time_threshold,
max_alerts,
min_alerts,
alert_text,
disable,
time_from,
time_to,
id_agent,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday,
recovery_notify,
priority,
al_f2_recovery,
al_f3_recovery) VALUES
(%d,%d,'%s','%s','%s','%s',%f,%f,%d,%d,%d,'%s',%d,'%s','%s',%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,'%s','%s')",
$id_agente_modulo, $tipo_alerta, $campo_1, $campo_2, $campo_3, $descripcion, $maximo, $minimo, $time_threshold, $max_alerts, $min_alerts, $alert_text, $disable_alert,
$time_from, $time_to, $alert_id_agent, $alert_d1, $alert_d2, $alert_d3, $alert_d4, $alert_d5, $alert_d6, $alert_d7, $alert_recovery, $alert_priority, $campo2_rec, $campo3_rec);
$id_alerta_agente_modulo = process_sql ($sql, "insert_id");
//False or 0 is invalid
if (empty ($id_alerta_agente_modulo)) {
echo '<h3 class="error">'.__('There was a problem creating alert').'</h3>';
} else {
echo '<h3 class="suc">'.__('Alert successfully created').'</h3>';
}
}
// Combined ALERT - Add component // Combined ALERT - Add component
// ================================ // ================================
if (isset($_POST["add_alert_combined"])){ // Update an existing alert if (isset($_POST["add_alert_combined"])){ // Update an existing alert
@ -402,89 +304,6 @@ if (isset($_POST["add_alert_combined"])){ // Update an existing alert
} }
// Update ALERT
// =============
if (isset($_POST["update_alert"])) { // Update an existing alert
$id_agente_modulo = get_parameter ("agente_modulo",0);
$id_aam = get_parameter ("id_aam",0);
$maximo = get_parameter ("maximo",0);
$minimo = get_parameter ("minimo",0);
$descripcion= get_parameter ('descripcion', '');
$campo_1 = get_parameter ('campo_1', '');
$campo_2 = get_parameter ('campo_2', '');
$campo_3 = get_parameter ('campo_3', '');
$tipo_alerta = get_parameter ("tipo_alerta",3);
$alert_text = get_parameter ("alert_text",'');
$time_threshold = get_parameter ("time_threshold",900);
$max_alerts = get_parameter ("max_alerts",1);
$min_alerts = get_parameter ("min_alerts",0);
$time_from = get_parameter ("time_from");
$time_to= get_parameter ("time_to");
$other = get_parameter ("other",0);
$disable_alert = get_parameter ("disable_alert");
$alert_d1 = get_parameter("alert_d1",0);
$alert_d2 = get_parameter("alert_d2",0);
$alert_d3 = get_parameter("alert_d3",0);
$alert_d4 = get_parameter("alert_d4",0);
$alert_d5 = get_parameter("alert_d5",0);
$alert_d6 = get_parameter("alert_d6",0);
$alert_d7 = get_parameter("alert_d7",0);
$alert_recovery = get_parameter("alert_recovery", 1);
$alert_priority = get_parameter("alert_priority", 0);
$campo2_rec = get_parameter ("campo_2_rec","");
$campo3_rec = get_parameter ("campo_3_rec","");
$alert_d1 = get_parameter("alert_d1",0);
$alert_d2 = get_parameter("alert_d2",0);
$alert_d3 = get_parameter("alert_d3",0);
$alert_d4 = get_parameter("alert_d4",0);
$alert_d5 = get_parameter("alert_d5",0);
$alert_d6 = get_parameter("alert_d6",0);
$alert_d7 = get_parameter("alert_d7",0);
$alert_recovery = get_parameter("alert_recovery", 1);
$alert_priority = get_parameter("alert_priority", 0);
$campo2_rec = get_parameter ("campo_2_rec","");
$campo3_rec = get_parameter ("campo_3_rec","");
if ($time_threshold == -1) {
$time_threshold = $other;
}
$sql = sprintf ("UPDATE talerta_agente_modulo SET
id_alerta = %d,
max_alerts = %d,
min_alerts = %d,
time_threshold = '%s',
dis_min = %f,
dis_max = %f,
al_campo3 = '%s',
al_campo2 = '%s',
al_campo1 = '%s',
descripcion = '%s',
alert_text = '%s',
time_to = '%s',
time_from = '%s',
disable = %d,
monday = %d,
tuesday = %d,
wednesday = %d,
thursday = %d,
friday = %d,
saturday = %d,
sunday = %d,
recovery_notify = %d,
priority = %d,
al_f2_recovery = '%s',
al_f3_recovery = '%s'
WHERE id_aam = %d", $tipo_alerta, $max_alerts, $min_alerts, $time_threshold, $minimo, $maximo, $campo_3, $campo_2, $campo_1, $descripcion, $alert_text,
$time_to, $time_from, $disable_alert, $alert_d1, $alert_d2, $alert_d3, $alert_d4, $alert_d5, $alert_d6, $alert_d7, $alert_recovery, $alert_priority,
$campo2_rec, $campo3_rec, $id_aam);
$result = process_sql ($sql);
if ($result === false) {
echo '<h3 class="error">'.__('There was a problem updating alert').'</h3>';
} else {
echo '<h3 class="suc">'.__('Alert successfully updated').'</h3>';
}
}
// ================ // ================
// Update AGENT // Update AGENT
// ================ // ================
@ -625,54 +444,6 @@ if ((isset ($_GET["update_module"])) && (!isset ($_POST["oid"])) && (!isset ($_P
} }
} }
// Read ALERT data if editing alert
// ==================================
if (isset ($_GET["update_alert"])) {
$id_grupo = dame_id_grupo ($id_agente);
if (give_acl ($config["id_user"], $id_grupo, "LW") == 0){
audit_db($config["id_user"],$REMOTE_ADDR, "ACL Violation","Trying to update an alert without admin rights");
require ("general/noaccess.php");
exit;
}
$update_alert = 1;
$id_aam = (int) get_parameter_get ("update_alert",0);
$alert = get_db_row ('talerta_agente_modulo', 'id_aam', $id_aam);
if ($alert === false) {
echo '<h3 class="error">'.__('There was a problem loading the alert').'</h3>';
} else {
$alerta_id_aam = $alert["id_aam"];
$alerta_campo1 = $alert["al_campo1"];
$alerta_campo2 = $alert["al_campo2"];
$alerta_campo3 = $alert["al_campo3"];
$alerta_campo2_rec = $alert["al_f2_recovery"];
$alerta_campo3_rec = $alert["al_f3_recovery"];
$alerta_dis_max = $alert["dis_max"];
$alerta_dis_min = $alert["dis_min"];
$tipo_alerta = $alert["id_alerta"];
$alert_text = $alert["alert_text"];
$alerta_max_alerts = $alert["max_alerts"];
$alerta_min_alerts = $alert["min_alerts"];
$alerta_time_threshold = $alert["time_threshold"];
$alerta_descripcion = $alert["descripcion"];
$alerta_disable = $alert["disable"];
$time_from = $alert["time_from"];
$time_to = $alert["time_to"];
$alerta_id_agentemodulo = $alert["id_agente_modulo"]; // Only to show, cannot be changed
$alert_id_agent = $alert["id_agent"];
$alert_d1 = $alert["monday"];
$alert_d2 = $alert["tuesday"];
$alert_d3 = $alert["wednesday"];
$alert_d4 = $alert["thursday"];
$alert_d5 = $alert["friday"];
$alert_d6 = $alert["saturday"];
$alert_d7 = $alert["sunday"];
$alert_recovery = $alert["recovery_notify"];
$alert_priority = $alert["priority"];
}
}
// GET DATA for MODULE UPDATE OR MODULE INSERT // GET DATA for MODULE UPDATE OR MODULE INSERT
// =========================================== // ===========================================
if ((isset ($_POST["update_module"])) || (isset ($_POST["insert_module"]))) { if ((isset ($_POST["update_module"])) || (isset ($_POST["insert_module"]))) {
@ -889,24 +660,20 @@ if (isset ($_GET["delete_module"])){ // DELETE agent module !
switch ($tab) { switch ($tab) {
case "main": case "main":
require "agent_manager.php"; require ("agent_manager.php");
break; break;
case "module": case "module":
if (($form_moduletype == "") && ($moduletype == "")) { if (($form_moduletype == "") && ($moduletype == "")) {
require "module_manager.php"; require ("module_manager.php");
} else { } else {
require "module_manager_editor.php"; require ("module_manager_editor.php");
} }
break; break;
case "alert": case "alert":
if (($form_alerttype == "") && (!isset($_GET["update_alert"]))) { require ("alert_manager.php");
require "alert_manager.php";
} else {
require "alert_manager_editor.php";
}
break; break;
case "template": case "template":
require "agent_template.php"; require ("agent_template.php");
break; break;
default: default:
if (enterprise_hook ('switch_agent_tab', array ($tab))) if (enterprise_hook ('switch_agent_tab', array ($tab)))

View File

@ -29,12 +29,12 @@ if (! give_acl ($config['id_user'], 0, "LM")) {
} }
$id_group = get_parameter ("id_group", 0); $id_group = (int) get_parameter ("id_group");
$origen = get_parameter ("origen", -1); $origen = (int) get_parameter_post ("origen", -1);
$update_agent = get_parameter ("update_agent", -1); $update_agent = (int) get_parameter ("update_agent", -1);
$update_group = get_parameter ("update_group", -1); $update_group = (int) get_parameter ("update_group", -1);
$destino = get_parameter_post ("destino",array ()); $destino = (array) get_parameter_post ("destino", array ());
$origen_modulo = get_parameter_post ("origen_modulo", array ()); $origen_modulo = (array) get_parameter_post ("origen_modulo", array ());
// Operations // Operations
// --------------- // ---------------
@ -54,30 +54,23 @@ if (isset($_POST["copy"])) {
return; return;
} }
// If selected modules or alerts $copy_modules = (bool) get_parameter ('modules');
if (isset($_POST["modules"])) { $copy_alerts = (bool) get_parameter ('alerts');
$modulos = 1;
} else {
$modulos = 0;
}
if (isset($_POST["alerts"])) { if (! $copy_alerts && ! $copy_modules) {
$alertas = 1;
} else {
$alertas = 0;
}
if (($alertas + $modulos) == 0){
echo '<h3 class="error">ERROR: '.__('You must check modules and/or alerts to be copied').'</h3>'; echo '<h3 class="error">ERROR: '.__('You must check modules and/or alerts to be copied').'</h3>';
return; return;
} }
require_once ("include/functions_alerts.php");
$origin_name = get_agent_name ($origen);
// Copy // Copy
// ----
$errors = 0; $errors = 0;
$id_new_module = 0; $id_new_module = 0;
process_sql ("SET AUTOCOMMIT = 0;"); process_sql ("SET AUTOCOMMIT = 0;");
process_sql ("START TRANSACTION;"); //Start a transaction process_sql ("START TRANSACTION;");
foreach ($origen_modulo as $id_module) { foreach ($origen_modulo as $id_module) {
//For each selected module //For each selected module
@ -85,9 +78,10 @@ if (isset($_POST["copy"])) {
foreach ($destino as $id_agent_dest) { foreach ($destino as $id_agent_dest) {
//For each destination agent //For each destination agent
$destiny_name = get_agent_name ($id_agent_dest);
if ($modulos == 1) { if ($copy_modules) {
echo '<br /><br />'.__('Copying module').'<b> ['.get_agent_name ($origen).' - '.$module["nombre"].'] -> ['.get_agent_name ($id_agent_dest).']</b>'; echo '<br /><br />'.__('Copying module').'<b> ['.$origin_name.' - '.$module["nombre"].'] -> ['.$destiny_name.']</b>';
$sql = sprintf ('INSERT INTO tagente_modulo $sql = sprintf ('INSERT INTO tagente_modulo
(id_agente, id_tipo_modulo, descripcion, (id_agente, id_tipo_modulo, descripcion,
nombre, max, min, module_interval, nombre, max, min, module_interval,
@ -151,70 +145,64 @@ if (isset($_POST["copy"])) {
}//If empty id_new_module }//If empty id_new_module
} //If modulos } //If modulos
if ($alertas == 1) { if ($copy_alerts) {
if (empty ($id_new_module)) { if (empty ($id_new_module)) {
//If we didn't copy modules or if we //If we didn't copy modules or if we
//didn't create new modules we have to //didn't create new modules we have to
//look for the module id //look for the module id
$sql = sprintf ("SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = '%s' AND id_agente = %d", $module["nombre"], $id_agent_dest); $sql = sprintf ('SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre = "%s"
AND id_agente = %d',
$module['nombre'], $id_agent_dest);
$id_new_module = get_db_sql ($sql); $id_new_module = get_db_sql ($sql);
if (empty ($id_new_module)) { if (empty ($id_new_module))
continue; //If we can't find a module belonging to this agent with the same name, skip the loop // We can't find a module belonging to this agent
} continue;
} }
$alerts = get_db_all_rows_field_filter ('talert_template_modules',
'id_agent_module', $id_module);
if (empty ($alerts))
// The module doesn't have alerts
continue;
$module_alerts = get_db_all_rows_field_filter ("talerta_agente_modulo", "id_agente_modulo", $id_module); foreach ($alerts as $alert) {
if (empty ($module_alerts)) { echo '<br />'.__('Copying alert').'<b> ['.$origin_name.' - '.$module["nombre"].'] -> ['.$destiny_name.']</b>';
$module_alerts = array ();
}
foreach ($module_alerts as $alert) {
echo '<br /><br />'.__('Copying alert').'<b> ['.get_agent_name ($origen).' - '.$module["nombre"].'] -> ['.get_agent_name ($id_agent_dest).']</b>';
if (!empty ($alert["id_agent"])) { if (!empty ($alert["id_agent"])) {
//Compound alert //Compound alert
$alert["id_agent"] = $id_agent_dest; $alert["id_agent"] = $id_agent_dest;
} }
$sql = sprintf ("INSERT INTO talerta_agente_modulo $values = array ('id_agent_module' => (int) $id_new_module,
(id_agente_modulo, id_alerta, al_campo1, al_campo2, al_campo3, descripcion, dis_max, dis_min, 'id_alert_template' => (int) $alert['id_alert_template']);
time_threshold, max_alerts, module_type, min_alerts, alert_text, disable, time_from, $id_alert = process_sql_insert ('talert_template_modules',
time_to, id_agent, monday, tuesday, wednesday, thursday, friday, saturday, sunday, $values);
recovery_notify, priority, al_f2_recovery, al_f3_recovery)
VALUES (
%d,%d,'%s','%s','%s','%s',%d,%d,
%d,%d,%d,%d,'%s',%d,'%s',
'%s',%d,%d,%d,%d,%d,%d,%d,%d,
%d,%d,'%s','%s')",
$id_new_module,$alert["id_alerta"],$alert["al_campo1"],$alert["al_campo2"],$alert["al_campo3"],$alert["descripcion"],$alert["dis_max"],$alert["dis_min"],
$alert["time_threshold"],$alert["max_alerts"],$alert["module_type"],$alert["min_alerts"],$alert["alert_text"],$alert["disable"],$alert["time_from"],
$alert["time_to"],$alert["id_agent"],$alert["monday"],$alert["tuesday"],$alert["wednesday"],$alert["thursday"],$alert["friday"],$alert["saturday"],$alert["sunday"],
$alert["recovery_notify"],$alert["priority"],$alert["al_f2_recovery"],$alert["al_f3_recovery"]);
$new_alert = process_sql ($sql, "insert_id"); if ($id_alert === false) {
if ($new_alert === false) {
$errors++; $errors++;
} elseif (!empty ($alert["id_agent"])) {
$sql = sprintf ("SELECT operation FROM tcompound_alert WHERE id_aam = %d", $alert["id_aam"]);
$result = get_db_all_row_sql ($sql);
if ($result === false)
/* This alert is supposed to be part of a
compound alert but there is no entry for
it in the tcompound_alert table so we skip this */
continue; continue;
foreach ($result as $comp_alert) { }
$sql = sprintf ("INSERT INTO tcompound_alert (id_aam, operation) VALUES (%d, '%s')",$new_alert,$comp_alert["operation"]);
$result = process_sql ($sql); $actions = get_alert_agent_module_actions ($alert['id']);
if (empty ($actions))
continue;
foreach ($actions as $action) {
$values = array ('id_alert_template_module' => (int) $id_alert,
'id_alert_action' => (int) $action['id'],
'fires_min' => (int) $action['fires_min'],
'fires_max' => (int) $action['fires_max']);
$result = process_sql_insert ('talert_template_module_actions',
$values);
if ($result === false) if ($result === false)
$errors++; $errors++;
} //foreach compound alert }
} //if-elseif compound alert
/* TODO: Copy compound alerts */
} //foreach alert } //foreach alert
} //if alerts } //if alerts
} //Foreach destino } //Foreach destino
} //Foreach origen_modulo } //Foreach origen_modulo
if ($errors > 1) { if ($errors > 1) {
echo '<h3 class="error">'.__('There was an error copying the module, the copy has been cancelled').'</h3>'; echo '<h3 class="error">'.__('There was an error copying the module, the copy has been cancelled').'</h3>';
process_sql ("ROLLBACK;"); process_sql ("ROLLBACK;");
@ -289,8 +277,9 @@ if (isset ($_POST["delete"])) {
if ($alertas == 1) { if ($alertas == 1) {
//Alert //Alert
temp_sql_delete ("tcompound_alert", "id_aam", "ANY(SELECT id_aam FROM talerta_agente_modulo WHERE id_agente_modulo = ".$id_module_dest.")"); /* TODO: Delete compound alerts */
temp_sql_delete ("talerta_agente_modulo", "id_agente_modulo", $id_module_dest);
temp_sql_delete ('talert_template_modules', "id_agent_module", $id_module_dest);
} }
if ($modulos == 1) { if ($modulos == 1) {

View File

@ -1,104 +0,0 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// 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.
// Load global vars
require_once ("include/config.php");
check_login ();
if (! give_acl ($config['id_user'], 0, "LM")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Alert Management");
require ("general/noaccess.php");
exit;
}
// Var init
$descripcion = "";
$nombre = "";
$comando ="";
if (isset($_GET["id_alerta"])){
$id_alerta = entrada_limpia($_GET["id_alerta"]);
$sql1='SELECT * FROM talerta WHERE id_alerta = '.$id_alerta;
$result=mysql_query($sql1);
if ($row=mysql_fetch_array($result)){
$descripcion = $row["descripcion"];
$nombre= $row["nombre"];
$comando = $row["comando"];
} else
{
echo "<h3 class='error'>".__('There was a problem loading alert')."</h3>";
echo "</table>";
include ("general/footer.php");
exit;
}
}
$creacion_alerta = 0;
if (isset($_GET["creacion"])){
$creacion_alerta = 1;
}
echo "<h2>".__('Alert configuration')." &gt; ";
if (isset($_GET["creacion"])){
echo __('Create alert');
}
if (isset($_GET["id_alerta"])){
echo __('Modify alert');
}
pandora_help ("manage_alerts");
echo "</h2>";
?>
<form name="alerta" method="post" action="index.php?sec=galertas&sec2=godmode/alerts/modify_alert&id_alerta=<?php echo $id_alerta ?>">
<?php
if ($creacion_alerta == 1)
echo "<input type='hidden' name='crear_alerta' value='1'>";
else {
echo "<input type='hidden' name='update_alerta' value='1'>";
echo "<input type='hidden' name='id_alerta' value='".$id_alerta."'>";
}
?>
<table width="500" cellspacing="4" cellpadding="4" class="databox_color">
<tr><td class="datos"><?php echo __('Alert name') ?></td>
<td class="datos">
<input type="text" name="nombre" size=30 value="<?php echo $nombre ?>"></td>
</tr>
<tr>
<td class="datos2"><?php echo __('Command') ?></td>
<td class="datos2">
<input type="text" name="comando" size="50" value="<?php echo $comando ?>">
</td></tr>
<tr><td class="datos"><?php echo __('Description') ?></td>
<td class="datos"><textarea name="descripcion" cols="50" rows="7">
<?php echo $descripcion ?>
</textarea>
</td></tr>
</table>
<table width=500>
<tr><td align="right">
<?php
if (isset($_GET["creacion"])){
echo "<input name='crtbutton' type='submit' class='sub wand' value='".__('Create')."'>";
} else {
echo "<input name='uptbutton' type='submit' class='sub upd' value='".__('Update')."'>";
} ?>
</form>
</table>

View File

@ -400,7 +400,7 @@ if ($edit_sla_report_content) {
$periods[360] = __('2 weeks'); $periods[360] = __('2 weeks');
$periods[720] = __('1 month'); $periods[720] = __('1 month');
$periods[4320] = __('6 months'); $periods[4320] = __('6 months');
$table->data[1][1] = print_select ($periods, 'period', 0, '', '--', 0, true); $table->data[1][1] = print_select ($periods, 'period', 0, '', '--', 0, true, false, false);
$table->data[2][0] = __('Source agent'); $table->data[2][0] = __('Source agent');
$table->data[2][1] = print_select ($agents, 'id_agent', $id_agent, '', '--', 0, true); $table->data[2][1] = print_select ($agents, 'id_agent', $id_agent, '', '--', 0, true);

View File

@ -43,13 +43,13 @@ function get_agent_alerts_simple ($id_agent, $filter = false) {
} }
$id_modules = array_keys (get_agent_modules ($id_agent)); $id_modules = array_keys (get_agent_modules ($id_agent));
if (empty ($id_modules))
//$modules = (); return array ();
$sql = sprintf ("SELECT talert_template_modules.* $sql = sprintf ("SELECT talert_template_modules.*
FROM talert_template_modules FROM talert_template_modules
WHERE id_agent_module in (%s)", WHERE id_agent_module in (%s)%s",
$id_agent, implode (",", $id_modules)); implode (",", $id_modules), $filter);
$alerts = get_db_all_rows_sql ($sql); $alerts = get_db_all_rows_sql ($sql);
@ -66,6 +66,8 @@ function get_agent_alerts_simple ($id_agent, $filter = false) {
* @return array An array with all combined alerts defined for an agent. * @return array An array with all combined alerts defined for an agent.
*/ */
function get_agent_alerts_combined ($id_agent, $filter = false) { function get_agent_alerts_combined ($id_agent, $filter = false) {
/* TODO: Combined alerts */
return array ();
switch ($filter) { switch ($filter) {
case "notfired": case "notfired":
$filter = ' AND times_fired = 0 AND disable = 0'; $filter = ' AND times_fired = 0 AND disable = 0';
@ -79,7 +81,14 @@ function get_agent_alerts_combined ($id_agent, $filter = false) {
default: default:
$filter = ''; $filter = '';
} }
$sql = sprintf ("SELECT * FROM talerta_agente_modulo WHERE id_agent = %d%s", $id_agent, $filter);
$id_modules = array_keys (get_agent_modules ($id_agent));
if (empty ($id_modules))
return array ();
$sql = sprintf ("SELECT * FROM talert_template_modules
WHERE id_agent_module IN (%s)%s",
implode (',', $id_modules), $filter);
$alerts = get_db_all_rows_sql ($sql); $alerts = get_db_all_rows_sql ($sql);
if ($alerts === false) if ($alerts === false)

View File

@ -635,22 +635,22 @@ function get_monitors_down ($monitors, $period = 0, $date = 0) {
/** /**
* Get all the times an alerts fired during a period. * Get all the times an alerts fired during a period.
* *
* @param int $id_agent_module Agent module of the alert. * @param int Alert module id.
* @param int $period Period timed to check from date * @param int Period timed to check from date
* @param int $date Date to check (now by default) * @param int Date to check (current time by default)
* *
* @return int The number of times an alert fired. * @return int The number of times an alert fired.
*/ */
function get_alert_fires_in_period ($id_agent_module, $period, $date = 0) { function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) {
if (!$date) if (!$date)
$date = get_system_time (); $date = get_system_time ();
$datelimit = $date - $period; $datelimit = $date - $period;
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE $sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
`event_type` = 'alert_fired' `event_type` = 'alert_fired'
AND `id_agentmodule` = %d AND `id_alert_am` = %d
AND `utimestamp` > %d AND `utimestamp` > %d
AND `utimestamp` <= %d", AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date); $id_alert_module, $datelimit, $date);
return (int) get_db_sql ($sql); return (int) get_db_sql ($sql);
} }
@ -666,7 +666,7 @@ function get_alert_fires_in_period ($id_agent_module, $period, $date = 0) {
function get_group_alerts ($id_group) { function get_group_alerts ($id_group) {
$alerts = array (); $alerts = array ();
$agents = get_group_agents ($id_group, false, "none"); $agents = get_group_agents ($id_group, false, "none");
require_once ('include/functions_agents.php');
foreach ($agents as $agent_id => $agent_name) { foreach ($agents as $agent_id => $agent_name) {
$agent_alerts = get_agent_alerts ($agent_id); $agent_alerts = get_agent_alerts ($agent_id);
$alerts = array_merge ($alerts, $agent_alerts); $alerts = array_merge ($alerts, $agent_alerts);
@ -678,9 +678,9 @@ function get_group_alerts ($id_group) {
/** /**
* Get all the alerts fired during a period, given a list of alerts. * Get all the alerts fired during a period, given a list of alerts.
* *
* @param array $alerts A list of alerts to check. See get_alerts_in_group() * @param array A list of alert modules to check. See get_alerts_in_group()
* @param int $period Period of time to check fired alerts. * @param int Period of time to check fired alerts.
* @param int $date Beginning date to check fired alerts in UNIX format (current date by default) * @param int Beginning date to check fired alerts in UNIX format (current date by default)
* *
* @return array An array with the alert id as key and the number of times * @return array An array with the alert id as key and the number of times
* the alert was fired (only included if it was fired). * the alert was fired (only included if it was fired).
@ -693,11 +693,11 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) {
$alerts_fired = array (); $alerts_fired = array ();
$agents = array (); $agents = array ();
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
$fires = get_alert_fires_in_period ($alert['id_agente_modulo'], $period, $date); $fires = get_alert_fires_in_period ($alert['id'], $period, $date);
if (! $fires) { if (! $fires) {
continue; continue;
} }
$alerts_fired[$alert['id_aam']] = $fires; $alerts_fired[$alert['id']] = $fires;
} }
return $alerts_fired; return $alerts_fired;
} }
@ -705,30 +705,30 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) {
/** /**
* Get the last time an alert fired during a period. * Get the last time an alert fired during a period.
* *
* @param int $id_agent_module Agent module of the monitor. * @param int Alert agent module id.
* @param int $period Period timed to check from date * @param int Period timed to check from date
* @param int $date Date to check (now by default) * @param int Date to check (current date by default)
* *
* @return int The last time an alert fired. * @return int The last time an alert fired. It's an UNIX timestamp.
*/ */
function get_alert_last_fire_timestamp_in_period ($id_agent_module, $period, $date = 0) { function get_alert_last_fire_timestamp_in_period ($id_alert_module, $period, $date = 0) {
if ($date == 0) { if ($date == 0) {
$date = get_system_time (); $date = get_system_time ();
} }
$datelimit = $date - $period; $datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(`timestamp`) FROM `tevento` WHERE $sql = sprintf ("SELECT MAX(`utimestamp`) FROM `tevento` WHERE
`event_type` = 'alert_fired' `event_type` = 'alert_fired'
AND `id_agentmodule` = %d AND `id_alert_am` = %d
AND `utimestamp` > %d AND `utimestamp` > %d
AND `utimestamp` <= %d", AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date); $id_alert_module, $datelimit, $date);
return get_db_sql ($sql); return get_db_sql ($sql);
} }
/** /**
* Get the server name. * Get the server name.
* *
* @param int $id_server Server id. * @param int Server id.
* *
* @return string Name of the given server * @return string Name of the given server
*/ */
@ -798,7 +798,7 @@ function dame_id_grupo ($id_agent) {
* In case an array is passed, it will have a value for every agent passed * In case an array is passed, it will have a value for every agent passed
* incl. a total otherwise it will just return the total * incl. a total otherwise it will just return the total
* *
* @param mixed $id_agent Agent id or array of agent id's, 0 for all * @param mixed Agent id or array of agent id's, 0 for all
* *
* @return mixed The number of data in the database * @return mixed The number of data in the database
*/ */
@ -846,7 +846,7 @@ function get_agent_modules_data_count ($id_agent = 0) {
/** /**
* Get the operating system name. * Get the operating system name.
* *
* @param int id_os Operating system id. * @param int Operating system id.
* *
* @return string Name of the given operating system. * @return string Name of the given operating system.
*/ */
@ -869,7 +869,7 @@ function update_user_contact ($id_user) {
/** /**
* Get the user email * Get the user email
* *
* @param string $id_user User id. * @param string User id.
* *
* @return string Get the email address of an user * @return string Get the email address of an user
*/ */
@ -880,7 +880,7 @@ function dame_email ($id_user) {
/** /**
* Checks if a user is administrator. * Checks if a user is administrator.
* *
* @param string $id_user User id. * @param string User id.
* *
* @return bool True is the user is admin * @return bool True is the user is admin
*/ */
@ -903,14 +903,16 @@ function comprueba_login () {
/** /**
* Check if an agent has alerts fired. * Check if an agent has alerts fired.
* *
* @param int $id_agent Agent id. * @param int Agent id.
* *
* @return bool True if the agent has fired alerts. * @return bool True if the agent has fired alerts.
*/ */
function check_alert_fired ($id_agent) { function check_alert_fired ($id_agent) {
$sql = "SELECT COUNT(*) FROM talerta_agente_modulo, tagente_modulo $sql = sprintf ("SELECT COUNT(*)
WHERE talerta_agente_modulo.id_agente_modulo = tagente_modulo.id_agente_modulo FROM talert_template_modules, tagente_modulo
AND times_fired > 0 AND id_agente = ".$id_agent; WHERE talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo
AND times_fired > 0 AND id_agente = %d",
$id_agent);
$value = get_db_sql ($sql); $value = get_db_sql ($sql);
if ($value > 0) if ($value > 0)
@ -921,7 +923,7 @@ function check_alert_fired ($id_agent) {
/** /**
* Check is a user exists in the system * Check is a user exists in the system
* *
* @param string $id_user User id. * @param string User id.
* *
* @return bool True if the user exists. * @return bool True if the user exists.
*/ */
@ -937,7 +939,7 @@ function existe ($id_user) {
* *
* If the module interval is not set, the agent interval is returned * If the module interval is not set, the agent interval is returned
* *
* @param int $id_agent_module Id agent module to get the interval value. * @param int Id agent module to get the interval value.
* *
* @return int Module interval or agent interval if no module interval * @return int Module interval or agent interval if no module interval
*/ */
@ -953,7 +955,7 @@ function get_module_interval ($id_agent_module) {
/** /**
* Get the interval of an agent. * Get the interval of an agent.
* *
* @param int $id_agent Agent id. * @param int Agent id.
* *
* @return int The interval value of a given agent * @return int The interval value of a given agent
*/ */
@ -964,7 +966,7 @@ function get_agent_interval ($id_agent) {
/** /**
* Get the flag value of an agent module. * Get the flag value of an agent module.
* *
* @param int $id_agent_module Agent module id. * @param int Agent module id.
* *
* @return bool The flag value of an agent module. * @return bool The flag value of an agent module.
*/ */
@ -979,8 +981,8 @@ function give_agentmodule_flag ($id_agent_module) {
* @deprecated Use get_user_groups () in combination with print_select () * @deprecated Use get_user_groups () in combination with print_select ()
* instead * instead
* *
* @param string $id_user User id * @param string User id
* @param bool $show_all Flag to show all the groups or not. True by default. * @param bool Flag to show all the groups or not. True by default.
* *
* @return array An array with all the groups * @return array An array with all the groups
*/ */
@ -1005,7 +1007,7 @@ function list_group ($id_user, $show_all = 1){
* *
* @deprecated Use get_user_groups () instead * @deprecated Use get_user_groups () instead
* *
* @param int $id_user User id * @param int User id
* *
* @return array A list of the groupid => groups the user has reading privileges. * @return array A list of the groupid => groups the user has reading privileges.
*/ */
@ -1026,7 +1028,7 @@ function list_group2 ($id_user) {
/** /**
* Get a list of all users in an array [username] => real name * Get a list of all users in an array [username] => real name
* *
* @param string $order by (id_usuario, nombre_real or fecha_registro) * @param string Field to order by (id_usuario, nombre_real or fecha_registro)
* *
* @return array An array of users * @return array An array of users
*/ */
@ -1055,8 +1057,9 @@ function list_users ($order = "nombre_real") {
/** /**
* Get all the groups a user has reading privileges. * Get all the groups a user has reading privileges.
* *
* @param string $id_user User id * @param string User id
* @param string $privilege The privilege to evaluate * @param string The privilege to evaluate
*
* @return array A list of the groups the user has certain privileges. * @return array A list of the groups the user has certain privileges.
*/ */
function get_user_groups ($id_user = 0, $privilege = "AR") { function get_user_groups ($id_user = 0, $privilege = "AR") {
@ -1086,7 +1089,7 @@ function get_user_groups ($id_user = 0, $privilege = "AR") {
* TODO: Create print_moduletype_icon and print the full tag including hover etc. * TODO: Create print_moduletype_icon and print the full tag including hover etc.
* @deprecated Use print_moduletype_icon instead * @deprecated Use print_moduletype_icon instead
* *
* @param int $id_type Module type id * @param int Module type id
* *
* @return string Icon filename of the given group * @return string Icon filename of the given group
*/ */
@ -1100,7 +1103,7 @@ function show_icon_type ($id_type) {
* *
* @deprecated Use print_servertype_icon instead * @deprecated Use print_servertype_icon instead
* *
* @param int $id Server type id * @param int Server type id
* *
* @return string Fully formatted IMG HTML tag with icon * @return string Fully formatted IMG HTML tag with icon
*/ */
@ -1129,7 +1132,7 @@ function show_server_type ($id) {
/** /**
* Get a module category name * Get a module category name
* *
* @param id_category Id category * @param int Id category
* *
* @return Name of the given category * @return Name of the given category
*/ */
@ -1154,7 +1157,7 @@ function give_modulecategory_name ($id_category) {
/** /**
* Get a network component group name * Get a network component group name
* *
* @param int $id_network_component_group Id network component group. * @param int Id network component group.
* *
* @return string Name of the given network component group * @return string Name of the given network component group
*/ */
@ -1165,7 +1168,7 @@ function give_network_component_group_name ($id_network_component_group) {
/** /**
* Get a network profile name. * Get a network profile name.
* *
* @param int $id_network_profile Id network profile * @param int Id network profile
* *
* @return string Name of the given network profile. * @return string Name of the given network profile.
*/ */
@ -1176,8 +1179,8 @@ function get_networkprofile_name ($id_network_profile) {
/** /**
* Assign an IP address to an agent. * Assign an IP address to an agent.
* *
* @param int id_agent Agent id * @param int Agent id
* @param string ip_address IP address to assign * @param string IP address to assign
*/ */
function agent_add_address ($id_agent, $ip_address) { function agent_add_address ($id_agent, $ip_address) {
// Check if already is attached to agent // Check if already is attached to agent
@ -1207,8 +1210,8 @@ function agent_add_address ($id_agent, $ip_address) {
/** /**
* Unassign an IP address from an agent. * Unassign an IP address from an agent.
* *
* @param int $id_agent Agent id * @param int Agent id
* @param string $ip_address IP address to unassign * @param string IP address to unassign
*/ */
function agent_delete_address ($id_agent, $ip_address) { function agent_delete_address ($id_agent, $ip_address) {
$sql = sprintf ("SELECT id_ag FROM taddress_agent, taddress $sql = sprintf ("SELECT id_ag FROM taddress_agent, taddress
@ -1231,7 +1234,7 @@ function agent_delete_address ($id_agent, $ip_address) {
/** /**
* Get address of an agent. * Get address of an agent.
* *
* @param int $id_agent Agent id * @param int Agent id
* *
* @return string The address of the given agent * @return string The address of the given agent
*/ */
@ -1242,7 +1245,7 @@ function get_agent_address ($id_agent) {
/** /**
* Get the agent that matches an IP address * Get the agent that matches an IP address
* *
* @param string $ip_address IP address to get the agents. * @param string IP address to get the agents.
* *
* @return mixed The agent that has the IP address given. False if none were found. * @return mixed The agent that has the IP address given. False if none were found.
*/ */
@ -1258,7 +1261,7 @@ function get_agent_with_ip ($ip_address) {
/** /**
* Get all IP addresses of an agent * Get all IP addresses of an agent
* *
* @param int $id_agent Agent id * @param int Agent id
* *
* @return array Array with the IP address of the given agent or an empty array. * @return array Array with the IP address of the given agent or an empty array.
*/ */
@ -1284,7 +1287,7 @@ function get_agent_addresses ($id_agent) {
/** /**
* Get agent id from an agent module. * Get agent id from an agent module.
* *
* @param int id_agent_module Id of the agent module. * @param int Id of the agent module.
* *
* @return int The agent if of the given module. * @return int The agent if of the given module.
*/ */
@ -1297,10 +1300,10 @@ $sql_cache = array ('saved' => 0);
/** /**
* Get the first value of the first row of a table in the database. * Get the first value of the first row of a table in the database.
* *
* @param string $field Field name to get * @param string Field name to get
* @param string $table Table to retrieve the data * @param string Table to retrieve the data
* @param string $field_search Field to filter elements * @param string Field to filter elements
* @param string $condition Condition the field must have * @param string Condition the field must have
* *
* @return mixed Value of first column of the first row. False if there were no row. * @return mixed Value of first column of the first row. False if there were no row.
*/ */
@ -1326,7 +1329,7 @@ function get_db_value ($field, $table, $field_search = 1, $condition = 1) {
/** /**
* Get the first row of an SQL database query. * Get the first row of an SQL database query.
* *
* @param string $sql SQL select statement to execute. * @param string SQL select statement to execute.
* *
* @return mixed The first row of the result or false * @return mixed The first row of the result or false
*/ */
@ -1346,9 +1349,9 @@ function get_db_row_sql ($sql) {
* The SQL statement executed would be something like: * The SQL statement executed would be something like:
* "SELECT * FROM $table WHERE $field_search = $condition" * "SELECT * FROM $table WHERE $field_search = $condition"
* *
* @param string $table Table to get the row * @param string Table to get the row
* @param string $field_search Field to filter elementes * @param string Field to filter elementes
* @param string $condition Condition the field must have. * @param string Condition the field must have.
* *
* @return mixed The first row of a database query or false. * @return mixed The first row of a database query or false.
*/ */
@ -1372,8 +1375,8 @@ function get_db_row ($table, $field_search, $condition) {
/** /**
* Get a single field in the databse from a SQL query. * Get a single field in the databse from a SQL query.
* *
* @param string $sql SQL statement to execute * @param string SQL statement to execute
* @param mixed $field Field number or row to get, beggining by 0. Default: 0 * @param mixed Field number or row to get, beggining by 0. Default: 0
* *
* @return mixed The selected field of the first row in a select statement. * @return mixed The selected field of the first row in a select statement.
*/ */
@ -1388,7 +1391,7 @@ function get_db_sql ($sql, $field = 0) {
/** /**
* Get all the result rows using an SQL statement. * Get all the result rows using an SQL statement.
* *
* @param string $sql SQL statement to execute. * @param string SQL statement to execute.
* *
* @return mixed A matrix with all the values returned from the SQL statement or * @return mixed A matrix with all the values returned from the SQL statement or
* false in case of empty result * false in case of empty result
@ -1405,10 +1408,10 @@ function get_db_all_rows_sql ($sql) {
/** /**
* Error handler function when an SQL error is triggered. * Error handler function when an SQL error is triggered.
* *
* @param int $errno Level of the error raised (not used, but required by set_error_handler()). * @param int Level of the error raised (not used, but required by set_error_handler()).
* @param string $errstr Contains the error message. * @param string Contains the error message.
* *
* @return bool * @return bool True if error level is lower or equal than errno.
*/ */
function sql_error_handler ($errno, $errstr) { function sql_error_handler ($errno, $errstr) {
if (error_reporting () <= $errno) if (error_reporting () <= $errno)
@ -1423,9 +1426,9 @@ function sql_error_handler ($errno, $errstr) {
* an empty array in case of SELECT without results * an empty array in case of SELECT without results
* Queries that return data will be cached so queries don't get repeated * Queries that return data will be cached so queries don't get repeated
* *
* @param string $sql SQL statement to execute * @param string SQL statement to execute
* *
* @param string $rettype (optional) What type of info to return in case of INSERT/UPDATE. * @param string What type of info to return in case of INSERT/UPDATE.
* 'affected_rows' will return mysql_affected_rows (default value) * 'affected_rows' will return mysql_affected_rows (default value)
* 'insert_id' will return the ID of an autoincrement value * 'insert_id' will return the ID of an autoincrement value
* 'info' will return the full (debug) information of a query * 'info' will return the full (debug) information of a query
@ -1478,8 +1481,8 @@ function process_sql ($sql, $rettype = "affected_rows") {
/** /**
* Get all the rows in a table of the database. * Get all the rows in a table of the database.
* *
* @param string $table Database table name. * @param string Database table name.
* @param string $order_field Field to order by. * @param string Field to order by.
* *
* @return mixed A matrix with all the values in the table * @return mixed A matrix with all the values in the table
*/ */
@ -1494,10 +1497,10 @@ function get_db_all_rows_in_table ($table, $order_field = "") {
/** /**
* Get all the rows in a table of the databes filtering from a field. * Get all the rows in a table of the databes filtering from a field.
* *
* @param string $table Database table name. * @param string Database table name.
* @param string $field Field of the table. * @param string Field of the table.
* @param string $condition Condition the field must have to be selected. * @param string Condition the field must have to be selected.
* @param string $order_field Field to order by. * @param string Field to order by.
* *
* @return mixed A matrix with all the values in the table that matches the condition in the field or false * @return mixed A matrix with all the values in the table that matches the condition in the field or false
*/ */
@ -1518,8 +1521,8 @@ function get_db_all_rows_field_filter ($table, $field, $condition, $order_field
/** /**
* Get all the rows in a table of the databes filtering from a field. * Get all the rows in a table of the databes filtering from a field.
* *
* @param string $table Database table name. * @param string Database table name.
* @param string $field Field of the table. * @param string Field of the table.
* *
* @return mixed A matrix with all the values in the table that matches the condition in the field * @return mixed A matrix with all the values in the table that matches the condition in the field
*/ */
@ -1583,7 +1586,7 @@ function format_array_to_update_sql ($values) {
/** /**
* Get the status of an alert assigned to an agent module. * Get the status of an alert assigned to an agent module.
* *
* @param int id_agentmodule Id agent module to check. * @param int Id agent module to check.
* *
* @return bool True if there were alerts fired. * @return bool True if there were alerts fired.
*/ */
@ -1592,8 +1595,8 @@ function return_status_agent_module ($id_agentmodule = 0) {
if ($status == 100) { if ($status == 100) {
// We need to check if there are any alert on this item // We need to check if there are any alert on this item
$times_fired = get_db_value ('SUM(times_fired)', 'talerta_agente_modulo', $times_fired = get_db_value ('SUM(times_fired)', 'talert_template_modules',
'id_agente_modulo', $id_agentmodule); 'id_agent_module', $id_agentmodule);
if ($times_fired > 0) { if ($times_fired > 0) {
return 0; return 0;
} }
@ -1613,7 +1616,7 @@ function return_status_agent_module ($id_agentmodule = 0) {
* layouts), and makes an AND operation to be sure that all the items * layouts), and makes an AND operation to be sure that all the items
* are OK. If any of them is down, then result is down (0) * are OK. If any of them is down, then result is down (0)
* *
* @param int $id_layout Id of the layout * @param int Id of the layout
* *
* @return bool The status of the given layout. * @return bool The status of the given layout.
*/ */
@ -1644,7 +1647,7 @@ function return_status_layout ($id_layout = 0) {
/** /**
* Get the current value of an agent module. * Get the current value of an agent module.
* *
* @param int $id_agentmodule * @param int Agent module id.
* *
* @return int a numerically formatted value * @return int a numerically formatted value
*/ */
@ -1656,7 +1659,7 @@ function return_value_agent_module ($id_agentmodule) {
/** /**
* Get the X axis coordinate of a layout item * Get the X axis coordinate of a layout item
* *
* @param int $id_layoutdata Id of the layout to get. * @param int Id of the layout to get.
* *
* @return int The X axis coordinate value. * @return int The X axis coordinate value.
*/ */
@ -1667,7 +1670,7 @@ function get_layoutdata_x ($id_layoutdata) {
/** /**
* Get the Y axis coordinate of a layout item * Get the Y axis coordinate of a layout item
* *
* @param int $id_layoutdata Id of the layout to get. * @param int Id of the layout to get.
* *
* @return int The Y axis coordinate value. * @return int The Y axis coordinate value.
*/ */
@ -1683,8 +1686,8 @@ function get_layoutdata_y ($id_layoutdata){
* before the beginning of the interval. All this calculation is due * before the beginning of the interval. All this calculation is due
* to the data compression algorithm. * to the data compression algorithm.
* *
* @param int $id_agent_module Agent module id * @param int Agent module id
* @param int $utimestamp The timestamp to look backwards from and get the data. * @param int The timestamp to look backwards from and get the data.
* *
* @return mixed The row of tagente_datos of the last period. False if there were no data. * @return mixed The row of tagente_datos of the last period. False if there were no data.
*/ */
@ -1706,9 +1709,9 @@ function get_previous_data ($id_agent_module, $utimestamp = 0) {
/** /**
* Get the average value of an agent module in a period of time. * Get the average value of an agent module in a period of time.
* *
* @param int $id_agent_module Agent module id * @param int Agent module id
* @param int $period Period of time to check (in seconds) * @param int Period of time to check (in seconds)
* @param int $date Top date to check the values. Default current time. * @param int Top date to check the values. Default current time.
* *
* @return int The average module value in the interval. * @return int The average module value in the interval.
*/ */
@ -1738,9 +1741,9 @@ function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
/** /**
* Get the maximum value of an agent module in a period of time. * Get the maximum value of an agent module in a period of time.
* *
* @param int $id_agent_module Agent module id to get the maximum value. * @param int Agent module id to get the maximum value.
* @param int $period Period of time to check (in seconds) * @param int Period of time to check (in seconds)
* @param int $date Top date to check the values. Default current time. * @param int Top date to check the values. Default current time.
* *
* @return float The maximum module value in the interval. * @return float The maximum module value in the interval.
*/ */
@ -1793,9 +1796,9 @@ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
/** /**
* Get the sum of values of an agent module in a period of time. * Get the sum of values of an agent module in a period of time.
* *
* @param int $id_agent_module Agent module id to get the sumatory. * @param int Agent module id to get the sumatory.
* @param int $period Period of time to check (in seconds) * @param int Period of time to check (in seconds)
* @param int $date Top date to check the values. Default current time. * @param int Top date to check the values. Default current time.
* *
* @return int The sumatory of the module values in the interval. * @return int The sumatory of the module values in the interval.
*/ */
@ -1872,7 +1875,7 @@ function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
/** /**
* Get a translated string * Get a translated string
* *
* @param string $string String to translate * @param string String to translate
* *
* @return string The translated string. If not defined, the same string will be returned * @return string The translated string. If not defined, the same string will be returned
*/ */
@ -1904,16 +1907,12 @@ function check_server_status () {
/** /**
* @deprecated Will show a small HTML table with some compound alert information * @deprecated Will show a small HTML table with some compound alert information
*
* @param int $id_combined_alert
*
* @return string HTML block
*/ */
function show_alert_row_mini ($id_combined_alert) { function show_alert_row_mini ($id_combined_alert) {
$color=1; $color=1;
$sql = sprintf ("SELECT talerta_agente_modulo.*,tcompound_alert.operation $sql = sprintf ("SELECT talert_template_modules.*,tcompound_alert.operation
FROM talerta_agente_modulo, tcompound_alert FROM talert_template_modules, tcompound_alert
WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam WHERE tcompound_alert.id_aam = talert_template_modules.id
AND tcompound_alert.id = %d", $id_combined_alert); AND tcompound_alert.id = %d", $id_combined_alert);
$result = get_db_all_rows_sql ($sql); $result = get_db_all_rows_sql ($sql);
@ -2026,7 +2025,8 @@ function show_alert_row_mini ($id_combined_alert) {
* @deprecated use get_server_info instead * @deprecated use get_server_info instead
* Get statistical information for a given server * Get statistical information for a given server
* *
* @param int Server id to get status * @param int Server id to get status.
*
* @return array Server info array * @return array Server info array
*/ */
function server_status ($id_server) { function server_status ($id_server) {
@ -2096,9 +2096,9 @@ function delete_agent ($id_agents) {
// daily maintance process, all data for that modules are deleted // daily maintance process, all data for that modules are deleted
//Alert //Alert
temp_sql_delete ("tcompound_alert", "id_aam", "ANY(SELECT id_aam FROM talerta_agente_modulo WHERE id_agent = ".$id_agent.")"); /* TODO: Compound alert */
temp_sql_delete ("talerta_agente_modulo", "id_agente_modulo", $tmodbase); //temp_sql_delete ("tcompound_alert", "id_aam", "ANY(SELECT id_aam FROM talerta_agente_modulo WHERE id_agent = ".$id_agent.")");
temp_sql_delete ("talerta_agente_modulo", "id_agent", $id_agent); temp_sql_delete ("talert_template_modules", "id_agent_module", $tmodbase);
//Events (up/down monitors) //Events (up/down monitors)
temp_sql_delete ("tevento", "id_agente", $id_agent); temp_sql_delete ("tevento", "id_agente", $id_agent);
@ -2331,62 +2331,50 @@ function get_modulegroup_name ($modulegroup_id) {
* All arrays and values should have been cleaned before passing. It's not neccessary to add quotes. * All arrays and values should have been cleaned before passing. It's not neccessary to add quotes.
* *
* @param string Table to insert into * @param string Table to insert into
* @param mixed A single row or array of rows to insert to
* @param mixed A single value or array of values to insert (can be a multiple amount of rows) * @param mixed A single value or array of values to insert (can be a multiple amount of rows)
* *
* @return mixed False in case of error or invalid values passed. Affected rows otherwise * @return mixed False in case of error or invalid values passed. Affected rows otherwise
*/ */
function process_sql_insert ($table, $rows, $values) { function process_sql_insert ($table, $values) {
if (empty ($rows) || empty ($values)) { //Empty rows or values not processed //Empty rows or values not processed
if (empty ($values))
return false; return false;
}
$rows = (array) $rows; //Convert single strings to array
$values = (array) $values; $values = (array) $values;
$row_count = count ($rows); //We're reusing so we put it in a variable
$value_count = count ($values);
if (($value_count % $row_count) != 0) {
//If values are not a clean multiple of rows, don't process
return false;
}
$query = sprintf ("INSERT INTO `%s` ", $table); $query = sprintf ("INSERT INTO `%s` ", $table);
$fields = array ();
foreach ($rows as $idx => $row) { //Add ` to each row name $values_str = '';
if ($row[0] != '`') { $i = 1;
$rows[$idx] = '`'.$row.'`'; $max = count ($values);
} foreach ($values as $field => $value) { //Add the correct escaping to values
if ($field[0] != "`") {
$field = "`".$field."`";
} }
foreach ($values as $idx => $value) { //Add the correct escaping to values array_push ($fields, $field);
if ($value[0] == "'") {
continue; //The value is already escaped if (is_null ($value)) {
} $values_str .= "NULL";
if ($value === NULL) { } elseif (is_int ($value) || is_bool ($value)) {
$values[$idx] = (string) "NULL"; $values_str .= sprintf ("%d", $value);
} elseif (is_numeric ($value)) { } else if (is_float ($value) || is_double ($value)) {
continue; //The value doesn't need esaped. $values_str .= sprintf ("%f", $value);
} elseif (is_bool ($value)) {
$values[$idx] = (int) $value; //SQL doesn't know boolean so we convert
} else { } else {
$values[$idx] = sprintf ("'%s'", $value); $values_str .= sprintf ("'%s'", $value);
}
} }
$query .= "(".implode (", ", $rows).")"; if ($i < $max) {
$query .= " VALUES "; $values_str .= ",";
for ($i = 0; $i < ($value_count / $row_count); $i++) {
//For the times the values are multiplied
$array = array_slice ($values, $i * $row_count, ($i+1) * $row_count);
$query .= "(".implode (",", $array).")";
if ($i != ($value_count / $row_count) - 1) {
$query .= ",";
} }
$i++;
} }
return process_sql ($query); $query .= '('.implode (', ', $fields).')';
$query .= ' VALUES ('.$values_str.')';
return process_sql ($query, 'insert_id');
} }
/** /**

View File

@ -22,11 +22,11 @@ require_once ("include/functions_agents.php");
/** /**
* Get SLA of a module. * Get SLA of a module.
* *
* @param int $id_agent_module Agent module to calculate SLA * @param int Agent module to calculate SLA
* @param int $period Period to check the SLA compliance. * @param int Period to check the SLA compliance.
* @param int $min_value Minimum data value the module in the right interval * @param int Minimum data value the module in the right interval
* @param int $max_value Maximum data value the module in the right interval * @param int Maximum data value the module in the right interval
* @param int $date Beginning date of the report in UNIX time (current date by default). * @param int Beginning date of the report in UNIX time (current date by default).
* *
* @return int SLA percentage of the requested module. * @return int SLA percentage of the requested module.
*/ */
@ -199,8 +199,8 @@ function get_group_stats ($id_group) {
$data["monitor_ok"]++; $data["monitor_ok"]++;
} }
$sql = sprintf ("SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = %d", $row["id_agente_modulo"]); $fired = get_db_value ('times_fired', 'talert_template_modules',
$fired = get_db_sql ($sql); 'id_agent_module', $row["id_agente_modulo"]);
if ($fired !== false) { if ($fired !== false) {
$data["monitor_alerts"]++; $data["monitor_alerts"]++;
if ($fired > 0) { if ($fired > 0) {
@ -225,8 +225,8 @@ function get_group_stats ($id_group) {
$data["data_ok"]++; $data["data_ok"]++;
} }
$sql = sprintf ("SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = %d", $row["id_agente_modulo"]); $fired = get_db_value ('times_fired', 'talert_template_modules',
$fired = get_db_sql ($sql); 'id_agent_module', $row["id_agente_modulo"]);
if ($fired !== false) { if ($fired !== false) {
$data["data_alerts"]++; $data["data_alerts"]++;
if ($fired > 0) { if ($fired > 0) {
@ -300,10 +300,10 @@ function get_group_stats ($id_group) {
* It construct a table object with all the events happened in a group * It construct a table object with all the events happened in a group
* during a period of time. * during a period of time.
* *
* @param int $id_group Group id to get the report. * @param int Group id to get the report.
* @param int $period Period of time to get the report. * @param int Period of time to get the report.
* @param int $date Beginning date of the report * @param int Beginning date of the report
* @param int $return Flag to return or echo the report table (echo by default). * @param int Flag to return or echo the report table (echo by default).
* *
* @return object A table object * @return object A table object
*/ */
@ -345,7 +345,7 @@ function event_reporting ($id_group, $period, $date = 0, $return = false) {
/** /**
* Get a table report from a alerts fired array. * Get a table report from a alerts fired array.
* *
* @param array $alerts_fired Alerts fired array. * @param array Alerts fired array.
* @see function get_alerts_fired () * @see function get_alerts_fired ()
* *
* @return object A table object with a report of the fired alerts. * @return object A table object with a report of the fired alerts.
@ -353,15 +353,19 @@ function event_reporting ($id_group, $period, $date = 0, $return = false) {
function get_fired_alerts_reporting_table ($alerts_fired) { function get_fired_alerts_reporting_table ($alerts_fired) {
$agents = array (); $agents = array ();
require_once ('include/functions_alerts.php');
foreach (array_keys ($alerts_fired) as $id_alert) { foreach (array_keys ($alerts_fired) as $id_alert) {
$alert = get_db_row ('talerta_agente_modulo', 'id_aam', $id_alert); $alert_module = get_alert_agent_module ($id_alert);
$template = get_alert_template ($id_alert);
/* Add alerts fired to $agents_fired_alerts indexed by id_agent */ /* Add alerts fired to $agents_fired_alerts indexed by id_agent */
$id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $alert['id_agente_modulo']); $id_agent = get_db_value ('id_agente', 'tagente_modulo',
'id_agente_modulo', $alert_module['id_agent_module']);
if (!isset ($agents[$id_agent])) { if (!isset ($agents[$id_agent])) {
$agents[$id_agent] = array (); $agents[$id_agent] = array ();
} }
array_push ($agents[$id_agent], $alert); array_push ($agents[$id_agent], array ($alert_module, $template));
} }
$table->data = array (); $table->data = array ();
@ -373,14 +377,16 @@ function get_fired_alerts_reporting_table ($alerts_fired) {
foreach ($agents as $id_agent => $alerts) { foreach ($agents as $id_agent => $alerts) {
$data = array (); $data = array ();
foreach ($alerts as $alert) { foreach ($alerts as $tuple) {
$alert_module = $tuple[0];
$template = $tuple[1];
if (! isset ($data[0])) if (! isset ($data[0]))
$data[0] = get_agent_name ($id_agent); $data[0] = get_agent_name ($id_agent);
else else
$data[0] = ''; $data[0] = '';
$data[1] = $alert['descripcion']; $data[1] = $template['name'];
$data[2] = $alerts_fired[$alert['id_aam']]; $data[2] = $alerts_fired[$alert_module['id']];
$data[3] = get_alert_priority ($alert['priority']); $data[3] = get_alert_priority ($alert_module['priority']);
array_push ($table->data, $data); array_push ($table->data, $data);
} }
} }
@ -490,7 +496,7 @@ function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return =
/** /**
* Get a report table with all the monitors down. * Get a report table with all the monitors down.
* *
* @param array $monitors_down An array with all the monitors down * @param array An array with all the monitors down
* @see function get_monitors_down() * @see function get_monitors_down()
* *
* @return object A table object with a monitors down report. * @return object A table object with a monitors down report.
@ -537,8 +543,8 @@ function get_monitors_down_reporting_table ($monitors_down) {
* *
* It shows the number of agents and no more things right now. * It shows the number of agents and no more things right now.
* *
* @param $id_group Group to get the report * @param int Group to get the report
* @param $return Flag to return or echo the report (by default). * @param bool Flag to return or echo the report (by default).
* *
* @return string * @return string
*/ */
@ -555,9 +561,9 @@ function general_group_reporting ($id_group, $return = false) {
/** /**
* Get a report table of the fired alerts group by agents. * Get a report table of the fired alerts group by agents.
* *
* @param int $id_agent Agent id to generate the report. * @param int Agent id to generate the report.
* @param int $period Period of time of the report. * @param int Period of time of the report.
* @param int $date Beginning date of the report in UNIX time (current date by default). * @param int Beginning date of the report in UNIX time (current date by default).
* *
* @return object A table object with the alert reporting.. * @return object A table object with the alert reporting..
*/ */
@ -566,27 +572,52 @@ function get_agent_alerts_reporting_table ($id_agent, $period = 0, $date = 0) {
$table->head = array (); $table->head = array ();
$table->head[0] = __('Type'); $table->head[0] = __('Type');
$table->head[1] = __('Description'); $table->head[1] = __('Description');
$table->head[2] = __('Minimum'); $table->head[2] = __('Value');
$table->head[3] = __('Maximum'); $table->head[3] = __('Threshold');
$table->head[4] = __('Threshold'); $table->head[4] = __('Last fired');
$table->head[5] = __('Last fired'); $table->head[5] = __('Times Fired');
$table->head[6] = __('Times Fired');
$alerts = get_agent_alerts ($id_agent); $alerts = get_agent_alerts ($id_agent);
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
$fires = get_alert_fires_in_period ($alert['id_agente_modulo'], $period, $date); $fires = get_alert_fires_in_period ($alert['id'], $period, $date);
if (! $fires) { if (! $fires) {
continue; continue;
} }
$alert_type = get_db_row ('talerta', 'id_alerta', $alert['id_alerta']);
$template = get_alert_template ($alert['id_alert_template']);
$data = array (); $data = array ();
$data[0] = $alert_type['nombre']; $data[0] = get_alert_templates_type_name ($template['type']);
$data[1] = $alert['descripcion']; $data[1] = $template['name'];
$data[2] = $alert['dis_min'];
$data[3] = $alert['dis_max']; switch ($template['type']) {
$data[4] = $alert['time_threshold']; case 'regex':
$data[5] = get_alert_last_fire_timestamp_in_period ($alert['id_agente_modulo'], $period, $date); if ($template['matches_value'])
$data[6] = $fires; $data[2] = '&#8771; "'.$template['value'].'"';
else
$data[2] = '&#8772; "'.$template['value'].'"';
break;
case 'equal':
case 'not_equal':
$data[2] = $template['value'];
break;
case 'max-min':
$data[2] = __('Min.').': '.$template['min_value']. ' ';
$data[2] .= __('Max.').': '.$template['max_value']. ' ';
break;
case 'max':
$data[2] = $template['max_value'];
break;
case 'min':
$data[2] = $template['min_value'];
break;
}
$data[3] = $template['time_threshold'];
$data[4] = print_timestamp (get_alert_last_fire_timestamp_in_period ($alert['id'], $period, $date), true);
$data[5] = $fires;
array_push ($table->data, $data); array_push ($table->data, $data);
} }
@ -596,9 +627,9 @@ function get_agent_alerts_reporting_table ($id_agent, $period = 0, $date = 0) {
/** /**
* Get a report of monitors in an agent. * Get a report of monitors in an agent.
* *
* @param int $id_agent Agent id to get the report * @param int Agent id to get the report
* @param int $period Period of time of the report. * @param int Period of time of the report.
* @param int $date Beginning date of the report in UNIX time (current date by default). * @param int Beginning date of the report in UNIX time (current date by default).
* *
* @return object A table object with the report. * @return object A table object with the report.
*/ */
@ -633,9 +664,9 @@ function get_agent_monitors_reporting_table ($id_agent, $period = 0, $date = 0)
/** /**
* Get a report of all the modules in an agent. * Get a report of all the modules in an agent.
* *
* @param int $id_agent Agent id to get the report. * @param int Agent id to get the report.
* @param int $period Period of time of the report * @param int Period of time of the report
* @param int $date Beginning date of the report in UNIX time (current date by default). * @param int Beginning date of the report in UNIX time (current date by default).
* *
* @return object * @return object
*/ */
@ -661,10 +692,10 @@ function get_agent_modules_reporting_table ($id_agent, $period = 0, $date = 0) {
/** /**
* Get a detailed report of an agent * Get a detailed report of an agent
* *
* @param int $id_agent Agent to get the report. * @param int Agent to get the report.
* @param int $period Period of time of the desired report. * @param int Period of time of the desired report.
* @param int $date Beginning date of the report in UNIX time (current date by default). * @param int Beginning date of the report in UNIX time (current date by default).
* @param bool $return Flag to return or echo the report (by default). * @param bool Flag to return or echo the report (by default).
* *
* @return string * @return string
*/ */
@ -714,10 +745,10 @@ function get_agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $retur
/** /**
* Get a detailed report of agents in a group. * Get a detailed report of agents in a group.
* *
* @param int $id_group Group to get the report * @param int Group to get the report
* @param int $period Period * @param int Period
* @param int $date Timestamp to start from * @param int Timestamp to start from
* @param bool $return Flag to return or echo the report (by default). * @param bool Flag to return or echo the report (by default).
* *
* @return string * @return string
*/ */

View File

@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Login check // Login check
require("include/config.php"); require ("include/config.php");
check_login(); check_login();

View File

@ -224,7 +224,7 @@ CREATE TABLE IF NOT EXISTS `talert_actions` (
CREATE TABLE IF NOT EXISTS `talert_templates` ( CREATE TABLE IF NOT EXISTS `talert_templates` (
`id` int(10) unsigned NOT NULL auto_increment, `id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) default '', `name` varchar(255) default '',
`description` mediumtext default '', `description` mediumtext,
`id_alert_action` int(10) unsigned NULL, `id_alert_action` int(10) unsigned NULL,
`field1` varchar(255) default '', `field1` varchar(255) default '',
`field2` varchar(255) default '', `field2` varchar(255) default '',
@ -308,7 +308,6 @@ CREATE TABLE IF NOT EXISTS `tattachment` (
PRIMARY KEY (`id_attachment`) PRIMARY KEY (`id_attachment`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tconfig` ( CREATE TABLE IF NOT EXISTS `tconfig` (
`id_config` int(10) unsigned NOT NULL auto_increment, `id_config` int(10) unsigned NOT NULL auto_increment,
`token` varchar(100) NOT NULL default '', `token` varchar(100) NOT NULL default '',
@ -703,7 +702,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_data` (
CREATE TABLE IF NOT EXISTS tplugin ( CREATE TABLE IF NOT EXISTS tplugin (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL, `name` varchar(200) NOT NULL,
`description` mediumtext default "", `description` mediumtext,
`max_timeout` int(4) UNSIGNED NOT NULL default 0, `max_timeout` int(4) UNSIGNED NOT NULL default 0,
`execute`varchar(250) NOT NULL, `execute`varchar(250) NOT NULL,
`net_dst_opt` varchar(50) default '', `net_dst_opt` varchar(50) default '',