Skip to content

Commit

Permalink
TLVHostgroupNode: Set downtime_handled based on service_in_notificati…
Browse files Browse the repository at this point in the history
…on_period

refs #2
  • Loading branch information
lazyfrosch committed Oct 11, 2017
1 parent 9b6c26b commit efd24df
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 23 deletions.
42 changes: 33 additions & 9 deletions library/Toplevelview/Monitoring/HostgroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,30 @@

/**
* Patched version of HostgroupQuery
*
* Changes:
* - add service_notifications_enabled to servicestatus join
*/
class HostgroupQuery extends IcingaHostgroupQuery
{
public function init()
{
$patchedColumnMap = array(
'servicestatus' => array(
'service_notifications_enabled' => 'ss.notifications_enabled',
'service_is_flapping' => 'ss.is_flapping',
'service_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_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'service_notifications_enabled' => 'ss.notifications_enabled',
'service_is_flapping' => 'ss.is_flapping',
'service_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_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
),
'hoststatus' => array(
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_is_flapping' => 'hs.is_flapping',
'host_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_handled' => 'CASE WHEN hs.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
)
),
'servicenotificationperiod' => array(
'service_notification_period' => 'ntpo.name1',
'service_in_notification_period' => 'CASE WHEN ntpr.timeperiod_id IS NOT NULL THEN 1 ELSE 0 END',
),
);

foreach ($patchedColumnMap as $table => $columns) {
Expand All @@ -40,4 +41,27 @@ public function init()

parent::init();
}

protected function joinServicenotificationperiod()
{
$this->select->joinLeft(
array('ntp' => $this->prefix . 'timeperiods'),
'ntp.timeperiod_object_id = s.notification_timeperiod_object_id AND ntp.config_type = 1 AND ntp.instance_id = s.instance_id',
array()
);
$this->select->joinLeft(
array('ntpo' => $this->prefix . 'objects'),
'ntpo.object_id = s.notification_timeperiod_object_id',
array()
);
$this->select->joinLeft(
array('ntpr' => $this->prefix . 'timeperiod_timeranges'),
'ntpr.timeperiod_id = ntp.timeperiod_id
AND ntpr.day = DAYOFWEEK(UTC_DATE())
AND ntpr.start_sec <= UNIX_TIMESTAMP() - UNIX_TIMESTAMP(UTC_DATE())
AND ntpr.end_sec >= UNIX_TIMESTAMP() - UNIX_TIMESTAMP(UTC_DATE())
',
array()
);
}
}
23 changes: 9 additions & 14 deletions library/Toplevelview/Monitoring/HostgroupsummaryQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@

/**
* Patched version of HostgroupsummaryQuery
*
* Changes:
* - join service_notifications_enabled from status tables
* - modify handled logic to include disabled notifications and flapping
* - use patched version of HostgroupQuery for subQueries
*/
class HostgroupsummaryQuery extends IcingaHostgroupsummaryQuery
{
public function init()
{
// TODO: service_notification_period

$serviceOutDowntime = 'service_notifications_enabled = 1 AND service_in_downtime = 0';
$serviceInDowntime = '(service_notifications_enabled = 0 OR service_in_downtime = 1)';
$serviceOutDowntime = 'service_notifications_enabled = 1 AND service_in_downtime = 0 AND service_in_notification_period = 1';
$serviceInDowntime = '(service_notifications_enabled = 0 OR service_in_downtime = 1 OR service_in_notification_period = 0)';
$hostOutDowntime = 'host_notifications_enabled = 1 AND host_in_downtime = 0';
$hostInDowntime = '(host_notifications_enabled = 0 OR host_in_downtime = 1)';
$patchServicesHandled = "(service_handled = 1 OR service_is_flapping = 1) AND $serviceOutDowntime";
Expand Down Expand Up @@ -83,11 +76,12 @@ protected function joinBaseTables()
'host_state',
'host_is_flapping',
'host_in_downtime',
'service_handled' => new Zend_Db_Expr('NULL'),
'service_state' => new Zend_Db_Expr('NULL'),
'service_notifications_enabled' => new Zend_Db_Expr('NULL'),
'service_is_flapping' => new Zend_Db_Expr('NULL'),
'service_in_downtime' => new Zend_Db_Expr('NULL'),
'service_handled' => new Zend_Db_Expr('NULL'),
'service_state' => new Zend_Db_Expr('NULL'),
'service_notifications_enabled' => new Zend_Db_Expr('NULL'),
'service_in_notification_period' => new Zend_Db_Expr('NULL'),
'service_is_flapping' => new Zend_Db_Expr('NULL'),
'service_in_downtime' => new Zend_Db_Expr('NULL'),
)
);
$this->subQueries[] = $hosts;
Expand All @@ -104,6 +98,7 @@ protected function joinBaseTables()
'service_handled',
'service_state',
'service_notifications_enabled',
'service_in_notification_period',
'service_is_flapping',
'service_in_downtime',
)
Expand Down
38 changes: 38 additions & 0 deletions library/Toplevelview/Monitoring/Servicestatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/* Copyright (C) 2017 Icinga Development Team <info@icinga.com> */

namespace Icinga\Module\Toplevelview\Monitoring;

use Icinga\Data\ConnectionInterface;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Module\Monitoring\DataView\ServiceStatus as IcingaServiceStatus;

class ServiceStatus extends IcingaServiceStatus
{
/** @noinspection PhpMissingParentConstructorInspection */
/**
* @param ConnectionInterface $connection
* @param array|null $columns
* @noinspection PhpMissingParentConstructorInspection
*/
public function __construct(ConnectionInterface $connection, array $columns = null)
{
/** @var MonitoringBackend $connection */
$this->connection = $connection;
$this->query = new ServicestatusQuery($connection->getResource(), $columns);
}

/**
* {@inheritdoc}
*/
public function getColumns()
{
return array_merge(
parent::getColumns(),
array(
//'service_in_notification_period',
'servicenotificationperiod_name',
)
);
}
}
43 changes: 43 additions & 0 deletions library/Toplevelview/Monitoring/ServicestatusQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* Copyright (C) 2017 Icinga Development Team <info@icinga.com> */

namespace Icinga\Module\Toplevelview\Monitoring;

use Icinga\Module\Monitoring\Backend\Ido\Query\HostgroupQuery as IcingaHostgroupQuery;

/**
* Patched version of HostgroupQuery
*
* Changes:
* - add service_notifications_enabled to servicestatus join
*/
class HostgroupQuery extends IcingaHostgroupQuery
{
public function init()
{
$patchedColumnMap = array(
'servicestatus' => array(
'service_notifications_enabled' => 'ss.notifications_enabled',
'service_is_flapping' => 'ss.is_flapping',
'service_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_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
),
'hoststatus' => array(
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_is_flapping' => 'hs.is_flapping',
'host_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_handled' => 'CASE WHEN hs.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
)
);

foreach ($patchedColumnMap as $table => $columns) {
foreach ($columns as $k => $v) {
$this->columnMap[$table][$k] = $v;
}
}

parent::init();
}
}

0 comments on commit efd24df

Please sign in to comment.