summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-08-02 16:50:08 +0200
committerSimon Rettberg2023-08-02 16:50:08 +0200
commiteae4090944fb922d44899913b6d5cdaa97dc1041 (patch)
tree7bbb14fdbb3b5229e3b1c08d65b13f2c82435f35
parent[minilinux] Only create new branch if it contains any versions (diff)
downloadslx-admin-eae4090944fb922d44899913b6d5cdaa97dc1041.tar.gz
slx-admin-eae4090944fb922d44899913b6d5cdaa97dc1041.tar.xz
slx-admin-eae4090944fb922d44899913b6d5cdaa97dc1041.zip
[statistics] Add button to copy existing rule
-rw-r--r--modules-available/eventlog/inc/filterruleprocessor.inc.php4
-rw-r--r--modules-available/eventlog/lang/de/template-tags.json2
-rw-r--r--modules-available/eventlog/lang/en/template-tags.json2
-rw-r--r--modules-available/eventlog/pages/rules.inc.php38
-rw-r--r--modules-available/eventlog/templates/page-filters-edit-rule.html12
-rw-r--r--modules-available/eventlog/templates/page-filters-rules.html36
-rw-r--r--modules-available/statistics/api.inc.php5
7 files changed, 64 insertions, 35 deletions
diff --git a/modules-available/eventlog/inc/filterruleprocessor.inc.php b/modules-available/eventlog/inc/filterruleprocessor.inc.php
index 17a63e38..24b37444 100644
--- a/modules-available/eventlog/inc/filterruleprocessor.inc.php
+++ b/modules-available/eventlog/inc/filterruleprocessor.inc.php
@@ -323,7 +323,9 @@ class FilterRuleProcessor
case 'd':
return Util::formatDuration((int)$v);
case 'L':
- return Location::getName((int)$v);
+ if (Module::isAvailable('locations'))
+ return Location::getName((int)$v) ?: '-';
+ break;
case '':
break;
default:
diff --git a/modules-available/eventlog/lang/de/template-tags.json b/modules-available/eventlog/lang/de/template-tags.json
index 34f7147b..df8e23d2 100644
--- a/modules-available/eventlog/lang/de/template-tags.json
+++ b/modules-available/eventlog/lang/de/template-tags.json
@@ -3,6 +3,8 @@
"lang_additionalMailAddresses": "Zus\u00e4tzliche EMail-Adressen",
"lang_autoJson": "Vollst\u00e4ndige JSON-Daten",
"lang_autoJsonHelp": "Das Feld \"POST-Format\" wird ignoriert. Die POST-Daten sind eine JSON-Struktur mit allen zum Ereignis geh\u00f6renden Daten. Die Felder \"Betreff\" und \"Nachricht\" werden ebenfalls ignoriert.",
+ "lang_copy": "Kopieren",
+ "lang_createFilter": "Filter erstellen",
"lang_details": "Details",
"lang_editFilter": "Filter bearbeiten",
"lang_editMail": "EMail bearbeiten",
diff --git a/modules-available/eventlog/lang/en/template-tags.json b/modules-available/eventlog/lang/en/template-tags.json
index 90425156..55ebda89 100644
--- a/modules-available/eventlog/lang/en/template-tags.json
+++ b/modules-available/eventlog/lang/en/template-tags.json
@@ -3,6 +3,8 @@
"lang_additionalMailAddresses": "Additional mail addresses",
"lang_autoJson": "Full JSON data",
"lang_autoJsonHelp": "The field \"POST format\" is ignored. The POST payload is a JSON struct with all available data regarding the according event. \"Subject\" and \"Message\" are ignored as well.",
+ "lang_copy": "Copy",
+ "lang_createFilter": "Create filter",
"lang_details": "Details",
"lang_editFilter": "Edit filter",
"lang_editMail": "Edit mail",
diff --git a/modules-available/eventlog/pages/rules.inc.php b/modules-available/eventlog/pages/rules.inc.php
index d60dcc07..6d240c73 100644
--- a/modules-available/eventlog/pages/rules.inc.php
+++ b/modules-available/eventlog/pages/rules.inc.php
@@ -101,6 +101,7 @@ class SubPage
LEFT JOIN notification_rule_x_transport sfxb USING (ruleid)
GROUP BY ruleid, title
ORDER BY title, ruleid');
+ Permission::addGlobalTags($data['perms'], null, ['filter.rules.edit']);
Render::addTemplate('page-filters-rules', $data);
}
}
@@ -112,8 +113,8 @@ class SubPage
{
// EDIT
User::assertPermission('filter.rules.edit');
- $index = 0;
- $existing = [];
+ $filterIdx = 0;
+ $knownIdxList = [];
if ($id !== 0) {
$data = Database::queryFirst('SELECT ruleid, title, type, datafilter, subject, message
FROM notification_rule WHERE ruleid = :id', ['id' => $id]);
@@ -121,21 +122,25 @@ class SubPage
Message::addError('invalid-rule-id', $id);
Util::redirect('?do=eventlog&show=rules');
}
+ if (Request::get('copy', false, 'bool')) {
+ $data['ruleid'] = 0;
+ $data['title'] = '';
+ }
$list = json_decode($data['datafilter'], true);
if (!is_array($list['list'])) {
$list['list'] = [];
}
foreach ($list['list'] as $item) {
if (isset($item['index'])) {
- $existing[] = $item['index'];
+ $knownIdxList[] = $item['index'];
}
}
foreach ($list['list'] as &$item) {
if (!isset($item['index'])) {
- while (in_array($index, $existing)) {
- $index++;
+ while (in_array($filterIdx, $knownIdxList)) {
+ $filterIdx++;
}
- $item['index'] = $index++;
+ $item['index'] = $filterIdx++;
}
$item['operators'] = [];
foreach (self::OP_LIST as $op) {
@@ -147,18 +152,9 @@ class SubPage
}
$data['filter'] = $list['list'];
} else {
+ // New entry
$data = ['filter' => [], 'ruleid' => 0];
}
- // Add a few empty rows at the bottom
- for ($i = 0; $i < 8; ++$i) {
- while (in_array($index, $existing)) {
- $index++;
- }
- $data['filter'][] = [
- 'index' => $index++,
- 'operators' => array_map(function ($item) { return ['name' => $item]; }, self::OP_LIST),
- ];
- }
// Add suggestions for type
$data['types'] = Database::queryColumnArray("SELECT DISTINCT type
FROM notification_sample
@@ -174,6 +170,16 @@ class SubPage
// Filter keys to suggest for events with machineuuid in data
$data['machine_keys'] = array_keys(FilterRuleProcessor::HW_QUERIES);
}
+ // Add a few empty rows at the bottom
+ for ($i = 0; $i < 8; ++$i) {
+ while (in_array($filterIdx, $knownIdxList)) {
+ $filterIdx++;
+ }
+ $data['filter'][] = [
+ 'index' => $filterIdx++,
+ 'operators' => array_map(function ($item) { return ['name' => $item]; }, self::OP_LIST),
+ ];
+ }
Render::addTemplate('page-filters-edit-rule', $data);
}
diff --git a/modules-available/eventlog/templates/page-filters-edit-rule.html b/modules-available/eventlog/templates/page-filters-edit-rule.html
index 0678dd97..318a8656 100644
--- a/modules-available/eventlog/templates/page-filters-edit-rule.html
+++ b/modules-available/eventlog/templates/page-filters-edit-rule.html
@@ -1,4 +1,12 @@
-<h2>{{lang_editFilter}} {{#title}}–{{/title}} {{title}}</h2>
+<h2>
+ {{#ruleid}}
+ {{lang_editFilter}}
+ {{/ruleid}}
+ {{^ruleid}}
+ {{lang_createFilter}}
+ {{/ruleid}}
+</h2>
+<h3>{{title}}</h3>
<p>{{lang_filterExampleHelpText}}</p>
@@ -199,7 +207,7 @@
}
});
};
- $fkInputs.on('input', chFn).change(chFn);
+ $fkInputs.on('input', chFn).change(chFn).each(chFn);
typeFieldChangeUpdate();
});
</script>
diff --git a/modules-available/eventlog/templates/page-filters-rules.html b/modules-available/eventlog/templates/page-filters-rules.html
index 524e71b2..56bf0871 100644
--- a/modules-available/eventlog/templates/page-filters-rules.html
+++ b/modules-available/eventlog/templates/page-filters-rules.html
@@ -14,22 +14,26 @@
</thead>
<tbody>
{{#filters}}
- <tr>
- <td>{{ruleid}}</td>
- <td>{{type}}</td>
- <td class="text-nowrap">{{title}}</td>
- <!--td class="small">{.{datafilter}.}</td-->
- <td><span class="badge">{{useCount}}</span></td>
- <td class="slx-smallcol">
- <a class="btn btn-xs btn-default" href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}">
+ <tr>
+ <td>{{ruleid}}</td>
+ <td>{{type}}</td>
+ <td class="text-nowrap">{{title}}</td>
+ <td><span class="badge">{{useCount}}</span></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}}">
<span class="glyphicon glyphicon-edit" aria-label="{{lang_edit}}"></span>
- </a>
- <button class="btn btn-xs btn-danger" type="submit" name="id" value="{{ruleid}}"
- data-confirm="{{lang_reallyDelete}}">
- <span class="glyphicon glyphicon-trash"></span>
- </button>
- </td>
- </tr>
+ </a>
+ <a class="btn btn-xs btn-default {{perms.filter.rules.edit.disabled}}"
+ href="?do=eventlog&amp;show=rules&amp;id={{ruleid}}&amp;copy=1" title="{{lang_copy}}">
+ <span class="glyphicon glyphicon-duplicate" aria-label="{{lang_copy}}"></span>
+ </a>
+ <button class="btn btn-xs btn-danger" type="submit" name="id" value="{{ruleid}}" title="{{lang_delete}}"
+ data-confirm="{{lang_reallyDelete}}" {{perms.filter.rules.edit.disabled}}>
+ <span class="glyphicon glyphicon-trash"></span>
+ </button>
+ </td>
+ </tr>
{{/filters}}
</tbody>
</table>
@@ -37,7 +41,7 @@
</form>
<div class="buttonbar text-right">
- <a class="btn btn-success" href="?do=eventlog&amp;show=rules&amp;id=0">
+ <a class="btn btn-success {{perms.filter.rules.edit.disabled}}" href="?do=eventlog&amp;show=rules&amp;id=0">
<span class="glyphicon glyphicon-plus"></span>
{{lang_add}}
</a>
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index d6549392..6875193d 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -193,6 +193,11 @@ if ($type[0] === '~') {
// Add anything not present in $new from $old
$new += $old;
$new['oldlastboot'] = $old['lastboot'];
+ } else {
+ // First boot, mock some important fields for event log filtering
+ $new['oldlastboot'] = 0;
+ $new['oldlastseen'] = 0;
+ $new['oldstate'] = 'OFFLINE';
}
unset($new['data']);