Skip to content

Commit

Permalink
Avoid host non-ok for service_handled for option host_never_unhandled
Browse files Browse the repository at this point in the history
fixes #20
  • Loading branch information
lazyfrosch committed Oct 17, 2017
1 parent cbd6e97 commit aa380b8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions library/Toplevelview/Monitoring/HostgroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function init()
'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_handled_wo_host' => 'CASE WHEN ss.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
),
'hoststatus' => array(
Expand Down
6 changes: 4 additions & 2 deletions library/Toplevelview/Monitoring/Hostgroupsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ class Hostgroupsummary extends IcingaHostgroupsummary
public function __construct(
ConnectionInterface $connection,
array $columns = null,
$notification_periods = false
$notification_periods = false,
$host_never_unhandled = false
) {
/** @var MonitoringBackend $connection */
$this->connection = $connection;
$this->query = new HostgroupsummaryQuery(
$connection->getResource(),
$columns,
$notification_periods
$notification_periods,
$host_never_unhandled
);
}
}
18 changes: 15 additions & 3 deletions library/Toplevelview/Monitoring/HostgroupsummaryQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
class HostgroupsummaryQuery extends IcingaHostgroupsummaryQuery
{
protected $notification_periods = false;
protected $host_never_unhandled = false;

public function __construct($ds, $columns = null, $notification_periods = false)
public function __construct($ds, $columns = null, $notification_periods = false, $host_never_unhandled = false)
{
$this->notification_periods = $notification_periods;
$this->host_never_unhandled = $host_never_unhandled;
parent::__construct($ds, $columns);
}

Expand All @@ -29,10 +31,18 @@ public function init()
$serviceOutDowntime = 'service_notifications_enabled = 1 AND service_in_downtime = 0';
$serviceInDowntime = '(service_notifications_enabled = 0 OR service_in_downtime = 1)';
}

$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";
$patchServicesUnhandled = "service_handled = 0 AND service_is_flapping = 0 AND $serviceOutDowntime";

if ($this->host_never_unhandled === true) {
$patchServicesHandled = "(service_handled_wo_host = 1 OR service_is_flapping = 1) AND $serviceOutDowntime";
$patchServicesUnhandled = "service_handled_wo_host = 0 AND service_is_flapping = 0 AND $serviceOutDowntime";
} else {
$patchServicesHandled = "(service_handled = 1 OR service_is_flapping = 1) AND $serviceOutDowntime";
$patchServicesUnhandled = "service_handled = 0 AND service_is_flapping = 0 AND $serviceOutDowntime";
}

$patchHostsHandled = "(host_handled = 1 OR host_is_flapping = 1) AND $hostOutDowntime";
$patchHostsUnhandled = "host_handled = 0 AND host_is_flapping = 0 AND $hostOutDowntime";

Expand Down Expand Up @@ -88,6 +98,7 @@ protected function joinBaseTables()
'host_is_flapping',
'host_in_downtime',
'service_handled' => new Zend_Db_Expr('NULL'),
'service_handled_wo_host' => 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'),
Expand All @@ -103,6 +114,7 @@ protected function joinBaseTables()
'host_is_flapping' => new Zend_Db_Expr('NULL'),
'host_in_downtime' => new Zend_Db_Expr('NULL'),
'service_handled',
'service_handled_wo_host',
'service_state',
'service_notifications_enabled',
'service_is_flapping',
Expand Down
3 changes: 3 additions & 0 deletions library/Toplevelview/Monitoring/ServicestatusQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class ServicestatusQuery extends IcingaServicestatusQuery
public function init()
{
$patchedColumnMap = array(
'servicestatus' => array(
'service_handled_wo_host' => 'CASE WHEN ss.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
),
'servicenotificationperiod' => array(
'service_notification_period' => 'ntpo.name1',
'service_in_notification_period' => 'CASE WHEN s.notification_timeperiod_object_id IS NULL THEN 1 ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL THEN 1 ELSE 0 END END',
Expand Down
4 changes: 2 additions & 2 deletions library/Toplevelview/Tree/TLVHostGroupNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Icinga\Application\Benchmark;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Toplevelview\Monitoring\Hostgroupsummary;
use Icinga\Module\Toplevelview\Monitoring\HostgroupsummaryQuery;

class TLVHostGroupNode extends TLVIcingaNode
{
Expand Down Expand Up @@ -50,7 +49,8 @@ public static function fetch(TLVTree $root)
'services_downtime_handled',
'services_downtime_active',
),
$root->get('notification_periods')
$root->get('notification_periods'),
$root->get('host_never_unhandled')
);

$hostgroups->where('hostgroup_name', $names);
Expand Down
13 changes: 9 additions & 4 deletions library/Toplevelview/Tree/TLVServiceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function fetch(TLVTree $root)
'service_description',
'service_hard_state',
'service_handled',
'service_handled_wo_host',
'service_notifications_enabled',
'service_notification_period',
'service_is_flapping',
Expand Down Expand Up @@ -94,6 +95,13 @@ public function getStatus()
$notInPeriod = false;
}

if ($this->getRoot()->get('host_never_unhandled') === true) {
$isHandled = $data->service_handled_wo_host === '1';
} else {
$isHandled = $data->service_handled === '1';
}
$isHandled = $isHandled || $data->service_is_flapping === '1';

if (
$data->service_in_downtime > 0
|| $data->service_notifications_enabled === '0'
Expand All @@ -105,10 +113,7 @@ public function getStatus()
}
}

if (
$data->service_handled === '1'
|| $data->service_is_flapping === '1'
) {
if ($isHandled) {
$handled = '_handled';
} else {
$handled = '_unhandled';
Expand Down

0 comments on commit aa380b8

Please sign in to comment.