summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol
diff options
context:
space:
mode:
authorSimon Rettberg2021-06-25 16:21:17 +0200
committerSimon Rettberg2021-06-25 16:21:17 +0200
commit32f0677dbca9e3347b931c1d0105eb37aa57e90d (patch)
treeddad4562e7ee8439a24e2462d44614692bb71d14 /modules-available/rebootcontrol
parentUpdate .idea (diff)
downloadslx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.gz
slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.tar.xz
slx-admin-32f0677dbca9e3347b931c1d0105eb37aa57e90d.zip
[eventlog] Add event filtering and notification system
Diffstat (limited to 'modules-available/rebootcontrol')
-rw-r--r--modules-available/rebootcontrol/inc/rebootcontrol.inc.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
index 71801f1a..59d20641 100644
--- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
+++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
@@ -49,6 +49,11 @@ class RebootControl
));
if (!Taskmanager::isFailed($task)) {
self::addTask($task['id'], self::TASK_REBOOTCTL, $list, $task['id'], ['action' => $mode]);
+ foreach ($list as $client) {
+ $client['mode'] = $mode;
+ $client['minutes'] = $minutes;
+ EventLog::applyFilterRules('#action-power', $client);
+ }
}
return $task;
}
@@ -297,6 +302,8 @@ class RebootControl
$errors = '';
$tasks = [];
$bad = $unknown = [];
+ // For event filtering by rule
+ $events = [];
// Need all subnets...
$subnets = [];
$res = Database::simpleQuery('SELECT subnetid, start, end, isdirect FROM reboot_subnet');
@@ -387,6 +394,8 @@ class RebootControl
// TODO: Figure out $subnet from $bcast and queue as indirect
// (rather, overhaul this whole spaghetti code)
$errors .= ".... FAILED TO LAUNCH TASK ON JUMPHOST!\n";
+ } else {
+ self::addEventList($events, $clients, 'jumphost', $jh['host']);
}
}
}
@@ -399,6 +408,8 @@ class RebootControl
$errors .= "Re-queueing clients for indirect wakeup\n";
$subnet['indirect'] = array_merge($subnet['indirect'], $subnet['direct']);
}
+ } else {
+ self::addEventList($events, $subnet['direct'], 'satellite');
}
}
if (!empty($subnet['indirect'])) {
@@ -411,10 +422,15 @@ class RebootControl
$errors .= "Re-re-queueing clients for indirect wakeup\n";
$ok = false;
}
+ } else {
+ self::addEventList($events, $subnet['indirect'], 'same-subnet', $subnet['dclients'][0]['clientip']);
}
}
if (!$ok && !empty($subnet['iclients'])) {
$ok = self::wakeGroup('across subnets', $tasks, $errors, $subnet['iclients'], $subnet['indirect'], $subnet['end']);
+ if ($ok) {
+ self::addEventList($events, $subnet['indirect'], 'other-subnet', $subnet['iclients'][0]['clientip']);
+ }
}
if (!$ok) {
$errors .= "I'm all out of ideas.\n";
@@ -432,6 +448,9 @@ class RebootControl
$failed = array_merge($bad, $unknown);
$id = Util::randomUuid();
self::addTask($id, self::TASK_WOL, $list, $tasks, ['log' => $errors]);
+ foreach ($events as $event) {
+ EventLog::applyFilterRules('#action-wol', $event);
+ }
return $id;
}
@@ -497,4 +516,22 @@ class RebootControl
Util::redirect('?do=rebootcontrol&show=exec&what=prepare&id=' . $id);
}
+ /**
+ * Add given clients to given event array
+ * @param array $events
+ * @param array $clients
+ * @param string $type
+ * @param null $via
+ */
+ private static function addEventList(array &$events, array $clients, string $type, $via = null)
+ {
+ foreach ($clients as $client) {
+ $client['type'] = $type;
+ if (!empty($via)) {
+ $client['via'] = $via;
+ }
+ $events[] = $client;
+ }
+ }
+
}