EventHistoryQuery: Do not fetch columns which only exist in one subquery

Uses the same technique as the NotificationhistoryQuery for the output.
This commit is contained in:
Johannes Meyer 2015-06-10 13:08:57 +02:00
parent db816e4a5c
commit 41ee39d48f
6 changed files with 6 additions and 38 deletions

View File

@ -575,8 +575,6 @@ class Monitoring_ListController extends Controller
'object_type',
'timestamp',
'state',
'attempt',
'max_attempts',
'output',
'type'
));

View File

@ -23,6 +23,7 @@ if (count($history) === 0) {
<?php foreach ($history as $event): ?>
<?php
$icon = 'help';
$msg = $event->output;
$title = $event->type;
$stateName = 'invalid';
$isService = isset($event->service_description);
@ -30,54 +31,44 @@ if (count($history) === 0) {
case 'notify':
$icon = 'bell';
$title = $this->translate('Notification');
$msg = $event->output;
break;
case 'comment':
$icon = 'comment';
$title = $this->translate('Comment');
$msg = $event->output;
break;
case 'ack':
$icon = 'ok';
$title = $this->translate('Acknowledgement');
$msg = $event->output;
break;
case 'dt_comment':
$icon = 'plug';
$title = $this->translate('In Downtime');
$msg = $event->output;
break;
case 'flapping':
$icon = 'flapping';
$title = $this->translate('Flapping');
$msg = $event->output;
break;
case 'flapping_deleted':
$icon = 'ok';
$title = $this->translate('Flapping Stopped');
$msg = $event->output;
break;
case 'hard_state':
$icon = $isService ? 'service' : 'host';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true);
break;
case 'soft_state':
$icon = 'lightbulb';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true);
break;
case 'dt_start':
$icon = 'starttime';
$title = $this->translate('Downtime Start');
$msg = $event->output;
break;
case 'dt_end':
$icon = 'endtime';
$title = $this->translate('Downtime End');
$msg = $event->output;
break;
}
?>

View File

@ -49,6 +49,7 @@ function contactsLink($match, $view) {
<?php foreach ($history as $event): ?>
<?php
$stateClass = 'invalid';
$msg = $this->escape($event->output);
$isService = isset($event->service_description);
switch ($event->type) {
case 'notify':
@ -59,70 +60,58 @@ function contactsLink($match, $view) {
$msg = preg_replace_callback(
'/^\[([^\]]+)\]/',
function($match) use ($self) { return contactsLink($match, $self); },
$this->escape($event->output)
$msg
);
break;
case 'comment':
$icon = 'comment';
$title = $this->translate('Comment');
$msg = $this->escape($event->output);
break;
case 'comment_deleted':
$icon = 'remove';
$title = $this->translate('Comment deleted');
$msg = $this->escape($event->output);
break;
case 'ack':
$icon = 'acknowledgement';
$title = $this->translate('Acknowledge');
$msg = $this->escape($event->output);
break;
case 'ack_deleted':
$icon = 'remove';
$title = $this->translate('Ack removed');
$msg = $this->escape($event->output);
break;
case 'dt_comment':
$icon = 'in_downtime';
$title = $this->translate('In Downtime');
$msg = $this->escape($event->output);
break;
case 'dt_comment_deleted':
$icon = 'remove';
$title = $this->translate('Downtime removed');
$msg = $this->escape($event->output);
break;
case 'flapping':
$icon = 'flapping';
$title = $this->translate('Flapping');
$msg = $this->escape($event->output);
break;
case 'flapping_deleted':
$icon = 'remove';
$title = $this->translate('Flapping stopped');
$msg = $this->escape($event->output);
break;
case 'hard_state':
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$icon = 'attention-alt';
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
break;
case 'soft_state':
$icon = 'spinner';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
break;
case 'dt_start':
$icon = 'downtime_start';
$title = $this->translate('Downtime Start');
$msg = $this->escape($event->output);
break;
case 'dt_end':
$icon = 'downtime_end';
$title = $this->translate('Downtime End');
$msg = $this->escape($event->output);
break;
}
?>

View File

@ -37,9 +37,7 @@ class EventHistoryQuery extends IdoQuery
'object_type' => 'eh.object_type',
'timestamp' => 'eh.timestamp',
'state' => 'eh.state',
'attempt' => 'eh.attempt',
'max_attempts' => 'eh.max_attempts',
'output' => 'eh.output', // we do not want long_output
'output' => 'eh.output',
'type' => 'eh.type'
),
'hostgroups' => array(
@ -70,10 +68,7 @@ class EventHistoryQuery extends IdoQuery
'type',
'output',
'state',
'state_type',
'object_type',
'attempt',
'max_attempts',
'object_type'
);
$this->subQueries = array(
$this->createSubQuery('Statehistory', $columns),

View File

@ -18,10 +18,7 @@ class StatehistoryQuery extends IdoQuery
'object_id' => 'sho.object_id',
'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)",
'state' => 'sh.state',
'state_type' => 'sh.state_type',
'output' => 'sh.output',
'attempt' => 'sh.current_check_attempt',
'max_attempts' => 'sh.max_check_attempts',
'output' => "('[ ' || sh.current_check_attempt || '/' || sh.max_check_attempts || ' ] ' || sh.output)",
'host' => 'sho.name1 COLLATE latin1_general_ci',
'service' => 'sho.name2 COLLATE latin1_general_ci',

View File

@ -457,8 +457,6 @@ abstract class MonitoredObject implements Filterable
'service_display_name',
'timestamp',
'state',
'attempt',
'max_attempts',
'output',
'type'
))