icingadb-web/library/Icingadb/Model/Service.php

298 lines
11 KiB
PHP
Raw Permalink Normal View History

2019-09-23 09:31:18 -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-23 09:31:18 -04:00
use Icinga\Module\Icingadb\Common\Auth;
2024-12-17 08:57:00 -05:00
use Icinga\Module\Icingadb\Common\Backend;
use ipl\Orm\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent;
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
use ipl\Orm\Defaults;
2019-09-23 09:31:18 -04:00
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
2019-09-23 09:31:18 -04:00
/**
* @property string $id
* @property string $environment_id
* @property string $name_checksum
* @property string $properties_checksum
* @property string $host_id
* @property string $name
* @property string $name_ci
* @property string $display_name
* @property string $checkcommand_name
* @property string $checkcommand_id
* @property int $max_check_attempts
* @property string $check_timeperiod_name
* @property ?string $check_timeperiod_id
* @property ?int $check_timeout
* @property int $check_interval
* @property int $check_retry_interval
* @property bool $active_checks_enabled
* @property bool $passive_checks_enabled
* @property bool $event_handler_enabled
* @property bool $notifications_enabled
* @property bool $flapping_enabled
* @property float $flapping_threshold_low
* @property float $flapping_threshold_high
* @property bool $perfdata_enabled
* @property string $eventcommand_name
* @property ?string $eventcommand_id
* @property bool $is_volatile
* @property ?string $action_url_id
* @property ?string $notes_url_id
* @property string $notes
* @property ?string $icon_image_id
* @property string $icon_image_alt
* @property string $zone_name
* @property ?string $zone_id
* @property string $command_endpoint_name
* @property ?string $command_endpoint_id
* @property ?int $total_children
*/
2019-09-23 09:31:18 -04:00
class Service extends Model
{
use Auth;
2019-09-23 09:31:18 -04:00
public function getTableName()
{
return 'service';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
2024-12-17 08:57:00 -05:00
$columns = [
2019-09-23 09:31:18 -04:00
'environment_id',
'name_checksum',
'properties_checksum',
'host_id',
'name',
'name_ci',
'display_name',
'checkcommand_name',
2019-09-23 09:31:18 -04:00
'checkcommand_id',
'max_check_attempts',
'check_timeperiod_name',
2019-09-23 09:31:18 -04:00
'check_timeperiod_id',
'check_timeout',
'check_interval',
'check_retry_interval',
'active_checks_enabled',
'passive_checks_enabled',
'event_handler_enabled',
'notifications_enabled',
'flapping_enabled',
'flapping_threshold_low',
'flapping_threshold_high',
'perfdata_enabled',
'eventcommand_name',
2019-09-23 09:31:18 -04:00
'eventcommand_id',
'is_volatile',
'action_url_id',
'notes_url_id',
'notes',
'icon_image_id',
'icon_image_alt',
'zone_name',
2019-09-23 09:31:18 -04:00
'zone_id',
'command_endpoint_name',
2024-12-17 08:57:00 -05:00
'command_endpoint_id'
2019-09-23 09:31:18 -04:00
];
2024-12-17 08:57:00 -05:00
if (Backend::supportsDependencies()) {
$columns[] = 'total_children';
2024-12-17 08:57:00 -05:00
}
return $columns;
2019-09-23 09:31:18 -04:00
}
public function getColumnDefinitions()
2020-11-02 10:08:36 -05:00
{
2024-12-17 08:57:00 -05:00
$columns = [
2022-07-11 11:31:53 -04:00
'environment_id' => t('Environment Id'),
2020-11-02 10:08:36 -05:00
'name_checksum' => t('Service Name Checksum'),
'properties_checksum' => t('Service Properties Checksum'),
2022-07-11 11:31:53 -04:00
'host_id' => t('Host Id'),
2020-11-02 10:08:36 -05:00
'name' => t('Service Name'),
'name_ci' => t('Service Name (CI)'),
'display_name' => t('Service Display Name'),
2022-07-11 11:31:53 -04:00
'checkcommand_name' => t('Checkcommand Name'),
'checkcommand_id' => t('Checkcommand Id'),
2020-11-02 10:08:36 -05:00
'max_check_attempts' => t('Service Max Check Attempts'),
2022-07-11 11:31:53 -04:00
'check_timeperiod_name' => t('Check Timeperiod Name'),
'check_timeperiod_id' => t('Check Timeperiod Id'),
2020-11-02 10:08:36 -05:00
'check_timeout' => t('Service Check Timeout'),
'check_interval' => t('Service Check Interval'),
'check_retry_interval' => t('Service Check Retry Interval'),
2020-11-02 10:08:36 -05:00
'active_checks_enabled' => t('Service Active Checks Enabled'),
'passive_checks_enabled' => t('Service Passive Checks Enabled'),
'event_handler_enabled' => t('Service Event Handler Enabled'),
'notifications_enabled' => t('Service Notifications Enabled'),
'flapping_enabled' => t('Service Flapping Enabled'),
'flapping_threshold_low' => t('Service Flapping Threshold Low'),
'flapping_threshold_high' => t('Service Flapping Threshold High'),
'perfdata_enabled' => t('Service Performance Data Enabled'),
2022-07-11 11:31:53 -04:00
'eventcommand_name' => t('Eventcommand Name'),
'eventcommand_id' => t('Eventcommand Id'),
2020-11-02 10:08:36 -05:00
'is_volatile' => t('Service Is Volatile'),
2022-07-11 11:31:53 -04:00
'action_url_id' => t('Action Url Id'),
'notes_url_id' => t('Notes Url Id'),
2020-11-02 10:08:36 -05:00
'notes' => t('Service Notes'),
2022-07-11 11:31:53 -04:00
'icon_image_id' => t('Icon Image Id'),
'icon_image_alt' => t('Icon Image Alt'),
'zone_name' => t('Zone Name'),
'zone_id' => t('Zone Id'),
'command_endpoint_name' => t('Endpoint Name'),
'command_endpoint_id' => t('Endpoint Id'),
2020-11-02 10:08:36 -05:00
];
2024-12-17 08:57:00 -05:00
if (Backend::supportsDependencies()) {
$columns['total_children'] = t('Total Children');
2024-12-17 08:57:00 -05:00
}
return $columns;
2020-11-02 10:08:36 -05:00
}
public function getSearchColumns()
{
return ['name_ci', 'display_name'];
}
public function getDefaultSort()
2019-11-04 10:39:53 -05:00
{
return 'service.display_name';
2019-11-04 10:39:53 -05:00
}
public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new BoolCast([
'active_checks_enabled',
'passive_checks_enabled',
'event_handler_enabled',
'notifications_enabled',
'flapping_enabled',
'is_volatile'
]));
$behaviors->add(new ReRoute([
'child' => 'to.from',
'parent' => 'from.to',
'user' => 'notification.user',
'usergroup' => 'notification.usergroup'
]));
2022-03-29 09:27:18 -04:00
$behaviors->add(new Binary([
'id',
'environment_id',
'name_checksum',
'properties_checksum',
'host_id',
'checkcommand_id',
'check_timeperiod_id',
'eventcommand_id',
'action_url_id',
'notes_url_id',
'icon_image_id',
'zone_id',
'command_endpoint_id'
]));
if (Backend::supportsDependencies()) {
2024-12-17 08:57:00 -05:00
$behaviors->add(new HasProblematicParent());
}
}
public function createDefaults(Defaults $defaults)
{
$defaults->add('vars', function (self $subject) {
if (! $subject->customvar_flat instanceof ResultSet) {
$this->applyRestrictions($subject->customvar_flat);
}
$vars = [];
foreach ($subject->customvar_flat as $customVar) {
$vars[$customVar->flatname] = $customVar->flatvalue;
}
return $vars;
});
$defaults->add('customvars', function (self $subject) {
if (! $subject->customvar instanceof ResultSet) {
$this->applyRestrictions($subject->customvar);
}
$vars = [];
foreach ($subject->customvar as $customVar) {
$vars[$customVar->name] = json_decode($customVar->value, true);
}
return $vars;
});
}
2019-09-23 09:31:18 -04:00
public function createRelations(Relations $relations)
{
$relations->hasOne('state', ServiceState::class)->setJoinType('LEFT');
$relations->hasOne('dependency_node', DependencyNode::class)->setJoinType('LEFT');
$relations->hasOne('unreachable_parent', UnreachableParent::class)->setJoinType('LEFT');
2019-09-23 09:31:18 -04:00
$relations->belongsTo('environment', Environment::class);
2019-11-03 07:33:51 -05:00
$relations->belongsTo('host', Host::class)->setJoinType('LEFT');
2019-09-23 09:31:18 -04:00
$relations->belongsTo('checkcommand', Checkcommand::class);
$relations->belongsTo('timeperiod', Timeperiod::class)
->setCandidateKey('check_timeperiod_id')
->setJoinType('LEFT');
2019-09-23 09:31:18 -04:00
$relations->belongsTo('eventcommand', Eventcommand::class);
$relations->belongsTo('action_url', ActionUrl::class)
->setCandidateKey('action_url_id')
->setForeignKey('id');
$relations->belongsTo('notes_url', NotesUrl::class)
->setCandidateKey('notes_url_id')
->setForeignKey('id');
$relations->belongsTo('icon_image', IconImage::class)
2022-04-08 10:13:51 -04:00
->setCandidateKey('icon_image_id')
->setJoinType('LEFT');
2019-09-23 09:31:18 -04:00
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('endpoint', Endpoint::class)
->setCandidateKey('command_endpoint_id');
$relations->belongsToMany('customvar', Customvar::class)
->through(ServiceCustomvar::class)
->setThroughAlias('t_service_customvar');
$relations->belongsToMany('customvar_flat', CustomvarFlat::class)
->through(ServiceCustomvar::class);
$relations->belongsToMany('vars', Vars::class)
->through(ServiceCustomvar::class);
2019-09-23 09:31:18 -04:00
$relations->belongsToMany('servicegroup', Servicegroup::class)
->through(ServicegroupMember::class);
$relations->belongsToMany('hostgroup', Hostgroup::class)
->through(HostgroupMember::class);
2019-09-23 09:31:18 -04:00
2019-12-16 04:44:50 -05:00
$relations->hasMany('comment', Comment::class)->setJoinType('LEFT');
2019-12-16 04:45:05 -05:00
$relations->hasMany('downtime', Downtime::class)->setJoinType('LEFT');
$relations->hasMany('history', History::class);
2020-01-17 10:30:51 -05:00
$relations->hasMany('notification', Notification::class)->setJoinType('LEFT');
$relations->hasMany('notification_history', NotificationHistory::class);
$relations->belongsToMany('from', DependencyEdge::class)
->setTargetCandidateKey('from_node_id')
->setTargetForeignKey('id')
->through(DependencyNode::class);
$relations->belongsToMany('to', DependencyEdge::class)
->setTargetCandidateKey('to_node_id')
->setTargetForeignKey('id')
->through(DependencyNode::class);
2019-09-23 09:31:18 -04:00
}
}