summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorSimon Rettberg2025-02-25 16:16:52 +0100
committerSimon Rettberg2025-02-25 16:16:52 +0100
commitf33b895e72c7cb849ebb742cd8331e8646b8acd6 (patch)
treeef8e3092c3d57819b7ba7a05fced3f8a4658c9a9 /modules-available
parent[eventlog] Add Matrix as transport protocol (diff)
downloadslx-admin-f33b895e72c7cb849ebb742cd8331e8646b8acd6.tar.gz
slx-admin-f33b895e72c7cb849ebb742cd8331e8646b8acd6.tar.xz
slx-admin-f33b895e72c7cb849ebb742cd8331e8646b8acd6.zip
[eventlog] Track when a filter rule was last triggered
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/eventlog/inc/filterruleprocessor.inc.php15
-rw-r--r--modules-available/eventlog/install.inc.php11
-rw-r--r--modules-available/eventlog/lang/de/template-tags.json1
-rw-r--r--modules-available/eventlog/lang/en/template-tags.json3
-rw-r--r--modules-available/eventlog/pages/rules.inc.php5
-rw-r--r--modules-available/eventlog/templates/page-filters-rules.html8
-rw-r--r--modules-available/eventlog/templates/page-filters-transports.html8
-rw-r--r--modules-available/eventlog/templates/page-header.html20
8 files changed, 58 insertions, 13 deletions
diff --git a/modules-available/eventlog/inc/filterruleprocessor.inc.php b/modules-available/eventlog/inc/filterruleprocessor.inc.php
index dd0160d7..ae60fb40 100644
--- a/modules-available/eventlog/inc/filterruleprocessor.inc.php
+++ b/modules-available/eventlog/inc/filterruleprocessor.inc.php
@@ -106,11 +106,13 @@ class FilterRuleProcessor
for ($i = 1; $i < count($types); ++$i) {
$types[$i] = $types[$i-1] . '-' . $types[$i];
}
- $res = Database::simpleQuery("SELECT ruleid, datafilter, subject, message
- FROM notification_rule
- WHERE type IN (:types)",
+ $res = Database::simpleQuery("SELECT DISTINCT r.ruleid, r.datafilter, r.subject, r.message
+ FROM notification_rule r
+ INNER JOIN notification_rule_x_transport USING (ruleid)
+ WHERE r.type IN (:types)",
['types' => $types]);
// Iterate over all matching filter rules
+ $firedRuleIds = [];
foreach ($res as $rule) {
if (empty($rule['message']) && empty($rule['subject'])) {
error_log('Filter rule with empty subject and message');
@@ -146,8 +148,15 @@ class FilterRuleProcessor
}
if ($globalMatch) {
self::fireEvent($rule, $values);
+ $firedRuleIds[] = $rule['ruleid'];
}
}
+ if (!empty($firedRuleIds)) {
+ Database::exec("UPDATE notification_rule
+ SET lasttime = UNIX_TIMESTAMP()
+ WHERE ruleid IN (:ruleids)",
+ ['ruleids' => $firedRuleIds]);
+ }
}
/**
diff --git a/modules-available/eventlog/install.inc.php b/modules-available/eventlog/install.inc.php
index 5827e225..8ea17187 100644
--- a/modules-available/eventlog/install.inc.php
+++ b/modules-available/eventlog/install.inc.php
@@ -22,6 +22,7 @@ $res[] = tableCreate('notification_rule', '
`subject` varchar(200) NOT NULL,
`message` text NOT NULL,
`predefid` int(10) UNSIGNED NULL DEFAULT NULL,
+ `lasttime` int(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`ruleid`),
KEY `type` (`type`),
UNIQUE KEY `predefid` (`predefid`)
@@ -107,9 +108,17 @@ $q = "INSERT IGNORE INTO `notification_rule`
(12,'Neues MaxiLinux verfügbar','Ein neues MaxiLinux (stabil oder beta) wurde veröffentlicht','#netboot-new-version','{\"list\":[{\"path\":\"branchid\",\"op\":\"*\",\"index\":0},{\"path\":\"versionid\",\"op\":\"*\",\"index\":1},{\"path\":\"title\",\"op\":\"*\",\"index\":2},{\"path\":\"description\",\"op\":\"*\",\"index\":3},{\"path\":\"dateline\",\"op\":\"*\",\"index\":4}]}','Neues MaxiLinux','Sehr geehrte Frau Müller,\r\n\r\nEs gibt ein neues MaxiLinux in der Kategorie %0%, veröffentlicht am %4ts%.\r\n%2%\r\n\r\nChangelog:\r\n%3%'),
(13,'dnbd3-proxy Korruption','Checksum-Prüfung auf einem dnbd3-proxy schlug fehl. (Bei regelmäßigem Auftreten RAM und HDD überprüfen.)','dnbd3-hashfail','{\"list\":[{\"path\":\"description\",\"op\":\"regex\",\"arg\":\"\\\\/\\\\\\\\[[0-9]+\\\\\\\\]: (.*)$\\\\/\",\"index\":0},{\"path\":\"clientip\",\"op\":\"*\",\"index\":1}]}','Checksum error dnbd3-proxy %1%','%0:1%')
";
-
Database::exec($q);
+// 2025-02-25: Add lasttime column to track when it was last triggered
+if (!tableHasColumn('notification_rule', 'lasttime')) {
+ if (Database::exec("ALTER TABLE notification_rule
+ ADD COLUMN `lasttime` int(10) UNSIGNED NULL DEFAULT NULL") === false) {
+ finalResponse(UPDATE_FAILED, 'Could not add lasttime to notification_rule: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+
// Create response for browser
if (in_array(UPDATE_DONE, $res)) {
diff --git a/modules-available/eventlog/lang/de/template-tags.json b/modules-available/eventlog/lang/de/template-tags.json
index d65b09de..b8e3ded5 100644
--- a/modules-available/eventlog/lang/de/template-tags.json
+++ b/modules-available/eventlog/lang/de/template-tags.json
@@ -33,6 +33,7 @@
"lang_ircServerPassword": "Server-Passwort",
"lang_ircTarget": "Senden an #Kanal\/Nick",
"lang_jsonStringHelp": "Formulieren Sie eine JSON-Struktur, die die Platzhalter %SUBJECT% und %TEXT% f\u00fcr beliebige Werte enth\u00e4lt.",
+ "lang_lastTriggeredColumn": "Zuletzt",
"lang_logAndEvents": "Server-Log und Ereignis\u00fcberwachung",
"lang_mail": "EMail",
"lang_mailConfig": "EMail-Konfiguration",
diff --git a/modules-available/eventlog/lang/en/template-tags.json b/modules-available/eventlog/lang/en/template-tags.json
index d88ef6e2..6bd914de 100644
--- a/modules-available/eventlog/lang/en/template-tags.json
+++ b/modules-available/eventlog/lang/en/template-tags.json
@@ -33,6 +33,7 @@
"lang_ircServerPassword": "Server password",
"lang_ircTarget": "Target Channel\/Nick",
"lang_jsonStringHelp": "Supply a json struct containing placeholders %SUBJECT% and\/or %TEXT% in the \"HTTP post payload\" fied above.",
+ "lang_lastTriggeredColumn": "Last",
"lang_logAndEvents": "Server log and event filtering",
"lang_mail": "Mail",
"lang_mailConfig": "Mail config",
@@ -42,6 +43,8 @@
"lang_matrixRoom": "RoomID",
"lang_matrixServer": "Server",
"lang_matrixUsageHints": "Please make sure the account is already a member of the desired room, as the client library will not automatically join rooms, or accept invitations. Please note that E2E-encryption is not supported. Messages will be sent unencrypted (apart from using https for the connection itself). If you want to use an access token, enter it in the password field and leave the username blank.",
+ "lang_matrixUser": "Account name",
+ "lang_matrixUserPassword": "Account password",
"lang_messageTemplate": "Message template",
"lang_messageTemplateHelp": "You can refer to the matched rules above by using their index in percentage-signs, like %0%, %1%, etc. If you use a regex with capture groups, you can refer to them individually by using %n:1%, %n:2% etc. Furthermode, you can format raw numbers by appending \"b\", \"kb\", \"mb\", \"gb\" to interpret the given value as bytes (or kilobytes, megabytes, etc.), \"ts\" if the input value is a unix timestamp, \"d\" to turn a duration in seconds into human readable format, and \"L\" to turn a location id into the according location name.",
"lang_noMailConfig": "No mail config",
diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php
index ca39b15b..ca40714f 100644
--- a/modules-available/eventlog/pages/rules.inc.php
+++ b/modules-available/eventlog/pages/rules.inc.php
@@ -96,13 +96,16 @@ class SubPage
} else {
// LIST
$data = [];
- $data['filters'] = Database::queryAll('SELECT ruleid, type, title, description, datafilter,
+ $data['filters'] = Database::queryAll('SELECT ruleid, type, title, description, datafilter, lasttime,
Count(transportid) AS useCount
FROM notification_rule
LEFT JOIN notification_rule_x_transport sfxb USING (ruleid)
GROUP BY ruleid, title
ORDER BY SIGN(Count(transportid)) DESC, title, ruleid');
//usort($data['filters'])
+ foreach ($data['filters'] as &$filter) {
+ $filter['lasttime_s'] = ($filter['useCount'] > 0 && $filter['lasttime'] > 0) ? Util::prettyTime($filter['lasttime']) : '-';
+ }
Permission::addGlobalTags($data['perms'], null, ['filter.rules.edit']);
Render::addTemplate('page-filters-rules', $data);
}
diff --git a/modules-available/eventlog/templates/page-filters-rules.html b/modules-available/eventlog/templates/page-filters-rules.html
index 680b71d8..babfc14a 100644
--- a/modules-available/eventlog/templates/page-filters-rules.html
+++ b/modules-available/eventlog/templates/page-filters-rules.html
@@ -7,7 +7,8 @@
<th class="slx-smallcol">{{lang_id}}</th>
<th class="slx-smallcol">{{lang_type}}</th>
<th>{{lang_title}}</th>
- <th class="slx-smallcol"></th>
+ <th class="slx-smallcol" title="{{lang_transports}}"><span class="glyphicon glyphicon-road"></span></th>
+ <th class="slx-smallcol">{{lang_lastTriggeredColumn}}</th>
<th class="slx-smallcol">{{lang_edit}}</th>
</tr>
</thead>
@@ -22,9 +23,12 @@
</td>
<td class="text-right">
{{#useCount}}
- <span class="badge">{{useCount}}</span>
+ <span class="badge" title="{{lang_transports}}">{{useCount}}</span>
{{/useCount}}
</td>
+ <td class="text-right">
+ {{lasttime_s}}
+ </td>
<td class="slx-smallcol">
<a class="btn btn-xs btn-default {{perms.filter.rules.edit.disabled}}"
href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}" title="{{lang_edit}}">
diff --git a/modules-available/eventlog/templates/page-filters-transports.html b/modules-available/eventlog/templates/page-filters-transports.html
index 3047e437..fe70eca8 100644
--- a/modules-available/eventlog/templates/page-filters-transports.html
+++ b/modules-available/eventlog/templates/page-filters-transports.html
@@ -8,7 +8,7 @@
<th class="slx-smallcol">{{lang_type}}</th>
<th>{{lang_title}}</th>
<th>{{lang_details}}</th>
- <th class="slx-smallcol"></th>
+ <th class="slx-smallcol" title="{{lang_filterRules}}"><span class="glyphicon glyphicon-filter"></span></th>
<th class="slx-smallcol">{{lang_edit}}</th>
</tr>
</thead>
@@ -19,7 +19,11 @@
<td>{{type}}</td>
<td>{{title}}</td>
<td class="small">{{details.toString}}</td>
- <td><span class="badge">{{useCount}}</span></td>
+ <td>
+ {{#useCount}}
+ <span class="badge" title="{{lang_filterRules}}">{{useCount}}</span>
+ {{/useCount}}
+ </td>
<td class="slx-smallcol">
<a class="btn btn-xs btn-default"
href="?do=eventlog&amp;show=transports&amp;id={{transportid}}">
diff --git a/modules-available/eventlog/templates/page-header.html b/modules-available/eventlog/templates/page-header.html
index a5e30af9..1da344eb 100644
--- a/modules-available/eventlog/templates/page-header.html
+++ b/modules-available/eventlog/templates/page-header.html
@@ -2,15 +2,27 @@
<ul class="nav nav-tabs">
<li class="{{active_log}}">
- <a href="?do=eventlog&amp;show=log">{{lang_eventLog}}</a>
+ <a href="?do=eventlog&amp;show=log">
+ <span class="glyphicon glyphicon-list"></span>
+ {{lang_eventLog}}
+ </a>
</li>
<li class="{{active_rules}}">
- <a href="?do=eventlog&amp;show=rules">{{lang_filterRules}}</a>
+ <a href="?do=eventlog&amp;show=rules">
+ <span class="glyphicon glyphicon-filter"></span>
+ {{lang_filterRules}}
+ </a>
</li>
<li class="{{active_transports}}">
- <a href="?do=eventlog&amp;show=transports">{{lang_transports}}</a>
+ <a href="?do=eventlog&amp;show=transports">
+ <span class="glyphicon glyphicon-road"></span>
+ {{lang_transports}}
+ </a>
</li>
<li class="{{active_mailconfigs}}">
- <a href="?do=eventlog&amp;show=mailconfigs">{{lang_mailconfigs}}</a>
+ <a href="?do=eventlog&amp;show=mailconfigs">
+ <span class="glyphicon glyphicon-envelope"></span>
+ {{lang_mailconfigs}}
+ </a>
</li>
</ul> \ No newline at end of file