From 32f0677dbca9e3347b931c1d0105eb37aa57e90d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 25 Jun 2021 16:21:17 +0200 Subject: [eventlog] Add event filtering and notification system --- .../rebootcontrol/inc/rebootcontrol.inc.php | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'modules-available/rebootcontrol') 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; + } + } + } -- cgit v1.2.3-55-g7522