From ee37487b7480f4e27726b26539fa697bea636db5 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 14 Jul 2023 11:44:37 +0200 Subject: [PATCH] #10598 unknown create template and show --- .../include/ajax/task_to_perform.php | 9 ++ .../include/class/WelcomeWindow.class.php | 121 ++++-------------- .../include/functions_welcome_wizard.php | 31 +++++ 3 files changed, 68 insertions(+), 93 deletions(-) diff --git a/pandora_console/include/ajax/task_to_perform.php b/pandora_console/include/ajax/task_to_perform.php index c889c37f8d..a8a13e08f2 100644 --- a/pandora_console/include/ajax/task_to_perform.php +++ b/pandora_console/include/ajax/task_to_perform.php @@ -35,6 +35,7 @@ $check_web = get_parameter('check_web', 0); $check_connectivity = get_parameter('check_connectivity', 0); $create_net_scan = get_parameter('create_net_scan', 0); $create_mail_alert = get_parameter('create_mail_alert', 0); +$create_unknown_template_alert = get_parameter('create_unknown_template_alert', 0); // Begin. global $config; @@ -179,3 +180,11 @@ if ($create_mail_alert) { ui_print_success_message(__('Congratulations, you have already created a simple alert. You can see it. Pandora FMS alerts are very flexible, you can do many more things with them, we recommend you to read the documentation for more information. You can create advanced alerts from here.')); } } + +if ($create_unknown_template_alert) { + if (is_array(alerts_get_alert_templates(['name' => io_safe_input('Unknown condition')]))) { + echo 1; + } else { + echo create_template_alert_unknown(); + } +} diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index d5dd35816c..0d1068ce67 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -822,7 +822,7 @@ class WelcomeWindow extends Wizard ' ); - $condition = alerts_get_alert_templates(['id IN (1,3)'], ['id', 'name']); + $condition = alerts_get_alert_templates(['(id IN (1,3) OR name = "'.io_safe_input('Unknown condition').'")'], ['id', 'name']); echo html_print_label_input_block( __('Contition'), @@ -1128,81 +1128,6 @@ class WelcomeWindow extends Wizard } }); - // Task to do buttons. - $('#button-go_wizard').click(function(){ - if ($('#task_to_perform :selected').val() === '') { - alert(""); - } else { - switch($('#task_to_perform :selected').val()) { - case 'wizard_agent': - deployAgent(); - break; - case 'check_mail_alert': - openCreateAlertMailDialog(); - break; - case 'check_connectivity': - openCreateConnectivityDialog(); - break; - case 'check_web': - openCreateModulesDialog(); - break; - case 'check_net': - openCreateBasicNetDialog(); - break; - }; - } - }); - - // Task to do buttons. - $('#button-go_wizard').click(function(){ - if ($('#task_to_perform :selected').val() === '') { - alert(""); - } else { - switch($('#task_to_perform :selected').val()) { - case 'wizard_agent': - deployAgent(); - break; - case 'check_mail_alert': - openCreateAlertMailDialog(); - break; - case 'check_connectivity': - openCreateConnectivityDialog(); - break; - case 'check_web': - openCreateModulesDialog(); - break; - case 'check_net': - openCreateBasicNetDialog(); - break; - }; - } - }); - - // Task to do buttons. - $('#button-go_wizard').click(function(){ - if ($('#task_to_perform :selected').val() === '') { - alert(""); - } else { - switch($('#task_to_perform :selected').val()) { - case 'wizard_agent': - deployAgent(); - break; - case 'check_mail_alert': - openCreateAlertMailDialog(); - break; - case 'check_connectivity': - openCreateConnectivityDialog(); - break; - case 'check_web': - openCreateModulesDialog(); - break; - case 'check_net': - openCreateBasicNetDialog(); - break; - }; - } - }); - function configureUpdateManager() { window.location = ''; } @@ -1276,23 +1201,33 @@ class WelcomeWindow extends Wizard } function openCreateAlertMailDialog() { - $('#dialog_alert_mail').dialog({ - title: '', - resizable: true, - draggable: true, - modal: true, - close: false, - height: 350, - width: 480, - overlay: { - opacity: 0.5, - background: "black" - } - }) - .show(); + $.ajax({ + async: false, + type: "POST", + url: "include/ajax/task_to_perform.php", + data: { + create_unknown_template_alert: 1, + }, + success: function(data) { + $('#dialog_alert_mail').dialog({ + title: '', + resizable: true, + draggable: true, + modal: true, + close: false, + height: 350, + width: 480, + overlay: { + opacity: 0.5, + background: "black" + } + }) + .show(); - $('#text-id_agent').autocomplete({ - appendTo: '#dialog_alert_mail' + $('#text-id_agent').autocomplete({ + appendTo: '#dialog_alert_mail' + }); + } }); } @@ -1351,7 +1286,7 @@ class WelcomeWindow extends Wizard type: "POST", url: "include/ajax/task_to_perform.php", data: { - create_net_scan: 1, + Contition: 1, ip_target: $('#text-ip_target_discovery').val(), }, success: function(data) { diff --git a/pandora_console/include/functions_welcome_wizard.php b/pandora_console/include/functions_welcome_wizard.php index 7f12048b1f..f1b8d672f1 100644 --- a/pandora_console/include/functions_welcome_wizard.php +++ b/pandora_console/include/functions_welcome_wizard.php @@ -535,3 +535,34 @@ function create_net_scan($ip_target) return 0; } } + + +/** + * Create new template unknown. + * + * @return boolean 1 correct create 0 bad create. + */ +function create_template_alert_unknown() +{ + $name = io_safe_input(__('Unknown condition')); + $type = 'critical'; + $values = [ + 'description' => __('This is a generic alert template to fire on UNKNOWN condition'), + 'max_value' => 0, + 'min_value' => 0, + 'id_group' => 0, + 'priority' => 4, + 'wizard_level' => 'nowizard', + 'time_threshold' => '300', + 'min_alerts_reset_counter' => 1, + 'schedule' => '{"monday":[{"start":"00:00:00","end":"00:00:00"}],"tuesday":[{"start":"00:00:00","end":"00:00:00"}],"wednesday":[{"start":"00:00:00","end":"00:00:00"}],"thursday":[{"start":"00:00:00","end":"00:00:00"}],"friday":[{"start":"00:00:00","end":"00:00:00"}],"saturday":[{"start":"00:00:00","end":"00:00:00"}],"sunday":[{"start":"00:00:00","end":"00:00:00"}]}', + 'recovery_notify' => true, + 'field2' => '[PANDORA] Alert for UNKNOWN status on _agent_ / _module_', + 'field2_recovery' => '[PANDORA] Alert RECOVERED for UNKNOWN status on _agent_ / _module_', + 'field3' => '

Automatic alert system


We have bad news for you, something is on UNKNOWN status!

Monitoring details

Data: _data_ (warning)

Agent: _agent_ _address_

Module: _module_ _moduledescription_

Timestamp: _timestamp_

This is a graph of latest 24hr data for this module

_modulegraph_24h_

Contact Us  |  Support  |  Docs

', + 'field3_recovery' => '

Automatic alert system


We have good news for you, alert has been recovered

Monitoring details

Data: _data_ (normal)

Agent: _agent_ _address_

Module: _module_ _moduledescription_

Timestamp: _timestamp_

This is a graph of latest 24hr data for this module

_modulegraph_24h_

Contact Us  |  Support  |  Docs

', + ]; + + $result = alerts_create_alert_template($name, $type, $values); + return $result; +}