'alert_checks', 'entity_type' => NULL]); $navbar['options']['all']['text'] = escape_html(nicecase('all')); if (!isset($vars['entity_type'])) { $navbar['options']['all']['class'] = "active"; $navbar['options']['all']['url'] = generate_url($vars, ['page' => 'alert_checks', 'entity_type' => NULL]); } foreach ($types as $thing) { if ($vars['entity_type'] == $thing['entity_type']) { $navbar['options'][$thing['entity_type']]['class'] = "active"; $navbar['options'][$thing['entity_type']]['url'] = generate_url($vars, ['page' => 'alert_checks', 'entity_type' => NULL]); } else { if ($types_count > 6) { $navbar['options'][$thing['entity_type']]['class'] = "icon"; } $navbar['options'][$thing['entity_type']]['url'] = generate_url($vars, ['page' => 'alert_checks', 'entity_type' => $thing['entity_type']]); } $navbar['options'][$thing['entity_type']]['icon'] = $config['entities'][$thing['entity_type']]['icon']; $navbar['options'][$thing['entity_type']]['text'] = escape_html(nicecase($thing['entity_type'])); } $navbar['options']['export']['text'] = 'Export'; $navbar['options']['export']['icon'] = $config['icon']['export']; $navbar['options']['export']['url'] = generate_url($vars, ['page' => 'alert_checks', 'export' => 'yes']); $navbar['options']['export']['right'] = TRUE; $navbar['options']['export']['userlevel'] = 7; // Print out the navbar defined above print_navbar($navbar); // Generate contacts cache array for use in table $contacts = []; $sql = "SELECT * FROM `alert_contacts_assoc` LEFT JOIN `alert_contacts` USING(`contact_id`) WHERE `aca_type` = ?"; $params = [ 'alert' ]; foreach (dbFetchRows($sql, $params) as $db_contact) { $contacts[$db_contact['alert_checker_id']][] = $db_contact; } if (get_var_true($vars['export'])) { // Export requested if (!get_var_true($vars['saveas'])) { $export_filename = 'observium_alerts_'; $export_filename .= $vars['entity_type'] ?: 'all'; $export_filename .= '.json'; $form = ['type' => 'rows', 'space' => '10px', 'url' => generate_url($vars)]; // Filename $form['row'][0]['filename'] = [ 'type' => 'text', 'name' => 'Filename', 'value' => $export_filename, 'grid_xs' => 8, 'width' => '100%', 'placeholder' => TRUE ]; // Save as human formatted XML $form['row'][0]['formatted'] = [ 'type' => 'select', 'grid_xs' => 4, 'value' => 'yes', 'values' => [ 'yes' => 'Formatted', 'no' => 'Unformatted' ] ]; // search button $form['row'][0]['saveas'] = [ 'type' => 'submit', 'name' => 'Save as..', 'icon' => 'icon-save', 'right' => TRUE, 'value' => 'yes' ]; print_form($form); } json_export('alerts', $vars); unset($export_filename, $form); } foreach (dbFetchRows("SELECT * FROM `alert_table`" . $where) as $entry) { $alert_table[$entry['alert_test_id']][$entry['alert_table_id']] = $entry; } echo generate_box_open(); echo '', PHP_EOL; // FIXME -- make sort order configurable $alert_check = array_sort($alert_check, 'alert_name'); foreach ($alert_check 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 ''; // Loop the tests used by this alert echo ''); echo(''; // Print the count of entities this alert applies to and a popup containing a list and Print breakdown of entities by status. // We assume each row here is going to be two lines, so we just
them. echo ''; } echo '
Name Tests Device Match / Entity Match Entities
'; echo '' . escape_html($check['alert_name']) . '
'; echo '', escape_html($check['alert_message']), ''; echo '
'; $text_block = []; //r($check); foreach ($check['conditions'] as $condition) { $text_block[] = escape_html($condition['metric'] . ' ' . $condition['condition'] . ' ' . $condition['value']); } echo ($check['and'] ? ' AND (ALL)' : ' OR (ANY)') . '
'; echo ''; $allowed_metrics = array_keys($config['entities'][$check['entity_type']]['metrics']); // FIXME. Currently hardcoded in check_entity(), need rewrite to timeranges. $allowed_metrics[] = 'time'; $allowed_metrics[] = 'weekday'; foreach ($check['conditions'] as $condition) { // Detect incorrect metric used if (!in_array($condition['metric'], $allowed_metrics, TRUE)) { print_error("Unknown condition metric '" . escape_html($condition['metric']) . "' for Entity type '" . escape_html($check['entity_type']) . "'"); foreach (array_keys($config['entities']) as $suggest_entity) { if (isset($config['entities'][$suggest_entity]['metrics'][$condition['metric']])) { print_warning("Suggested Entity type: '$suggest_entity'. Change Entity in Edit Alert below."); $suggest_entity_types[$suggest_entity] = ['name' => $config['entities'][$suggest_entity]['name'], 'icon' => $config['entities'][$suggest_entity]['icon']]; } } } echo ''; $condition_text_block[] = $condition['metric'] . ' ' . $condition['condition'] . ' ' . $condition['value']; //str_replace(',', ',​', $condition['value']); // Add hidden space char (​) for wrap long lists } echo '
' . escape_html($condition['metric']) . '' . escape_html($condition['condition']) . '' . escape_html(str_replace(",", ", ", $condition['value'])) . '
'; echo('
'); if (!is_null($check['alert_assoc'])) { $check['assoc'] = safe_json_decode($check['alert_assoc']); echo render_qb_rules($check['entity_type'], $check['assoc']); } else { echo generate_box_open(); echo(''); // Loop the associations which link this alert to this device foreach ($alert_assoc[$check['alert_test_id']] as $assoc_id => $assoc) { echo(''); echo(''); echo(''); echo(''); } // End loop of associations echo '
'); if (is_array($assoc['device_attribs'])) { $text_block = []; foreach ($assoc['device_attribs'] as $attribute) { $text_block[] = escape_html($attribute['attrib'] . ' ' . $attribute['condition'] . ' ' . $attribute['value']); } echo('' . implode('
', $text_block) . '
'); } else { echo '*'; } echo('
'); if (is_array($assoc['entity_attribs'])) { $text_block = []; foreach ($assoc['entity_attribs'] as $attribute) { $text_block[] = escape_html($attribute['attrib'] . ' ' . $attribute['condition'] . ' ' . $attribute['value']); } echo('' . implode('
', $text_block) . '
'); } else { echo '*'; } echo('
'; echo generate_box_close(); } echo '
'; #echo overlib_link('#', count($entities), $entities_content, NULL)); echo '', $check['num_entities'], ' '; //echo '
'; echo $check['status_numbers']; echo '
'; if ($notifiers_count = safe_count($contacts[$check['alert_test_id']])) { $content = ""; foreach ($contacts[$check['alert_test_id']] as $contact) { $content .= '' . $contact['contact_method'] . ' ' . escape_html($contact['contact_descr']) . '
'; } echo generate_tooltip_link('', '' . $notifiers_count . ' Notifiers', $content); } else { echo 'Default Notifier'; } echo '
'; echo generate_box_close(); register_html_title('Alert checkers'); // EOF