-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathExternalCommand.php
More file actions
99 lines (83 loc) · 4.28 KB
/
Copy pathExternalCommand.php
File metadata and controls
99 lines (83 loc) · 4.28 KB
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
<?php
/**
* Statusengine UI
* Copyright (C) 2016-2018 Daniel Ziegler
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Statusengine\Controller;
use Statusengine\Loader\Crate\ExternalCommandSaver;
use Statusengine\Loader\HostDowntimeLoaderInterface;
use Statusengine\Loader\ScheduleddowntimeHostLoaderInterface;
use Statusengine\Loader\ScheduleddowntimeServiceLoaderInterface;
use Statusengine\Loader\ServiceDowntimeLoaderInterface;
use Statusengine\Saver\ExternalCommandSaverInterface;
use Statusengine\ValueObjects\ExternalCommandArgsQueryOptions;
use Statusengine\ValueObjects\ExternalCommandQueryOptions;
class ExternalCommand extends Controller {
/**
* @var ExternalCommandSaver
*/
private $ExternalCommandSaver;
/**
* ExternalCommand constructor.
* @param ExternalCommandSaverInterface $ExternalCommandSaver
*/
public function __construct(ExternalCommandSaverInterface $ExternalCommandSaver) {
$this->ExternalCommandSaver = $ExternalCommandSaver;
}
/**
* @param ExternalCommandQueryOptions $ExternalCommandQueryOptions
* @return bool
*/
public function index(ExternalCommandQueryOptions $ExternalCommandQueryOptions) {
$ExternalCommand = new \Statusengine\Generators\ExternalCommand($ExternalCommandQueryOptions);
$commandAsStringOrArray = $ExternalCommand->getCommand();
if(is_array($commandAsStringOrArray)){
foreach($commandAsStringOrArray as $command){
$this->ExternalCommandSaver->saveCommand($command, $ExternalCommandQueryOptions->getNodeName());
}
return true;
}
return $this->ExternalCommandSaver->saveCommand($commandAsStringOrArray, $ExternalCommandQueryOptions->getNodeName());
}
/**
* @param ExternalCommandArgsQueryOptions $ExternalCommandArgsQueryOptions
* @return bool
*/
public function args(ExternalCommandArgsQueryOptions $ExternalCommandArgsQueryOptions) {
$ExternalCommand = new \Statusengine\Generators\ExternalCommandArgs($ExternalCommandArgsQueryOptions);
$commandAsStringOrArray = $ExternalCommand->getCommand();
if(is_array($commandAsStringOrArray)){
foreach($commandAsStringOrArray as $command){
$this->ExternalCommandSaver->saveCommand($command, $ExternalCommandArgsQueryOptions->getNodeName());
}
return true;
}
return $this->ExternalCommandSaver->saveCommand($commandAsStringOrArray, $ExternalCommandArgsQueryOptions->getNodeName());
}
public function deleteHostIncludingServiceDowntimes(ExternalCommandArgsQueryOptions $ExternalCommandArgsQueryOptions, ScheduleddowntimeHostLoaderInterface $ScheduleddowntimeHostLoader, ScheduleddowntimeServiceLoaderInterface $ScheduleddowntimeServiceLoader){
$hostDowntime = $ScheduleddowntimeHostLoader->getScheduledHostdowntimeById($ExternalCommandArgsQueryOptions->getDowntimeId());
if(!empty($hostDowntime)){
$serviceDowntimes = $ScheduleddowntimeServiceLoader->getScheduledServicedowntimesByHostdowntime($hostDowntime[0]);
//Delete host downtime
$command = sprintf('[%s] DEL_HOST_DOWNTIME;%s', time(), $ExternalCommandArgsQueryOptions->getDowntimeId());
$this->ExternalCommandSaver->saveCommand($command, $ExternalCommandArgsQueryOptions->getNodeName());
//Delete service downtimes
foreach($serviceDowntimes as $serviceDowntime){
$command = sprintf('[%s] DEL_SVC_DOWNTIME;%s', time(), $serviceDowntime['internal_downtime_id']);
$this->ExternalCommandSaver->saveCommand($command, $ExternalCommandArgsQueryOptions->getNodeName());
}
}
}
}