1
1
<?php
2
- // Copyright (C) <2015> <it-novum GmbH>
2
+ // Copyright (C) <2015-present > <it-novum GmbH>
3
3
//
4
4
// This file is dual licensed
5
5
//
6
6
// 1.
7
- // This program is free software: you can redistribute it and/or modify
8
- // it under the terms of the GNU General Public License as published by
9
- // the Free Software Foundation, version 3 of the License.
7
+ // This program is free software: you can redistribute it and/or modify
8
+ // it under the terms of the GNU General Public License as published by
9
+ // the Free Software Foundation, version 3 of the License.
10
10
//
11
- // This program is distributed in the hope that it will be useful,
12
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- // GNU General Public License for more details.
11
+ // This program is distributed in the hope that it will be useful,
12
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ // GNU General Public License for more details.
15
15
//
16
- // You should have received a copy of the GNU General Public License
17
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ // You should have received a copy of the GNU General Public License
17
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
//
19
+ // 2.
20
+ // If you purchased an openITCOCKPIT Enterprise Edition you can use this file
21
+ // under the terms of the openITCOCKPIT Enterprise Edition license agreement.
22
+ // License agreement and license key will be shipped with the order
23
+ // confirmation.
19
24
20
25
// 2.
21
26
// If you purchased an openITCOCKPIT Enterprise Edition you can use this file
27
32
28
33
namespace NagiosModule \Controller ;
29
34
35
+ use App \itnovum \openITCOCKPIT \Monitoring \Naemon \ExternalCommands ;
30
36
use Cake \Http \Exception \BadRequestException ;
31
37
use Cake \Http \Exception \MethodNotAllowedException ;
32
38
use Cake \Http \Exception \NotFoundException ;
39
+ use Cake \Log \Log ;
33
40
use Cake \Utility \Hash ;
34
41
use itnovum \openITCOCKPIT \Core \System \Gearman ;
35
- use App \ itnovum \openITCOCKPIT \Monitoring \ Naemon \ ExternalCommands ;
42
+ use itnovum \openITCOCKPIT \Resolver \ NameToUuidResolver ;
36
43
37
44
class CmdController extends AppController {
38
45
@@ -84,6 +91,31 @@ public function submit() {
84
91
$ command = $ args ['command ' ];
85
92
unset($ args ['command ' ]);
86
93
94
+ // ITC-3373 Check if hostUuid and serviceUuid are valid UUIDs.
95
+ // Otherwise, the user passed a human name such as "localhost" or "PING" and we try to resolve it.
96
+ if (isset ($ args ['hostUuid ' ]) || isset ($ args ['serviceUuid ' ])) {
97
+ $ Resolver = NameToUuidResolver::createResolver ();
98
+ if (isset ($ args ['serviceUuid ' ])) {
99
+ // Resolve both host and service name into a UUID (if needed)
100
+ $ result = $ Resolver ->resolveHostAndServicename ($ args ['hostUuid ' ], $ args ['serviceUuid ' ]);
101
+ if ($ result ['hostUuid ' ] === false || $ result ['serviceUuid ' ] === false ) {
102
+ Log::error (sprintf ('CmdController: Could not resolve service name for "%s/%s" into a UUID ' , $ args ['hostUuid ' ], $ args ['serviceUuid ' ]));
103
+ throw new BadRequestException (sprintf ('CmdController: Could not resolve service name for "%s/%s" into a UUID ' , $ args ['hostUuid ' ], $ args ['serviceUuid ' ]));
104
+ }
105
+
106
+ $ args ['hostUuid ' ] = $ result ['hostUuid ' ];
107
+ $ args ['serviceUuid ' ] = $ result ['serviceUuid ' ];
108
+ } else {
109
+ // Resolve host name into a UUID (if needed)
110
+ $ hostUuid = $ Resolver ->resolveHostname ($ args ['hostUuid ' ]);
111
+ if ($ hostUuid === false ) {
112
+ Log::error (sprintf ('CmdController: Could not resolve hostname "%s" into a UUID ' , $ args ['hostUuid ' ]));
113
+ throw new BadRequestException (sprintf ('CmdController: Could not resolve hostname "%s" into a UUID ' , $ args ['hostUuid ' ]));
114
+ }
115
+ $ args ['hostUuid ' ] = $ hostUuid ;
116
+ }
117
+ }
118
+
87
119
// Command is now ready to submit to sudo_server
88
120
// Auto-Lookup if Master System or SAT system (satelliteId=null)
89
121
$ GearmanClient = new Gearman ();
@@ -178,7 +210,7 @@ public function submit_bulk() {
178
210
]);
179
211
}
180
212
181
- public function submit_bulk_naemon (){
213
+ public function submit_bulk_naemon () {
182
214
if (!$ this ->request ->is ('post ' ) && !$ this ->request ->is ('get ' )) {
183
215
throw new MethodNotAllowedException ();
184
216
}
@@ -195,34 +227,34 @@ public function submit_bulk_naemon(){
195
227
throw new BadRequestException ();
196
228
}
197
229
$ externalNaemonCommands = new ExternalCommands ();
198
- foreach ($ data as $ value ){
230
+ foreach ($ data as $ value ) {
199
231
switch ($ value ['command ' ]) {
200
232
case 'rescheduleHost ' :
201
- $ result = $ externalNaemonCommands ->rescheduleHost (['uuid ' => $ value ['hostUuid ' ], 'type ' =>$ value ['type ' ], 'satellite_id ' => $ value ['satelliteId ' ]]);
233
+ $ result = $ externalNaemonCommands ->rescheduleHost (['uuid ' => $ value ['hostUuid ' ], 'type ' => $ value ['type ' ], 'satellite_id ' => $ value ['satelliteId ' ]]);
202
234
break ;
203
235
case 'rescheduleService ' :
204
- $ result = $ externalNaemonCommands ->rescheduleService (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'satellite_id ' => $ value ['satelliteId ' ]]);
236
+ $ result = $ externalNaemonCommands ->rescheduleService (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'satellite_id ' => $ value ['satelliteId ' ]]);
205
237
break ;
206
238
case 'submitHostDowntime ' :
207
- $ result = $ externalNaemonCommands ->setHostDowntime (['hostUuid ' => $ value ['hostUuid ' ], 'start ' => $ value ['start ' ], 'end ' => $ value ['end ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'downtimetype ' => $ value ['downtimetype ' ]]);
239
+ $ result = $ externalNaemonCommands ->setHostDowntime (['hostUuid ' => $ value ['hostUuid ' ], 'start ' => $ value ['start ' ], 'end ' => $ value ['end ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'downtimetype ' => $ value ['downtimetype ' ]]);
208
240
break ;
209
241
case 'submitServiceDowntime ' :
210
- $ result = $ externalNaemonCommands ->setServiceDowntime (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'start ' => $ value ['start ' ], 'end ' => $ value ['end ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ]]);
242
+ $ result = $ externalNaemonCommands ->setServiceDowntime (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'start ' => $ value ['start ' ], 'end ' => $ value ['end ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ]]);
211
243
break ;
212
244
case 'submitHoststateAck ' :
213
- $ result = $ externalNaemonCommands ->setHostAck (['hostUuid ' => $ value ['hostUuid ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'sticky ' => $ value ['sticky ' ], 'type ' => $ value ['hostAckType ' ], 'notify ' => $ value ['notify ' ]]);
245
+ $ result = $ externalNaemonCommands ->setHostAck (['hostUuid ' => $ value ['hostUuid ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'sticky ' => $ value ['sticky ' ], 'type ' => $ value ['hostAckType ' ], 'notify ' => $ value ['notify ' ]]);
214
246
break ;
215
247
case 'submitServicestateAck ' :
216
- $ result = $ externalNaemonCommands ->setServiceAck (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'sticky ' => $ value ['sticky ' ], 'notify ' => $ value ['notify ' ]]);
248
+ $ result = $ externalNaemonCommands ->setServiceAck (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'comment ' => $ value ['comment ' ], 'author ' => $ value ['author ' ], 'sticky ' => $ value ['sticky ' ], 'notify ' => $ value ['notify ' ]]);
217
249
break ;
218
250
case 'commitPassiveServiceResult ' :
219
- $ result = $ externalNaemonCommands ->passiveTransferServiceCheckresult (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'comment ' => $ value ['plugin_output ' ], 'state ' => $ value ['status_code ' ], 'forceHardstate ' => $ value ['forceHardstate ' ], 'repetitions ' => $ value ['maxCheckAttempts ' ]]);
251
+ $ result = $ externalNaemonCommands ->passiveTransferServiceCheckresult (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'comment ' => $ value ['plugin_output ' ], 'state ' => $ value ['status_code ' ], 'forceHardstate ' => $ value ['forceHardstate ' ], 'repetitions ' => $ value ['maxCheckAttempts ' ]]);
220
252
break ;
221
253
case 'commitPassiveResult ' :
222
- $ result = $ externalNaemonCommands ->passiveTransferHostCheckresult (['uuid ' => $ value ['hostUuid ' ], 'comment ' => $ value ['plugin_output ' ], 'state ' => $ value ['status_code ' ], 'forceHardstate ' => $ value ['forceHardstate ' ], 'repetitions ' => $ value ['maxCheckAttempts ' ]]);
254
+ $ result = $ externalNaemonCommands ->passiveTransferHostCheckresult (['uuid ' => $ value ['hostUuid ' ], 'comment ' => $ value ['plugin_output ' ], 'state ' => $ value ['status_code ' ], 'forceHardstate ' => $ value ['forceHardstate ' ], 'repetitions ' => $ value ['maxCheckAttempts ' ]]);
223
255
break ;
224
256
case 'sendCustomServiceNotification ' :
225
- $ result = $ externalNaemonCommands ->sendCustomServiceNotification (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'type ' => $ value ['options ' ], 'author ' => $ value ['author ' ], 'comment ' => $ value ['comment ' ]]);
257
+ $ result = $ externalNaemonCommands ->sendCustomServiceNotification (['hostUuid ' => $ value ['hostUuid ' ], 'serviceUuid ' => $ value ['serviceUuid ' ], 'type ' => $ value ['options ' ], 'author ' => $ value ['author ' ], 'comment ' => $ value ['comment ' ]]);
226
258
break ;
227
259
case 'sendCustomHostNotification ' :
228
260
$ result = $ externalNaemonCommands ->sendCustomHostNotification (['hostUuid ' => $ value ['hostUuid ' ], 'type ' => $ value ['options ' ], 'author ' => $ value ['author ' ], 'comment ' => $ value ['comment ' ]]);
@@ -249,7 +281,7 @@ public function submit_bulk_naemon(){
249
281
$ result = false ;
250
282
break ;
251
283
}
252
- if (!$ result ) {
284
+ if (!$ result ) {
253
285
throw new BadRequestException ('Could not send command ' );
254
286
}
255
287
}
0 commit comments