2019-10-17 04:15:25 -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-10-17 04:15:25 -04:00
|
|
|
|
2024-01-23 02:43:02 -05:00
|
|
|
use DateTime;
|
2025-06-05 10:56:46 -04:00
|
|
|
use ipl\Orm\Behavior\BoolCast;
|
2019-11-22 09:56:07 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
|
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-17 04:15:25 -04:00
|
|
|
use ipl\Orm\Behaviors;
|
|
|
|
|
use ipl\Orm\Model;
|
|
|
|
|
use ipl\Orm\Relations;
|
|
|
|
|
|
2024-01-23 02:43:02 -05:00
|
|
|
/**
|
|
|
|
|
* @property string $id
|
|
|
|
|
* @property string $environment_id
|
|
|
|
|
* @property ?string $triggered_by_id
|
|
|
|
|
* @property ?string $parent_id
|
|
|
|
|
* @property string $object_type
|
|
|
|
|
* @property string $host_id
|
|
|
|
|
* @property ?string $service_id
|
|
|
|
|
* @property string $name_checksum
|
|
|
|
|
* @property string $properties_checksum
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $author
|
|
|
|
|
* @property string $comment
|
|
|
|
|
* @property DateTime $entry_time
|
|
|
|
|
* @property DateTime $scheduled_start_time
|
|
|
|
|
* @property DateTime $scheduled_end_time
|
|
|
|
|
* @property int $scheduled_duration
|
|
|
|
|
* @property bool $is_flexible
|
|
|
|
|
* @property int $flexible_duration
|
|
|
|
|
* @property bool $is_in_effect
|
|
|
|
|
* @property ?DateTime $start_time
|
|
|
|
|
* @property ?DateTime $end_time
|
|
|
|
|
* @property int $duration
|
|
|
|
|
* @property ?string $scheduled_by
|
|
|
|
|
* @property ?string $zone_id
|
|
|
|
|
*/
|
2019-10-17 04:15:25 -04:00
|
|
|
class Downtime extends Model
|
|
|
|
|
{
|
|
|
|
|
public function getTableName()
|
|
|
|
|
{
|
|
|
|
|
return 'downtime';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getKeyName()
|
|
|
|
|
{
|
|
|
|
|
return 'id';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getColumns()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'environment_id',
|
2021-08-12 10:27:59 -04:00
|
|
|
'triggered_by_id',
|
|
|
|
|
'parent_id',
|
2019-10-17 04:15:25 -04:00
|
|
|
'object_type',
|
|
|
|
|
'host_id',
|
|
|
|
|
'service_id',
|
|
|
|
|
'name_checksum',
|
|
|
|
|
'properties_checksum',
|
|
|
|
|
'name',
|
|
|
|
|
'author',
|
|
|
|
|
'comment',
|
|
|
|
|
'entry_time',
|
|
|
|
|
'scheduled_start_time',
|
|
|
|
|
'scheduled_end_time',
|
2021-11-09 04:44:45 -05:00
|
|
|
'scheduled_duration',
|
2019-10-17 04:15:25 -04:00
|
|
|
'is_flexible',
|
2021-11-09 04:44:45 -05:00
|
|
|
'flexible_duration',
|
2019-10-17 04:15:25 -04:00
|
|
|
'is_in_effect',
|
2019-11-01 18:16:45 -04:00
|
|
|
'start_time',
|
|
|
|
|
'end_time',
|
2021-11-09 04:44:45 -05:00
|
|
|
'duration',
|
2021-09-06 02:42:12 -04:00
|
|
|
'scheduled_by',
|
2021-11-09 04:44:45 -05:00
|
|
|
'zone_id'
|
2019-10-17 04:15:25 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 09:34:01 -04:00
|
|
|
public function getColumnDefinitions()
|
2020-11-02 10:07:47 -05:00
|
|
|
{
|
|
|
|
|
return [
|
2022-07-11 11:31:53 -04:00
|
|
|
'environment_id' => t('Environment Id'),
|
|
|
|
|
'triggered_by_id' => t('Triggered By Downtime Id'),
|
|
|
|
|
'parent_id' => t('Parent Downtime Id'),
|
|
|
|
|
'object_type' => t('Object Type'),
|
|
|
|
|
'host_id' => t('Host Id'),
|
|
|
|
|
'service_id' => t('Service Id'),
|
2021-11-09 04:44:45 -05:00
|
|
|
'name_checksum' => t('Downtime Name Checksum'),
|
|
|
|
|
'properties_checksum' => t('Downtime Properties Checksum'),
|
|
|
|
|
'name' => t('Downtime Name'),
|
|
|
|
|
'author' => t('Downtime Author'),
|
|
|
|
|
'comment' => t('Downtime Comment'),
|
|
|
|
|
'entry_time' => t('Downtime Entry Time'),
|
|
|
|
|
'scheduled_start_time' => t('Downtime Scheduled Start'),
|
|
|
|
|
'scheduled_end_time' => t('Downtime Scheduled End'),
|
|
|
|
|
'scheduled_duration' => t('Downtime Scheduled Duration'),
|
|
|
|
|
'is_flexible' => t('Downtime Is Flexible'),
|
|
|
|
|
'flexible_duration' => t('Downtime Flexible Duration'),
|
|
|
|
|
'is_in_effect' => t('Downtime Is In Effect'),
|
|
|
|
|
'start_time' => t('Downtime Actual Start'),
|
|
|
|
|
'end_time' => t('Downtime Actual End'),
|
|
|
|
|
'duration' => t('Downtime Duration'),
|
2022-07-11 11:31:53 -04:00
|
|
|
'scheduled_by' => t('Scheduled By Downtime'),
|
|
|
|
|
'zone_id' => t('Zone Id')
|
2020-11-02 10:07:47 -05:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-03 04:20:49 -05:00
|
|
|
public function getSearchColumns()
|
|
|
|
|
{
|
|
|
|
|
return ['comment'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 09:58:53 -05:00
|
|
|
public function getDefaultSort()
|
2019-11-04 10:40:44 -05:00
|
|
|
{
|
2021-11-12 05:43:05 -05:00
|
|
|
return ['downtime.is_in_effect desc', 'downtime.start_time desc'];
|
2019-11-04 10:40:44 -05:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:15:25 -04:00
|
|
|
public function createBehaviors(Behaviors $behaviors)
|
|
|
|
|
{
|
|
|
|
|
$behaviors->add(new BoolCast([
|
|
|
|
|
'is_flexible',
|
|
|
|
|
'is_in_effect'
|
|
|
|
|
]));
|
2022-03-29 09:27:18 -04:00
|
|
|
|
2023-05-30 10:05:11 -04:00
|
|
|
$behaviors->add(new MillisecondTimestamp([
|
2019-10-17 04:15:25 -04:00
|
|
|
'entry_time',
|
|
|
|
|
'scheduled_start_time',
|
|
|
|
|
'scheduled_end_time',
|
2019-11-01 18:16:45 -04:00
|
|
|
'start_time',
|
2023-05-30 10:05:11 -04:00
|
|
|
'end_time'
|
2019-10-17 04:15:25 -04:00
|
|
|
]));
|
2022-03-29 09:27:18 -04:00
|
|
|
|
|
|
|
|
$behaviors->add(new Binary([
|
|
|
|
|
'id',
|
|
|
|
|
'environment_id',
|
|
|
|
|
'triggered_by_id',
|
|
|
|
|
'parent_id',
|
|
|
|
|
'host_id',
|
|
|
|
|
'service_id',
|
|
|
|
|
'name_checksum',
|
|
|
|
|
'properties_checksum',
|
|
|
|
|
'zone_id'
|
|
|
|
|
]));
|
2022-06-29 10:31:40 -04:00
|
|
|
|
|
|
|
|
// As long as the rewriteCondition() expects only Filter\Condition as a first argument
|
|
|
|
|
// We have to add this reroute behavior after the binary because the filter condition might
|
|
|
|
|
// be transformed into a filter chain!
|
|
|
|
|
$behaviors->add(new ReRoute([
|
|
|
|
|
'hostgroup' => 'host.hostgroup',
|
|
|
|
|
'servicegroup' => 'service.servicegroup'
|
|
|
|
|
]));
|
2019-10-17 04:15:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createRelations(Relations $relations)
|
|
|
|
|
{
|
2021-08-12 10:27:59 -04:00
|
|
|
$relations->belongsTo('triggered_by', self::class)
|
|
|
|
|
->setCandidateKey('triggered_by_id')
|
|
|
|
|
->setJoinType('LEFT');
|
|
|
|
|
$relations->belongsTo('parent', self::class)
|
|
|
|
|
->setCandidateKey('parent_id')
|
|
|
|
|
->setJoinType('LEFT');
|
2019-10-17 04:15:25 -04:00
|
|
|
$relations->belongsTo('environment', Environment::class);
|
|
|
|
|
$relations->belongsTo('host', Host::class)->setJoinType('LEFT');
|
|
|
|
|
$relations->belongsTo('service', Service::class)->setJoinType('LEFT');
|
|
|
|
|
$relations->belongsTo('zone', Zone::class);
|
|
|
|
|
}
|
|
|
|
|
}
|