Merge branch 'feature/monitoring-restrictions-9009'
Wohooo!!1 fixes #8343 fixes #8927 fixes #8928 fixes #9008 fixes #9319 fixes #9384 resolves #9009
This commit is contained in:
commit
c8b0fabf26
|
@ -3,13 +3,14 @@
|
|||
|
||||
namespace Icinga\Data\Db;
|
||||
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Data\Filter\FilterChain;
|
||||
use Icinga\Data\Filter\FilterOr;
|
||||
use Icinga\Data\Filter\FilterAnd;
|
||||
use Icinga\Data\Filter\FilterNot;
|
||||
use Icinga\Exception\QueryException;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\FilterAnd;
|
||||
use Icinga\Data\Filter\FilterChain;
|
||||
use Icinga\Data\Filter\FilterNot;
|
||||
use Icinga\Data\Filter\FilterOr;
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\QueryException;
|
||||
|
||||
/**
|
||||
* Database query class
|
||||
|
@ -21,6 +22,15 @@ class DbQuery extends SimpleQuery
|
|||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Whether or not the query is a sub query
|
||||
*
|
||||
* Sub queries are automatically wrapped in parentheses
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isSubQuery = false;
|
||||
|
||||
/**
|
||||
* Select query
|
||||
*
|
||||
|
@ -70,6 +80,27 @@ class DbQuery extends SimpleQuery
|
|||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not the query is a sub query
|
||||
*/
|
||||
public function getIsSubQuery()
|
||||
{
|
||||
return $this->isSubQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the query is a sub query
|
||||
*
|
||||
* @param bool $isSubQuery
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIsSubQuery($isSubQuery = true)
|
||||
{
|
||||
$this->isSubQuery = (bool) $isSubQuery;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUseSubqueryCount($useSubqueryCount = true)
|
||||
{
|
||||
$this->useSubqueryCount = $useSubqueryCount;
|
||||
|
@ -115,8 +146,9 @@ class DbQuery extends SimpleQuery
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->group) {
|
||||
$select->group($this->group);
|
||||
$group = $this->getGroup();
|
||||
if ($group) {
|
||||
$select->group($group);
|
||||
}
|
||||
|
||||
$select->columns($this->columns);
|
||||
|
@ -255,12 +287,27 @@ class DbQuery extends SimpleQuery
|
|||
if ($this->isTimestamp($col)) {
|
||||
$expression = $this->valueToTimestamp($expression);
|
||||
}
|
||||
|
||||
if (is_array($expression) && $sign === '=') {
|
||||
// TODO: Should we support this? Doesn't work for blub*
|
||||
return $col . ' IN (' . $this->escapeForSql($expression) . ')';
|
||||
} elseif ($sign === '=' && strpos($expression, '*') !== false) {
|
||||
if ($expression === '*') {
|
||||
// We'll ignore such filters as it prevents index usage and because "*" means anything, anything means
|
||||
// all whereas all means that whether we use a filter to match anything or no filter at all makes no
|
||||
// difference, except for performance reasons...
|
||||
return '';
|
||||
}
|
||||
|
||||
return $col . ' LIKE ' . $this->escapeForSql($this->escapeWildcards($expression));
|
||||
} elseif ($sign === '!=' && strpos($expression, '*') !== false) {
|
||||
if ($expression === '*') {
|
||||
// We'll ignore such filters as it prevents index usage and because "*" means nothing, so whether we're
|
||||
// using a real column with a valid comparison here or just an expression which cannot be evaluated to
|
||||
// true makes no difference, except for performance reasons...
|
||||
return $this->escapeForSql(0);
|
||||
}
|
||||
|
||||
return $col . ' NOT LIKE ' . $this->escapeForSql($this->escapeWildcards($expression));
|
||||
} else {
|
||||
return $col . ' ' . $sign . ' ' . $this->escapeForSql($expression);
|
||||
|
@ -276,8 +323,9 @@ class DbQuery extends SimpleQuery
|
|||
{
|
||||
// TODO: there may be situations where we should clone the "select"
|
||||
$count = $this->dbSelect();
|
||||
if ($this->group) {
|
||||
$count->group($this->group);
|
||||
$group = $this->getGroup();
|
||||
if ($group) {
|
||||
$count->group($group);
|
||||
}
|
||||
$this->applyFilterSql($count);
|
||||
if ($this->useSubqueryCount || $this->group) {
|
||||
|
@ -331,7 +379,8 @@ class DbQuery extends SimpleQuery
|
|||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->getSelectQuery();
|
||||
$select = (string) $this->getSelectQuery();
|
||||
return $this->getIsSubQuery() ? ('(' . $select . ')') : $select;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,6 +396,16 @@ class DbQuery extends SimpleQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the GROUP BY clause
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given table has been joined
|
||||
*
|
||||
|
@ -370,6 +429,35 @@ class DbQuery extends SimpleQuery
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the alias used for joining the given table
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string|null null in case no alias is being used
|
||||
*
|
||||
* @throws ProgrammingError In case the given table has not been joined
|
||||
*/
|
||||
public function getJoinedTableAlias($table)
|
||||
{
|
||||
$fromPart = $this->select->getPart(Zend_Db_Select::FROM);
|
||||
if (isset($fromPart[$table])) {
|
||||
if ($fromPart[$table]['joinType'] === Zend_Db_Select::FROM) {
|
||||
throw new ProgrammingError('Table "%s" has not been joined', $table);
|
||||
}
|
||||
|
||||
return; // No alias in use
|
||||
}
|
||||
|
||||
foreach ($fromPart as $alias => $options) {
|
||||
if ($options['tableName'] === $table && $options['joinType'] !== Zend_Db_Select::FROM) {
|
||||
return $alias;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProgrammingError('Table "%s" has not been joined', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an INNER JOIN table and colums to the query
|
||||
*
|
||||
|
|
|
@ -156,7 +156,7 @@ class ListCommand extends Command
|
|||
'service_perfdata',
|
||||
'service_last_state_change'
|
||||
);
|
||||
$query = $this->getQuery('serviceStatus', $columns)
|
||||
$query = $this->getQuery('servicestatus', $columns)
|
||||
->order('host_name');
|
||||
echo $this->renderStatusQuery($query);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'notification_state'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->notifications = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -91,10 +92,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'notification_start_time'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->setFilter(
|
||||
$query->addFilter(
|
||||
new Icinga\Data\Filter\FilterExpression(
|
||||
'n.start_time',
|
||||
'notification_start_time',
|
||||
'>=',
|
||||
$this->getBeginDate($interval)->format('Y-m-d H:i:s')
|
||||
)
|
||||
|
@ -139,10 +141,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'notification_start_time'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->setFilter(
|
||||
$query->addFilter(
|
||||
new Icinga\Data\Filter\FilterExpression(
|
||||
'n.start_time',
|
||||
'notification_start_time',
|
||||
'>=',
|
||||
$beginDate->format('Y-m-d H:i:s')
|
||||
)
|
||||
|
@ -206,10 +209,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'notification_start_time'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->setFilter(
|
||||
$query->addFilter(
|
||||
new Icinga\Data\Filter\FilterExpression(
|
||||
'n.start_time',
|
||||
'notification_start_time',
|
||||
'>=',
|
||||
$this->getBeginDate($interval)->format('Y-m-d H:i:s')
|
||||
)
|
||||
|
@ -251,11 +255,12 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
$interval = $this->getInterval();
|
||||
|
||||
$query = $this->backend->select()->from(
|
||||
'eventHistory',
|
||||
'eventhistory',
|
||||
array(
|
||||
'timestamp'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->addFilter(
|
||||
new Icinga\Data\Filter\FilterExpression(
|
||||
|
@ -321,10 +326,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'acknowledgement_entry_time'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->setFilter(
|
||||
$query->addFilter(
|
||||
new Icinga\Data\Filter\FilterExpression(
|
||||
'n.start_time',
|
||||
'notification_start_time',
|
||||
'>=',
|
||||
$this->getBeginDate($interval)->format('Y-m-d H:i:s')
|
||||
)
|
||||
|
@ -490,6 +496,7 @@ class Monitoring_AlertsummaryController extends Controller
|
|||
'notification_state'
|
||||
)
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$query->order('notification_start_time', 'desc');
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ class Monitoring_CommentController extends Controller
|
|||
{
|
||||
$commentId = $this->params->getRequired('comment_id');
|
||||
|
||||
$this->comment = $this->backend->select()->from('comment', array(
|
||||
$query = $this->backend->select()->from('comment', array(
|
||||
'id' => 'comment_internal_id',
|
||||
'objecttype' => 'comment_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'comment_data',
|
||||
'author' => 'comment_author_name',
|
||||
'timestamp' => 'comment_timestamp',
|
||||
|
@ -38,8 +38,10 @@ class Monitoring_CommentController extends Controller
|
|||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->where('comment_internal_id', $commentId)->getQuery()->fetchRow();
|
||||
))->where('comment_internal_id', $commentId);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->comment = $query->getQuery()->fetchRow();
|
||||
if ($this->comment === false) {
|
||||
$this->httpNotFound($this->translate('Comment not found'));
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ class Monitoring_CommentsController extends Controller
|
|||
'comment_internal_id',
|
||||
(string)$this->params
|
||||
));
|
||||
$this->comments = $this->backend->select()->from('comment', array(
|
||||
$query = $this->backend->select()->from('comment', array(
|
||||
'id' => 'comment_internal_id',
|
||||
'objecttype' => 'comment_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'comment_data',
|
||||
'author' => 'comment_author_name',
|
||||
'timestamp' => 'comment_timestamp',
|
||||
|
@ -43,12 +43,14 @@ class Monitoring_CommentsController extends Controller
|
|||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->addFilter($this->filter)->getQuery()->fetchAll();
|
||||
|
||||
))->addFilter($this->filter);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->comments = $query->getQuery()->fetchAll();
|
||||
if (false === $this->comments) {
|
||||
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
|
||||
}
|
||||
|
||||
|
||||
$this->getTabs()->add(
|
||||
'comments',
|
||||
array(
|
||||
|
|
|
@ -35,9 +35,9 @@ class Monitoring_DowntimeController extends Controller
|
|||
{
|
||||
$downtimeId = $this->params->getRequired('downtime_id');
|
||||
|
||||
$this->downtime = $this->backend->select()->from('downtime', array(
|
||||
$query = $this->backend->select()->from('downtime', array(
|
||||
'id' => 'downtime_internal_id',
|
||||
'objecttype' => 'downtime_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'downtime_comment',
|
||||
'author_name' => 'downtime_author_name',
|
||||
'start' => 'downtime_start',
|
||||
|
@ -49,16 +49,16 @@ class Monitoring_DowntimeController extends Controller
|
|||
'is_fixed' => 'downtime_is_fixed',
|
||||
'is_in_effect' => 'downtime_is_in_effect',
|
||||
'entry_time' => 'downtime_entry_time',
|
||||
'host_state' => 'downtime_host_state',
|
||||
'service_state' => 'downtime_service_state',
|
||||
'host_state',
|
||||
'service_state',
|
||||
'host_name',
|
||||
'host',
|
||||
'service',
|
||||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->where('downtime_internal_id', $downtimeId)->getQuery()->fetchRow();
|
||||
))->where('downtime_internal_id', $downtimeId);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->downtime = $query->getQuery()->fetchRow();
|
||||
if ($this->downtime === false) {
|
||||
$this->httpNotFound($this->translate('Downtime not found'));
|
||||
}
|
||||
|
@ -95,9 +95,9 @@ class Monitoring_DowntimeController extends Controller
|
|||
Host::getStateText($this->downtime->host_state);
|
||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
||||
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
||||
->setParam('host', $this->downtime->host);
|
||||
->setParam('host', $this->downtime->host_name);
|
||||
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
||||
->setParam('host', $this->downtime->host)
|
||||
->setParam('host', $this->downtime->host_name)
|
||||
->setParam('service', $this->downtime->service_description);
|
||||
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
||||
|
|
|
@ -39,9 +39,9 @@ class Monitoring_DowntimesController extends Controller
|
|||
'downtime_internal_id',
|
||||
(string)$this->params
|
||||
));
|
||||
$this->downtimes = $this->backend->select()->from('downtime', array(
|
||||
$query = $this->backend->select()->from('downtime', array(
|
||||
'id' => 'downtime_internal_id',
|
||||
'objecttype' => 'downtime_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'downtime_comment',
|
||||
'author_name' => 'downtime_author_name',
|
||||
'start' => 'downtime_start',
|
||||
|
@ -53,22 +53,22 @@ class Monitoring_DowntimesController extends Controller
|
|||
'is_fixed' => 'downtime_is_fixed',
|
||||
'is_in_effect' => 'downtime_is_in_effect',
|
||||
'entry_time' => 'downtime_entry_time',
|
||||
'host_state' => 'downtime_host_state',
|
||||
'service_state' => 'downtime_service_state',
|
||||
'host_state',
|
||||
'service_state',
|
||||
'host_name',
|
||||
'host',
|
||||
'service',
|
||||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->addFilter($this->filter)->getQuery()->fetchAll();
|
||||
))->addFilter($this->filter);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->downtimes = $query->getQuery()->fetchAll();
|
||||
if (false === $this->downtimes) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
$this->translate('Downtime not found')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$this->getTabs()->add(
|
||||
'downtimes',
|
||||
array(
|
||||
|
@ -80,14 +80,14 @@ class Monitoring_DowntimesController extends Controller
|
|||
'url' =>'monitoring/downtimes/show'
|
||||
)
|
||||
)->activate('downtimes');
|
||||
|
||||
|
||||
foreach ($this->downtimes as $downtime) {
|
||||
if (isset($downtime->service_description)) {
|
||||
$downtime->isService = true;
|
||||
} else {
|
||||
$downtime->isService = false;
|
||||
}
|
||||
|
||||
|
||||
if ($downtime->isService) {
|
||||
$downtime->stateText = Service::getStateText($downtime->service_state);
|
||||
} else {
|
||||
|
@ -127,4 +127,4 @@ class Monitoring_DowntimesController extends Controller
|
|||
$delDowntimeForm->setDowntimes($this->downtimes)->handleRequest();
|
||||
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class Monitoring_HostController extends MonitoredObjectController
|
|||
{
|
||||
$host = new Host($this->backend, $this->params->getRequired('host'));
|
||||
|
||||
$this->applyRestriction('monitoring/hosts/filter', $host);
|
||||
$this->applyRestriction('monitoring/filter/objects', $host);
|
||||
|
||||
if ($host->fetch() === false) {
|
||||
$this->httpNotFound($this->translate('Host not found'));
|
||||
|
@ -70,7 +70,7 @@ class Monitoring_HostController extends MonitoredObjectController
|
|||
{
|
||||
$this->setAutorefreshInterval(10);
|
||||
$this->getTabs()->activate('services');
|
||||
$query = $this->backend->select()->from('serviceStatus', array(
|
||||
$query = $this->backend->select()->from('servicestatus', array(
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'host_state',
|
||||
|
|
|
@ -26,14 +26,10 @@ class Monitoring_HostsController extends Controller
|
|||
|
||||
public function init()
|
||||
{
|
||||
// Support switching from service-view using the host and service selection. The filter would error
|
||||
// on any occurrence of a filter based on service.
|
||||
$filterString = preg_replace('/(service=[^)&]*)/', '', (string)$this->params);
|
||||
|
||||
$hostList = new HostList($this->backend);
|
||||
$hostList->setFilter(Filter::fromQueryString((string) $this->params->without('view')));
|
||||
$hostList->setFilter(Filter::fromQueryString((string) $this->params));
|
||||
$this->applyRestriction('monitoring/filter/objects', $hostList);
|
||||
$this->hostList = $hostList;
|
||||
|
||||
$this->getTabs()->add(
|
||||
'show',
|
||||
array(
|
||||
|
@ -46,8 +42,7 @@ class Monitoring_HostsController extends Controller
|
|||
'icon' => 'host'
|
||||
)
|
||||
)->extend(new DashboardAction())->activate('show');
|
||||
|
||||
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts')->setQueryString($filterString);
|
||||
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
|
||||
}
|
||||
|
||||
protected function handleCommandForm(ObjectsCommandForm $form)
|
||||
|
|
|
@ -66,10 +66,9 @@ class Monitoring_ListController extends Controller
|
|||
$stateColumn = 'host_state';
|
||||
$stateChangeColumn = 'host_last_state_change';
|
||||
}
|
||||
|
||||
$this->addTitleTab('hosts', $this->translate('Hosts'), $this->translate('List hosts'));
|
||||
$this->setAutorefreshInterval(10);
|
||||
$query = $this->backend->select()->from('hostStatus', array_merge(array(
|
||||
$query = $this->backend->select()->from('hoststatus', array_merge(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
|
@ -98,10 +97,9 @@ class Monitoring_ListController extends Controller
|
|||
'host_max_check_attempts'
|
||||
), $this->addColumns()));
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/hosts/filter', $query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->hosts = $query;
|
||||
|
||||
$this->view->stats = $this->backend->select()->from('statusSummary', array(
|
||||
$stats = $this->backend->select()->from('hoststatussummary', array(
|
||||
'hosts_total',
|
||||
'hosts_up',
|
||||
'hosts_down',
|
||||
|
@ -111,8 +109,9 @@ class Monitoring_ListController extends Controller
|
|||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_pending',
|
||||
))->getQuery()->fetchRow();
|
||||
|
||||
));
|
||||
$this->applyRestriction('monitoring/filter/objects', $stats);
|
||||
$this->view->stats = $stats->fetchRow();
|
||||
$this->setupLimitControl();
|
||||
$this->setupPaginationControl($this->view->hosts);
|
||||
$this->setupSortControl(array(
|
||||
|
@ -181,9 +180,9 @@ class Monitoring_ListController extends Controller
|
|||
'current_check_attempt' => 'service_current_check_attempt',
|
||||
'max_check_attempts' => 'service_max_check_attempts'
|
||||
), $this->addColumns());
|
||||
$query = $this->backend->select()->from('serviceStatus', $columns);
|
||||
$query = $this->backend->select()->from('servicestatus', $columns);
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/services/filter', $query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->services = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -200,23 +199,22 @@ class Monitoring_ListController extends Controller
|
|||
'host_last_check' => $this->translate('Last Host Check')
|
||||
), $query);
|
||||
|
||||
$this->view->stats = $this->backend->select()->from('statusSummary', array(
|
||||
'services_total',
|
||||
'services_ok',
|
||||
'services_problem',
|
||||
'services_problem_handled',
|
||||
'services_problem_unhandled',
|
||||
$stats = $this->backend->select()->from('servicestatussummary', array(
|
||||
'services_critical',
|
||||
'services_critical_unhandled',
|
||||
'services_critical_handled',
|
||||
'services_warning',
|
||||
'services_warning_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_unknown',
|
||||
'services_unknown_unhandled',
|
||||
'services_unknown_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_pending',
|
||||
))->getQuery()->fetchRow();
|
||||
'services_total',
|
||||
'services_unknown',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled'
|
||||
));
|
||||
$this->applyRestriction('monitoring/filter/objects', $stats);
|
||||
$this->view->stats = $stats->fetchRow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +227,7 @@ class Monitoring_ListController extends Controller
|
|||
|
||||
$query = $this->backend->select()->from('downtime', array(
|
||||
'id' => 'downtime_internal_id',
|
||||
'objecttype' => 'downtime_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'downtime_comment',
|
||||
'author_name' => 'downtime_author_name',
|
||||
'start' => 'downtime_start',
|
||||
|
@ -241,14 +239,17 @@ class Monitoring_ListController extends Controller
|
|||
'is_fixed' => 'downtime_is_fixed',
|
||||
'is_in_effect' => 'downtime_is_in_effect',
|
||||
'entry_time' => 'downtime_entry_time',
|
||||
'host_state' => 'downtime_host_state',
|
||||
'service_state' => 'downtime_service_state',
|
||||
'host_state',
|
||||
'service_state',
|
||||
'host_name',
|
||||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->view->downtimes = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -295,6 +296,7 @@ class Monitoring_ListController extends Controller
|
|||
'service_display_name'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->notifications = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -310,25 +312,14 @@ class Monitoring_ListController extends Controller
|
|||
|
||||
$query = $this->backend->select()->from('contact', array(
|
||||
'contact_name',
|
||||
'contact_id',
|
||||
'contact_alias',
|
||||
'contact_email',
|
||||
'contact_pager',
|
||||
'contact_notify_service_timeperiod',
|
||||
'contact_notify_service_recovery',
|
||||
'contact_notify_service_warning',
|
||||
'contact_notify_service_critical',
|
||||
'contact_notify_service_unknown',
|
||||
'contact_notify_service_flapping',
|
||||
'contact_notify_service_downtime',
|
||||
'contact_notify_host_timeperiod',
|
||||
'contact_notify_host_recovery',
|
||||
'contact_notify_host_down',
|
||||
'contact_notify_host_unreachable',
|
||||
'contact_notify_host_flapping',
|
||||
'contact_notify_host_downtime',
|
||||
'contact_notify_host_timeperiod'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->contacts = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -376,6 +367,7 @@ class Monitoring_ListController extends Controller
|
|||
$this->params->remove(array('objecttype', 'from', 'to', 'state', 'btn_submit'));
|
||||
$this->view->filter = Filter::fromQuerystring((string) $this->params);
|
||||
$query->applyFilter($this->view->filter);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->view->summary = $query->getQuery()->fetchAll();
|
||||
$this->view->column = $form->getValue('state');
|
||||
// $this->view->orientationBox = $orientationBox;
|
||||
|
@ -396,9 +388,15 @@ class Monitoring_ListController extends Controller
|
|||
'contact_name',
|
||||
'contact_alias',
|
||||
'contact_email',
|
||||
'contact_pager',
|
||||
'contact_pager'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->setupSortControl(array(
|
||||
'contactgroup_name' => $this->translate('Contactgroup Name'),
|
||||
'contactgroup_alias' => $this->translate('Contactgroup Alias')
|
||||
), $query);
|
||||
|
||||
// Fetch and prepare all contact groups:
|
||||
$contactgroups = $query->getQuery()->fetchAll();
|
||||
|
@ -412,13 +410,9 @@ class Monitoring_ListController extends Controller
|
|||
}
|
||||
$groupData[$c->contactgroup_name]['contacts'][] = $c;
|
||||
}
|
||||
|
||||
// TODO: Find a better naming
|
||||
$this->view->groupData = $groupData;
|
||||
|
||||
$this->setupSortControl(array(
|
||||
'contactgroup_name' => $this->translate('Contactgroup Name'),
|
||||
'contactgroup_alias' => $this->translate('Contactgroup Alias')
|
||||
), $query);
|
||||
}
|
||||
|
||||
public function commentsAction()
|
||||
|
@ -428,7 +422,7 @@ class Monitoring_ListController extends Controller
|
|||
|
||||
$query = $this->backend->select()->from('comment', array(
|
||||
'id' => 'comment_internal_id',
|
||||
'objecttype' => 'comment_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'comment_data',
|
||||
'author' => 'comment_author_name',
|
||||
'timestamp' => 'comment_timestamp',
|
||||
|
@ -441,6 +435,9 @@ class Monitoring_ListController extends Controller
|
|||
'service_display_name'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->view->comments = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -472,17 +469,11 @@ class Monitoring_ListController extends Controller
|
|||
$this->setAutorefreshInterval(12);
|
||||
|
||||
$query = $this->backend->select()->from('servicegroupsummary', array(
|
||||
'hosts_down_handled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'services_critical_handled',
|
||||
'services_critical_last_state_change_handled',
|
||||
'services_critical_last_state_change_unhandled',
|
||||
'services_critical_last_state_change_handled' => 'services_critical_handled_last_state_change',
|
||||
'services_critical_last_state_change_unhandled' => 'services_critical_unhandled_last_state_change',
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_ok_last_state_change',
|
||||
|
@ -490,15 +481,18 @@ class Monitoring_ListController extends Controller
|
|||
'services_pending_last_state_change',
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_unknown_last_state_change_unhandled',
|
||||
'services_unknown_last_state_change_handled' => 'services_unknown_handled_last_state_change',
|
||||
'services_unknown_last_state_change_unhandled' => 'services_unknown_unhandled_last_state_change',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_warning_last_state_change_handled' => 'services_warning_handled_last_state_change',
|
||||
'services_warning_last_state_change_unhandled' => 'services_warning_unhandled_last_state_change',
|
||||
'services_warning_unhandled'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->view->servicegroups = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -519,15 +513,15 @@ class Monitoring_ListController extends Controller
|
|||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'hosts_down_handled',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_down_last_state_change_handled' => 'hosts_down_handled_last_state_change',
|
||||
'hosts_down_last_state_change_unhandled' => 'hosts_down_unhandled_last_state_change',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_pending_last_state_change',
|
||||
'hosts_total',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'hosts_unreachable_last_state_change_handled' => 'hosts_unreachable_handled_last_state_change',
|
||||
'hosts_unreachable_last_state_change_unhandled' => 'hosts_unreachable_unhandled_last_state_change',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'hosts_up_last_state_change',
|
||||
|
@ -542,6 +536,9 @@ class Monitoring_ListController extends Controller
|
|||
'services_warning_unhandled'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->view->hostgroups = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
|
@ -562,7 +559,7 @@ class Monitoring_ListController extends Controller
|
|||
$this->translate('List event records')
|
||||
);
|
||||
|
||||
$query = $this->backend->select()->from('eventHistory', array(
|
||||
$query = $this->backend->select()->from('eventhistory', array(
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'service_description',
|
||||
|
@ -570,12 +567,11 @@ class Monitoring_ListController extends Controller
|
|||
'object_type',
|
||||
'timestamp',
|
||||
'state',
|
||||
'attempt',
|
||||
'max_attempts',
|
||||
'output',
|
||||
'type'
|
||||
));
|
||||
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->filterQuery($query);
|
||||
$this->view->history = $query;
|
||||
|
||||
|
@ -590,7 +586,7 @@ class Monitoring_ListController extends Controller
|
|||
{
|
||||
$this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid'));
|
||||
$this->setAutorefreshInterval(15);
|
||||
$query = $this->backend->select()->from('serviceStatus', array(
|
||||
$query = $this->backend->select()->from('servicestatus', array(
|
||||
'host_name',
|
||||
'service_description',
|
||||
'service_state',
|
||||
|
@ -598,6 +594,7 @@ class Monitoring_ListController extends Controller
|
|||
'service_handled'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$this->setupSortControl(array(
|
||||
'host_name' => $this->translate('Hostname'),
|
||||
'service_description' => $this->translate('Service description')
|
||||
|
|
|
@ -28,7 +28,7 @@ class Monitoring_ServiceController extends MonitoredObjectController
|
|||
$this->backend, $this->params->getRequired('host'), $this->params->getRequired('service')
|
||||
);
|
||||
|
||||
$this->applyRestriction('monitoring/services/filter', $service);
|
||||
$this->applyRestriction('monitoring/filter/objects', $service);
|
||||
|
||||
if ($service->fetch() === false) {
|
||||
$this->httpNotFound($this->translate('Service not found'));
|
||||
|
|
|
@ -30,9 +30,9 @@ class Monitoring_ServicesController extends Controller
|
|||
$serviceList->setFilter(Filter::fromQueryString(
|
||||
(string) $this->params->without(array('service_problem', 'service_handled', 'view'))
|
||||
));
|
||||
$this->applyRestriction('monitoring/filter/objects', $serviceList);
|
||||
$this->serviceList = $serviceList;
|
||||
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
|
||||
|
||||
$this->getTabs()->add(
|
||||
'show',
|
||||
array(
|
||||
|
|
|
@ -78,6 +78,7 @@ class Monitoring_ShowController extends Controller
|
|||
'contact_notify_host_downtime',
|
||||
));
|
||||
$query->where('contact_name', $contactName);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
$contact = $query->getQuery()->fetchRow();
|
||||
|
||||
if ($contact) {
|
||||
|
@ -100,6 +101,7 @@ class Monitoring_ShowController extends Controller
|
|||
));
|
||||
|
||||
$notifications->where('contact_object_id', $contact->contact_object_id);
|
||||
$this->applyRestriction('monitoring/filter/objects', $notifications);
|
||||
$this->view->notifications = $notifications;
|
||||
$this->setupLimitControl();
|
||||
$this->setupPaginationControl($this->view->notifications);
|
||||
|
|
|
@ -20,9 +20,8 @@ class Monitoring_TacticalController extends MonitoringController
|
|||
'url' => Url::fromRequest()
|
||||
)
|
||||
)->extend(new DashboardAction())->activate('tactical_overview');
|
||||
|
||||
$this->view->statusSummary = $this->backend->select()->from(
|
||||
'statusSummary',
|
||||
$stats = $this->backend->select()->from(
|
||||
'statussummary',
|
||||
array(
|
||||
'hosts_up',
|
||||
'hosts_pending',
|
||||
|
@ -79,6 +78,8 @@ class Monitoring_TacticalController extends MonitoringController
|
|||
'hosts_flapping',
|
||||
'services_flapping'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
);
|
||||
$this->applyRestriction('monitoring/filter/objects', $stats);
|
||||
$this->view->statusSummary = $stats->fetchRow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,13 @@ class Monitoring_TimelineController extends Controller
|
|||
$detailUrl = Url::fromPath('monitoring/list/eventhistory');
|
||||
|
||||
$timeline = new TimeLine(
|
||||
$this->backend->select()->from('eventHistory',
|
||||
array(
|
||||
'name' => 'type',
|
||||
'time' => 'timestamp'
|
||||
$this->applyRestriction(
|
||||
'monitoring/filter/objects',
|
||||
$this->backend->select()->from('eventhistory',
|
||||
array(
|
||||
'name' => 'type',
|
||||
'time' => 'timestamp'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
|
|
|
@ -44,6 +44,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':
|
||||
|
@ -51,73 +52,61 @@ function contactsLink($match, $view) {
|
|||
$title = $this->translate('Notification');
|
||||
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
|
||||
|
||||
$msg = preg_replace_callback(
|
||||
$msg = $msg ? preg_replace_callback(
|
||||
'/^\[([^\]]+)\]/',
|
||||
function($match) use ($self) { return contactsLink($match, $self); },
|
||||
$this->escape($event->output)
|
||||
);
|
||||
$msg
|
||||
) : $this->translate('This notification was not sent out to any contact.');
|
||||
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;
|
||||
}
|
||||
?>
|
||||
|
@ -166,4 +155,4 @@ $output = $this->tickets ? preg_replace_callback(
|
|||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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,45 @@ if (count($history) === 0) {
|
|||
case 'notify':
|
||||
$icon = 'bell';
|
||||
$title = $this->translate('Notification');
|
||||
$msg = $event->output;
|
||||
$msg = $msg ?: $this->translate('This notification was not sent out to any contact.');
|
||||
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;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -52,6 +52,7 @@ if (count($notifications) === 0) {
|
|||
<br>
|
||||
<?php if (! $this->contact): ?>
|
||||
<small>
|
||||
<?php if ($notification->notification_contact_name): ?>
|
||||
<?= sprintf(
|
||||
$this->translate('Sent to %s'),
|
||||
$this->qlink(
|
||||
|
@ -60,6 +61,9 @@ if (count($notifications) === 0) {
|
|||
array('contact_name' => $notification->notification_contact_name)
|
||||
)
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?= $this->translate('This notification was not sent out to any contact.'); ?>
|
||||
<?php endif ?>
|
||||
</small>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
|
|
|
@ -43,79 +43,68 @@ function contactsLink($match, $view) {
|
|||
<?php foreach ($history as $event): ?>
|
||||
<?php
|
||||
$stateClass = 'invalid';
|
||||
$msg = $this->escape($event->output);
|
||||
switch ($event->type) {
|
||||
case 'notify':
|
||||
$icon = 'notification';
|
||||
$title = $this->translate('Notification');
|
||||
$stateClass = Service::getStateText($event->state);
|
||||
|
||||
$msg = preg_replace_callback(
|
||||
$msg = $msg ? preg_replace_callback(
|
||||
'/^\[([^\]]+)\]/',
|
||||
function($match) use ($self) { return contactsLink($match, $self); },
|
||||
$this->escape($event->output)
|
||||
);
|
||||
$msg
|
||||
) : $this->translate('This notification was not sent out to any contact.');
|
||||
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 = Service::getStateText($event->state);
|
||||
$icon = 'attention-alt';
|
||||
$title = Service::getStateText($event->state);
|
||||
break;
|
||||
case 'soft_state':
|
||||
$icon = 'spinner';
|
||||
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
|
||||
$stateClass = Service::getStateText($event->state);
|
||||
$title = Service::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;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -61,13 +61,8 @@ $this->providePermission(
|
|||
);
|
||||
|
||||
$this->provideRestriction(
|
||||
'monitoring/hosts/filter',
|
||||
$this->translate('Restrict hosts view to the hosts that match the filter')
|
||||
);
|
||||
|
||||
$this->provideRestriction(
|
||||
'monitoring/services/filter',
|
||||
$this->translate('Restrict services view to the services that match the filter')
|
||||
'monitoring/filter/objects',
|
||||
$this->translate('Restrict views to the Icinga objects that match the filter')
|
||||
);
|
||||
|
||||
$this->provideConfigTab('backends', array(
|
||||
|
|
|
@ -3,78 +3,126 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query map for comments
|
||||
* Query for host and service comments
|
||||
*/
|
||||
class CommentQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'comments' => array(
|
||||
'comment_internal_id' => 'cm.internal_comment_id',
|
||||
'comment_data' => 'cm.comment_data',
|
||||
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
|
||||
'comment_author_name' => 'cm.author_name',
|
||||
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
|
||||
'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
|
||||
'comment_is_persistent' => 'cm.is_persistent',
|
||||
'comment_expiration' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END',
|
||||
'comment_objecttype' => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END",
|
||||
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
|
||||
'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
'comment_author' => 'c.comment_author',
|
||||
'comment_author_name' => 'c.comment_author_name',
|
||||
'comment_data' => 'c.comment_data',
|
||||
'comment_expiration' => 'c.comment_expiration',
|
||||
'comment_internal_id' => 'c.comment_internal_id',
|
||||
'comment_is_persistent' => 'c.comment_is_persistent',
|
||||
'comment_timestamp' => 'c.comment_timestamp',
|
||||
'comment_type' => 'c.comment_type',
|
||||
'object_type' => 'c.object_type'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'
|
||||
'host_display_name' => 'c.host_display_name',
|
||||
'host_name' => 'c.host_name',
|
||||
'host_state' => 'c.host_state'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name'
|
||||
'service_description' => 'c.service_description',
|
||||
'service_display_name' => 'c.service_display_name',
|
||||
'service_host_name' => 'c.service_host_name',
|
||||
'service_state' => 'c.service_state'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('cm' => $this->prefix . 'comments'),
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'cm.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'cm.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('comments' => true);
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $commentQuery;
|
||||
|
||||
protected function joinHosts()
|
||||
/**
|
||||
* Subqueries used for the comment query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->commentQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('c' => $this->commentQuery),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['comments'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts']);
|
||||
foreach (array_keys($this->columnMap['services']) as $column) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
$hosts = $this->createSubQuery('hostcomment', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->commentQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('sh' => $this->prefix . 'hosts'),
|
||||
'sh.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
$columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts'] + $this->columnMap['services']);
|
||||
$services = $this->createSubQuery('servicecomment', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->commentQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,49 +3,151 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service comment removal records
|
||||
*/
|
||||
class CommentdeletionhistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'commenthistory' => array(
|
||||
'state_time' => 'h.deletion_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(h.deletion_time)',
|
||||
'raw_timestamp' => 'h.deletion_time',
|
||||
'object_id' => 'h.object_id',
|
||||
'type' => "(CASE h.entry_type WHEN 1 THEN 'comment_deleted' WHEN 2 THEN 'dt_comment_deleted' WHEN 3 THEN 'flapping_deleted' WHEN 4 THEN 'ack_deleted' END)",
|
||||
'state' => '(NULL)',
|
||||
'state_type' => '(NULL)',
|
||||
'output' => "('[' || h.author_name || '] ' || h.comment_data)",
|
||||
'attempt' => '(NULL)',
|
||||
'max_attempts' => '(NULL)',
|
||||
|
||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'o.name1',
|
||||
'service_description' => 'o.name2',
|
||||
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
||||
'object_type' => 'cdh.object_type'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => 'cdh.type',
|
||||
'timestamp' => 'cdh.timestamp',
|
||||
'object_id' => 'cdh.object_id',
|
||||
'state' => 'cdh.state',
|
||||
'output' => 'cdh.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'cdh.host_display_name',
|
||||
'host_name' => 'cdh.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_description' => 'cdh.service_description',
|
||||
'service_display_name' => 'cdh.service_display_name',
|
||||
'service_host_name' => 'cdh.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(h.deletion_time)') {
|
||||
return 'h.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $commentDeletionHistoryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the comment history query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->commentDeletionHistoryQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'commenthistory'),
|
||||
'o.' . $this->object_id . ' = h.' . $this->object_id . " AND o.is_active = 1 AND h.deletion_time > '1970-01-02 00:00:00' AND h.entry_type <> 2",
|
||||
array('cdh' => $this->commentDeletionHistoryQuery),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('commenthistory' => true);
|
||||
$this->joinedVirtualTables['commenthistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['commenthistory'] + $this->columnMap['hosts']
|
||||
);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('Hostcommentdeletionhistory', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->commentDeletionHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['commenthistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
|
||||
);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$services = $this->createSubQuery('Servicecommentdeletionhistory', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->commentDeletionHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,49 +3,151 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service comment history records
|
||||
*/
|
||||
class CommenthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'commenthistory' => array(
|
||||
'state_time' => 'h.comment_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(h.comment_time)',
|
||||
'raw_timestamp' => 'h.comment_time',
|
||||
'object_id' => 'h.object_id',
|
||||
'type' => "(CASE h.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)",
|
||||
'state' => '(NULL)',
|
||||
'state_type' => '(NULL)',
|
||||
'output' => "('[' || h.author_name || '] ' || h.comment_data)",
|
||||
'attempt' => '(NULL)',
|
||||
'max_attempts' => '(NULL)',
|
||||
|
||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'o.name1',
|
||||
'service_description' => 'o.name2',
|
||||
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
||||
'object_type' => 'ch.object_type'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => 'ch.type',
|
||||
'timestamp' => 'ch.timestamp',
|
||||
'object_id' => 'ch.object_id',
|
||||
'state' => 'ch.state',
|
||||
'output' => 'ch.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'ch.host_display_name',
|
||||
'host_name' => 'ch.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_description' => 'ch.service_description',
|
||||
'service_display_name' => 'ch.service_display_name',
|
||||
'service_host_name' => 'ch.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(h.comment_time)') {
|
||||
return 'h.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $commentHistoryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the comment history query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->commentHistoryQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'commenthistory'),
|
||||
'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1 AND h.entry_type <> 2',
|
||||
array('ch' => $this->commentHistoryQuery),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('commenthistory' => true);
|
||||
$this->joinedVirtualTables['commenthistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['commenthistory'] + $this->columnMap['hosts']
|
||||
);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('Hostcommenthistory', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->commentHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['commenthistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
|
||||
);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$services = $this->createSubQuery('Servicecommenthistory', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->commentHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,19 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for contacts
|
||||
*/
|
||||
class ContactQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'contacts' => array(
|
||||
'contact_id' => 'c.contact_id',
|
||||
|
@ -33,18 +44,33 @@ class ContactQuery extends IdoQuery
|
|||
'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci',
|
||||
'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1'
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
|
@ -52,46 +78,15 @@ class ContactQuery extends IdoQuery
|
|||
array()
|
||||
)->join(
|
||||
array('co' => $this->prefix . 'objects'),
|
||||
'c.contact_object_id = co.' . $this->object_id . ' AND co.is_active = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('contacts' => true);
|
||||
}
|
||||
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hc' => $this->prefix . 'host_contacts'),
|
||||
'hc.contact_object_id = c.contact_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hc.host_id = h.host_id',
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('sc' => $this->prefix . 'service_contacts'),
|
||||
'sc.contact_object_id = c.contact_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
'sc.service_id = s.service_id',
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
's.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1',
|
||||
'co.object_id = c.contact_object_id AND co.is_active = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['contacts'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join timeperiods
|
||||
*/
|
||||
protected function joinTimeperiods()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
|
@ -105,4 +100,103 @@ class ContactQuery extends IdoQuery
|
|||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hc' => $this->prefix . 'host_contacts'),
|
||||
'hc.contact_object_id = c.contact_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_id = hc.host_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = h.host_object_id AND ho.is_active = 1',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.servicegroup_id = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sc' => $this->prefix . 'service_contacts'),
|
||||
'sc.contact_object_id = c.contact_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_id = sc.service_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hosts') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('c.contact_id', 'co.object_id');
|
||||
if ($this->hasJoinedVirtualTable('timeperiods')) {
|
||||
$group[] = 'ht.timeperiod_id';
|
||||
$group[] = 'st.timeperiod_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,19 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for contact groups
|
||||
*/
|
||||
class ContactgroupQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'contactgroups' => array(
|
||||
'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci',
|
||||
|
@ -12,11 +23,13 @@ class ContactgroupQuery extends IdoQuery
|
|||
'contactgroup_alias' => 'cg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'contacts' => array(
|
||||
'contact_id' => 'c.contact_id',
|
||||
'contact' => 'co.name1 COLLATE latin1_general_ci',
|
||||
'contact_name' => 'co.name1',
|
||||
'contact_alias' => 'c.alias COLLATE latin1_general_ci',
|
||||
'contact_email' => 'c.email_address COLLATE latin1_general_ci',
|
||||
'contact_pager' => 'c.pager_address',
|
||||
'contact_object_id' => 'c.contact_object_id',
|
||||
'contact_has_host_notfications' => 'c.host_notifications_enabled',
|
||||
'contact_has_service_notfications' => 'c.service_notifications_enabled',
|
||||
'contact_can_submit_commands' => 'c.can_submit_commands',
|
||||
|
@ -30,22 +43,35 @@ class ContactgroupQuery extends IdoQuery
|
|||
'contact_notify_host_down' => 'c.notify_host_down',
|
||||
'contact_notify_host_unreachable' => 'c.notify_host_unreachable',
|
||||
'contact_notify_host_flapping' => 'c.notify_host_flapping',
|
||||
'contact_notify_host_downtime' => 'c.notify_host_downtime',
|
||||
'contact_notify_host_downtime' => 'c.notify_host_downtime'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1'
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
protected $useSubqueryCount = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
|
@ -53,81 +79,135 @@ class ContactgroupQuery extends IdoQuery
|
|||
array()
|
||||
)->join(
|
||||
array('cgo' => $this->prefix . 'objects'),
|
||||
'cg.contactgroup_object_id = cgo.' . $this->object_id . ' AND cgo.is_active = 1',
|
||||
'cgo.object_id = cg.contactgroup_object_id AND cgo.is_active = 1 AND cgo.objecttype_id = 11',
|
||||
array()
|
||||
);
|
||||
|
||||
$this->joinedVirtualTables = array('contactgroups' => true);
|
||||
$this->joinedVirtualTables['contactgroups'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join contacts
|
||||
*/
|
||||
protected function joinContacts()
|
||||
{
|
||||
$this->select->distinct()->join(
|
||||
$this->select->joinLeft(
|
||||
array('cgm' => $this->prefix . 'contactgroup_members'),
|
||||
'cgm.contactgroup_id = cg.contactgroup_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('co' => $this->prefix . 'objects'),
|
||||
'cgm.contact_object_id = co.object_id AND co.is_active = 1',
|
||||
'co.object_id = cgm.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('c' => $this->prefix . 'contacts'),
|
||||
'c.contact_object_id = co.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->distinct()->join(
|
||||
$this->select->joinLeft(
|
||||
array('hcg' => $this->prefix . 'host_contactgroups'),
|
||||
'hcg.contactgroup_object_id = cg.contactgroup_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hcg.host_id = h.host_id',
|
||||
'h.host_id = hcg.host_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1',
|
||||
'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.servicegroup_id = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
// $scgSub = $this->db->select()->distinct()->from(
|
||||
// $this->prefix . 'service_contactgroups',
|
||||
// array('contactgroup_object_id', 'service_id')
|
||||
// );
|
||||
|
||||
/*
|
||||
This subselect is a workaround for a fucking stupid bug. Other tables
|
||||
may be affected too. We absolutely need uniqueness here.
|
||||
|
||||
mysql> SELECT * FROM icinga_service_contactgroups WHERE
|
||||
contactgroup_object_id = 143 AND service_id = 2079564;
|
||||
+-------------------------+-------------+------------+------------------------+
|
||||
| service_contactgroup_id | instance_id | service_id | contactgroup_object_id |
|
||||
+-------------------------+-------------+------------+------------------------+
|
||||
| 4904240 | 1 | 2079564 | 143 |
|
||||
| 4904244 | 1 | 2079564 | 143 |
|
||||
+-------------------------+-------------+------------+------------------------+
|
||||
*/
|
||||
|
||||
$this->select->distinct()->join(
|
||||
$this->select->joinLeft(
|
||||
array('scg' => $this->prefix . 'service_contactgroups'),
|
||||
// array('scg' => $scgSub),
|
||||
'scg.contactgroup_object_id = cg.contactgroup_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
'scg.service_id = s.service_id',
|
||||
's.service_id = scg.service_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
's.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1',
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hosts') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('cg.contactgroup_id', 'cgo.object_id');
|
||||
if ($this->hasJoinedVirtualTable('contacts')) {
|
||||
$group[] = 'c.contact_id';
|
||||
$group[] = 'co.object_id';
|
||||
}
|
||||
} elseif ($this->hasJoinedVirtualTable('contacts')) {
|
||||
$group = array(
|
||||
'cg.contactgroup_id',
|
||||
'cgo.object_id',
|
||||
'c.contact_id',
|
||||
'co.object_id'
|
||||
);
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service downtimes
|
||||
*/
|
||||
|
@ -12,127 +16,118 @@ class DowntimeQuery extends IdoQuery
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtime' => array(
|
||||
'downtime_author_name' => 'sd.author_name',
|
||||
'author' => 'sd.author_name COLLATE latin1_general_ci',
|
||||
'downtime_comment' => 'sd.comment_data',
|
||||
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
|
||||
'downtime_is_fixed' => 'sd.is_fixed',
|
||||
'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END',
|
||||
'downtime_triggered_by_id' => 'sd.triggered_by_id',
|
||||
'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)',
|
||||
'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)',
|
||||
'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)",
|
||||
'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END',
|
||||
'downtime_duration' => 'sd.duration',
|
||||
'downtime_is_in_effect' => 'sd.is_in_effect',
|
||||
'downtime_internal_id' => 'sd.internal_downtime_id',
|
||||
'downtime_objecttype' => "CASE WHEN ho.object_id IS NULL THEN 'service' ELSE 'host' END",
|
||||
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
|
||||
'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
'downtimes' => array(
|
||||
'downtime_author' => 'd.downtime_author',
|
||||
'downtime_author_name' => 'd.downtime_author_name',
|
||||
'downtime_comment' => 'd.downtime_comment',
|
||||
'downtime_duration' => 'd.downtime_duration',
|
||||
'downtime_end' => 'd.downtime_end',
|
||||
'downtime_entry_time' => 'd.downtime_entry_time',
|
||||
'downtime_internal_id' => 'd.downtime_internal_id',
|
||||
'downtime_is_fixed' => 'd.downtime_is_fixed',
|
||||
'downtime_is_flexible' => 'd.downtime_is_flexible',
|
||||
'downtime_is_in_effect' => 'd.downtime_is_in_effect',
|
||||
'downtime_scheduled_end' => 'd.downtime_scheduled_end',
|
||||
'downtime_scheduled_start' => 'd.downtime_scheduled_start',
|
||||
'downtime_start' => 'd.downtime_start',
|
||||
'object_type' => 'd.object_type'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'CASE WHEN h.display_name IS NULL THEN sh.display_name ELSE h.display_name END'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'downtime_host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
|
||||
'host_display_name' => 'd.host_display_name',
|
||||
'host_name' => 'd.host_name',
|
||||
'host_state' => 'd.host_state'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name'
|
||||
),
|
||||
'servicestatus' => array(
|
||||
'downtime_service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
|
||||
'service_description' => 'd.service_description',
|
||||
'service_display_name' => 'd.service_display_name',
|
||||
'service_host_name' => 'd.service_host_name',
|
||||
'service_state' => 'd.service_state'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $downtimeQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the downtime query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->downtimeQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('sd' => $this->prefix . 'scheduleddowntime'),
|
||||
array('d' => $this->downtimeQuery),
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'sd.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('downtime' => true);
|
||||
$this->joinedVirtualTables['downtimes'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join downtimes' hosts
|
||||
*
|
||||
* @return $this
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
$columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts']);
|
||||
foreach (array_keys($this->columnMap['services']) as $column) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
$hosts = $this->createSubQuery('hostdowntime', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->downtimeQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join downtimes' hosts' status
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'ho.object_id = hs.host_object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join downtimes' services
|
||||
*
|
||||
* @return $this
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('sh' => $this->prefix . 'hosts'),
|
||||
'sh.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
$columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts'] + $this->columnMap['services']);
|
||||
$services = $this->createSubQuery('servicedowntime', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->downtimeQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join downtimes' services' status
|
||||
*
|
||||
* @return $this
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinServicestatus()
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'so.object_id = ss.service_object_id',
|
||||
array()
|
||||
);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,49 +3,151 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service downtime end history records
|
||||
*/
|
||||
class DowntimeendhistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'state_time' => 'h.actual_end_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(h.actual_end_time)',
|
||||
'raw_timestamp' => 'h.actual_end_time',
|
||||
'object_id' => 'h.object_id',
|
||||
'type' => "('dt_end')",
|
||||
'state' => '(NULL)',
|
||||
'state_type' => '(NULL)',
|
||||
'output' => "('[' || h.author_name || '] ' || h.comment_data)",
|
||||
'attempt' => '(NULL)',
|
||||
'max_attempts' => '(NULL)',
|
||||
|
||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'o.name1',
|
||||
'service_description' => 'o.name2',
|
||||
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
||||
'object_type' => 'deh.object_type'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => 'deh.type',
|
||||
'timestamp' => 'deh.timestamp',
|
||||
'object_id' => 'deh.object_id',
|
||||
'state' => 'deh.state',
|
||||
'output' => 'deh.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'deh.host_display_name',
|
||||
'host_name' => 'deh.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_description' => 'deh.service_description',
|
||||
'service_display_name' => 'deh.service_display_name',
|
||||
'service_host_name' => 'deh.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(h.actual_end_time)') {
|
||||
return 'h.actual_end_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $downtimeEndHistoryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the downtime end history query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->downtimeEndHistoryQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
array('deh' => $this->downtimeEndHistoryQuery),
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'downtimehistory'),
|
||||
'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1',
|
||||
array()
|
||||
)->where('h.actual_end_time > ?', '1970-01-02 00:00:00');
|
||||
$this->joinedVirtualTables = array('downtimehistory' => true);
|
||||
);
|
||||
$this->joinedVirtualTables['downtimehistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['downtimehistory'] + $this->columnMap['hosts']
|
||||
);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('Hostdowntimeendhistory', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->downtimeEndHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
|
||||
);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$services = $this->createSubQuery('Servicedowntimeendhistory', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->downtimeEndHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,49 +3,151 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service downtime start history records
|
||||
*/
|
||||
class DowntimestarthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'state_time' => 'h.actual_start_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(h.actual_start_time)',
|
||||
'raw_timestamp' => 'h.actual_start_time',
|
||||
'object_id' => 'h.object_id',
|
||||
'type' => "('dt_start')",
|
||||
'state' => '(NULL)',
|
||||
'state_type' => '(NULL)',
|
||||
'output' => "('[' || h.author_name || '] ' || h.comment_data)",
|
||||
'attempt' => '(NULL)',
|
||||
'max_attempts' => '(NULL)',
|
||||
|
||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'o.name1',
|
||||
'service_description' => 'o.name2',
|
||||
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
||||
'object_type' => 'dsh.object_type'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => 'dsh.type',
|
||||
'timestamp' => 'dsh.timestamp',
|
||||
'object_id' => 'dsh.object_id',
|
||||
'state' => 'dsh.state',
|
||||
'output' => 'dsh.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'dsh.host_display_name',
|
||||
'host_name' => 'dsh.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_description' => 'dsh.service_description',
|
||||
'service_display_name' => 'dsh.service_display_name',
|
||||
'service_host_name' => 'dsh.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(h.actual_start_time)') {
|
||||
return 'h.actual_start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $downtimeStartHistoryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the downtime start history query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->downtimeStartHistoryQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
array('dsh' => $this->downtimeStartHistoryQuery),
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'downtimehistory'),
|
||||
'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1',
|
||||
array()
|
||||
)->where('h.actual_start_time > ?', '1970-01-02 00:00:00');
|
||||
$this->joinedVirtualTables = array('downtimehistory' => true);
|
||||
);
|
||||
$this->joinedVirtualTables['downtimehistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['downtimehistory'] + $this->columnMap['hosts']
|
||||
);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('Hostdowntimestarthistory', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->downtimeStartHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
|
||||
);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$services = $this->createSubQuery('Servicedowntimestarthistory', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->downtimeStartHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,190 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for event history
|
||||
*/
|
||||
class EventHistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* Subqueries used for the event history query
|
||||
*
|
||||
* @type IdoQuery[]
|
||||
*
|
||||
* @see EventHistoryQuery::joinBaseTables() For the used subqueries.
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'eventhistory' => array(
|
||||
'cnt_notification' => "SUM(CASE eh.type WHEN 'notify' THEN 1 ELSE 0 END)",
|
||||
'cnt_hard_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_soft_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_downtime_start' => "SUM(CASE eh.type WHEN 'dt_start' THEN 1 ELSE 0 END)",
|
||||
'cnt_downtime_end' => "SUM(CASE eh.type WHEN 'dt_end' THEN 1 ELSE 0 END)",
|
||||
'host' => 'eho.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'eho.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'eho.name1',
|
||||
'service_description' => 'eho.name2',
|
||||
'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
|
||||
'type' => 'eh.type'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $useSubqueryCount = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$columns = array(
|
||||
'timestamp',
|
||||
'object_id',
|
||||
'type',
|
||||
'output',
|
||||
'state',
|
||||
'state_type',
|
||||
'object_type',
|
||||
'attempt',
|
||||
'max_attempts',
|
||||
);
|
||||
$this->subQueries = array(
|
||||
$this->createSubQuery('Statehistory', $columns),
|
||||
$this->createSubQuery('Downtimestarthistory', $columns),
|
||||
$this->createSubQuery('Downtimeendhistory', $columns),
|
||||
$this->createSubQuery('Commenthistory', $columns),
|
||||
$this->createSubQuery('Commentdeletionhistory', $columns),
|
||||
$this->createSubQuery('Notificationhistory', $columns)
|
||||
);
|
||||
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);
|
||||
|
||||
$this->select->from(
|
||||
array('eho' => $this->prefix . 'objects'),
|
||||
'*'
|
||||
)->join(
|
||||
array('eh' => $sub),
|
||||
'eho.' . $this->object_id . ' = eh.' . $this->object_id . ' AND eho.is_active = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('eventhistory' => true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = eho.object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
|
||||
array()
|
||||
)->join(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.' . $this->object_id. ' = hg.hostgroup_object_id' . ' AND hgo.is_active = 1',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = eho.object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = eho.object_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('sh' => $this->prefix . 'hosts'),
|
||||
'sh.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -3,89 +3,55 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
class EventgridQuery extends IdoQuery
|
||||
class EventgridQuery extends StatehistoryQuery
|
||||
{
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'day' => 'DATE(sh.state_time)',
|
||||
'cnt_events' => 'COUNT(*)',
|
||||
'objecttype_id' => 'sho.objecttype_id',
|
||||
'cnt_up' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 0 THEN 1 ELSE 0 END)',
|
||||
'cnt_down_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_down' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unreachable_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unreachable' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_critical' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 THEN 1 ELSE 0 END)',
|
||||
'cnt_critical_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_warning' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_warning_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_ok' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 0 THEN 1 ELSE 0 END)',
|
||||
'host' => 'sho.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'sho.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'sho.name1',
|
||||
'service_description' => 'sho.name2',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)'
|
||||
),
|
||||
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1'
|
||||
),
|
||||
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
)
|
||||
/**
|
||||
* The columns additionally provided by this query
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $additionalColumns = array(
|
||||
'day' => 'DATE(FROM_UNIXTIME(sth.timestamp))',
|
||||
'cnt_up' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 0 THEN 1 ELSE 0 END)",
|
||||
'cnt_down_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_down' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 THEN 1 ELSE 0 END)",
|
||||
'cnt_unreachable_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_unreachable' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 2 THEN 1 ELSE 0 END)",
|
||||
'cnt_unknown_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_unknown' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 THEN 1 ELSE 0 END)",
|
||||
'cnt_unknown_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_critical' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 THEN 1 ELSE 0 END)",
|
||||
'cnt_critical_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_warning' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 THEN 1 ELSE 0 END)",
|
||||
'cnt_warning_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_ok' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 0 THEN 1 ELSE 0 END)"
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sh' => $this->prefix . 'statehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('sho' => $this->prefix . 'objects'),
|
||||
'sh.object_id = sho.object_id AND sho.is_active = 1',
|
||||
array()
|
||||
)
|
||||
->group('DATE(sh.state_time)');
|
||||
$this->joinedVirtualTables = array('statehistory' => true);
|
||||
parent::joinBaseTables();
|
||||
$this->requireVirtualTable('history');
|
||||
$this->columnMap['statehistory'] += $this->additionalColumns;
|
||||
$this->select->group(array('DATE(FROM_UNIXTIME(sth.timestamp))'));
|
||||
}
|
||||
|
||||
protected function joinHostgroups()
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
$this->select->join(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = sho.object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('hgs' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hgs.hostgroup_id',
|
||||
array()
|
||||
)->join(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hgs.hostgroup_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
if (array_key_exists($columnOrAlias, $this->additionalColumns)) {
|
||||
$subQueries = $this->subQueries;
|
||||
$this->subQueries = array();
|
||||
parent::order($columnOrAlias, $dir);
|
||||
$this->subQueries = $subQueries;
|
||||
} else {
|
||||
parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->join(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = sho.object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('sgs' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sgs.servicegroup_id',
|
||||
array()
|
||||
)->join(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sgs.servicegroup_object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for event history records
|
||||
*/
|
||||
class EventHistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $useSubqueryCount = true;
|
||||
|
||||
/**
|
||||
* Subqueries used for the event history query
|
||||
*
|
||||
* @type IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'eventhistory' => array(
|
||||
'cnt_notification' => "SUM(CASE eh.type WHEN 'notify' THEN 1 ELSE 0 END)",
|
||||
'cnt_hard_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_soft_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)",
|
||||
'cnt_downtime_start' => "SUM(CASE eh.type WHEN 'dt_start' THEN 1 ELSE 0 END)",
|
||||
'cnt_downtime_end' => "SUM(CASE eh.type WHEN 'dt_end' THEN 1 ELSE 0 END)",
|
||||
'host_name' => 'eh.host_name',
|
||||
'service_description' => 'eh.service_description',
|
||||
'object_type' => 'eh.object_type',
|
||||
'timestamp' => 'eh.timestamp',
|
||||
'state' => 'eh.state',
|
||||
'output' => 'eh.output',
|
||||
'type' => 'eh.type',
|
||||
'host_display_name' => 'eh.host_display_name',
|
||||
'service_display_name' => 'eh.service_display_name'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$columns = array(
|
||||
'timestamp',
|
||||
'output',
|
||||
'type',
|
||||
'state',
|
||||
'object_type',
|
||||
'object_id',
|
||||
'host_name',
|
||||
'service_description',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
);
|
||||
$this->subQueries = array(
|
||||
$this->createSubQuery('Statehistory', $columns),
|
||||
$this->createSubQuery('Downtimestarthistory', $columns),
|
||||
$this->createSubQuery('Downtimeendhistory', $columns),
|
||||
$this->createSubQuery('Commenthistory', $columns),
|
||||
$this->createSubQuery('Commentdeletionhistory', $columns),
|
||||
$this->createSubQuery('Notification', $columns)
|
||||
);
|
||||
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->select->from(array('eh' => $sub), array());
|
||||
$this->joinedVirtualTables['eventhistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host comments
|
||||
*/
|
||||
class HostcommentQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'comments' => array(
|
||||
'comment_author' => 'c.author_name COLLATE latin1_general_ci',
|
||||
'comment_author_name' => 'c.author_name',
|
||||
'comment_data' => 'c.comment_data',
|
||||
'comment_expiration' => 'CASE c.expires WHEN 1 THEN UNIX_TIMESTAMP(c.expiration_time) ELSE NULL END',
|
||||
'comment_internal_id' => 'c.internal_comment_id',
|
||||
'comment_is_persistent' => 'c.is_persistent',
|
||||
'comment_timestamp' => 'UNIX_TIMESTAMP(c.comment_time)',
|
||||
'comment_type' => "CASE c.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('c' => $this->prefix . 'comments'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = c.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['comments'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('c.comment_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host comment removal records
|
||||
*/
|
||||
class HostcommentdeletionhistoryQuery extends HostcommenthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hch.deletion_time)') {
|
||||
return 'hch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
parent::joinBaseTables();
|
||||
$this->select->where("hch.deletion_time > '1970-01-02 00:00:00'");
|
||||
$this->columnMap['history']['timestamp'] = str_replace(
|
||||
'comment_time',
|
||||
'deletion_time',
|
||||
$this->columnMap['history']['timestamp']
|
||||
);
|
||||
$this->columnMap['history']['type'] = str_replace(
|
||||
'END)',
|
||||
"END || '_deleted')",
|
||||
$this->columnMap['history']['type']
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host comment history records
|
||||
*/
|
||||
class HostcommenthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'commenthistory' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)',
|
||||
'object_id' => 'hch.object_id',
|
||||
'state' => '(-1)',
|
||||
'output' => "('[' || hch.author_name || '] ' || hch.comment_data)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hch.comment_time)') {
|
||||
return 'hch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('hch' => $this->prefix . 'commenthistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = hch.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['commenthistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('hch.commenthistory_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host downtimes
|
||||
*/
|
||||
class HostdowntimeQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimes' => array(
|
||||
'downtime_author' => 'sd.author_name COLLATE latin1_general_ci',
|
||||
'downtime_author_name' => 'sd.author_name',
|
||||
'downtime_comment' => 'sd.comment_data',
|
||||
'downtime_duration' => 'sd.duration',
|
||||
'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END',
|
||||
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
|
||||
'downtime_internal_id' => 'sd.internal_downtime_id',
|
||||
'downtime_is_fixed' => 'sd.is_fixed',
|
||||
'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END',
|
||||
'downtime_is_in_effect' => 'sd.is_in_effect',
|
||||
'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)',
|
||||
'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)',
|
||||
'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)',
|
||||
'downtime_triggered_by_id' => 'sd.triggered_by_id',
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sd' => $this->prefix . 'scheduleddowntime'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'sd.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['downtimes'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('sd.scheduleddowntime_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host downtime end history records
|
||||
*/
|
||||
class HostdowntimeendhistoryQuery extends HostdowntimestarthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_end_time)') {
|
||||
return 'hdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
parent::joinBaseTables(true);
|
||||
$this->select->where("hdh.actual_end_time > '1970-01-02 00:00:00'");
|
||||
$this->columnMap['history']['type'] = "('dt_end')";
|
||||
$this->columnMap['history']['timestamp'] = str_replace(
|
||||
'actual_start_time',
|
||||
'actual_end_time',
|
||||
$this->columnMap['history']['timestamp']
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host downtime start history records
|
||||
*/
|
||||
class HostdowntimestarthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "('dt_start')",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)',
|
||||
'object_id' => 'hdh.object_id',
|
||||
'state' => '(-1)',
|
||||
'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_start_time)') {
|
||||
return 'hdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('hdh' => $this->prefix . 'downtimehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = hdh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
|
||||
if (@func_get_arg(0) === false) {
|
||||
$this->select->where(
|
||||
"hdh.actual_start_time > '1970-01-02 00:00:00'"
|
||||
);
|
||||
}
|
||||
|
||||
$this->joinedVirtualTables['downtimehistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('hdh.downtimehistory_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -3,21 +3,49 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host groups
|
||||
*/
|
||||
class HostgroupQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hostgroups' => array(
|
||||
'hostgroups' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1',
|
||||
'hostgroup_alias' => 'hg.alias',
|
||||
'hostgroup_id' => 'hg.hostgroup_id'
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hostobjects' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1'
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
|
@ -25,22 +53,89 @@ class HostgroupQuery extends IdoQuery
|
|||
array()
|
||||
)->join(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hg.hostgroup_object_id = hgo.' . $this->object_id . ' AND hgo.is_active = 1',
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('hostgroups' => true);
|
||||
$this->joinedVirtualTables['hostgroups'] = true;
|
||||
}
|
||||
|
||||
protected function joinHosts()
|
||||
/**
|
||||
* Join host objects
|
||||
*/
|
||||
protected function joinHostobjects()
|
||||
{
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.hostgroup_id = hg.hostgroup_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'hgm.host_object_id = ho.object_id AND ho.is_active = 1',
|
||||
'hgm.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('hostobjects');
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostobjects')) {
|
||||
$group = array('hg.hostgroup_id', 'hgo.object_id');
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
|
||||
/**
|
||||
* Query for host group summary
|
||||
*/
|
||||
class HostgroupsummaryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hoststatussummary' => array(
|
||||
'hostgroup' => 'hostgroup COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hostgroup_alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hostgroup_name',
|
||||
'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'hosts_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 99 THEN state_change ELSE 0 END)',
|
||||
'hosts_severity' => 'MAX(CASE WHEN object_type = \'host\' THEN severity ELSE 0 END)',
|
||||
'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)',
|
||||
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
|
||||
'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $summaryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the summary query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
// TODO(el): Allow to switch between hard and soft states
|
||||
$hosts = $this->createSubQuery(
|
||||
'Hoststatus',
|
||||
array(
|
||||
'handled' => 'host_handled',
|
||||
'host_state' => new Zend_Db_Expr('NULL'),
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'object_type',
|
||||
'severity' => 'host_severity',
|
||||
'state' => 'host_state',
|
||||
'state_change' => 'host_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $hosts;
|
||||
$services = $this->createSubQuery(
|
||||
'Servicestatus',
|
||||
array(
|
||||
'handled' => 'service_handled',
|
||||
'host_state' => 'host_hard_state',
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'object_type',
|
||||
'severity' => new Zend_Db_Expr('NULL'),
|
||||
'state' => 'service_state',
|
||||
'state_change' => 'service_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $services;
|
||||
$this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->select->from(array('statussummary' => $this->summaryQuery), array());
|
||||
$this->group(array('hostgroup_name', 'hostgroup_alias'));
|
||||
$this->joinedVirtualTables['hoststatussummary'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
if (! $this->hasAliasName($columnOrAlias)) {
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host notifications
|
||||
*/
|
||||
class HostnotificationQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'notifications' => array(
|
||||
'notification_output' => 'hn.output',
|
||||
'notification_start_time' => 'UNIX_TIMESTAMP(hn.start_time)',
|
||||
'notification_state' => 'hn.state',
|
||||
'notification_object_id' => 'hn.object_id',
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "('notify')",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
||||
'object_id' => 'hn.object_id',
|
||||
'state' => 'hn.state',
|
||||
'output' => null
|
||||
),
|
||||
'contactnotifications' => array(
|
||||
'contact' => 'cno.name1 COLLATE latin1_general_ci',
|
||||
'notification_contact_name' => 'cno.name1',
|
||||
'contact_object_id' => 'cno.object_id'
|
||||
),
|
||||
'acknowledgements' => array(
|
||||
'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)',
|
||||
'acknowledgement_author_name' => 'a.author_name',
|
||||
'acknowledgement_comment_data' => 'a.comment_data'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hn.start_time)') {
|
||||
return 'hn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
switch ($this->ds->getDbType()) {
|
||||
case 'mysql':
|
||||
$concattedContacts = "GROUP_CONCAT("
|
||||
. "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '"
|
||||
. ") COLLATE latin1_general_ci";
|
||||
break;
|
||||
case 'pgsql':
|
||||
// TODO: Find a way to order the contact alias list:
|
||||
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')";
|
||||
break;
|
||||
case 'oracle':
|
||||
// TODO: This is only valid for Oracle >= 11g Release 2
|
||||
$concattedContacts = "LISTAGG(cno.name1, ', ') WITHIN GROUP (ORDER BY cno.name1)";
|
||||
// Alternatives:
|
||||
//
|
||||
// RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')),
|
||||
//
|
||||
// not supported and not documented but works since 10.1,
|
||||
// however it is NOT always present:
|
||||
// WM_CONCAT(c.alias)
|
||||
break;
|
||||
}
|
||||
|
||||
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || hn.output)";
|
||||
|
||||
$this->select->from(
|
||||
array('hn' => $this->prefix . 'notifications'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = hn.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['notifications'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join virtual table history
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
$this->requireVirtualTable('contactnotifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join contact notifications
|
||||
*/
|
||||
protected function joinContactnotifications()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('cn' => $this->prefix . 'contactnotifications'),
|
||||
'cn.notification_id = hn.notification_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('cno' => $this->prefix . 'objects'),
|
||||
'cno.object_id = cn.contact_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join acknowledgements
|
||||
*/
|
||||
protected function joinAcknowledgements()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('a' => $this->prefix . 'acknowledgements'),
|
||||
'a.object_id = hn.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
if (
|
||||
$this->hasJoinedVirtualTable('history')
|
||||
|| $this->hasJoinedVirtualTable('services')
|
||||
|| $this->hasJoinedVirtualTable('hostgroups')
|
||||
) {
|
||||
$group = array('hn.notification_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
||||
$group[] = 'cno.object_id';
|
||||
}
|
||||
} elseif ($this->hasJoinedVirtualTable('contactnotifications')) {
|
||||
$group = array('hn.notification_id', 'cno.object_id', 'ho.object_id');
|
||||
}
|
||||
|
||||
if (! empty($group)) {
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('acknowledgements')) {
|
||||
$group[] = 'a.acknowledgement_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host state history records
|
||||
*/
|
||||
class HoststatehistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* Array to map type names to type ids for query optimization
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $types = array(
|
||||
'soft_state' => 0,
|
||||
'hard_state' => 1
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hh.state_time)',
|
||||
'object_id' => 'hh.object_id',
|
||||
'state' => 'hh.state',
|
||||
'output' => "('[ ' || hh.current_check_attempt || '/' || hh.max_check_attempts || ' ] ' || hh.output)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hh.state_time)') {
|
||||
return 'hh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif (
|
||||
$col === $this->columnMap['history']['type']
|
||||
&& ! is_array($expression)
|
||||
&& array_key_exists($expression, $this->types)
|
||||
) {
|
||||
return 'hh.state_type ' . $sign . ' ' . $this->types[$expression];
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('hh' => $this->prefix . 'statehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = hh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['statehistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('hh.statehistory_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -3,49 +3,93 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
|
||||
class HoststatusQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_address' => 'h.address',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'object_type' => '(\'host\')'
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_action_url' => 'h.action_url',
|
||||
'host_address' => 'h.address',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'host_icon_image_alt' => 'h.icon_image_alt',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_name' => 'ho.name1',
|
||||
'host_notes' => 'h.notes',
|
||||
'host_notes_url' => 'h.notes_url',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
|
||||
'handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
|
||||
'unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END',
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'host_output' => 'hs.output',
|
||||
'host_long_output' => 'hs.long_output',
|
||||
'host_perfdata' => 'hs.perfdata',
|
||||
'host_problem' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
|
||||
'host_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
|
||||
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
|
||||
'host_does_active_checks' => 'hs.active_checks_enabled',
|
||||
'host_accepts_passive_checks' => 'hs.passive_checks_enabled',
|
||||
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
|
||||
'host_last_hard_state' => 'hs.last_hard_state',
|
||||
'host_check_command' => 'hs.check_command',
|
||||
'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)',
|
||||
'host_next_check' => 'CASE WHEN hs.should_be_scheduled THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END',
|
||||
'host_check_execution_time' => 'hs.execution_time',
|
||||
'host_check_latency' => 'hs.latency',
|
||||
'host_notifications_enabled' => 'hs.notifications_enabled',
|
||||
'host_last_time_up' => 'hs.last_time_up',
|
||||
'host_last_time_down' => 'hs.last_time_down',
|
||||
'host_last_time_unreachable' => 'hs.last_time_unreachable',
|
||||
'host_current_check_attempt' => 'hs.current_check_attempt',
|
||||
'host_max_check_attempts' => 'hs.max_check_attempts',
|
||||
'host_severity' => 'CASE WHEN hs.current_state = 0
|
||||
'host_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'host_acknowledgement_type' => 'hs.acknowledgement_type',
|
||||
'host_active_checks_enabled' => 'hs.active_checks_enabled',
|
||||
'host_active_checks_enabled_changed' => 'CASE WHEN hs.active_checks_enabled = h.active_checks_enabled THEN 0 ELSE 1 END',
|
||||
'host_attempt' => 'hs.current_check_attempt || \'/\' || hs.max_check_attempts',
|
||||
'host_check_command' => 'hs.check_command',
|
||||
'host_check_execution_time' => 'hs.execution_time',
|
||||
'host_check_latency' => 'hs.latency',
|
||||
'host_check_source' => 'hs.check_source',
|
||||
'host_check_type' => 'hs.check_type',
|
||||
'host_current_check_attempt' => 'hs.current_check_attempt',
|
||||
'host_current_notification_number' => 'hs.current_notification_number',
|
||||
'host_event_handler' => 'hs.event_handler',
|
||||
'host_event_handler_enabled' => 'hs.event_handler_enabled',
|
||||
'host_event_handler_enabled_changed' => 'CASE WHEN hs.event_handler_enabled = h.event_handler_enabled THEN 0 ELSE 1 END',
|
||||
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
|
||||
'host_flap_detection_enabled' => 'hs.flap_detection_enabled',
|
||||
'host_flap_detection_enabled_changed' => 'CASE WHEN hs.flap_detection_enabled = h.flap_detection_enabled THEN 0 ELSE 1 END',
|
||||
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
|
||||
'host_hard_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END',
|
||||
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
|
||||
'host_is_flapping' => 'hs.is_flapping',
|
||||
'host_is_passive_checked' => 'CASE WHEN hs.active_checks_enabled = 0 AND hs.passive_checks_enabled = 1 THEN 1 ELSE 0 END',
|
||||
'host_is_reachable' => 'hs.is_reachable',
|
||||
'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)',
|
||||
'host_last_hard_state' => 'hs.last_hard_state',
|
||||
'host_last_hard_state_change' => 'UNIX_TIMESTAMP(hs.last_hard_state_change)',
|
||||
'host_last_notification' => 'UNIX_TIMESTAMP(hs.last_notification)',
|
||||
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
|
||||
'host_last_time_down' => 'UNIX_TIMESTAMP(hs.last_time_down)',
|
||||
'host_last_time_unreachable' => 'UNIX_TIMESTAMP(hs.last_time_unreachable)',
|
||||
'host_last_time_up' => 'UNIX_TIMESTAMP(hs.last_time_up)',
|
||||
'host_long_output' => 'hs.long_output',
|
||||
'host_max_check_attempts' => 'hs.max_check_attempts',
|
||||
'host_modified_host_attributes' => 'hs.modified_host_attributes',
|
||||
'host_next_check' => 'CASE hs.should_be_scheduled WHEN 1 THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END',
|
||||
'host_next_notification' => 'UNIX_TIMESTAMP(hs.next_notification)',
|
||||
'host_no_more_notifications' => 'hs.no_more_notifications',
|
||||
'host_normal_check_interval' => 'hs.normal_check_interval',
|
||||
'host_notifications_enabled' => 'hs.notifications_enabled',
|
||||
'host_notifications_enabled_changed' => 'CASE WHEN hs.notifications_enabled = h.notifications_enabled THEN 0 ELSE 1 END',
|
||||
'host_obsessing' => 'hs.obsess_over_host',
|
||||
'host_obsessing_changed' => 'CASE WHEN hs.obsess_over_host = h.obsess_over_host THEN 0 ELSE 1 END',
|
||||
'host_output' => 'hs.output',
|
||||
'host_passive_checks_enabled' => 'hs.passive_checks_enabled',
|
||||
'host_passive_checks_enabled_changed' => 'CASE WHEN hs.passive_checks_enabled = h.passive_checks_enabled THEN 0 ELSE 1 END',
|
||||
'host_percent_state_change' => 'hs.percent_state_change',
|
||||
'host_perfdata' => 'hs.perfdata',
|
||||
'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END',
|
||||
'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'host_process_performance_data' => 'hs.process_performance_data',
|
||||
'host_retry_check_interval' => 'hs.retry_check_interval',
|
||||
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
|
||||
'host_severity' => 'CASE WHEN hs.current_state = 0
|
||||
THEN
|
||||
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
|
||||
THEN 16
|
||||
|
@ -80,247 +124,328 @@ class HoststatusQuery extends IdoQuery
|
|||
CASE WHEN hs.state_type = 1
|
||||
THEN 8
|
||||
ELSE 0
|
||||
END'
|
||||
END',
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'host_state_type' => 'hs.state_type',
|
||||
'host_status_update_time' => 'hs.status_update_time',
|
||||
'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci'
|
||||
'lasthostackcomment' => array(
|
||||
'host_last_ack' => 'hlac.last_ack_data'
|
||||
),
|
||||
'lasthostcomment' => array(
|
||||
'host_last_comment' => 'hlc.last_comment_data'
|
||||
),
|
||||
'lasthostdowntimecomment' => array(
|
||||
'host_last_downtime' => 'hldc.last_downtime_data'
|
||||
),
|
||||
'lasthostflappingcomment' => array(
|
||||
'host_last_flapping' => 'hlfc.last_flapping_data'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias'
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'contactgroups' => array(
|
||||
'contactgroup' => 'contactgroup',
|
||||
),
|
||||
'contacts' => array(
|
||||
'contact' => 'hco.name1 COLLATE latin1_general_ci',
|
||||
'serviceproblemsummary' => array(
|
||||
'host_unhandled_services' => 'sps.unhandled_services_count'
|
||||
),
|
||||
'services' => array(
|
||||
'services_cnt' => 'SUM(1)',
|
||||
'services_ok' => 'SUM(CASE WHEN ss.current_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN ss.current_state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_critical' => 'SUM(CASE WHEN ss.current_state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_unknown' => 'SUM(CASE WHEN ss.current_state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 1 ELSE 0 END)',
|
||||
'services_problem' => 'SUM(CASE WHEN ss.current_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_problem_handled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)',
|
||||
'services_problem_unhandled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)',
|
||||
),
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
)
|
||||
);
|
||||
|
||||
protected $aggregateColumnIdx = array(
|
||||
'services_cnt' => true,
|
||||
'services_problem' => true,
|
||||
'services_problem_handled' => true,
|
||||
'services_problem_unhandled' => true,
|
||||
);
|
||||
|
||||
protected $hcgSub;
|
||||
|
||||
public function getDefaultColumns()
|
||||
/**
|
||||
* Create a sub query to join comments into status query
|
||||
*
|
||||
* @param int $entryType
|
||||
* @param string $alias
|
||||
*
|
||||
* @return Zend_Db_Expr
|
||||
*/
|
||||
protected function createLastCommentSubQuery($entryType, $alias)
|
||||
{
|
||||
return $this->columnMap['hosts'] + $this->columnMap['hoststatus'];
|
||||
$sql = <<<SQL
|
||||
SELECT
|
||||
c.object_id,
|
||||
'[' || c.author_name || '] ' || c.comment_data AS $alias
|
||||
FROM
|
||||
icinga_comments c
|
||||
INNER JOIN
|
||||
(
|
||||
SELECT
|
||||
MAX(comment_id) AS comment_id,
|
||||
object_id
|
||||
FROM
|
||||
icinga_comments
|
||||
WHERE
|
||||
entry_type = $entryType
|
||||
GROUP BY object_id
|
||||
) ec ON ec.comment_id = c.comment_id
|
||||
SQL;
|
||||
return new Zend_Db_Expr('(' . $sql . ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
// TODO: Shall we always add hostobject?
|
||||
$this->select->from(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'ho.' . $this->object_id . ' = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hs.host_object_id = h.host_object_id',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array(
|
||||
'hosts' => true,
|
||||
'hoststatus' => true,
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinStatus()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
protected function joinServiceStatus()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'so.' . $this->object_id . ' = ss.service_object_id',
|
||||
array()
|
||||
);
|
||||
foreach ($this->getColumns() as $col) {
|
||||
$real = $this->aliasToColumnName($col);
|
||||
if (substr($real, 0, 4) === 'SUM(') {
|
||||
continue;
|
||||
}
|
||||
$this->select->group($real);
|
||||
if (version_compare($this->getIdoVersion(), '1.10.0', '<')) {
|
||||
$this->columnMap['hoststatus']['host_check_source'] = '(NULL)';
|
||||
}
|
||||
$this->useSubqueryCount = true;
|
||||
|
||||
if (version_compare($this->getIdoVersion(), '1.13.0', '<')) {
|
||||
$this->columnMap['hoststatus']['host_is_reachable'] = '(NULL)';
|
||||
}
|
||||
|
||||
$this->select->from(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['hosts'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
return $this->joinServiceHostgroups();
|
||||
} else {
|
||||
return $this->joinHostHostgroups();
|
||||
}
|
||||
}
|
||||
|
||||
protected function joinServiceHostgroups()
|
||||
{
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
'hgm.host_object_id = ho.object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id'
|
||||
. ' AND hgo.is_active = 1',
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function joinHostHostgroups()
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
|
||||
array()
|
||||
)->join(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id' . ' AND hgo.is_active = 1',
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function joinContacts()
|
||||
/**
|
||||
* Join last host acknowledgement comment
|
||||
*/
|
||||
protected function joinLasthostackcomment()
|
||||
{
|
||||
$this->hcgcSub = $this->db->select()->distinct()->from(
|
||||
array('hcgc' => $this->prefix . 'host_contactgroups'),
|
||||
array('host_name' => 'ho.name1')
|
||||
)->join(
|
||||
array('cgo' => $this->prefix . 'objects'),
|
||||
'hcg.contactgroup_object_id = cgo.' . $this->object_id . ' AND cgo.is_active = 1',
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hcg.host_id = h.host_id',
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1',
|
||||
$this->select->joinLeft(
|
||||
array('hlac' => $this->createLastCommentSubQuery(4, 'last_ack_data')),
|
||||
'hlac.object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
$this->select->join(
|
||||
array('hcg' => $this->hcgSub),
|
||||
'hcg.host_name = ho.name1',
|
||||
array()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function filterContactgroup($value)
|
||||
/**
|
||||
* Join last host comment
|
||||
*/
|
||||
protected function joinLasthostcomment()
|
||||
{
|
||||
$this->hcgSub->where(
|
||||
$this->prepareFilterStringForColumn(
|
||||
'cgo.name1 COLLATE latin1_general_ci',
|
||||
$value
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function joinContactgroups()
|
||||
{
|
||||
$this->hcgSub = $this->createContactgroupFilterSubselect();
|
||||
$this->select->join(
|
||||
array('hcg' => $this->hcgSub),
|
||||
'hcg.object_id = ho.object_id',
|
||||
$this->select->joinLeft(
|
||||
array('hlc' => $this->createLastCommentSubQuery(1, 'last_comment_data')),
|
||||
'hlc.object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function createContactgroupFilterSubselect()
|
||||
/**
|
||||
* Join last host downtime comment
|
||||
*/
|
||||
protected function joinLasthostdowntimeComment()
|
||||
{
|
||||
die((string) $this->db->select()->distinct()->from(
|
||||
array('hcg' => $this->prefix . 'host_contactgroups'),
|
||||
array('object_id' => 'ho.object_id')
|
||||
)->join(
|
||||
array('cgo' => $this->prefix . 'objects'),
|
||||
'hcg.contactgroup_object_id = cgo.' . $this->object_id
|
||||
. ' AND cgo.is_active = 1',
|
||||
$this->select->joinLeft(
|
||||
array('hldc' => $this->createLastCommentSubQuery(2, 'last_downtime_data')),
|
||||
'hldc.object_id = ho.object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hcg.host_id = h.host_id',
|
||||
array()
|
||||
)->join(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1',
|
||||
array()
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join last host flapping comment
|
||||
*/
|
||||
protected function joinLasthostflappingcomment()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hlfc' => $this->createLastCommentSubQuery(3, 'last_flapping_data')),
|
||||
'hlfc.object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
// TODO: Only hosts with services having such servicegroups
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.' . $this->object_id . ' = sg.servicegroup_object_id'
|
||||
. ' AND sgo.is_active = 1',
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service problem summary
|
||||
*/
|
||||
protected function joinServiceproblemsummary()
|
||||
{
|
||||
$select = <<<'SQL'
|
||||
SELECT
|
||||
SUM(
|
||||
CASE WHEN(ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END
|
||||
) AS unhandled_services_count,
|
||||
SUM(
|
||||
CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0) ) > 0
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
) AS handled_services_count,
|
||||
s.host_object_id
|
||||
FROM
|
||||
icinga_servicestatus ss
|
||||
JOIN icinga_objects o ON o.object_id = ss.service_object_id
|
||||
JOIN icinga_services s ON s.service_object_id = o.object_id
|
||||
JOIN icinga_hoststatus hs ON hs.host_object_id = s.host_object_id
|
||||
WHERE
|
||||
o.is_active = 1
|
||||
AND o.objecttype_id = 2
|
||||
AND ss.current_state > 0
|
||||
GROUP BY
|
||||
s.host_object_id
|
||||
SQL;
|
||||
$this->select->joinLeft(
|
||||
array('sps' => new Zend_Db_Expr('(' . $select . ')')),
|
||||
'sps.host_object_id = ho.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) {
|
||||
$group = array('h.host_id', 'ho.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('serviceproblemsummary')) {
|
||||
$group[] = 'sps.unhandled_services_count';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('lasthostackcomment')) {
|
||||
$group[] = 'hlac.last_ack_data';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('lasthostcomment')) {
|
||||
$group[] = 'hlc.last_comment_data';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('lasthostdowntimecomment')) {
|
||||
$group[] = 'hldc.last_downtime_data';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('lasthostflappingcomment')) {
|
||||
$group[] = 'hlfc.last_flapping_data';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hostgroups')) {
|
||||
$selected = false;
|
||||
foreach ($this->columns as $alias => $column) {
|
||||
if ($column instanceof Zend_Db_Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$table = $this->aliasToTableName(
|
||||
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
|
||||
);
|
||||
if ($table === 'hostgroups') {
|
||||
$selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($selected) {
|
||||
$group[] = 'hg.hostgroup_id';
|
||||
$group[] = 'hgo.object_id';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$selected = false;
|
||||
foreach ($this->columns as $alias => $column) {
|
||||
if ($column instanceof Zend_Db_Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$table = $this->aliasToTableName(
|
||||
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
|
||||
);
|
||||
if ($table === 'servicegroups') {
|
||||
$selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($selected) {
|
||||
$group[] = 'sg.servicegroup_id';
|
||||
$group[] = 'sgo.object_id';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host group summaries
|
||||
*/
|
||||
class HoststatussummaryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hoststatussummary' => array(
|
||||
'hosts_down' => 'SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled' => 'SUM(CASE WHEN state = 1 AND handled = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_unhandled' => 'SUM(CASE WHEN state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_pending' => 'SUM(CASE WHEN state = 99 THEN 1 ELSE 0 END)',
|
||||
'hosts_total' => 'SUM(1)',
|
||||
'hosts_unreachable' => 'SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled' => 'SUM(CASE WHEN state = 2 AND handled = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_up' => 'SUM(CASE WHEN state = 0 THEN 1 ELSE 0 END)'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The host status sub select
|
||||
*
|
||||
* @var HostStatusQuery
|
||||
*/
|
||||
protected $subSelect;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->subSelect->applyFilter(clone $filter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
// TODO(el): Allow to switch between hard and soft states
|
||||
$this->subSelect = $this->createSubQuery(
|
||||
'Hoststatus',
|
||||
array(
|
||||
'handled' => 'host_handled',
|
||||
'state' => 'host_state',
|
||||
'state_change' => 'host_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->select->from(
|
||||
array('hoststatussummary' => $this->subSelect->setIsSubQuery(true)),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['hoststatussummary'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->subSelect->where($condition, $value);
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -3,14 +3,16 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Zend_Db_Expr;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Data\Db\DbQuery;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filter\FilterExpression;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\NotImplementedError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Session;
|
||||
|
||||
/**
|
||||
* Base class for Ido Queries
|
||||
|
@ -45,24 +47,31 @@ abstract class IdoQuery extends DbQuery
|
|||
/**
|
||||
* The prefix to use
|
||||
*
|
||||
* @var String
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* The alias name for the index column
|
||||
* An array to map aliases to table names
|
||||
*
|
||||
* @var String
|
||||
* @var array
|
||||
*/
|
||||
protected $idxAliasColumn;
|
||||
|
||||
/**
|
||||
* The table containing the index column alias
|
||||
* An array to map aliases to column names
|
||||
*
|
||||
* @var String
|
||||
* @var array
|
||||
*/
|
||||
protected $idxAliasTable;
|
||||
|
||||
/**
|
||||
* An array to map custom aliases to aliases
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $idxCustomAliases;
|
||||
|
||||
/**
|
||||
* The column map containing all filterable columns
|
||||
*
|
||||
|
@ -110,53 +119,235 @@ abstract class IdoQuery extends DbQuery
|
|||
protected $joinedVirtualTables = array();
|
||||
|
||||
/**
|
||||
* The primary field name for the object table
|
||||
* The primary key column for the instances table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $instance_id = 'instance_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the objects table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $object_id = 'object_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO host table
|
||||
* The primary key column for the acknowledgements table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host_id = 'host_id';
|
||||
protected $acknowledgement_id = 'acknowledgement_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO hostgroup table
|
||||
* The primary key column for the commenthistory table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hostgroup_id = 'hostgroup_id';
|
||||
protected $commenthistory_id = 'commenthistory_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO service table
|
||||
* The primary key column for the contactnotifications table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $service_id = 'service_id';
|
||||
protected $contactnotification_id = 'contactnotification_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO serviegroup table
|
||||
* The primary key column for the downtimehistory table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $downtimehistory_id = 'downtimehistory_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the flappinghistory table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $flappinghistory_id = 'flappinghistory_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the notifications table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $notification_id = 'notification_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the statehistory table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $statehistory_id = 'statehistory_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the comments table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_id = 'comment_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the customvariablestatus table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $customvariablestatus_id = 'customvariablestatus_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the hoststatus table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hoststatus_id = 'hoststatus_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the programstatus table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $programstatus_id = 'programstatus_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the runtimevariables table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $runtimevariable_id = 'runtimevariable_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the scheduleddowntime table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scheduleddowntime_id = 'scheduleddowntime_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the servicestatus table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $servicestatus_id = 'servicestatus_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the contactstatus table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contactstatus_id = 'contactstatus_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the commands table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command_id = 'command_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the contactgroup_members table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contactgroup_member_id = 'contactgroup_member_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the contactgroups table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contactgroup_id = 'contactgroup_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the contacts table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contact_id = 'contact_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the customvariables table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $customvariable_id = 'customvariable_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the host_contactgroups table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host_contactgroup_id = 'host_contactgroup_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the host_contacts table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host_contact_id = 'host_contact_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the hostgroup_members table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hostgroup_member_id = 'hostgroup_member_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the hostgroups table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hostgroup_id = 'hostgroup_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the hosts table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host_id = 'host_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the service_contactgroup table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $service_contactgroup_id = 'service_contactgroup_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the service_contact table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $service_contact_id = 'service_contact_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the servicegroup_members table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $servicegroup_member_id = 'servicegroup_member_id';
|
||||
|
||||
/**
|
||||
* The primary key column for the servicegroups table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $servicegroup_id = 'servicegroup_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO contact table
|
||||
* The primary key column for the services table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contact_id = 'contact_id';
|
||||
protected $service_id = 'service_id';
|
||||
|
||||
/**
|
||||
* The primary field name for the IDO contactgroup table
|
||||
* The primary key column for the timeperiods table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $contactgroup_id = 'contactgroup_id';
|
||||
protected $timeperiod_id = 'timeperiod_id';
|
||||
|
||||
/**
|
||||
* An array containing Column names that cause an aggregation of the query
|
||||
|
@ -266,6 +457,10 @@ abstract class IdoQuery extends DbQuery
|
|||
protected function requireFilterColumns(Filter $filter)
|
||||
{
|
||||
if ($filter instanceof FilterExpression) {
|
||||
if ($filter->getExpression() === '*') {
|
||||
return; // Wildcard only filters are ignored so stop early here to avoid joining a table for nothing
|
||||
}
|
||||
|
||||
$col = $filter->getColumn();
|
||||
$this->requireColumn($col);
|
||||
|
||||
|
@ -327,6 +522,10 @@ abstract class IdoQuery extends DbQuery
|
|||
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
if ($value === '*') {
|
||||
return $this; // Wildcard only filters are ignored so stop early here to avoid joining a table for nothing
|
||||
}
|
||||
|
||||
$this->requireColumn($condition);
|
||||
$col = $this->getMappedField($condition);
|
||||
if ($col === null) {
|
||||
|
@ -461,6 +660,11 @@ abstract class IdoQuery extends DbQuery
|
|||
$resolvedColumns = array();
|
||||
|
||||
foreach ($columns as $alias => $col) {
|
||||
if ($col instanceof Zend_Db_Expr) {
|
||||
// Support selecting NULL as column for example
|
||||
$resolvedColumns[$alias] = $col;
|
||||
continue;
|
||||
}
|
||||
$this->requireColumn($col);
|
||||
if ($this->isCustomvar($col)) {
|
||||
$name = $this->getCustomvarColumnName($col);
|
||||
|
@ -469,6 +673,8 @@ abstract class IdoQuery extends DbQuery
|
|||
}
|
||||
if (is_int($alias)) {
|
||||
$alias = $col;
|
||||
} else {
|
||||
$this->idxCustomAliases[$alias] = $col;
|
||||
}
|
||||
|
||||
$resolvedColumns[$alias] = preg_replace('|\n|', ' ', $name);
|
||||
|
@ -620,12 +826,14 @@ abstract class IdoQuery extends DbQuery
|
|||
|
||||
$this->customVars[$customvar] = $alias;
|
||||
|
||||
// TODO: extend if we allow queries with only hosts / only services
|
||||
// ($leftcol s.host_object_id vs h.host_object_id
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$leftcol = 's.' . $type . '_object_id';
|
||||
} elseif ($type === 'service') {
|
||||
$this->requireVirtualTable('services');
|
||||
$leftcol = 's.service_object_id';
|
||||
} else {
|
||||
$leftcol = 'h.' . $type . '_object_id';
|
||||
$this->requireVirtualTable('hosts');
|
||||
$leftcol = 'h.host_object_id';
|
||||
}
|
||||
|
||||
$joinOn = sprintf(
|
||||
|
@ -672,6 +880,19 @@ abstract class IdoQuery extends DbQuery
|
|||
return $this->idxAliasColumn[$alias];
|
||||
}
|
||||
|
||||
public function customAliasToAlias($alias)
|
||||
{
|
||||
return $this->idxCustomAliases[$alias];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sub query
|
||||
*
|
||||
* @param string $queryName
|
||||
* @param array $columns
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
protected function createSubQuery($queryName, $columns = array())
|
||||
{
|
||||
$class = '\\'
|
||||
|
@ -690,12 +911,55 @@ abstract class IdoQuery extends DbQuery
|
|||
*/
|
||||
public function columns(array $columns)
|
||||
{
|
||||
$this->idxCustomAliases = array();
|
||||
$this->columns = $this->resolveColumns($columns);
|
||||
// TODO: we need to refresh our select!
|
||||
// $this->select->columns($columns);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function _getGroup()
|
||||
{
|
||||
throw new NotImplementedError('Does not work in its current state but will, probably, in the future');
|
||||
|
||||
// TODO: order by??
|
||||
$group = parent::getGroup();
|
||||
if (! empty($group) && $this->ds->getDbType() === 'pgsql') {
|
||||
$group = is_array($group) ? $group : array($group);
|
||||
foreach ($this->columns as $alias => $column) {
|
||||
if ($column instanceof Zend_Db_Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: What if $alias is neither a native nor a custom alias???
|
||||
$table = $this->aliasToTableName(
|
||||
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
|
||||
);
|
||||
|
||||
// TODO: We cannot rely on the underlying select here, tables may be joined multiple times with
|
||||
// different aliases so the only way to get the correct alias here is to register such by ourself
|
||||
// for each virtual column (We may also inspect $column for the alias but this will probably lead
|
||||
// to false positives.. AND prevents custom implementations from providing their own "mapping")
|
||||
if (($tableAlias = $this->getJoinedTableAlias($this->prefix . $table)) === null) {
|
||||
$tableAlias = $table;
|
||||
}
|
||||
|
||||
// TODO: Same issue as with identifying table aliases; Our virtual tables are not named exactly how
|
||||
// they are in the IDO. We definitely need to register aliases explicitly (hint: DbRepository
|
||||
// is already providing such..)
|
||||
$aliasedPk = $tableAlias . '.' . $this->getPrimaryKeyColumn($table);
|
||||
if (! in_array($aliasedPk, $group)) {
|
||||
$group[] = $aliasedPk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
// TODO: Move this away, see note related to $idoVersion var
|
||||
protected function getIdoVersion()
|
||||
{
|
||||
|
@ -721,4 +985,90 @@ abstract class IdoQuery extends DbQuery
|
|||
}
|
||||
return self::$idoVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the primary key column for the given table name
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ProgrammingError In case $table is unknown
|
||||
*/
|
||||
protected function getPrimaryKeyColumn($table)
|
||||
{
|
||||
// TODO: For god's sake, make this being a mapping
|
||||
// (instead of matching a ton of properties using a ridiculous long switch case)
|
||||
switch ($table)
|
||||
{
|
||||
case 'instances':
|
||||
return $this->instance_id;
|
||||
case 'objects':
|
||||
return $this->object_id;
|
||||
case 'acknowledgements':
|
||||
return $this->acknowledgement_id;
|
||||
case 'commenthistory':
|
||||
return $this->commenthistory_id;
|
||||
case 'contactnotifiations':
|
||||
return $this->contactnotification_id;
|
||||
case 'downtimehistory':
|
||||
return $this->downtimehistory_id;
|
||||
case 'flappinghistory':
|
||||
return $this->flappinghistory_id;
|
||||
case 'notifications':
|
||||
return $this->notification_id;
|
||||
case 'statehistory':
|
||||
return $this->statehistory_id;
|
||||
case 'comments':
|
||||
return $this->comment_id;
|
||||
case 'customvariablestatus':
|
||||
return $this->customvariablestatus_id;
|
||||
case 'hoststatus':
|
||||
return $this->hoststatus_id;
|
||||
case 'programstatus':
|
||||
return $this->programstatus_id;
|
||||
case 'runtimevariables':
|
||||
return $this->runtimevariable_id;
|
||||
case 'scheduleddowntime':
|
||||
return $this->scheduleddowntime_id;
|
||||
case 'servicestatus':
|
||||
return $this->servicestatus_id;
|
||||
case 'contactstatus':
|
||||
return $this->contactstatus_id;
|
||||
case 'commands':
|
||||
return $this->command_id;
|
||||
case 'contactgroup_members':
|
||||
return $this->contactgroup_member_id;
|
||||
case 'contactgroups':
|
||||
return $this->contactgroup_id;
|
||||
case 'contacts':
|
||||
return $this->contact_id;
|
||||
case 'customvariables':
|
||||
return $this->customvariable_id;
|
||||
case 'host_contactgroups':
|
||||
return $this->host_contactgroup_id;
|
||||
case 'host_contacts':
|
||||
return $this->host_contact_id;
|
||||
case 'hostgroup_members':
|
||||
return $this->hostgroup_member_id;
|
||||
case 'hostgroups':
|
||||
return $this->hostgroup_id;
|
||||
case 'hosts':
|
||||
return $this->host_id;
|
||||
case 'service_contactgroups':
|
||||
return $this->service_contactgroup_id;
|
||||
case 'service_contacts':
|
||||
return $this->service_contact_id;
|
||||
case 'servicegroup_members':
|
||||
return $this->servicegroup_member_id;
|
||||
case 'servicegroups':
|
||||
return $this->servicegroup_id;
|
||||
case 'services':
|
||||
return $this->service_id;
|
||||
case 'timeperiods':
|
||||
return $this->timeperiod_id;
|
||||
default:
|
||||
throw new ProgrammingError('Cannot provide a primary key column. Table "%s" is unknown', $table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,136 +3,172 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service notifications
|
||||
*/
|
||||
class NotificationQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'notification' => array(
|
||||
'notification_output' => 'n.output',
|
||||
'notification_start_time' => 'UNIX_TIMESTAMP(n.start_time)',
|
||||
'notification_state' => 'n.state',
|
||||
'notification_object_id' => 'n.object_id'
|
||||
'notifications' => array(
|
||||
'notification_state' => 'n.notification_state',
|
||||
'notification_start_time' => 'n.notification_start_time',
|
||||
'notification_contact_name' => 'n.notification_contact_name',
|
||||
'notification_output' => 'n.notification_output',
|
||||
'notification_object_id' => 'n.notification_object_id',
|
||||
'contact_object_id' => 'n.contact_object_id',
|
||||
'acknowledgement_entry_time' => 'n.acknowledgement_entry_time',
|
||||
'acknowledgement_author_name' => 'n.acknowledgement_author_name',
|
||||
'acknowledgement_comment_data' => 'n.acknowledgement_comment_data',
|
||||
'object_type' => 'n.object_type'
|
||||
),
|
||||
'objects' => array(
|
||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'o.name1',
|
||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2'
|
||||
),
|
||||
'contact' => array(
|
||||
'contact' => 'c_o.name1 COLLATE latin1_general_ci',
|
||||
'notification_contact_name' => 'c_o.name1',
|
||||
'contact_object_id' => 'c_o.object_id'
|
||||
),
|
||||
'command' => array(
|
||||
'notification_command' => 'cmd_o.name1'
|
||||
),
|
||||
'acknowledgement' => array(
|
||||
'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)',
|
||||
'acknowledgement_author_name' => 'a.author_name',
|
||||
'acknowledgement_comment_data' => 'a.comment_data'
|
||||
'history' => array(
|
||||
'type' => 'n.type',
|
||||
'timestamp' => 'n.timestamp',
|
||||
'object_id' => 'n.object_id',
|
||||
'state' => 'n.state',
|
||||
'output' => 'n.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'
|
||||
'host_display_name' => 'n.host_display_name',
|
||||
'host_name' => 'n.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name'
|
||||
'service_description' => 'n.service_description',
|
||||
'service_display_name' => 'n.service_display_name',
|
||||
'service_host_name' => 'n.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Fetch basic information about notifications
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $notificationQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the notification query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->notificationQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('n' => $this->prefix . 'notifications'),
|
||||
array('n' => $this->notificationQuery),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('notification' => true);
|
||||
$this->joinedVirtualTables['notifications'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch description of each affected host/service
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinObjects()
|
||||
protected function joinHistory()
|
||||
{
|
||||
$this->select->join(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
'n.object_id = o.object_id AND o.is_active = 1 AND o.objecttype_id IN (1, 2)',
|
||||
array()
|
||||
);
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch name of involved contacts and/or contact groups
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinContact()
|
||||
{
|
||||
$this->select->join(
|
||||
array('c' => $this->prefix . 'contactnotifications'),
|
||||
'n.notification_id = c.notification_id',
|
||||
array()
|
||||
);
|
||||
$this->select->join(
|
||||
array('c_o' => $this->prefix . 'objects'),
|
||||
'c.contact_object_id = c_o.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch name of the command which was used to send out a notification
|
||||
*/
|
||||
protected function joinCommand()
|
||||
{
|
||||
$this->select->join(
|
||||
array('cmd_c' => $this->prefix . 'contactnotifications'),
|
||||
'n.notification_id = cmd_c.notification_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('cmd_m' => $this->prefix . 'contactnotificationmethods'),
|
||||
'cmd_c.contactnotification_id = cmd_m.contactnotification_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('cmd_o' => $this->prefix . 'objects'),
|
||||
'cmd_m.command_object_id = cmd_o.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinAcknowledgement()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('a' => $this->prefix . 'acknowledgements'),
|
||||
'n.object_id = a.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = o.object_id',
|
||||
array()
|
||||
);
|
||||
$columns = array_keys($this->columnMap['hosts']);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
$columns[] = 'object_type';
|
||||
} else {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['notifications']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('hostnotification', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys($this->columnMap['hosts'] + $this->columnMap['services']);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
$columns[] = 'object_type';
|
||||
} else {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['notifications']));
|
||||
}
|
||||
$services = $this->createSubQuery('servicenotification', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function joinServices()
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = o.object_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('sh' => $this->prefix . 'hosts'),
|
||||
'sh.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function columns(array $columns)
|
||||
{
|
||||
parent::columns($columns);
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service comments
|
||||
*/
|
||||
class ServicecommentQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'comments' => array(
|
||||
'comment_author' => 'c.author_name COLLATE latin1_general_ci',
|
||||
'comment_author_name' => 'c.author_name',
|
||||
'comment_data' => 'c.comment_data',
|
||||
'comment_expiration' => 'CASE c.expires WHEN 1 THEN UNIX_TIMESTAMP(c.expiration_time) ELSE NULL END',
|
||||
'comment_internal_id' => 'c.internal_comment_id',
|
||||
'comment_is_persistent' => 'c.is_persistent',
|
||||
'comment_timestamp' => 'UNIX_TIMESTAMP(c.comment_time)',
|
||||
'comment_type' => "CASE c.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicestatus' => array(
|
||||
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('c' => $this->prefix . 'comments'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = c.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['comments'] = true;
|
||||
}
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service status
|
||||
*/
|
||||
protected function joinServicestatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'ss.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('c.comment_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('servicestatus')) {
|
||||
$group[] = 'ss.servicestatus_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service comment removal records
|
||||
*/
|
||||
class ServicecommentdeletionhistoryQuery extends ServicecommenthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sch.deletion_time)') {
|
||||
return 'sch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
parent::joinBaseTables();
|
||||
$this->select->where("sch.deletion_time > '1970-01-02 00:00:00'");
|
||||
$this->columnMap['history']['timestamp'] = str_replace(
|
||||
'comment_time',
|
||||
'deletion_time',
|
||||
$this->columnMap['history']['timestamp']
|
||||
);
|
||||
$this->columnMap['history']['type'] = str_replace(
|
||||
'END)',
|
||||
"END || '_deleted')",
|
||||
$this->columnMap['history']['type']
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service comment history records
|
||||
*/
|
||||
class ServicecommenthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'commenthistory' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)',
|
||||
'object_id' => 'sch.object_id',
|
||||
'state' => '(-1)',
|
||||
'output' => "('[' || sch.author_name || '] ' || sch.comment_data)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sch.comment_time)') {
|
||||
return 'sch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sch' => $this->prefix . 'commenthistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = sch.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['commenthistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('sch.commenthistory_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 'h.host_id';
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service downtimes
|
||||
*/
|
||||
class ServicedowntimeQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimes' => array(
|
||||
'downtime_author' => 'sd.author_name COLLATE latin1_general_ci',
|
||||
'downtime_author_name' => 'sd.author_name',
|
||||
'downtime_comment' => 'sd.comment_data',
|
||||
'downtime_duration' => 'sd.duration',
|
||||
'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END',
|
||||
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
|
||||
'downtime_internal_id' => 'sd.internal_downtime_id',
|
||||
'downtime_is_fixed' => 'sd.is_fixed',
|
||||
'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END',
|
||||
'downtime_is_in_effect' => 'sd.is_in_effect',
|
||||
'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)',
|
||||
'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)',
|
||||
'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)',
|
||||
'downtime_triggered_by_id' => 'sd.triggered_by_id',
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicestatus' => array(
|
||||
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sd' => $this->prefix . 'scheduleddowntime'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['downtimes'] = true;
|
||||
}
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service status
|
||||
*/
|
||||
protected function joinServicestatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'ss.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('sd.scheduleddowntime_id', 'so.object_id');
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('servicestatus')) {
|
||||
$group[] = 'ss.servicestatus_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for host downtime end history records
|
||||
*/
|
||||
class ServicedowntimeendhistoryQuery extends ServicedowntimestarthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_end_time)') {
|
||||
return 'sdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
parent::joinBaseTables(true);
|
||||
$this->select->where("sdh.actual_end_time > '1970-01-02 00:00:00'");
|
||||
$this->columnMap['history']['type'] = "('dt_end')";
|
||||
$this->columnMap['history']['timestamp'] = str_replace(
|
||||
'actual_start_time',
|
||||
'actual_end_time',
|
||||
$this->columnMap['history']['timestamp']
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service downtime start history records
|
||||
*/
|
||||
class ServicedowntimestarthistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "('dt_start')",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)',
|
||||
'object_id' => 'sdh.object_id',
|
||||
'state' => '(-1)',
|
||||
'output' => "('[' || sdh.author_name || '] ' || sdh.comment_data)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_start_time)') {
|
||||
return 'sdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sdh' => $this->prefix . 'downtimehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = sdh.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
|
||||
if (@func_get_arg(0) === false) {
|
||||
$this->select->where(
|
||||
"sdh.actual_start_time > '1970-01-02 00:00:00'"
|
||||
);
|
||||
}
|
||||
|
||||
$this->joinedVirtualTables['downtimehistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('sdh.downtimehistory_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 'h.host_id';
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -5,21 +5,43 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
|
||||
class ServicegroupQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1'
|
||||
),
|
||||
'serviceobjects' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2'
|
||||
),
|
||||
'services' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'service_description' => 'so.name2'
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
|
@ -27,24 +49,85 @@ class ServicegroupQuery extends IdoQuery
|
|||
array()
|
||||
)->join(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sg.servicegroup_object_id = sgo.' . $this->object_id
|
||||
. ' AND sgo.is_active = 1',
|
||||
'sg.servicegroup_object_id = sgo.object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
|
||||
$this->joinedVirtualTables = array('servicegroups' => true);
|
||||
}
|
||||
|
||||
protected function joinServices()
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->join(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.' . $this->servicegroup_id . ' = sg.' . $this->servicegroup_id,
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'sgm.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1',
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service objects
|
||||
*/
|
||||
protected function joinServiceobjects()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.' . $this->servicegroup_id . ' = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->requireVirtualTable('serviceobjects');
|
||||
$this->select->joinLeft(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('serviceobjects')) {
|
||||
$group = array('sg.servicegroup_id', 'sgo.object_id');
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
|
||||
/**
|
||||
* Query for service group summary
|
||||
*/
|
||||
class ServicegroupsummaryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'servicestatussummary' => array(
|
||||
'servicegroup' => 'servicegroup COLLATE latin1_general_ci',
|
||||
'servicegroup_alias' => 'servicegroup_alias COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'servicegroup_name',
|
||||
'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)',
|
||||
'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)',
|
||||
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
|
||||
'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN state_change ELSE 0 END)'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $summaryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the summary query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
// TODO(el): Allow to switch between hard and soft states
|
||||
$hosts = $this->createSubQuery(
|
||||
'Hoststatus',
|
||||
array(
|
||||
'handled' => 'host_handled',
|
||||
'host_state' => new Zend_Db_Expr('NULL'),
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'object_type',
|
||||
'severity' => new Zend_Db_Expr('NULL'),
|
||||
'state' => 'host_state',
|
||||
'state_change' => 'host_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $hosts;
|
||||
$services = $this->createSubQuery(
|
||||
'Servicestatus',
|
||||
array(
|
||||
'handled' => 'service_handled',
|
||||
'host_state' => 'host_state',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'object_type',
|
||||
'severity' => 'service_severity',
|
||||
'state' => 'service_state',
|
||||
'state_change' => 'service_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $services;
|
||||
$this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->select->from(array('statussummary' => $this->summaryQuery), array());
|
||||
$this->group(array('servicegroup_name', 'servicegroup_alias'));
|
||||
$this->joinedVirtualTables['servicestatussummary'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
if (! $this->hasAliasName($columnOrAlias)) {
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service notifications
|
||||
*/
|
||||
class ServicenotificationQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'notifications' => array(
|
||||
'notification_output' => 'sn.output',
|
||||
'notification_start_time' => 'UNIX_TIMESTAMP(sn.start_time)',
|
||||
'notification_state' => 'sn.state',
|
||||
'notification_object_id' => 'sn.object_id',
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "('notify')",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
||||
'object_id' => 'sn.object_id',
|
||||
'state' => 'sn.state',
|
||||
'output' => null
|
||||
),
|
||||
'contactnotifications' => array(
|
||||
'contact' => 'cno.name1 COLLATE latin1_general_ci',
|
||||
'notification_contact_name' => 'cno.name1',
|
||||
'contact_object_id' => 'cno.object_id'
|
||||
),
|
||||
'acknowledgements' => array(
|
||||
'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)',
|
||||
'acknowledgement_author_name' => 'a.author_name',
|
||||
'acknowledgement_comment_data' => 'a.comment_data'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sn.start_time)') {
|
||||
return 'sn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
switch ($this->ds->getDbType()) {
|
||||
case 'mysql':
|
||||
$concattedContacts = "GROUP_CONCAT("
|
||||
. "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '"
|
||||
. ") COLLATE latin1_general_ci";
|
||||
break;
|
||||
case 'pgsql':
|
||||
// TODO: Find a way to order the contact alias list:
|
||||
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')";
|
||||
break;
|
||||
case 'oracle':
|
||||
// TODO: This is only valid for Oracle >= 11g Release 2
|
||||
$concattedContacts = "LISTAGG(cno.name1, ', ') WITHIN GROUP (ORDER BY cno.name1)";
|
||||
// Alternatives:
|
||||
//
|
||||
// RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')),
|
||||
//
|
||||
// not supported and not documented but works since 10.1,
|
||||
// however it is NOT always present:
|
||||
// WM_CONCAT(c.alias)
|
||||
break;
|
||||
}
|
||||
|
||||
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || sn.output)";
|
||||
|
||||
$this->select->from(
|
||||
array('sn' => $this->prefix . 'notifications'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = sn.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['notifications'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join virtual table history
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
$this->requireVirtualTable('contactnotifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join contact notifications
|
||||
*/
|
||||
protected function joinContactnotifications()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('cn' => $this->prefix . 'contactnotifications'),
|
||||
'cn.notification_id = sn.notification_id',
|
||||
array()
|
||||
);
|
||||
$this->select->joinLeft(
|
||||
array('cno' => $this->prefix . 'objects'),
|
||||
'cno.object_id = cn.contact_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join acknowledgements
|
||||
*/
|
||||
protected function joinAcknowledgements()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('a' => $this->prefix . 'acknowledgements'),
|
||||
'a.object_id = sn.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if (
|
||||
$this->hasJoinedVirtualTable('history')
|
||||
|| $this->hasJoinedVirtualTable('hostgroups')
|
||||
|| $this->hasJoinedVirtualTable('servicegroups')
|
||||
) {
|
||||
$group = array('sn.notification_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
||||
$group[] = 'cno.object_id';
|
||||
}
|
||||
} elseif ($this->hasJoinedVirtualTable('contactnotifications')) {
|
||||
$group = array('sn.notification_id', 'cno.object_id', 'so.object_id');
|
||||
}
|
||||
|
||||
if (! empty($group)) {
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('acknowledgements')) {
|
||||
$group[] = 'a.acknowledgement_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
/**
|
||||
* Query for service state history records
|
||||
*/
|
||||
class ServicestatehistoryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* Array to map type names to type ids for query optimization
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $types = array(
|
||||
'soft_state' => 0,
|
||||
'hard_state' => 1
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)",
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)',
|
||||
'object_id' => 'sh.object_id',
|
||||
'state' => 'sh.state',
|
||||
'output' => "('[ ' || sh.current_check_attempt || '/' || sh.max_check_attempts || ' ] ' || sh.output)",
|
||||
),
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_alias' => 'h.alias',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sh.state_time)') {
|
||||
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif (
|
||||
$col === $this->columnMap['history']['type']
|
||||
&& ! is_array($expression)
|
||||
&& array_key_exists($expression, $this->types)
|
||||
) {
|
||||
return 'sh.state_type ' . $sign . ' ' . $this->types[$expression];
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('sh' => $this->prefix . 'statehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.object_id = sh.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['statehistory'] = true;
|
||||
$this->joinedVirtualTables['history'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$this->select->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('sh.statehistory_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('services')) {
|
||||
$group[] = 'h.host_id';
|
||||
$group[] = 's.service_id';
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
|
||||
/**
|
||||
* Query for service status
|
||||
*/
|
||||
class ServicestatusQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_action_url' => 'h.action_url',
|
||||
'host_address' => 'h.address',
|
||||
'host_alias' => 'h.alias COLLATE latin1_general_ci',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'host_icon_image_alt' => 'h.icon_image_alt',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_notes_url' => 'h.notes_url'
|
||||
),
|
||||
'hoststatus' => array(
|
||||
'host_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'host_acknowledgement_type' => 'hs.acknowledgement_type',
|
||||
'host_active_checks_enabled' => 'hs.active_checks_enabled',
|
||||
'host_active_checks_enabled_changed' => 'CASE WHEN hs.active_checks_enabled = h.active_checks_enabled THEN 0 ELSE 1 END',
|
||||
'host_attempt' => 'hs.current_check_attempt || \'/\' || hs.max_check_attempts',
|
||||
'host_check_command' => 'hs.check_command',
|
||||
'host_check_execution_time' => 'hs.execution_time',
|
||||
'host_check_latency' => 'hs.latency',
|
||||
'host_check_source' => 'hs.check_source',
|
||||
'host_check_type' => 'hs.check_type',
|
||||
'host_current_check_attempt' => 'hs.current_check_attempt',
|
||||
'host_current_notification_number' => 'hs.current_notification_number',
|
||||
'host_event_handler' => 'hs.event_handler',
|
||||
'host_event_handler_enabled' => 'hs.event_handler_enabled',
|
||||
'host_event_handler_enabled_changed' => 'CASE WHEN hs.event_handler_enabled = h.event_handler_enabled THEN 0 ELSE 1 END',
|
||||
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
|
||||
'host_flap_detection_enabled' => 'hs.flap_detection_enabled',
|
||||
'host_flap_detection_enabled_changed' => 'CASE WHEN hs.flap_detection_enabled = h.flap_detection_enabled THEN 0 ELSE 1 END',
|
||||
'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END',
|
||||
'host_hard_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END',
|
||||
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
|
||||
'host_is_flapping' => 'hs.is_flapping',
|
||||
'host_is_reachable' => 'hs.is_reachable',
|
||||
'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)',
|
||||
'host_last_hard_state' => 'hs.last_hard_state',
|
||||
'host_last_hard_state_change' => 'UNIX_TIMESTAMP(hs.last_hard_state_change)',
|
||||
'host_last_notification' => 'UNIX_TIMESTAMP(hs.last_notification)',
|
||||
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
|
||||
'host_last_time_down' => 'UNIX_TIMESTAMP(hs.last_time_down)',
|
||||
'host_last_time_unreachable' => 'UNIX_TIMESTAMP(hs.last_time_unreachable)',
|
||||
'host_last_time_up' => 'UNIX_TIMESTAMP(hs.last_time_up)',
|
||||
'host_long_output' => 'hs.long_output',
|
||||
'host_max_check_attempts' => 'hs.max_check_attempts',
|
||||
'host_modified_host_attributes' => 'hs.modified_host_attributes',
|
||||
'host_next_check' => 'CASE hs.should_be_scheduled WHEN 1 THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END',
|
||||
'host_next_notification' => 'UNIX_TIMESTAMP(hs.next_notification)',
|
||||
'host_no_more_notifications' => 'hs.no_more_notifications',
|
||||
'host_normal_check_interval' => 'hs.normal_check_interval',
|
||||
'host_notifications_enabled' => 'hs.notifications_enabled',
|
||||
'host_notifications_enabled_changed' => 'CASE WHEN hs.notifications_enabled = h.notifications_enabled THEN 0 ELSE 1 END',
|
||||
'host_obsessing' => 'hs.obsess_over_host',
|
||||
'host_obsessing_changed' => 'CASE WHEN hs.obsess_over_host = h.obsess_over_host THEN 0 ELSE 1 END',
|
||||
'host_output' => 'hs.output',
|
||||
'host_passive_checks_enabled' => 'hs.passive_checks_enabled',
|
||||
'host_passive_checks_enabled_changed' => 'CASE WHEN hs.passive_checks_enabled = h.passive_checks_enabled THEN 0 ELSE 1 END',
|
||||
'host_percent_state_change' => 'hs.percent_state_change',
|
||||
'host_perfdata' => 'hs.perfdata',
|
||||
'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END',
|
||||
'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'host_process_performance_data' => 'hs.process_performance_data',
|
||||
'host_retry_check_interval' => 'hs.retry_check_interval',
|
||||
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
|
||||
'host_severity' => 'CASE WHEN hs.current_state = 0
|
||||
THEN
|
||||
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
|
||||
THEN 16
|
||||
ELSE 0
|
||||
END
|
||||
+
|
||||
CASE WHEN hs.problem_has_been_acknowledged = 1
|
||||
THEN 2
|
||||
ELSE
|
||||
CASE WHEN hs.scheduled_downtime_depth > 0
|
||||
THEN 1
|
||||
ELSE 4
|
||||
END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 16
|
||||
WHEN hs.current_state = 1 THEN 32
|
||||
WHEN hs.current_state = 2 THEN 64
|
||||
ELSE 256
|
||||
END
|
||||
+
|
||||
CASE WHEN hs.problem_has_been_acknowledged = 1
|
||||
THEN 2
|
||||
ELSE
|
||||
CASE WHEN hs.scheduled_downtime_depth > 0
|
||||
THEN 1
|
||||
ELSE 4
|
||||
END
|
||||
END
|
||||
END
|
||||
+
|
||||
CASE WHEN hs.state_type = 1
|
||||
THEN 8
|
||||
ELSE 0
|
||||
END',
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'host_state_type' => 'hs.state_type',
|
||||
'host_status_update_time' => 'hs.status_update_time',
|
||||
'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END'
|
||||
),
|
||||
'services' => array(
|
||||
'host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'so.name1',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_action_url' => 's.action_url',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'service_icon_image' => 's.icon_image',
|
||||
'service_icon_image_alt' => 's.icon_image_alt',
|
||||
'service_notes_url' => 's.notes_url'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicestatus' => array(
|
||||
'service_active_checks_enabled' => 'ss.active_checks_enabled',
|
||||
'service_event_handler_enabled' => 'ss.event_handler_enabled',
|
||||
'service_flap_detection_enabled' => 'ss.flap_detection_enabled',
|
||||
'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
|
||||
'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END',
|
||||
'service_is_flapping' => 'ss.is_flapping',
|
||||
'service_is_passive_checked' => 'CASE WHEN ss.active_checks_enabled = 0 AND ss.passive_checks_enabled = 1 THEN 1 ELSE 0 END',
|
||||
'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)',
|
||||
'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)',
|
||||
'service_notifications_enabled' => 'ss.notifications_enabled',
|
||||
'service_severity' => 'CASE WHEN ss.current_state = 0
|
||||
THEN
|
||||
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL
|
||||
THEN 16
|
||||
ELSE 0
|
||||
END
|
||||
+
|
||||
CASE WHEN ss.problem_has_been_acknowledged = 1
|
||||
THEN 2
|
||||
ELSE
|
||||
CASE WHEN ss.scheduled_downtime_depth > 0
|
||||
THEN 1
|
||||
ELSE 4
|
||||
END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 16
|
||||
WHEN ss.current_state = 1 THEN 32
|
||||
WHEN ss.current_state = 2 THEN 128
|
||||
WHEN ss.current_state = 3 THEN 64
|
||||
ELSE 256
|
||||
END
|
||||
+
|
||||
CASE WHEN hs.current_state > 0
|
||||
THEN 1024
|
||||
ELSE
|
||||
CASE WHEN ss.problem_has_been_acknowledged = 1
|
||||
THEN 512
|
||||
ELSE
|
||||
CASE WHEN ss.scheduled_downtime_depth > 0
|
||||
THEN 256
|
||||
ELSE 2048
|
||||
END
|
||||
END
|
||||
END
|
||||
END
|
||||
+
|
||||
CASE WHEN ss.state_type = 1
|
||||
THEN 8
|
||||
ELSE 0
|
||||
END',
|
||||
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
|
||||
'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.service_object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['services'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host groups
|
||||
*/
|
||||
protected function joinHostgroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$this->select->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'h.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join host status
|
||||
*/
|
||||
protected function joinHoststatus()
|
||||
{
|
||||
$this->select->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'hs.host_object_id = s.host_object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service groups
|
||||
*/
|
||||
protected function joinServicegroups()
|
||||
{
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = so.object_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join service status
|
||||
*/
|
||||
protected function joinServicestatus()
|
||||
{
|
||||
$this->requireVirtualTable('hoststatus');
|
||||
$this->select->join(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'ss.service_object_id = so.object_id',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$group = array();
|
||||
if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$group = array('s.service_id', 'so.object_id');
|
||||
if ($this->hasJoinedVirtualTable('hosts')) {
|
||||
$group[] = 'h.host_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hoststatus')) {
|
||||
$group[] = 'hs.hoststatus_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('servicestatus')) {
|
||||
$group[] = 'ss.servicestatus_id';
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('hostgroups')) {
|
||||
$selected = false;
|
||||
foreach ($this->columns as $alias => $column) {
|
||||
if ($column instanceof Zend_Db_Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$table = $this->aliasToTableName(
|
||||
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
|
||||
);
|
||||
if ($table === 'hostgroups') {
|
||||
$selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($selected) {
|
||||
$group[] = 'hg.hostgroup_id';
|
||||
$group[] = 'hgo.object_id';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->hasJoinedVirtualTable('servicegroups')) {
|
||||
$selected = false;
|
||||
foreach ($this->columns as $alias => $column) {
|
||||
if ($column instanceof Zend_Db_Expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$table = $this->aliasToTableName(
|
||||
$this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)
|
||||
);
|
||||
if ($table === 'servicegroups') {
|
||||
$selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($selected) {
|
||||
$group[] = 'sg.servicegroup_id';
|
||||
$group[] = 'sgo.object_id';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for service status summary
|
||||
*
|
||||
* TODO(el): Allow to switch between hard and soft states
|
||||
*/
|
||||
class ServicestatussummaryQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'servicestatussummary' => array(
|
||||
'services_critical' => 'SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN state = 2 AND handled = 1 THEN 1 ELSE 0 END)',
|
||||
// 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN state = 2 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
// 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN state = 2 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_ok' => 'SUM(CASE WHEN state = 0 THEN 1 ELSE 0 END)',
|
||||
// 'services_ok_last_state_change' => 'MAX(CASE WHEN state = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_pending' => 'SUM(CASE WHEN state = 99 THEN 1 ELSE 0 END)',
|
||||
// 'services_pending_last_state_change' => 'MAX(CASE WHEN state = 99 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_total' => 'SUM(1)',
|
||||
'services_unknown' => 'SUM(CASE WHEN state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN state = 3 AND handled = 1 THEN 1 ELSE 0 END)',
|
||||
// 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN state = 3 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN state = 3 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
// 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN state = 3 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_warning' => 'SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN state = 1 AND handled = 1 THEN 1 ELSE 0 END)',
|
||||
// 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN state = 1 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
// 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN state = 1 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The service status sub select
|
||||
*
|
||||
* @var ServiceStatusQuery
|
||||
*/
|
||||
protected $subSelect;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->subSelect->applyFilter(clone $filter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
// TODO(el): Allow to switch between hard and soft states
|
||||
$this->subSelect = $this->createSubQuery(
|
||||
'servicestatus',
|
||||
array(
|
||||
'handled' => 'service_handled',
|
||||
'state' => 'service_state',
|
||||
'state_change' => 'service_last_state_change'
|
||||
)
|
||||
);
|
||||
$this->select->from(
|
||||
array('servicestatussummary' => $this->subSelect->setIsSubQuery(true)),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables['servicestatussummary'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->subSelect->where($condition, $value);
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -3,58 +3,151 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service state history records
|
||||
*/
|
||||
class StatehistoryQuery extends IdoQuery
|
||||
{
|
||||
protected $types = array(
|
||||
'soft_state' => 0,
|
||||
'hard_state' => 1
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'state_time' => 'sh.state_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)',
|
||||
'raw_timestamp' => 'sh.state_time',
|
||||
'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',
|
||||
|
||||
'host' => 'sho.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'sho.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'sho.name1',
|
||||
'service_description' => 'sho.name2',
|
||||
'object_type' => "CASE WHEN sho.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
||||
'object_type' => 'sth.object_type'
|
||||
),
|
||||
'history' => array(
|
||||
'type' => 'sth.type',
|
||||
'timestamp' => 'sth.timestamp',
|
||||
'object_id' => 'sth.object_id',
|
||||
'state' => 'sth.state',
|
||||
'output' => 'sth.output'
|
||||
),
|
||||
'hosts' => array(
|
||||
'host_display_name' => 'sth.host_display_name',
|
||||
'host_name' => 'sth.host_name'
|
||||
),
|
||||
'services' => array(
|
||||
'service_description' => 'sth.service_description',
|
||||
'service_display_name' => 'sth.service_display_name',
|
||||
'service_host_name' => 'sth.service_host_name'
|
||||
)
|
||||
);
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sh.state_time)') {
|
||||
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif ($col === $this->columnMap['statehistory']['type']
|
||||
&& is_array($expression) === false
|
||||
&& array_key_exists($expression, $this->types) === true
|
||||
) {
|
||||
return 'sh.state_type ' . $sign . ' ' . $this->types[$expression];
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $stateHistoryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the state history query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* Whether to additionally select all history columns
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetchHistoryColumns = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->stateHistoryQuery = $this->db->select();
|
||||
$this->select->from(
|
||||
array('sho' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('sh' => $this->prefix . 'statehistory'),
|
||||
'sho.' . $this->object_id . ' = sh.' . $this->object_id . ' AND sho.is_active = 1',
|
||||
array('sth' => $this->stateHistoryQuery),
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('statehistory' => true);
|
||||
$this->joinedVirtualTables['statehistory'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join history related columns and tables
|
||||
*/
|
||||
protected function joinHistory()
|
||||
{
|
||||
// TODO: Ensure that one is selecting the history columns first...
|
||||
$this->fetchHistoryColumns = true;
|
||||
$this->requireVirtualTable('hosts');
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Join hosts
|
||||
*/
|
||||
protected function joinHosts()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['statehistory'] + $this->columnMap['hosts']
|
||||
);
|
||||
foreach ($this->columnMap['services'] as $column => $_) {
|
||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
||||
}
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$hosts = $this->createSubQuery('Hoststatehistory', $columns);
|
||||
$this->subQueries[] = $hosts;
|
||||
$this->stateHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join services
|
||||
*/
|
||||
protected function joinServices()
|
||||
{
|
||||
$columns = array_keys(
|
||||
$this->columnMap['statehistory'] + $this->columnMap['hosts'] + $this->columnMap['services']
|
||||
);
|
||||
if ($this->fetchHistoryColumns) {
|
||||
$columns = array_merge($columns, array_keys($this->columnMap['history']));
|
||||
}
|
||||
$services = $this->createSubQuery('Servicestatehistory', $columns);
|
||||
$this->subQueries[] = $services;
|
||||
$this->stateHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -434,7 +434,7 @@ class StatusQuery extends IdoQuery
|
|||
array('so' => $this->prefix . 'objects'),
|
||||
'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1',
|
||||
array()
|
||||
)->joinLeft(
|
||||
)->join(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'so.' . $this->object_id . ' = ss.service_object_id',
|
||||
array()
|
||||
|
@ -452,15 +452,15 @@ class StatusQuery extends IdoQuery
|
|||
|
||||
protected function joinHostHostgroups()
|
||||
{
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id AND hgo.is_active = 1',
|
||||
array()
|
||||
|
@ -477,15 +477,15 @@ class StatusQuery extends IdoQuery
|
|||
|
||||
protected function joinServiceHostgroups()
|
||||
{
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||
'hgm.host_object_id = s.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hg' => $this->prefix . 'hostgroups'),
|
||||
'hgm.hostgroup_id = hg.' . $this->hostgroup_id,
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('hgo' => $this->prefix . 'objects'),
|
||||
'hgo.' . $this->object_id . ' = hg.hostgroup_object_id'
|
||||
. ' AND hgo.is_active = 1',
|
||||
|
@ -502,15 +502,15 @@ class StatusQuery extends IdoQuery
|
|||
protected function joinServicegroups()
|
||||
{
|
||||
$this->requireVirtualTable('services');
|
||||
$this->select->join(
|
||||
$this->select->joinLeft(
|
||||
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||
'sgm.service_object_id = s.service_object_id',
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('sg' => $this->prefix . 'servicegroups'),
|
||||
'sgm.servicegroup_id = sg.' . $this->servicegroup_id,
|
||||
array()
|
||||
)->join(
|
||||
)->joinLeft(
|
||||
array('sgo' => $this->prefix . 'objects'),
|
||||
'sgo.' . $this->object_id. ' = sg.servicegroup_object_id'
|
||||
. ' AND sgo.is_active = 1',
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Query for host and service status summary
|
||||
*/
|
||||
class StatusSummaryQuery extends IdoQuery
|
||||
{
|
||||
protected $subHosts;
|
||||
|
||||
protected $subServices;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'services' => array(
|
||||
'service_host_name' => 'so.name1',
|
||||
'service_description' => 'so.name2',
|
||||
),
|
||||
'hoststatussummary' => array(
|
||||
'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)',
|
||||
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
|
@ -23,13 +23,13 @@ class StatusSummaryQuery extends IdoQuery
|
|||
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'hosts_pending_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_passive' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_passive' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_active' => 'SUM(CASE WHEN object_type = \'host\' AND is_active_checked = 1 THEN 1 ELSE 0 END)',
|
||||
|
@ -43,25 +43,25 @@ class StatusSummaryQuery extends IdoQuery
|
|||
'servicestatussummary' => array(
|
||||
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
|
||||
'services_problem' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_problem_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_problem_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_problem_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND handled + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_problem_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND handled + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_pending_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_critical_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_problem > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_problem = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_active' => 'SUM(CASE WHEN object_type = \'service\' AND is_active_checked = 1 THEN 1 ELSE 0 END)',
|
||||
|
@ -85,114 +85,138 @@ We have to find a better solution here.
|
|||
'services_ok_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_pending_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_pending_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_critical_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_pending_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_pending_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_critical_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND handled > 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND handled = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
/**
|
||||
* The union
|
||||
*
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $summaryQuery;
|
||||
|
||||
/**
|
||||
* Subqueries used for the summary query
|
||||
*
|
||||
* @var IdoQuery[]
|
||||
*/
|
||||
protected $subQueries = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$hosts = $this->db->select()->from(
|
||||
array('ho' => $this->prefix . 'objects'),
|
||||
array()
|
||||
)->join(
|
||||
array('hs' => $this->prefix . 'hoststatus'),
|
||||
'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
|
||||
array(
|
||||
''
|
||||
)
|
||||
)->join(
|
||||
array('h' => $this->prefix . 'hosts'),
|
||||
'hs.host_object_id = h.host_object_id',
|
||||
array()
|
||||
);
|
||||
$services = clone $hosts;
|
||||
$services->join(
|
||||
array('s' => $this->prefix . 'services'),
|
||||
's.host_object_id = h.host_object_id',
|
||||
array()
|
||||
)->join(
|
||||
array('so' => $this->prefix . 'objects'),
|
||||
'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('ss' => $this->prefix . 'servicestatus'),
|
||||
'so.' . $this->object_id . ' = ss.service_object_id',
|
||||
array()
|
||||
);
|
||||
$hosts->columns(array(
|
||||
'state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||
'in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END',
|
||||
'is_passive_checked' => 'CASE WHEN hs.active_checks_enabled = 0 AND hs.passive_checks_enabled = 1 THEN 1 ELSE 0 END',
|
||||
'is_active_checked' => 'hs.active_checks_enabled',
|
||||
'is_processing_events' => 'hs.event_handler_enabled',
|
||||
'is_triggering_notifications' => 'hs.notifications_enabled',
|
||||
'is_allowed_to_flap' => 'hs.flap_detection_enabled',
|
||||
'is_flapping' => 'hs.is_flapping',
|
||||
'object_type' => '(\'host\')'
|
||||
));
|
||||
$services->columns(array(
|
||||
'state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END',
|
||||
'acknowledged' => 'ss.problem_has_been_acknowledged',
|
||||
'in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
|
||||
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
|
||||
'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END',
|
||||
'is_passive_checked' => 'CASE WHEN ss.active_checks_enabled = 0 AND ss.passive_checks_enabled = 1 THEN 1 ELSE 0 END',
|
||||
'is_active_checked' => 'ss.active_checks_enabled',
|
||||
'is_processing_events' => 'ss.event_handler_enabled',
|
||||
'is_triggering_notifications' => 'ss.notifications_enabled',
|
||||
'is_allowed_to_flap' => 'ss.flap_detection_enabled',
|
||||
'is_flapping' => 'ss.is_flapping',
|
||||
'object_type' => '(\'service\')'
|
||||
));
|
||||
$union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->subHosts = $hosts;
|
||||
$this->subServices = $services;
|
||||
$this->select->from(array('statussummary' => $union), array());
|
||||
$this->joinedVirtualTables = array(
|
||||
'services' => true,
|
||||
'servicestatussummary' => true,
|
||||
'hoststatussummary' => true
|
||||
);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->applyFilter(clone $filter);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
if ($col === 'so.name1') {
|
||||
$this->subServices->where('so.name1 ' . $sign . ' ?', $expression);
|
||||
return '';
|
||||
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
// TODO(el): Allow to switch between hard and soft states
|
||||
$hosts = $this->createSubQuery(
|
||||
'Hoststatus',
|
||||
array(
|
||||
'handled' => 'host_handled',
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'host_problem',
|
||||
'host_state' => new Zend_Db_Expr('NULL'),
|
||||
'is_active_checked' => 'host_active_checks_enabled',
|
||||
'is_allowed_to_flap' => 'host_flap_detection_enabled',
|
||||
'is_flapping' => 'host_is_flapping',
|
||||
'is_passive_checked' => 'host_is_passive_checked',
|
||||
'is_processing_events' => 'host_event_handler_enabled',
|
||||
'is_triggering_notifications' => 'host_notifications_enabled',
|
||||
'object_type',
|
||||
'severity' => 'host_severity',
|
||||
'state_change' => 'host_last_state_change',
|
||||
'state' => 'host_state'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $hosts;
|
||||
$services = $this->createSubQuery(
|
||||
'Servicestatus',
|
||||
array(
|
||||
'handled' => 'service_handled',
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'host_problem',
|
||||
'host_state' => 'host_hard_state',
|
||||
'is_active_checked' => 'service_active_checks_enabled',
|
||||
'is_allowed_to_flap' => 'service_flap_detection_enabled',
|
||||
'is_flapping' => 'service_is_flapping',
|
||||
'is_passive_checked' => 'service_is_passive_checked',
|
||||
'is_processing_events' => 'service_event_handler_enabled',
|
||||
'is_triggering_notifications' => 'service_notifications_enabled',
|
||||
'object_type',
|
||||
'severity' => 'service_severity',
|
||||
'state_change' => 'service_last_state_change',
|
||||
'state' => 'service_state'
|
||||
)
|
||||
);
|
||||
$this->subQueries[] = $services;
|
||||
$this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->select->from(array('statussummary' => $this->summaryQuery), array());
|
||||
$this->joinedVirtualTables['hoststatussummary'] = true;
|
||||
$this->joinedVirtualTables['servicestatussummary'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function order($columnOrAlias, $dir = null)
|
||||
{
|
||||
if (! $this->hasAliasName($columnOrAlias)) {
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->requireColumn($columnOrAlias);
|
||||
}
|
||||
}
|
||||
return parent::order($columnOrAlias, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->requireColumn($condition);
|
||||
foreach ($this->subQueries as $sub) {
|
||||
$sub->where($condition, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -263,21 +263,21 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
|
|||
/**
|
||||
* View name to class name resolution
|
||||
*
|
||||
* @param string $viewName
|
||||
* @param string $view
|
||||
*
|
||||
* @return string
|
||||
* @throws ProgrammingError When the view does not exist
|
||||
*
|
||||
* @throws ProgrammingError In case the view does not exist
|
||||
*/
|
||||
protected function buildViewClassName($view)
|
||||
{
|
||||
$class = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($view);
|
||||
if (!class_exists($class)) {
|
||||
throw new ProgrammingError(
|
||||
'DataView %s does not exist',
|
||||
ucfirst($view)
|
||||
);
|
||||
$class = ucfirst(strtolower($view));
|
||||
$classPath = '\\Icinga\\Module\\Monitoring\\DataView\\' . $class;
|
||||
if (! class_exists($classPath)) {
|
||||
throw new ProgrammingError('DataView %s does not exist', $class);
|
||||
}
|
||||
return $class;
|
||||
|
||||
return $classPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -287,6 +287,8 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
|
|||
* @param array $columns Optional column list
|
||||
*
|
||||
* @return Icinga\Data\QueryInterface
|
||||
*
|
||||
* @throws ProgrammingError When the query does not exist for this backend
|
||||
*/
|
||||
public function query($name, $columns = null)
|
||||
{
|
||||
|
@ -318,16 +320,15 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
|
|||
/**
|
||||
* Query name to class name resolution
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query
|
||||
*
|
||||
* @return string
|
||||
* @throws ProgrammingError When the query does not exist for this backend
|
||||
*/
|
||||
protected function buildQueryClassName($query)
|
||||
{
|
||||
$parts = preg_split('~\\\~', get_class($this));
|
||||
array_pop($parts);
|
||||
array_push($parts, 'Query', ucfirst($query) . 'Query');
|
||||
array_push($parts, 'Query', ucfirst(strtolower($query)) . 'Query');
|
||||
return implode('\\', $parts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,9 +58,11 @@ class Controller extends IcingaWebController
|
|||
*/
|
||||
protected function applyRestriction($restriction, Filterable $view)
|
||||
{
|
||||
$restrictions = Filter::matchAny();
|
||||
foreach ($this->getRestrictions($restriction) as $filter) {
|
||||
$view->applyFilter(Filter::fromQueryString($filter));
|
||||
$restrictions->addFilter(Filter::fromQueryString($filter));
|
||||
}
|
||||
$view->applyFilter($restrictions);
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,32 +4,59 @@
|
|||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* View representation for comments
|
||||
* Host and service comments view
|
||||
*/
|
||||
class Comment extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'comment_objecttype',
|
||||
'comment_internal_id',
|
||||
'comment_data',
|
||||
'comment_author_name',
|
||||
'comment_data',
|
||||
'comment_expiration',
|
||||
'comment_internal_id',
|
||||
'comment_is_persistent',
|
||||
'comment_timestamp',
|
||||
'comment_type',
|
||||
'comment_is_persistent',
|
||||
'comment_expiration',
|
||||
'host_name',
|
||||
'service_description',
|
||||
'host_display_name',
|
||||
'host_name',
|
||||
'object_type',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_host_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'comment_author ',
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -55,12 +82,4 @@ class Comment extends DataView
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('comment_author', 'host', 'service', 'service_host');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,26 +3,32 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Describes the data needed by the 'Contact' DataView
|
||||
*/
|
||||
class Contact extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'contact_object_id',
|
||||
'contact_id',
|
||||
'contact_name',
|
||||
'contact_alias',
|
||||
'contact_email',
|
||||
'contact_pager',
|
||||
'contact_notify_hosts',
|
||||
'contact_notify_services',
|
||||
'contact_has_host_notfications',
|
||||
'contact_has_service_notfications',
|
||||
'contact_can_submit_commands',
|
||||
|
@ -37,33 +43,34 @@ class Contact extends DataView
|
|||
'contact_notify_host_unreachable',
|
||||
'contact_notify_host_flapping',
|
||||
'contact_notify_host_downtime',
|
||||
'contact_object_id',
|
||||
'host_object_id',
|
||||
'host_name',
|
||||
'service_object_id',
|
||||
'service_host_name',
|
||||
'service_description',
|
||||
'contact_notify_host_timeperiod',
|
||||
'contact_notify_service_timeperiod'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
'contact_alias' => array(
|
||||
'order' => self::SORT_DESC
|
||||
'contact_name' => array(
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('contact', 'alias', 'email', 'host', 'service', 'service_host');
|
||||
return array(
|
||||
'contact',
|
||||
'host', 'host_name', 'host_display_name', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,21 +3,30 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Describes the data needed by the Contactgroup DataView
|
||||
*/
|
||||
class Contactgroup extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'contactgroup_name',
|
||||
'contactgroup_alias',
|
||||
'contact_object_id',
|
||||
'contact_id',
|
||||
'contact_name',
|
||||
'contact_alias',
|
||||
'contact_email',
|
||||
|
@ -36,16 +45,13 @@ class Contactgroup extends DataView
|
|||
'contact_notify_host_unreachable',
|
||||
'contact_notify_host_flapping',
|
||||
'contact_notify_host_downtime',
|
||||
'host_name',
|
||||
'service_description',
|
||||
'service_host_name'
|
||||
'contact_notify_host_timeperiod',
|
||||
'contact_notify_service_timeperiod'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
|
@ -59,8 +65,17 @@ class Contactgroup extends DataView
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('contactgroup', 'contact', 'host', 'service', 'service_host');
|
||||
return array(
|
||||
'contactgroup', 'contact',
|
||||
'host', 'host_name', 'host_display_name', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,40 +3,70 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Host and service downtimes view
|
||||
*/
|
||||
class Downtime extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'downtime_objecttype',
|
||||
'downtime_author_name',
|
||||
'downtime_comment',
|
||||
'downtime_duration',
|
||||
'downtime_end',
|
||||
'downtime_entry_time',
|
||||
'downtime_internal_id',
|
||||
'downtime_is_fixed',
|
||||
'downtime_is_flexible',
|
||||
'downtime_start',
|
||||
'downtime_scheduled_start',
|
||||
'downtime_scheduled_end',
|
||||
'downtime_end',
|
||||
'downtime_duration',
|
||||
'downtime_is_in_effect',
|
||||
'downtime_triggered_by_id',
|
||||
'downtime_internal_id',
|
||||
'downtime_host_state',
|
||||
'downtime_service_state',
|
||||
'downtime_scheduled_end',
|
||||
'downtime_scheduled_start',
|
||||
'downtime_start',
|
||||
'host_display_name',
|
||||
'service_display_name',
|
||||
'host_name',
|
||||
'host_state',
|
||||
'object_type',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_host_name',
|
||||
'service_description'
|
||||
'service_state'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'downtime_author',
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
|
@ -66,9 +96,4 @@ class Downtime extends DataView
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('author', 'host', 'service', 'service_host');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,18 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
|
||||
class Eventgrid extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
|
@ -14,8 +26,6 @@ class Eventgrid extends DataView
|
|||
{
|
||||
return array(
|
||||
'day',
|
||||
'cnt_events',
|
||||
'objecttype_id',
|
||||
'cnt_up',
|
||||
'cnt_down_hard',
|
||||
'cnt_down',
|
||||
|
@ -29,13 +39,16 @@ class Eventgrid extends DataView
|
|||
'cnt_warning_hard',
|
||||
'cnt_ok',
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'service_description',
|
||||
'timestamp',
|
||||
'servicegroup_name',
|
||||
'hostgroup_name'
|
||||
'service_display_name',
|
||||
'timestamp'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
|
@ -45,8 +58,16 @@ class Eventgrid extends DataView
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('host', 'service', 'hostgroup', 'servicegroup');
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_host_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,18 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
|
||||
class EventHistory extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
|
@ -22,17 +34,17 @@ class EventHistory extends DataView
|
|||
'host_display_name',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'hostgroup_name',
|
||||
'object_type',
|
||||
'timestamp',
|
||||
'state',
|
||||
'attempt',
|
||||
'max_attempts',
|
||||
'output',
|
||||
'type'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
|
@ -43,8 +55,16 @@ class EventHistory extends DataView
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('host', 'service', 'hostgroup');
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Host comment view
|
||||
*/
|
||||
class Hostcomment extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'comment_author',
|
||||
'comment_author_name',
|
||||
'comment_data',
|
||||
'comment_expiration',
|
||||
'comment_internal_id',
|
||||
'comment_is_persistent',
|
||||
'comment_timestamp',
|
||||
'comment_type',
|
||||
'host_display_name',
|
||||
'host_name',
|
||||
'object_type'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Host downtime view
|
||||
*/
|
||||
class Hostdowntime extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'downtime_author',
|
||||
'downtime_author_name',
|
||||
'downtime_comment',
|
||||
'downtime_duration',
|
||||
'downtime_end',
|
||||
'downtime_entry_time',
|
||||
'downtime_internal_id',
|
||||
'downtime_is_fixed',
|
||||
'downtime_is_flexible',
|
||||
'downtime_is_in_effect',
|
||||
'downtime_scheduled_end',
|
||||
'downtime_scheduled_start',
|
||||
'downtime_start',
|
||||
'host_display_name',
|
||||
'host_name',
|
||||
'object_type'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
|
@ -4,44 +4,45 @@
|
|||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* View for hostgroups
|
||||
* Host group data view
|
||||
*/
|
||||
class Hostgroup extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'hostgroup_name',
|
||||
'hostgroup_alias',
|
||||
'hostgroup_id',
|
||||
'host_name'
|
||||
'hostgroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'hostgroup_name' => array(
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'hostgroup_alias' => array(
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterColumns()
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
return array('hostgroup', 'host');
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,16 @@ class Hostgroupsummary extends DataView
|
|||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'hosts_down_handled',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_down_handled_last_state_change',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_down_unhandled_last_state_change',
|
||||
'hosts_pending',
|
||||
'hosts_pending_last_state_change',
|
||||
'hosts_severity',
|
||||
'hosts_total',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'hosts_unreachable_handled_last_state_change',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_unreachable_unhandled_last_state_change',
|
||||
'hosts_up',
|
||||
'hosts_up_last_state_change',
|
||||
'services_critical_handled',
|
||||
|
@ -47,15 +46,13 @@ class Hostgroupsummary extends DataView
|
|||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('hostgroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getQueryName()
|
||||
{
|
||||
return 'groupsummary';
|
||||
return array(
|
||||
'hosts_severity',
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,4 +95,18 @@ class Hostgroupsummary extends DataView
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,7 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
class HostStatus extends DataView
|
||||
{
|
||||
/**
|
||||
* @see DataView::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->query->setMode('host');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
|
@ -76,9 +66,25 @@ class HostStatus extends DataView
|
|||
);
|
||||
}
|
||||
|
||||
public static function getQueryName()
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return 'status';
|
||||
return array(
|
||||
'host',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('host', 'host_display_name');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,11 +118,9 @@ class HostStatus extends DataView
|
|||
);
|
||||
}
|
||||
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('host', 'hostgroup', 'hostgroup_name', 'service', 'servicegroup', 'servicegroup_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
|
@ -126,12 +130,4 @@ class HostStatus extends DataView
|
|||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('host', 'host_display_name');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Data view for host status summaries
|
||||
*/
|
||||
class Hoststatussummary extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'hosts_down_handled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_total',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return in_array($column, $this->getFilterColumns());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,19 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
|
||||
class Notification extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
|
@ -13,30 +26,62 @@ class Notification extends DataView
|
|||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'host_name',
|
||||
'service_description',
|
||||
'notification_state',
|
||||
'notification_start_time',
|
||||
'notification_contact_name',
|
||||
'notification_output',
|
||||
'notification_command',
|
||||
'notification_object_id',
|
||||
'contact_object_id',
|
||||
'acknowledgement_entry_time',
|
||||
'acknowledgement_author_name',
|
||||
'acknowledgement_comment_data',
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
'host_name',
|
||||
'object_type',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_host_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
'notification_start_time' => array(
|
||||
'order' => self::SORT_DESC,
|
||||
'title' => 'Notification Start'
|
||||
),
|
||||
'host_display_name' => array(
|
||||
'columns' => array(
|
||||
'host_display_name',
|
||||
'service_display_name'
|
||||
),
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'service_display_name' => array(
|
||||
'columns' => array(
|
||||
'service_display_name',
|
||||
'host_display_name'
|
||||
),
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('host', 'service', 'contact');
|
||||
return array(
|
||||
'contact',
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Service comment view
|
||||
*/
|
||||
class Servicecomment extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'comment_author',
|
||||
'comment_author_name',
|
||||
'comment_data',
|
||||
'comment_expiration',
|
||||
'comment_internal_id',
|
||||
'comment_is_persistent',
|
||||
'comment_timestamp',
|
||||
'comment_type',
|
||||
'host_display_name',
|
||||
'host_name',
|
||||
'object_type',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_host_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
class Servicedowntime extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'downtime_author',
|
||||
'downtime_author_name',
|
||||
'downtime_comment',
|
||||
'downtime_duration',
|
||||
'downtime_end',
|
||||
'downtime_entry_time',
|
||||
'downtime_internal_id',
|
||||
'downtime_is_fixed',
|
||||
'downtime_is_flexible',
|
||||
'downtime_is_in_effect',
|
||||
'downtime_scheduled_end',
|
||||
'downtime_scheduled_start',
|
||||
'downtime_start',
|
||||
'host_display_name',
|
||||
'host_name',
|
||||
'object_type',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_host_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
|
@ -3,43 +3,45 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Service group view */
|
||||
class Servicegroup extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'servicegroup_name',
|
||||
'servicegroup_alias',
|
||||
'host_name',
|
||||
'service_host_name',
|
||||
'service_description'
|
||||
'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'servicegroup_name' => array(
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'servicegroup_alias' => array(
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup'
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterColumns()
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
return array('servicegroup', 'host', 'service');
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Data view for service group summaries
|
||||
*/
|
||||
class Servicegroupsummary extends DataView
|
||||
{
|
||||
/**
|
||||
|
@ -11,32 +14,25 @@ class Servicegroupsummary extends DataView
|
|||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'hosts_down_handled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'services_critical_handled',
|
||||
'services_critical_last_state_change_handled',
|
||||
'services_critical_last_state_change_unhandled',
|
||||
'services_critical_handled_last_state_change',
|
||||
'services_critical_unhandled',
|
||||
'services_critical_unhandled_last_state_change',
|
||||
'services_ok',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending',
|
||||
'services_pending_last_state_change',
|
||||
'services_severity',
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_unknown_last_state_change_unhandled',
|
||||
'services_unknown_handled_last_state_change',
|
||||
'services_unknown_unhandled',
|
||||
'services_unknown_unhandled_last_state_change',
|
||||
'services_warning_handled',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_warning_unhandled'
|
||||
'services_warning_handled_last_state_change',
|
||||
'services_warning_unhandled',
|
||||
'services_warning_unhandled_last_state_change'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -45,15 +41,13 @@ class Servicegroupsummary extends DataView
|
|||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('servicegroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getQueryName()
|
||||
{
|
||||
return 'groupsummary';
|
||||
return array(
|
||||
'services_severity',
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,4 +83,18 @@ class Servicegroupsummary extends DataView
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,10 +166,12 @@ class ServiceStatus extends DataView
|
|||
return array(
|
||||
'host',
|
||||
'hostgroup',
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'service',
|
||||
'service_host',
|
||||
'servicegroup',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name'
|
||||
);
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Data view for service status summaries
|
||||
*/
|
||||
class Servicestatussummary extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'services_critical',
|
||||
'services_critical_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_pending',
|
||||
'services_total',
|
||||
'services_unknown',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return in_array($column, $this->getFilterColumns());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,4 +96,31 @@ class StatusSummary extends DataView
|
|||
'services_unknown_not_checked_on_problem_hosts'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array(
|
||||
'host', 'host_alias', 'host_display_name', 'host_name',
|
||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||
'service', 'service_description', 'service_display_name',
|
||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValidFilterTarget($column)
|
||||
{
|
||||
if ($column[0] === '_'
|
||||
&& preg_match('/^_(?:host|service)_/', $column)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return in_array($column, $this->getFilterColumns());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -137,7 +137,7 @@ class Host extends MonitoredObject
|
|||
if ($this->backend->getType() === 'livestatus') {
|
||||
$columns[] = 'host_contacts';
|
||||
}
|
||||
return $this->backend->select()->from('hostStatus', $columns)
|
||||
return $this->backend->select()->from('hoststatus', $columns)
|
||||
->where('host_name', $this->host);
|
||||
}
|
||||
|
||||
|
@ -149,10 +149,10 @@ class Host extends MonitoredObject
|
|||
public function fetchServices()
|
||||
{
|
||||
$services = array();
|
||||
foreach ($this->backend->select()->from('serviceStatus', array('service_description'))
|
||||
foreach ($this->backend->select()->from('servicestatus', array('service_description'))
|
||||
->where('host_name', $this->host)
|
||||
->getQuery()
|
||||
->fetchAll() as $service) {
|
||||
->applyFilter($this->getFilter())
|
||||
->getQuery() as $service) {
|
||||
$services[] = new Service($this->backend, $this->host, $service->service_description);
|
||||
}
|
||||
$this->services = $services;
|
||||
|
|
|
@ -12,7 +12,7 @@ use Icinga\Util\String;
|
|||
*/
|
||||
class HostList extends ObjectList
|
||||
{
|
||||
protected $dataViewName = 'hostStatus';
|
||||
protected $dataViewName = 'hoststatus';
|
||||
|
||||
protected $columns = array('host_name');
|
||||
|
||||
|
@ -87,17 +87,30 @@ class HostList extends ObjectList
|
|||
return FilterOr::matchAny($filterExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comments
|
||||
*
|
||||
* @return \Icinga\Module\Monitoring\DataView\Hostcomment
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->backend
|
||||
->select()
|
||||
->from('hostcomment', array('host_name'))
|
||||
->applyFilter(clone $this->filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scheduled downtimes
|
||||
*
|
||||
* @return type
|
||||
* @return \Icinga\Module\Monitoring\DataView\Hostdowntime
|
||||
*/
|
||||
public function getScheduledDowntimes()
|
||||
{
|
||||
return $this->backend->select()
|
||||
->from('downtime')
|
||||
->applyFilter(clone $this->filter)
|
||||
->where('downtime_objecttype', 'host');
|
||||
return $this->backend
|
||||
->select()
|
||||
->from('hostdowntime', array('host_name'))
|
||||
->applyFilter(clone $this->filter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -155,7 +155,7 @@ abstract class MonitoredObject implements Filterable
|
|||
public function getFilter()
|
||||
{
|
||||
if ($this->filter === null) {
|
||||
$this->filter = Filter::matchAny();
|
||||
$this->filter = Filter::matchAll();
|
||||
}
|
||||
return $this->filter;
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ abstract class MonitoredObject implements Filterable
|
|||
'type' => 'comment_type',
|
||||
))
|
||||
->where('comment_type', array('comment', 'ack'))
|
||||
->where('comment_objecttype', $this->type);
|
||||
->where('object_type', $this->type);
|
||||
if ($this->type === self::TYPE_SERVICE) {
|
||||
$comments
|
||||
->where('service_host_name', $this->host_name)
|
||||
|
@ -274,7 +274,7 @@ abstract class MonitoredObject implements Filterable
|
|||
{
|
||||
$downtimes = $this->backend->select()->from('downtime', array(
|
||||
'id' => 'downtime_internal_id',
|
||||
'objecttype' => 'downtime_objecttype',
|
||||
'objecttype' => 'object_type',
|
||||
'comment' => 'downtime_comment',
|
||||
'author_name' => 'downtime_author_name',
|
||||
'start' => 'downtime_start',
|
||||
|
@ -286,7 +286,7 @@ abstract class MonitoredObject implements Filterable
|
|||
'is_in_effect' => 'downtime_is_in_effect',
|
||||
'entry_time' => 'downtime_entry_time'
|
||||
))
|
||||
->where('downtime_objecttype', $this->type)
|
||||
->where('object_type', $this->type)
|
||||
->order('downtime_is_in_effect', 'DESC')
|
||||
->order('downtime_scheduled_start', 'ASC');
|
||||
if ($this->type === self::TYPE_SERVICE) {
|
||||
|
@ -308,12 +308,11 @@ abstract class MonitoredObject implements Filterable
|
|||
*/
|
||||
public function fetchHostgroups()
|
||||
{
|
||||
$hostGroups = $this->backend->select()->from('hostgroup', array(
|
||||
'hostgroup_name',
|
||||
'hostgroup_alias'
|
||||
))
|
||||
->where('host_name', $this->host);
|
||||
$this->hostgroups = $hostGroups->getQuery()->fetchPairs();
|
||||
$this->hostgroups = $this->backend->select()
|
||||
->from('hostgroup', array('hostgroup_name', 'hostgroup_alias'))
|
||||
->where('host_name', $this->host_name)
|
||||
->applyFilter($this->getFilter())
|
||||
->fetchPairs();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -396,7 +395,7 @@ abstract class MonitoredObject implements Filterable
|
|||
} else {
|
||||
$contacts->where('host_name', $this->host_name);
|
||||
}
|
||||
$this->contacts = $contacts->getQuery()->fetchAll();
|
||||
$this->contacts = $contacts->applyFilter($this->getFilter())->getQuery()->fetchAll();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -407,13 +406,12 @@ abstract class MonitoredObject implements Filterable
|
|||
*/
|
||||
public function fetchServicegroups()
|
||||
{
|
||||
$serviceGroups = $this->backend->select()->from('servicegroup', array(
|
||||
'servicegroup_name',
|
||||
'servicegroup_alias'
|
||||
))
|
||||
->where('service_host_name', $this->host_name)
|
||||
->where('service_description', $this->service_description);
|
||||
$this->servicegroups = $serviceGroups->getQuery()->fetchPairs();
|
||||
$this->servicegroups = $this->backend->select()
|
||||
->from('servicegroup', array('servicegroup_name', 'servicegroup_alias'))
|
||||
->where('host_name', $this->host_name)
|
||||
->where('service_description', $this->service_description)
|
||||
->applyFilter($this->getFilter())
|
||||
->fetchPairs();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -440,7 +438,7 @@ abstract class MonitoredObject implements Filterable
|
|||
} else {
|
||||
$contactsGroups->where('host_name', $this->host_name);
|
||||
}
|
||||
$this->contactgroups = $contactsGroups->getQuery()->fetchAll();
|
||||
$this->contactgroups = $contactsGroups->applyFilter($this->getFilter())->getQuery()->fetchAll();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -451,7 +449,7 @@ abstract class MonitoredObject implements Filterable
|
|||
*/
|
||||
public function fetchEventhistory()
|
||||
{
|
||||
$eventHistory = $this->backend->select()->from('eventHistory', array(
|
||||
$eventHistory = $this->backend->select()->from('eventhistory', array(
|
||||
'object_type',
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
|
@ -459,8 +457,6 @@ abstract class MonitoredObject implements Filterable
|
|||
'service_display_name',
|
||||
'timestamp',
|
||||
'state',
|
||||
'attempt',
|
||||
'max_attempts',
|
||||
'output',
|
||||
'type'
|
||||
))
|
||||
|
@ -468,7 +464,7 @@ abstract class MonitoredObject implements Filterable
|
|||
if ($this->type === self::TYPE_SERVICE) {
|
||||
$eventHistory->where('service_description', $this->service_description);
|
||||
}
|
||||
$this->eventhistory = $eventHistory;
|
||||
$this->eventhistory = $eventHistory->applyFilter($this->getFilter());
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -479,12 +475,9 @@ abstract class MonitoredObject implements Filterable
|
|||
*/
|
||||
public function fetchStats()
|
||||
{
|
||||
$this->stats = $this->backend->select()->from('statusSummary', array(
|
||||
$this->stats = $this->backend->select()->from('servicestatussummary', array(
|
||||
'services_total',
|
||||
'services_ok',
|
||||
'services_problem',
|
||||
'services_problem_handled',
|
||||
'services_problem_unhandled',
|
||||
'services_critical',
|
||||
'services_critical_unhandled',
|
||||
'services_critical_handled',
|
||||
|
@ -497,7 +490,7 @@ abstract class MonitoredObject implements Filterable
|
|||
'services_pending',
|
||||
))
|
||||
->where('service_host_name', $this->host_name)
|
||||
->getQuery()
|
||||
->applyFilter($this->getFilter())
|
||||
->fetchRow();
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ namespace Icinga\Module\Monitoring\Object;
|
|||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filterable;
|
||||
use IteratorAggregate;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
|
||||
abstract class ObjectList implements Countable, IteratorAggregate
|
||||
abstract class ObjectList implements Countable, IteratorAggregate, Filterable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
@ -66,11 +67,11 @@ abstract class ObjectList implements Countable, IteratorAggregate
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilter($filter)
|
||||
public function setFilter(Filter $filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
return $this;
|
||||
|
@ -81,9 +82,29 @@ abstract class ObjectList implements Countable, IteratorAggregate
|
|||
*/
|
||||
public function getFilter()
|
||||
{
|
||||
if ($this->filter === null) {
|
||||
$this->filter = Filter::matchAny();
|
||||
}
|
||||
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function applyFilter(Filter $filter)
|
||||
{
|
||||
$this->getFilter()->addFilter($filter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->getFilter()->addFilter($filter);
|
||||
}
|
||||
|
||||
public function where($condition, $value = null)
|
||||
{
|
||||
$this->getFilter()->addFilter(Filter::where($condition, $value));
|
||||
}
|
||||
|
||||
abstract protected function fetchObjects();
|
||||
|
||||
/**
|
||||
|
|
|
@ -105,7 +105,7 @@ class Service extends MonitoredObject
|
|||
*/
|
||||
protected function getDataView()
|
||||
{
|
||||
return $this->backend->select()->from('serviceStatus', array(
|
||||
return $this->backend->select()->from('servicestatus', array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_acknowledged',
|
||||
|
|
|
@ -16,7 +16,7 @@ class ServiceList extends ObjectList
|
|||
|
||||
protected $serviceStateSummary;
|
||||
|
||||
protected $dataViewName = 'serviceStatus';
|
||||
protected $dataViewName = 'servicestatus';
|
||||
|
||||
protected $columns = array('host_name', 'service_description');
|
||||
|
||||
|
@ -135,17 +135,30 @@ class ServiceList extends ObjectList
|
|||
return FilterOr::matchAny($filterExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comments
|
||||
*
|
||||
* @return \Icinga\Module\Monitoring\DataView\Hostcomment
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->backend
|
||||
->select()
|
||||
->from('servicecomment', array('host_name', 'service_description'))
|
||||
->applyFilter(clone $this->filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scheduled downtimes
|
||||
*
|
||||
* @return type
|
||||
* @return \Icinga\Module\Monitoring\DataView\Servicedowntime
|
||||
*/
|
||||
public function getScheduledDowntimes()
|
||||
{
|
||||
return $this->backend->select()
|
||||
->from('downtime')
|
||||
->applyFilter(clone $this->filter)
|
||||
->where('downtime_objecttype', 'service');
|
||||
return $this->backend
|
||||
->select()
|
||||
->from('servicedowntime', array('host_name', 'service_description'))
|
||||
->applyFilter(clone $this->filter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -100,6 +100,7 @@ abstract class MonitoredObjectController extends Controller
|
|||
{
|
||||
$this->getTabs()->activate('history');
|
||||
$this->view->history = $this->object->fetchEventHistory()->eventhistory;
|
||||
$this->applyRestriction('monitoring/filter/objects', $this->view->history);
|
||||
|
||||
$this->setupLimitControl(50);
|
||||
$this->setupPaginationControl($this->view->history, 50);
|
||||
|
@ -210,7 +211,7 @@ abstract class MonitoredObjectController extends Controller
|
|||
'urlParams' => $params
|
||||
)
|
||||
);
|
||||
if ($this->backend->hasQuery('eventHistory')) {
|
||||
if ($this->backend->hasQuery('eventhistory')) {
|
||||
$tabs->add(
|
||||
'history',
|
||||
array(
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Web\Menu;
|
||||
|
||||
use Icinga\Web\Menu as Menu;
|
||||
use Icinga\Authentication\Manager;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filterable;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Web\Menu\MenuItemRenderer;
|
||||
|
||||
|
@ -13,16 +16,36 @@ class MonitoringMenuItemRenderer extends MenuItemRenderer
|
|||
|
||||
protected $columns = array();
|
||||
|
||||
/**
|
||||
* Apply a restriction on the given data view
|
||||
*
|
||||
* @param string $restriction The name of restriction
|
||||
* @param Filterable $filterable The filterable to restrict
|
||||
*
|
||||
* @return Filterable The filterable
|
||||
*/
|
||||
protected static function applyRestriction($restriction, Filterable $filterable)
|
||||
{
|
||||
$restrictions = Filter::matchAny();
|
||||
foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
|
||||
$restrictions->addFilter(Filter::fromQueryString($filter));
|
||||
}
|
||||
$filterable->applyFilter($restrictions);
|
||||
return $filterable;
|
||||
}
|
||||
|
||||
protected static function summary($column = null)
|
||||
{
|
||||
if (self::$summary === null) {
|
||||
self::$summary = MonitoringBackend::instance()->select()->from(
|
||||
'statusSummary',
|
||||
$summary = MonitoringBackend::instance()->select()->from(
|
||||
'statussummary',
|
||||
array(
|
||||
'hosts_down_unhandled',
|
||||
'services_critical_unhandled'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
);
|
||||
static::applyRestriction('monitoring/filter/objects', $summary);
|
||||
self::$summary = $summary->fetchRow();
|
||||
}
|
||||
|
||||
if ($column === null) {
|
||||
|
|
Loading…
Reference in New Issue