Merge branch 'ent-8733-giss-anadir-alertas-externas-desde-varias-politicas-sin-pisar-las-anteriores' into 'develop'
multiple external alert policies pandora_enterprise#8733 See merge request artica/pandorafms!5205
This commit is contained in:
commit
7646f0629b
|
@ -20,4 +20,7 @@ ALTER TABLE `tagente_estado` ADD COLUMN `warning_count` int(10) UNSIGNED DEFAULT
|
|||
|
||||
ALTER TABLE `tcredential_store` MODIFY COLUMN `product` ENUM('CUSTOM', 'AWS', 'AZURE', 'GOOGLE', 'SAP', 'WMI', 'SNMP') DEFAULT 'CUSTOM';
|
||||
|
||||
ALTER TABLE `talert_template_modules` DROP INDEX `id_agent_module`;
|
||||
ALTER TABLE `talert_template_modules` ADD UNIQUE (`id_agent_module`, `id_alert_template`, `id_policy_alerts`);
|
||||
|
||||
COMMIT;
|
||||
|
|
|
@ -102,13 +102,20 @@ if ($create_alert) {
|
|||
$id_alert_template = (int) get_parameter('template');
|
||||
$id_agent_module = (int) get_parameter('id_agent_module');
|
||||
|
||||
if (db_get_value_sql(
|
||||
'SELECT COUNT(id)
|
||||
FROM talert_template_modules
|
||||
WHERE id_agent_module = '.$id_agent_module.'
|
||||
AND id_alert_template = '.$id_alert_template
|
||||
) > 0
|
||||
) {
|
||||
$exist = db_get_value_sql(
|
||||
sprintf(
|
||||
'SELECT COUNT(id)
|
||||
FROM talert_template_modules
|
||||
WHERE id_agent_module = %d
|
||||
AND id_alert_template = %d
|
||||
AND id_policy_alerts = 0
|
||||
',
|
||||
$id_agent_module,
|
||||
$id_alert_template
|
||||
)
|
||||
);
|
||||
|
||||
if ($exist > 0) {
|
||||
$messageAction = ui_print_result_message(
|
||||
false,
|
||||
'',
|
||||
|
|
|
@ -1147,13 +1147,31 @@ function alerts_create_alert_agent_module($id_agent_module, $id_alert_template,
|
|||
$values['id_alert_template'] = (int) $id_alert_template;
|
||||
$values['last_reference'] = time();
|
||||
|
||||
$sql = sprintf(
|
||||
'INSERT IGNORE INTO talert_template_modules(%s) VALUES(%s)',
|
||||
implode(', ', array_keys($values)),
|
||||
implode(', ', array_values($values))
|
||||
$exist = db_get_value_sql(
|
||||
sprintf(
|
||||
'SELECT COUNT(id)
|
||||
FROM talert_template_modules
|
||||
WHERE id_agent_module = %d
|
||||
AND id_alert_template = %d
|
||||
AND id_policy_alerts = 0
|
||||
',
|
||||
$id_agent_module,
|
||||
$id_alert_template
|
||||
)
|
||||
);
|
||||
|
||||
return @db_process_sql($sql, 'insert_id');
|
||||
$result = false;
|
||||
if ((int) $exist === 0) {
|
||||
$sql = sprintf(
|
||||
'INSERT INTO talert_template_modules(%s) VALUES(%s)',
|
||||
implode(', ', array_keys($values)),
|
||||
implode(', ', array_values($values))
|
||||
);
|
||||
|
||||
$result = db_process_sql($sql, 'insert_id');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ CREATE TABLE IF NOT EXISTS `talert_template_modules` (
|
|||
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (`id_alert_template`) REFERENCES talert_templates(`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
UNIQUE (`id_agent_module`, `id_alert_template`),
|
||||
UNIQUE (`id_agent_module`, `id_alert_template`, `id_policy_alerts`),
|
||||
INDEX force_execution (`force_execution`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
|
|
|
@ -1150,10 +1150,10 @@ sub db_update ($$;@) {
|
|||
##########################################################################
|
||||
## Return alert template-module ID given the module and template ids.
|
||||
##########################################################################
|
||||
sub get_alert_template_module_id ($$$) {
|
||||
my ($dbh, $id_module, $id_template) = @_;
|
||||
sub get_alert_template_module_id ($$$$) {
|
||||
my ($dbh, $id_module, $id_template, $id_policy_alerts) = @_;
|
||||
|
||||
my $rc = get_db_value ($dbh, "SELECT id FROM talert_template_modules WHERE id_agent_module = ? AND id_alert_template = ?", $id_module, $id_template);
|
||||
my $rc = get_db_value ($dbh, "SELECT id FROM talert_template_modules WHERE id_agent_module = ? AND id_alert_template = ? AND id_policy_alerts = ?", $id_module, $id_template, $id_policy_alerts);
|
||||
return defined ($rc) ? $rc : -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue