$value) { if (!safe_empty($value)) { switch ($var) { // Search by device_id if we have a device or device_id case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'entity_type': if ($value !== 'all') { $where .= generate_query_values($value, 'entity_type'); } break; case 'entity_id': $where .= generate_query_values($value, 'entity_id'); break; case 'alert_test_id': $where .= generate_query_values($value, 'alert_test_id'); break; case 'status': if ($value === 'failed_delayed') { $where .= " AND `alert_status` IN (0,2)"; } elseif ($value === 'failed') { $where .= " AND `alert_status` IN (0)"; } elseif ($value === 'suppressed') { $where .= " AND `alert_status` = 3"; } break; case 'sort': if ($value === 'changed') { $sort = ' ORDER BY `last_changed` DESC '; } elseif ($value === 'device') { // fix this to sort by hostname $sort = ' ORDER BY `device_id` '; } break; } } } // Permissions query $query_permitted = generate_query_permitted(array('device', 'alert'), array('hide_ignored' => TRUE)); // Base query $query = 'FROM `alert_table` '; //$query .= 'LEFT JOIN `alert_table-state` USING(`alert_table_id`) '; $query .= $where . $query_permitted; // Build the query to get a count of entries $query_count = 'SELECT COUNT(`alert_table_id`) '.$query; // Build the query to get the list of entries $query = 'SELECT * '.$query; //$query .= ' ORDER BY `device_id`, `alert_test_id`, `entity_type`, `entity_id` DESC '; $query .= $sort; if (isset($vars['pagination']) && $vars['pagination']) { pagination($vars, 0, TRUE); // Get default pagesize/pageno $vars['start'] = $vars['pagesize'] * $vars['pageno'] - $vars['pagesize']; $query .= 'LIMIT '.$vars['start'].','.$vars['pagesize']; } return array($query, [], $query_count); } /** * Display alert_table entries. * * @param array $vars * @return void * */ function print_alert_table($vars) { global $alert_rules, $config; // This should be set outside, but do it here if it isn't if (!is_array($alert_rules)) { $alert_rules = cache_alert_rules(); } /// WARN HERE if (isset($vars['device']) && !isset($vars['device_id'])) { $vars['device_id'] = $vars['device']; } if (isset($vars['entity']) && !isset($vars['entity_id'])) { $vars['entity_id'] = $vars['entity']; } // Short? (no pagination, small out) $short = (isset($vars['short']) && $vars['short']); list($query, $param, $query_count) = build_alert_table_query($vars); // Fetch alerts $count = dbFetchCell($query_count, $param); $alerts = dbFetchRows($query, $param); // Set which columns we're going to show. // We hide the columns that have been given as search options via $vars $list = array('device_id' => FALSE, 'entity_id' => FALSE, 'entity_type' => FALSE, 'alert_test_id' => FALSE); foreach ($list as $argument => $nope) { if (!isset($vars[$argument]) || empty($vars[$argument]) || $vars[$argument] === "all") { $list[$argument] = TRUE; } } if ($vars['format'] !== "condensed") { $list['checked'] = TRUE; $list['changed'] = TRUE; $list['alerted'] = TRUE; } if ($vars['short']) { $list['checked'] = FALSE; $list['alerted'] = FALSE; } // Hide device if we know entity_id if (isset($vars['entity_id'])) { $list['device_id'] = FALSE; } // Hide entity_type if we know the alert_test_id if (isset($vars['alert_test_id']) || TRUE) { $list['entity_type'] = FALSE; } // Hide entity types in favour of icons to save space if ($vars['pagination'] && !$short) { $pagination_html = pagination($vars, $count); echo $pagination_html; } echo generate_box_open($vars['header']); echo '
'; if ($list['device_id']) { echo(' | Device | '); } if ($list['entity_type']) { echo('Type | '); } if ($list['entity_id']) { echo('Entity | '); } if ($list['alert_test_id']) { echo('Alert | '); } echo 'Status | '; if ($list['checked']) { echo 'Checked | '; } if ($list['changed']) { echo 'Changed | '; } if ($list['alerted']) { echo 'Alerted | '; } echo '|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'); echo(' | '); // If we know the device, don't show the device if ($list['device_id']) { echo(' | '.generate_device_link_short($device).' | '); } // If we're showing all entity types, print the entity type here if ($list['entity_type']) { echo(''.nicecase($alert['entity_type']).' | '); } // Print a link to the entity if ($list['entity_id']) { echo ''; // If we have a parent type, display it here. // FIXME - this is perhaps messy. Find a better way and a better layout. We can't have a new table column because it would be empty 90% of the time! if (isset($entity_type['parent_type'])) { echo ' '.generate_entity_link($entity_type['parent_type'], $entity[$entity_type['parent_id_field']]).' - '; } echo ' '.generate_entity_link($alert['entity_type'], $alert['entity_id'], NULL, NULL, TRUE, $short).''; echo ' | '; } // Print link to the alert rule page if ($list['alert_test_id']) { echo '', escape_html($alert_rule['alert_name']), ' | '; } echo('');
echo('' . generate_tooltip_link('', $alert['status'], ' '.$alert['last_message'].' ', $alert['alert_class']) . '');
echo(' | ');
// echo(''.$alert['last_message'].' | '); if ($list['checked']) { echo(''.generate_tooltip_link('', $alert['checked'], format_unixtime($alert['last_checked'], 'r')).' | '); } if ($list['changed']) { echo(''.generate_tooltip_link('', $alert['changed'], format_unixtime($alert['last_changed'], 'r')).' | '); } if ($list['alerted']) { echo(''.generate_tooltip_link('', $alert['alerted'], format_unixtime($alert['last_alerted'], 'r')).' | '); } echo('');
// This stuff should go in an external entity popup in the future.
$state = safe_json_decode($alert['state']);
$alert['state_popup'] = '';
if (safe_count($state['failed'])) {
$alert['state_popup'] .= generate_box_open(array('title' => 'Failed Tests')); //'Failed Tests'; $alert['state_popup'] .= '
Warning!// This association will be deleted! | ');
echo('