From a86a2ddb781d5368a0b1f4b8a913dd21a7f67588 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 3 Aug 2023 15:57:36 +0200 Subject: [eventlog] Add example filter rules --- modules-available/eventlog/install.inc.php | 28 +++++++++++++++++++++- modules-available/eventlog/pages/rules.inc.php | 9 +++---- .../eventlog/templates/page-filters-edit-rule.html | 6 +++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/modules-available/eventlog/install.inc.php b/modules-available/eventlog/install.inc.php index def608aa..75286af5 100644 --- a/modules-available/eventlog/install.inc.php +++ b/modules-available/eventlog/install.inc.php @@ -21,8 +21,10 @@ $res[] = tableCreate('notification_rule', ' `datafilter` blob NOT NULL, `subject` varchar(200) NOT NULL, `message` text NOT NULL, + `predefid` int(10) UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (`ruleid`), - KEY `type` (`type`) + KEY `type` (`type`), + UNIQUE KEY `predefid` (`predefid`) '); $res[] = tableCreate('notification_backend', ' @@ -79,6 +81,30 @@ if (!tableHasColumn('notification_sample', 'extended')) { $res[] = UPDATE_DONE; } +// 2023-08-03: Add a few example filters +if (!tableHasColumn('notification_rule', 'predefid')) { + if (Database::exec("ALTER TABLE notification_rule + ADD COLUMN `predefid` int(10) UNSIGNED NULL DEFAULT NULL, + ADD UNIQUE KEY `predefid` (`predefid`)") === false) { + finalResponse(UPDATE_FAILED, 'Could not add predefid to notification_rule: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} +$q = "INSERT IGNORE INTO `notification_rule` + (predefid, title, `description`, type, datafilter, subject, message) + VALUES + (1,'Session start','Benachrichtigung über jede gestartete Session','.vmchooser-session','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentuser\",\"op\":\"*\",\"index\":2},{\"path\":\"sessionName\",\"op\":\"*\",\"index\":3}]}','Sitzungsstart','Client %0% - User %2% startet Veranstaltung %3%'), + (2,'PowerON: bwlp-Default','Kein spezieller Betriebsmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"\",\"index\":1},{\"path\":\"locationid\",\"op\":\"*\",\"index\":2}]}','PowerON-Event','Client %0% in Raum %2L% startet im Modus \'Standard\''), + (3,'Serverlog','Jegliche neue Einträge im Server-Log','#serverlog','{\"list\":[{\"path\":\"type\",\"op\":\"*\",\"index\":0},{\"path\":\"message\",\"op\":\"*\",\"index\":1},{\"path\":\"details\",\"op\":\"*\",\"index\":2}]}','','[%0%] - %1% - %2%'), + (4,'PowerON: Exammode','Rechner startet im Klausurmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"exams\",\"index\":1}]}','','Client %0% startet im Modus \'Prüfung\''), + (5,'PowerON: Remoteaccess','Rechner startet im Fernzugriffsmodus','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"currentrunmode\",\"op\":\"=\",\"arg\":\"remoteaccess\",\"index\":1}]}','','Client %0% startet im Modus \'Fernzugriff\''), + (6,'NIC: Slow Uplink','Rechner ist mit weniger als 1GBit/s mit dem Switch verbunden','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"nic_speed\",\"op\":\"<\",\"arg\":\"1000\",\"index\":1}]}','','Client %0% hat einen Uplink von %1% MBit/s'), + (7,'First boot of new Client','Neuer Client wurde gestartet, der dem Server bisher nicht bekannt war','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"hostname\",\"op\":\"*\",\"index\":1},{\"path\":\"oldlastseen\",\"op\":\"=\",\"arg\":\"0\",\"index\":2}]}','','Neuer Client %0% (%1%) bootet bwLehrpool'), + (8,'Rechner mit Platte, ohne ID44','Besagter Rechner hat zwar eine HDD/SSD verbaut, aber keine ID44-Partition','~poweron','{\"list\":[{\"path\":\"clientip\",\"op\":\"*\",\"index\":0},{\"path\":\"hdd_size\",\"op\":\">\",\"arg\":\"0\",\"index\":1},{\"path\":\"id44mb\",\"op\":\"=\",\"arg\":\"0\",\"index\":2},{\"path\":\"hostname\",\"op\":\"*\",\"index\":3}]}','Hallo','%3% (%0%) hat HDD %1b%, keine ID44 Partition'), + (9,'Lahmes Netzwerk, keine ID45','Rechner ist mit weniger als 1GBit/s mit dem Switch verbunden, und besitzt keine ID45-Partition','~poweron','{\"list\":[{\"path\":\"id45mb\",\"op\":\"=\",\"arg\":\"0\",\"index\":0},{\"path\":\"nic_speed\",\"op\":\"<\",\"arg\":\"1000\",\"index\":1},{\"path\":\"hostname\",\"op\":\"*\",\"index\":2},{\"path\":\"nic_speed\",\"op\":\">\",\"arg\":\"0\",\"index\":3},{\"path\":\"clientip\",\"op\":\"*\",\"index\":4}]}','Lahm','%2% (%4%) hat %1%MBit und keine ID45'), + (10,'Drehende Platte','Rechner hat eine Rotierende HDD und keine SSD.','~poweron','{\"list\":[{\"path\":\"hdd_rpm\",\"op\":\">\",\"arg\":\"0\",\"index\":0},{\"path\":\"clientip\",\"op\":\"*\",\"index\":1},{\"path\":\"hostname\",\"op\":\"*\",\"index\":2}]}','Da dreht was im Rechner...','Rechner %2% (%1%) hat drehende Platte (%0% RPM)')"; +Database::exec($q); + // Create response for browser if (in_array(UPDATE_DONE, $res)) { diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php index 6d240c73..7b43cfdb 100644 --- a/modules-available/eventlog/pages/rules.inc.php +++ b/modules-available/eventlog/pages/rules.inc.php @@ -48,17 +48,18 @@ class SubPage 'id' => $id, 'type' => $type, 'title' => $title, + 'description' => Request::post('description', '', 'string'), 'data' => json_encode(['list' => array_values($filters)]), 'subject' => Request::post('subject', '', 'string'), 'message' => $message, ]; if ($id === null) { // NEW - Database::exec("INSERT INTO notification_rule (ruleid, type, title, datafilter, subject, message) - VALUES (:id, :type, :title, :data, :subject, :message)", $data); + Database::exec("INSERT INTO notification_rule (ruleid, title, description, type, datafilter, subject, message) + VALUES (:id, :title, :description, :type, :data, :subject, :message)", $data); $id = Database::lastInsertId(); } else { - Database::exec("UPDATE notification_rule SET type = :type, title = :title, datafilter = :data, + Database::exec("UPDATE notification_rule SET type = :type, title = :title, description = :description, datafilter = :data, subject = :subject, message = :message WHERE ruleid = :id", $data); } @@ -116,7 +117,7 @@ class SubPage $filterIdx = 0; $knownIdxList = []; if ($id !== 0) { - $data = Database::queryFirst('SELECT ruleid, title, type, datafilter, subject, message + $data = Database::queryFirst('SELECT ruleid, title, description, type, datafilter, subject, message FROM notification_rule WHERE ruleid = :id', ['id' => $id]); if ($data === false) { Message::addError('invalid-rule-id', $id); diff --git a/modules-available/eventlog/templates/page-filters-edit-rule.html b/modules-available/eventlog/templates/page-filters-edit-rule.html index 318a8656..42d601f2 100644 --- a/modules-available/eventlog/templates/page-filters-edit-rule.html +++ b/modules-available/eventlog/templates/page-filters-edit-rule.html @@ -29,6 +29,12 @@ +
+
+ + +
+
-- cgit v1.2.3-55-g7522