1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Model;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
use ipl\Orm\Defaults;
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
class Service extends Model
{
use Auth;
public function getTableName()
{
return 'service';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
return [
'environment_id',
'name_checksum',
'properties_checksum',
'host_id',
'name',
'name_ci',
'display_name',
'checkcommand_name',
'checkcommand_id',
'max_check_attempts',
'check_timeperiod_name',
'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',
'eventcommand_id',
'is_volatile',
'action_url_id',
'notes_url_id',
'notes',
'icon_image_id',
'icon_image_alt',
'zone_name',
'zone_id',
'command_endpoint_name',
'command_endpoint_id'
];
}
public function getColumnDefinitions()
{
return [
'environment_id' => t('Environment Id'),
'name_checksum' => t('Service Name Checksum'),
'properties_checksum' => t('Service Properties Checksum'),
'host_id' => t('Host Id'),
'name' => t('Service Name'),
'name_ci' => t('Service Name (CI)'),
'display_name' => t('Service Display Name'),
'checkcommand_name' => t('Checkcommand Name'),
'checkcommand_id' => t('Checkcommand Id'),
'max_check_attempts' => t('Service Max Check Attempts'),
'check_timeperiod_name' => t('Check Timeperiod Name'),
'check_timeperiod_id' => t('Check Timeperiod Id'),
'check_timeout' => t('Service Check Timeout'),
'check_interval' => t('Service Check Interval'),
'check_retry_interval' => t('Service Check Retry Inverval'),
'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'),
'eventcommand_name' => t('Eventcommand Name'),
'eventcommand_id' => t('Eventcommand Id'),
'is_volatile' => t('Service Is Volatile'),
'action_url_id' => t('Action Url Id'),
'notes_url_id' => t('Notes Url Id'),
'notes' => t('Service Notes'),
'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')
];
}
public function getSearchColumns()
{
return ['name_ci'];
}
public function getDefaultSort()
{
return 'service.display_name';
}
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([
'user' => 'notification.user',
'usergroup' => 'notification.usergroup'
]));
$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'
]));
}
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;
});
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class)->setJoinType('LEFT');
$relations->belongsTo('checkcommand', Checkcommand::class);
$relations->belongsTo('timeperiod', Timeperiod::class)
->setCandidateKey('check_timeperiod_id');
$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)
->setCandidateKey('icon_image_id')
->setJoinType('LEFT');
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('endpoint', Endpoint::class)
->setCandidateKey('command_endpoint_id');
$relations->belongsToMany('customvar', Customvar::class)
->through(ServiceCustomvar::class);
$relations->belongsToMany('customvar_flat', CustomvarFlat::class)
->through(ServiceCustomvar::class);
$relations->belongsToMany('vars', Vars::class)
->through(ServiceCustomvar::class);
$relations->belongsToMany('servicegroup', Servicegroup::class)
->through(ServicegroupMember::class);
$relations->belongsToMany('hostgroup', Hostgroup::class)
->through(HostgroupMember::class);
$relations->hasOne('state', ServiceState::class)->setJoinType('LEFT');
$relations->hasMany('comment', Comment::class)->setJoinType('LEFT');
$relations->hasMany('downtime', Downtime::class)->setJoinType('LEFT');
$relations->hasMany('history', History::class);
$relations->hasMany('notification', Notification::class)->setJoinType('LEFT');
$relations->hasMany('notification_history', NotificationHistory::class);
}
}
|