#10598 unknown create template and show

This commit is contained in:
Jonathan 2023-07-14 11:44:37 +02:00
parent f748a07c75
commit ee37487b74
3 changed files with 68 additions and 93 deletions

View File

@ -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. <a href='.ui_get_full_url('index.php?sec=galertas&sec2=godmode/alerts/alert_list&tab=list&pure=0').'>You can see it.</a> Pandora FMS alerts are very flexible, you can do many more things with them, we recommend you to read the <a href="https://pandorafms.com/manual/start?id=en/documentation/04_using/01_alerts">documentation</a> for more information. You can create advanced alerts from <a href='.ui_get_full_url('index.php?sec=galertas&sec2=godmode/alerts/alert_actions').'>here</a>.'));
}
}
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();
}
}

View File

@ -822,7 +822,7 @@ class WelcomeWindow extends Wizard
<span id="module_loading" class="invisible">'.html_print_image('images/spinner.gif', true).'</span>'
);
$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("<?php echo __('You must chose an option'); ?>");
} 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("<?php echo __('You must chose an option'); ?>");
} 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("<?php echo __('You must chose an option'); ?>");
} 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 = '<?php echo ui_get_full_url('index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online'); ?>';
}
@ -1276,6 +1201,14 @@ class WelcomeWindow extends Wizard
}
function openCreateAlertMailDialog() {
$.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: '<?php echo __('Create email alert'); ?>',
resizable: true,
@ -1295,6 +1228,8 @@ class WelcomeWindow extends Wizard
appendTo: '#dialog_alert_mail'
});
}
});
}
$('#button-create_goliat').click(function(){
$.ajax({
@ -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) {

View File

@ -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' => '<div style="background-color: #eaf0f6; font-family: Arial, Helvetica, sans-serif; padding: 30px; margin: 0;"><table style="max-width: 560px; background-color: white; border-radius: 10px; padding: 10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"><thead><tr><td style="padding: 0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank" rel="noopener"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td><td style="padding: 0px 0px 5px;"><p style="text-align: right; color: #223549; font-weight: bold; line-height: 36px; padding: 0px; font-size: 12px;">Automatic alert system</p></td></tr><tr><td style="padding: 0px 0px 5px;" colspan="2"><hr style="border: 1px solid #f5f5f5; width: 100%; margin: 0px;"></td></tr></thead><tbody><tr><td colspan="2"><img style="display: block; margin-left: auto; margin-right: auto; width: 105px; margin-top: 20px; padding: 0px;" src="https://pandorafms.com/wp-content/uploads/2022/03/Warning-news.png" width="105px"></td></tr><tr><td colspan="2"><p style="font-size: 24px; text-align: center; color: #223549; padding: 0px 10%; line-height: 34px; margin: 20px 0px;">We have bad news for you, something is on <span style="text-transform: uppercase; font-weight: 800;">UNKNOWN</span>&nbsp;status!</p><div><!-- [if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius: 100px; max-width: 50%; margin-top: 0px; font-weight: bold;" href="_homeurl_">Go to Pandora FMS Console</a><!-- [if mso]></center></v:rect><![endif]--></div></td></tr><tr><td colspan="2"><div style="background-color: #f6f6f6; border-radius: 10px; padding: 10px 20px; margin-top: 40px;"><p style="font-size: 18px; line-height: 30px; color: #223549;">Monitoring details</p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Data: <span style="font-weight: 400!important;">_data_ <em>(warning)</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Agent: <span style="font-weight: 400!important;">_agent_ <em>_address_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Module: <span style="font-weight: 400!important;">_module_ <em>_moduledescription_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Timestamp: <span style="font-weight: 400!important;">_timestamp_</span></p></div></td></tr><tr><td style="padding: 20px 0px;" colspan="2"><p style="font-size: 18px; line-height: 30px; color: #223549;">This is a graph of latest 24hr data for this module</p><p style="font-weight: 400!important;">_modulegraph_24h_</p></td></tr></tbody></table><div style="text-align: center; margin-top: 10px;"><p style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;"><a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/en/contact/">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/community/forums/forum/english/">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/manual/en/start">Docs</a></p></div></div>',
'field3_recovery' => '<div style="background-color:#EAF0F6; font-family: Arial, Helvetica, sans-serif; padding:30px; margin:0;"><table style="max-width:560px; background-color:white; border-radius:10px; padding:10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"><thead><tr><td style="padding:0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td><td style="padding:0px 0px 5px;"><p style="text-align:right; color:#223549; font-weight:700; line-height:36px; padding:0px; font-size:12px;">Automatic alert system</p></td></tr><tr><td colspan="2" style="padding:0px 0px 5px;"><hr style="border: 1px solid #f5f5f5; width:100%; margin:0px;"></td></tr></thead><tbody><tr><td colspan="2"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Good-news.png" style="display: block; margin-left: auto; margin-right: auto; width:105px; margin-top:20px; padding:0px;" width="105px"></td></tr><tr><td colspan="2"><p style="font-size:24px; text-align:center; color:#223549; padding:0px 10%; line-height:34px; margin:20px 0px;">We have good news for you, alert has been <span style="text-transform:uppercase; font-weight:800;">recovered</span></p><div><!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius:100px; max-width:50%; margin-top:0px; font-weight:700;" href="_homeurl_">Go to Pandora FMS Console</a><!--[if mso]></center></v:rect><![endif]--></div></td></tr><tr><td colspan="2"><div style="background-color:#F6F6F6; border-radius:10px; padding:10px 20px; margin-top:40px;"><p style="font-size:18px; line-height:30px; color:#223549;">Monitoring details</p><p style="font-size:15px; color:#333333; font-weight:800; line-height:15px;">Data: <span style="font-weight:400!important;">_data_ <em>(normal)</em></span></p><p style="font-size:15px; color:#333333; font-weight:800; line-height:15px;">Agent: <span style="font-weight:400!important;">_agent_ <em>_address_</em></span></p><p style="font-size:15px; color:#333333; font-weight:800; line-height:15px;">Module: <span style="font-weight:400!important;">_module_ <em>_moduledescription_</em></span></p><p style="font-size:15px; color:#333333; font-weight:800; line-height:15px;">Timestamp: <span style="font-weight:400!important;">_timestamp_</span></p></div></td></tr><tr><td style="padding:20px 0px;" colspan="2"><p style="font-size:18px; line-height:30px; color:#223549;">This is a graph of latest 24hr data for this module</p><p style="font-weight:400!important;">_modulegraph_24h_</p></td></tr></tbody></table><div style="text-align:center; margin-top:10px;"><p style="font-size:12px; text-decoration: none; font-weight:400; color:#777;"><a href="https://pandorafms.com/en/contact/" style="font-size:12px; text-decoration: none; font-weight:400; color:#777;">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="https://pandorafms.com/community/forums/forum/english/" style="font-size:12px; text-decoration: none; font-weight:400; color:#777;">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="https://pandorafms.com/manual/en/start" style="font-size:12px; text-decoration: none; font-weight:400; color:#777;">Docs</a></p></div></div>',
];
$result = alerts_create_alert_template($name, $type, $values);
return $result;
}