'Select Alert Checker Entity Type', 'padding' => true, 'header-border' => true)); //echo '

Select Entity Type

'; ksort($config['entities']); foreach ($config['entities'] as $entity_type => $entity_type_array) { if (!$entity_type_array['hide']) { //echo ''; echo ' '.nicecase($entity_type).''; } } echo generate_box_close(); echo ''; /* // Allow duplication of existing checks echo generate_box_open(array('title' => 'Duplicate Existing Checker', 'padding' => true, 'header-border' => true)); $alert_checks = cache_alert_rules($vars); $alert_checks = array_sort($alert_checks, 'alert_name'); echo '', PHP_EOL; foreach ($alert_checks as $check) { // Process the alert checker to add classes and colours and count status. humanize_alert_check($check); echo(''); echo(' '); // Print the conditions applied by this alert echo ''; echo ''; echo(''); echo(''); } // End loop of associations echo '
Name
'; echo '' . escape_html($check['alert_name']) . '
'; echo '', escape_html($check['alert_message']), ''; echo '
'; echo generate_box_close(); // End duplication of existing checks */ } else { if(isset($vars['duplicate_id']) && $alert_dupe = get_alert_test_by_id($vars['duplicate_id'])){ humanize_alert_check($alert_dupe); $conditions = safe_json_decode($alert_dupe['conditions']); $condition_text_block = array(); foreach ($conditions as $condition) { $condition_text_block[] = $condition['metric'] .' '. $condition['condition'] .' ' . str_replace(',', ',​', $condition['value']); // Add hidden space char (​) for wrap long lists } $vars['alert_conditions'] = implode(PHP_EOL, $condition_text_block); $vars = array_merge($vars, $alert_dupe); } //r($vars); ?>
'New Checker Details', 'header-border' => TRUE, 'padding' => TRUE, ); echo generate_box_open($box_args); ?>
'.nicecase($vars['entity_type']).''; ?>
'alert_name', 'name' => 'Alert name', 'placeholder' => TRUE, 'width' => '220px', 'value' => $vars['alert_name']); echo(generate_form_element($item, 'text')); ?>
'alert_message', 'name' => 'Alert message', 'placeholder' => TRUE, //'width' => '220px', 'class' => 'col-md-11', 'rows' => 3, 'value' => $vars['alert_message']); echo(generate_form_element($item, 'textarea')); ?>
'alert_delay', 'name' => '№ of checks to delay alert', 'placeholder' => TRUE, 'width' => '220px', 'value' => $vars['alert_delay']); echo(generate_form_element($item, 'text')); ?>
'alert_send_recovery', 'size' => 'big', 'view' => 'toggle', 'palette' => 'blue', 'value' => (isset($vars['alert_send_recovery']) ? $vars['alert_send_recovery'] : 1)); // Set to on by default echo(generate_form_element($item, 'toggle')); ?>
'alert_severity', //'name' => 'Severity', 'live-search' => FALSE, 'width' => '220px', 'value' => $vars['alert_severity'], 'values' => $config['alert']['severity'], ); echo(generate_form_element($item, 'select')); ?>
'Test Conditions', 'header-border' => TRUE, 'padding' => TRUE, ); $box_args['header-controls'] = array('controls' => array('tooltip' => array('icon' => $config['icon']['info'], 'anchor' => TRUE, 'class' => 'tooltip-from-element', //'url' => '#', 'data' => 'data-tooltip-id="tooltip-help-conditions"'))); echo generate_box_open($box_args); ?>
'alert_and', //'name' => 'Severity', 'live-search' => FALSE, 'width' => '220px', 'value' => (isset($vars['alert_and']) ? $vars['alert_and'] : 1), // Set to and by default 'values' => array('0' => array('name' => 'Require any condition', 'icon' => $config['icon']['or-gate']), '1' => array('name' => 'Require all conditions', 'icon' => $config['icon']['and-gate']), ) ); echo(generate_form_element($item, 'select')); echo(PHP_EOL . '
' . PHP_EOL); /// FIXME. Better styling on page... $metrics_list = []; foreach ($config['entities'][$vars['entity_type']]['metrics'] as $metric => $entry) { $metric_list = [ 'metric' => $metric, 'description' => $entry['label'], ]; $metric_list['values'] = ''; if (is_array($entry['values'])) { if (is_array_list($entry['values'])) { $values = $entry['values']; } else { $values = []; foreach ($entry['values'] as $value => $descr) { $values[] = "$value ($descr)"; } } $metric_list['values'] = ''.implode(' ', $values).''; } elseif ($entry['type'] === 'integer') { $metric_list['values'] = escape_html(''); if (str_contains($metric, 'value')) { $metric_list['values'] .= '
'; // some table fields foreach ([ 'limit_high', 'limit_high_warn', 'limit_low', 'limit_low_warn' ] as $field) { if (isset($config['entities'][$vars['entity_type']]['table_fields'][$field])) { $metric_list['values'] .= '@' . $config['entities'][$vars['entity_type']]['table_fields'][$field].' '; } } } } else { $metric_list['values'] = escape_html('<'.$entry['type'].'>'); } $metrics_list[] = $metric_list; //$metrics_list[] = ''.$metric.' - '.$entry['label']; } //$form_params['metrics'] = implode(',
', $metrics_list); $metrics_opts = [ 'columns' => [ [ 'Metrics', 'style="width: 5%;"' ], 'Description', 'Values' ], 'metric' => [ 'class' => 'label' ], 'description' => [ 'class' => 'text-nowrap' ], 'values' => [ 'escape' => FALSE ] ]; $item = array('id' => 'alert_conditions', 'name' => 'Metric Conditions', 'placeholder' => TRUE, //'width' => '220px', 'class' => 'col-md-10', 'style' => 'margin-right: 10px', 'rows' => count($metrics_list) > 3 ? count($metrics_list) : 3, 'value' => $vars['alert_conditions']); echo generate_form_element($item, 'textarea'); echo('
List of known metrics:
' . build_table($metrics_list, $metrics_opts) . '
'); echo generate_box_close(); $box_args = array('title' => 'Association Ruleset', 'header-border' => TRUE, 'padding' => TRUE, ); $box_args['header-controls'] = array('controls' => array('tooltip' => array('icon' => $config['icon']['info'], 'anchor' => TRUE, 'class' => 'tooltip-from-element', //'url' => '#', 'data' => 'data-tooltip-id="tooltip-help-associations"'))); echo generate_box_open($box_args); $form_id = 'rules-' . generate_random_string(8); echo '
'; generate_querybuilder_form($vars['entity_type'], 'attribs', $form_id, $alert_dupe['alert_assoc']); // generate_querybuilder_form($vars['entity_type'], 'metrics'); $footer_content = '
Clear Rules Add Checker
'.$script; echo generate_box_close(array('footer_content' => $footer_content)); // echo generate_box_close(); ?>
$('#btn-save').on('click', function() { var result = $('#" . $form_id . "').queryBuilder('getRules'); var div = $('#output'); if (!$.isEmptyObject(result)) { var formData = JSON.stringify({ action: 'alert_check_add', alert_assoc: JSON.stringify(result), entity_type: '" . $vars['entity_type'] . "', alert_name: document.getElementById('alert_name').value, alert_message: document.getElementById('alert_message').value, alert_delay: document.getElementById('alert_delay').value, alert_send_recovery: document.getElementById('alert_send_recovery').value, alert_severity: document.getElementById('alert_severity').value, alert_and: document.getElementById('alert_and').value, alert_conditions: document.getElementById('alert_conditions').value, requesttoken: document.getElementById('requesttoken').value }); var request = $.ajax({ type: 'POST', url: 'ajax/actions.php', data: formData, dataType: 'json', contentType : 'application/json', }); request.success( function(json) { if (json.status === 'ok') { div.html('
Creation Succeeded. Redirecting!
') window.setTimeout(window.location.href = json.redirect,5000); } else { div.html('
Creation Failed: ' + json.message + '
') } }); } }); $('#btn-reset').on('click', function() { $('#" . $form_id . "').queryBuilder('reset'); }); "; echo $script; ?>