<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ 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; 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.
global $config;
require_once 'include/functions_alerts.php';
enterprise_include_once('include/functions_policies.php');
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_modules.php';
// TODO: CLEAN extra_sql
$extra_sql = '';
$searchAlerts = check_acl($config['id_user'], 0, 'AR');
$selectDisabledUp = '';
$selectDisabledDown = '';
$selectAgentUp = '';
$selectAgentDown = '';
$selectModuleUp = '';
$selectModuleDown = '';
$selectTemplateUp = '';
$selectTemplateDown = '';
switch ($sortField) {
case 'disabled':
switch ($sort) {
case 'up':
$selectAgentUp = $selected;
$order = [
'field' => 'disabled',
'order' => 'ASC',
];
break;
case 'down':
$selectAgentDown = $selected;
'order' => 'DESC',
}
case 'agent':
'field' => 'agent_name',
case 'module':
$selectModuleUp = $selected;
'field' => 'module_name',
$selectModuleDown = $selected;
case 'template':
$selectTemplateUp = $selected;
'field' => 'template_name',
$selectTemplateDown = $selected;
default:
$alerts = false;
if ($searchAlerts) {
$agents = array_keys(agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AR', false))));
switch ($config['dbtype']) {
case 'mysql':
$whereAlerts = 'AND (
id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE "%'.$stringSearchSQL.'%") OR
id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
FROM talert_actions
WHERE name LIKE "%'.$stringSearchSQL.'%")) OR
talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE "%'.$stringSearchSQL.'%") OR
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.'))
)';
case 'postgresql':
case 'oracle':
id_alert_template IN (SELECT id FROM talert_templates WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR
WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.'))
$agents = false;
$alertsraw = agents_get_alerts_simple(
$agents,
'all_enabled',
[
'offset' => get_parameter('offset', 0),
'limit' => $config['block_size'],
],
$whereAlerts,
false,
$order['field'].' '.$order['order']
);
$stringSearchPHP = substr($stringSearchSQL, 1, (strlen($stringSearchSQL) - 2));
$alerts = [];
foreach ($alertsraw as $key => $alert) {
$finded = false;
$alerts[$key]['disabled'] = $alert['disabled'];
$alerts[$key]['id_agente'] = modules_get_agentmodule_agent($alert['id_agent_module']);
$alerts[$key]['agent_name'] = $alert['agent_name'];
$alerts[$key]['module_name'] = $alert['agent_module_name'];
$alerts[$key]['template_name'] = $alert['template_name'];
$actions = alerts_get_alert_agent_module_actions($alert['id']);
$actions_name = [];
foreach ($actions as $action) {
$actions_name[] = $action['name'];
$alerts[$key]['actions'] = implode(',', $actions_name);
$totalAlerts = count($alerts);
if ($only_count) {
unset($alerts);