2019-09-09 07:17:02 -04:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-13 03:38:01 -04:00
|
|
|
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
|
|
|
|
|
|
2019-11-04 19:07:30 -05:00
|
|
|
namespace Icinga\Module\Icingadb\Model;
|
2019-09-09 07:17:02 -04:00
|
|
|
|
2023-09-04 07:40:56 -04:00
|
|
|
use DateTime;
|
2024-12-17 08:57:00 -05:00
|
|
|
use Icinga\Module\Icingadb\Common\Backend;
|
2023-06-15 03:17:45 -04:00
|
|
|
use Icinga\Module\Icingadb\Common\Icons;
|
2025-06-05 10:56:46 -04:00
|
|
|
use ipl\Orm\Behavior\BoolCast;
|
2022-05-19 10:28:45 -04:00
|
|
|
use ipl\Orm\Behavior\Binary;
|
2023-05-30 10:05:11 -04:00
|
|
|
use ipl\Orm\Behavior\MillisecondTimestamp;
|
2019-10-11 09:52:11 -04:00
|
|
|
use ipl\Orm\Behaviors;
|
2019-09-09 07:17:02 -04:00
|
|
|
use ipl\Orm\Model;
|
2023-06-15 03:17:45 -04:00
|
|
|
use ipl\Web\Widget\Icon;
|
2019-09-09 07:17:02 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for the {@link HostState} and {@link ServiceState} models providing common columns.
|
2023-09-04 07:40:56 -04:00
|
|
|
*
|
2024-03-14 06:52:09 -04:00
|
|
|
* @property string $id
|
2023-09-04 07:40:56 -04:00
|
|
|
* @property string $environment_id The environment id
|
|
|
|
|
* @property string $state_type The state type (hard or soft)
|
|
|
|
|
* @property int $soft_state The current soft state code (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN)
|
|
|
|
|
* @property int $hard_state The current hard state code (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN)
|
|
|
|
|
* @property int $previous_soft_state The previous soft state code (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN)
|
|
|
|
|
* @property int $previous_hard_state The previous hard state code (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN)
|
|
|
|
|
* @property int $check_attempt The check attempt count
|
|
|
|
|
* @property int $severity The calculated severity
|
|
|
|
|
* @property ?string $output The check output
|
|
|
|
|
* @property ?string $long_output The long check output
|
|
|
|
|
* @property ?string $performance_data The performance data
|
|
|
|
|
* @property ?string $normalized_performance_data The normalized performance data (converted ms to s, GiB to byte etc.)
|
|
|
|
|
* @property ?string $check_commandline The executed check command
|
|
|
|
|
* @property bool $is_problem Whether in non-OK state
|
|
|
|
|
* @property bool $is_handled Whether the state is handled
|
|
|
|
|
* @property bool $is_reachable Whether the node is reachable
|
|
|
|
|
* @property bool $is_flapping Whether the state is flapping
|
|
|
|
|
* @property bool $is_overdue Whether the check is overdue
|
2025-06-03 05:58:19 -04:00
|
|
|
* @property bool $is_acknowledged Whether the state is acknowledged
|
|
|
|
|
* @property bool $is_sticky_acknowledgement Whether the acknowledgement is sticky
|
2023-09-04 07:40:56 -04:00
|
|
|
* @property ?string $acknowledgement_comment_id The id of acknowledgement comment
|
|
|
|
|
* @property ?string $last_comment_id The id of last comment
|
|
|
|
|
* @property bool $in_downtime Whether the node is in downtime
|
|
|
|
|
* @property ?int $execution_time The check execution time
|
|
|
|
|
* @property ?int $latency The check latency
|
|
|
|
|
* @property ?int $check_timeout The check timeout
|
|
|
|
|
* @property ?string $check_source The name of the node that executes the check
|
|
|
|
|
* @property ?string $scheduling_source The name of the node that schedules the check
|
|
|
|
|
* @property ?DateTime $last_update The time when the node was last updated
|
2024-03-14 06:52:09 -04:00
|
|
|
* @property DateTime $last_state_change The time when the node last got a status change
|
|
|
|
|
* @property DateTime $next_check The time when the node will execute the next check
|
|
|
|
|
* @property DateTime $next_update The time when the next check of the node is expected to end
|
2024-09-22 19:36:04 -04:00
|
|
|
* @property bool $affects_children Whether any of the children is affected if there is a problem
|
2019-09-09 07:17:02 -04:00
|
|
|
*/
|
|
|
|
|
abstract class State extends Model
|
|
|
|
|
{
|
2023-08-21 08:13:32 -04:00
|
|
|
/**
|
|
|
|
|
* Get the state as the textual representation
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
abstract public function getStateText(): string;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state as the translated textual representation
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
abstract public function getStateTextTranslated(): string;
|
|
|
|
|
|
2019-09-09 07:17:02 -04:00
|
|
|
public function getColumns()
|
|
|
|
|
{
|
2024-12-17 08:57:00 -05:00
|
|
|
$columns = [
|
2019-09-23 09:31:18 -04:00
|
|
|
'environment_id',
|
2019-09-09 07:17:02 -04:00
|
|
|
'state_type',
|
|
|
|
|
'soft_state',
|
|
|
|
|
'hard_state',
|
2022-02-24 11:27:25 -05:00
|
|
|
'previous_soft_state',
|
2019-11-19 08:24:09 -05:00
|
|
|
'previous_hard_state',
|
2022-06-23 08:36:05 -04:00
|
|
|
'check_attempt',
|
2019-09-09 07:17:02 -04:00
|
|
|
'severity',
|
|
|
|
|
'output',
|
|
|
|
|
'long_output',
|
|
|
|
|
'performance_data',
|
2021-07-16 09:32:39 -04:00
|
|
|
'normalized_performance_data',
|
2019-09-09 07:17:02 -04:00
|
|
|
'check_commandline',
|
|
|
|
|
'is_problem',
|
|
|
|
|
'is_handled',
|
|
|
|
|
'is_reachable',
|
|
|
|
|
'is_flapping',
|
2019-12-04 07:44:09 -05:00
|
|
|
'is_overdue',
|
2019-09-09 07:17:02 -04:00
|
|
|
'is_acknowledged',
|
|
|
|
|
'acknowledgement_comment_id',
|
2021-08-12 05:42:09 -04:00
|
|
|
'last_comment_id',
|
2019-09-09 07:17:02 -04:00
|
|
|
'in_downtime',
|
|
|
|
|
'execution_time',
|
|
|
|
|
'latency',
|
2022-06-23 08:36:05 -04:00
|
|
|
'check_timeout',
|
2019-11-05 06:25:11 -05:00
|
|
|
'check_source',
|
2021-09-28 07:22:46 -04:00
|
|
|
'scheduling_source',
|
2019-09-09 07:17:02 -04:00
|
|
|
'last_update',
|
|
|
|
|
'last_state_change',
|
2019-09-23 09:31:18 -04:00
|
|
|
'next_check',
|
2024-12-17 08:57:00 -05:00
|
|
|
'next_update'
|
2019-09-09 07:17:02 -04:00
|
|
|
];
|
2024-12-17 08:57:00 -05:00
|
|
|
|
2025-01-13 05:29:53 -05:00
|
|
|
if (Backend::supportsDependencies()) {
|
2024-12-17 08:57:00 -05:00
|
|
|
$columns[] = 'affects_children';
|
2025-06-03 05:58:19 -04:00
|
|
|
$columns[] = 'is_sticky_acknowledgement';
|
2024-12-17 08:57:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $columns;
|
2019-09-09 07:17:02 -04:00
|
|
|
}
|
2019-10-10 03:49:56 -04:00
|
|
|
|
2019-10-11 09:52:11 -04:00
|
|
|
public function createBehaviors(Behaviors $behaviors)
|
|
|
|
|
{
|
2019-11-03 07:35:03 -05:00
|
|
|
$behaviors->add(new BoolCast([
|
|
|
|
|
'is_problem',
|
|
|
|
|
'is_handled',
|
|
|
|
|
'is_reachable',
|
|
|
|
|
'is_flapping',
|
2019-12-04 07:44:09 -05:00
|
|
|
'is_overdue',
|
2019-11-03 07:35:03 -05:00
|
|
|
'is_acknowledged',
|
2025-06-03 05:58:19 -04:00
|
|
|
'is_sticky_acknowledgement',
|
2024-09-22 19:36:04 -04:00
|
|
|
'in_downtime',
|
|
|
|
|
'affects_children'
|
2019-11-03 07:35:03 -05:00
|
|
|
]));
|
2022-03-29 09:27:18 -04:00
|
|
|
|
2023-05-30 10:05:11 -04:00
|
|
|
$behaviors->add(new MillisecondTimestamp([
|
2019-10-11 09:53:34 -04:00
|
|
|
'last_update',
|
|
|
|
|
'last_state_change',
|
|
|
|
|
'next_check',
|
|
|
|
|
'next_update'
|
|
|
|
|
]));
|
2022-03-29 09:27:18 -04:00
|
|
|
|
|
|
|
|
$behaviors->add(new Binary([
|
|
|
|
|
$this->getKeyName(),
|
|
|
|
|
'environment_id',
|
|
|
|
|
'acknowledgement_comment_id',
|
|
|
|
|
'last_comment_id'
|
|
|
|
|
]));
|
2019-10-11 09:52:11 -04:00
|
|
|
}
|
2023-06-15 03:17:45 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state icon
|
|
|
|
|
*
|
|
|
|
|
* @return Icon|null
|
|
|
|
|
*/
|
|
|
|
|
public function getIcon(): ?Icon
|
|
|
|
|
{
|
|
|
|
|
$icon = null;
|
|
|
|
|
switch (true) {
|
|
|
|
|
case $this->is_acknowledged:
|
|
|
|
|
$icon = new Icon(Icons::IS_ACKNOWLEDGED);
|
2023-07-10 09:37:52 -04:00
|
|
|
|
2023-06-15 03:17:45 -04:00
|
|
|
break;
|
|
|
|
|
case $this->in_downtime:
|
|
|
|
|
$icon = new Icon(
|
|
|
|
|
Icons::IN_DOWNTIME,
|
|
|
|
|
['title' => sprintf(
|
|
|
|
|
'%s (%s)',
|
|
|
|
|
strtoupper($this->getStateTextTranslated()),
|
|
|
|
|
$this->is_handled ? t('handled by Downtime') : t('in Downtime')
|
|
|
|
|
)]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case $this->is_flapping:
|
|
|
|
|
$icon = new Icon(Icons::IS_FLAPPING);
|
2023-07-10 09:37:52 -04:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ! $this->is_reachable:
|
|
|
|
|
$icon = new Icon(Icons::HOST_DOWN, [
|
|
|
|
|
'title' => sprintf(
|
|
|
|
|
'%s (%s)',
|
|
|
|
|
strtoupper($this->getStateTextTranslated()),
|
|
|
|
|
t('is unreachable')
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
|
2023-06-15 03:17:45 -04:00
|
|
|
break;
|
|
|
|
|
case $this->is_handled:
|
|
|
|
|
$icon = new Icon(Icons::HOST_DOWN);
|
2023-07-10 09:37:52 -04:00
|
|
|
|
2023-06-15 03:17:45 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $icon;
|
|
|
|
|
}
|
2019-09-09 07:17:02 -04:00
|
|
|
}
|