icingadb-web/library/Icingadb/Util/FeatureStatus.php
Eric Lippmann 272e791390 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-11 14:03:05 +01:00

51 lines
1.6 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2021 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Icingadb\Util;
use ArrayObject;
use Icinga\Module\Icingadb\Command\Object\ToggleObjectFeatureCommand;
class FeatureStatus extends ArrayObject
{
public function __construct(string $type, $summary)
{
$prefix = "{$type}s";
$featureStatus = [
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS =>
$this->getFeatureStatus('active_checks_enabled', $prefix, $summary),
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS =>
$this->getFeatureStatus('passive_checks_enabled', $prefix, $summary),
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS =>
$this->getFeatureStatus('notifications_enabled', $prefix, $summary),
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER =>
$this->getFeatureStatus('event_handler_enabled', $prefix, $summary),
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION =>
$this->getFeatureStatus('flapping_enabled', $prefix, $summary)
];
parent::__construct($featureStatus, ArrayObject::ARRAY_AS_PROPS);
}
protected function getFeatureStatus(string $feature, string $prefix, $summary): int
{
$key = "{$prefix}_{$feature}";
$value = (int) $summary->$key;
if ($value === 0) {
return 0;
}
$totalKey = "{$prefix}_total";
$total = (int) $summary->$totalKey;
if ($value === $total) {
return 1;
}
return 2;
}
}