Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overrides Enabled #419

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1361,13 +1361,13 @@ <h3 class="text--primary">{{ i18n.commentAddDetection }}</h3>
</div>
</v-col>
<v-data-table :sort-by.sync="sortBy" :expanded.sync="expanded" :sort-desc.sync="sortDesc" must-sort :headers="overrideHeaders"
:items="detect.overrides" item-key="index" show-expand single-expand :custom-sort="sortOverrides" hide-default-footer="true">
<template v-slot:item="{ item, index }">
:items="detect.overrides" show-expand single-expand :custom-sort="sortOverrides" hide-default-footer="true">
<template v-slot:item="{ item, index, expand, isExpanded }">
<tr>
<td>
<v-btn id="expandOverrideArrow" icon small @click="expand(item)">
<v-icon v-if="isExpanded(item)" :alt="i18n.overrideExpand" :title="i18n.eventExpandHelp" data-aid="detection_overrides_collapse">fa-angle-down</v-icon>
<v-icon v-if="!isExpanded(item)" :alt="i18n.overrideExpand" :title="i18n.eventExpandHelp" data-aid="detection_overrides_expand">fa-angle-right</v-icon>
<v-btn id="expandOverrideArrow" icon small @click="expand(!isExpanded)">
<v-icon v-if="isExpanded" :alt="i18n.overrideExpand" :title="i18n.eventExpandHelp" data-aid="detection_overrides_collapse">fa-angle-down</v-icon>
<v-icon v-else :alt="i18n.overrideExpand" :title="i18n.eventExpandHelp" data-aid="detection_overrides_expand">fa-angle-right</v-icon>
</v-btn>
</td>
<td v-for="field in overrideHeaders" :key="field.value" data-aid="detection_overrides_headers_display">
Expand Down Expand Up @@ -1543,32 +1543,32 @@ <h3 class="text--primary">{{ i18n.commentAddDetection }}</h3>
<v-data-table ref="historyTable" :sort-by.sync="historyTableOpts.sortBy" :sort-desc.sync="historyTableOpts.sortDesc" :items-per-page.sync="historyTableOpts.itemsPerPage"
:search="historyTableOpts.search" :footer-props="historyTableOpts.footerProps" must-sort :headers="historyTableOpts.headers"
:items="history" item-key="id" :loading="historyTableOpts.loading" :expanded="historyTableOpts.expanded" class="history-table">
<template v-slot:item="props">
<template v-slot:item="{item, index, expand, isExpanded}">
<tr>
<td class="associated actions">
<v-btn :id="`history-${props.index}-expand`" icon small @click="expandRow(props.item)">
<v-icon v-if="isExpanded(props.item)" :alt="i18n.expand" :title="i18n.expandHelp" data-aid="detection_history_collapse">fa-angle-down</v-icon>
<v-icon v-if="!isExpanded(props.item)" :alt="i18n.expand" :title="i18n.expandHelp" data-aid="detection_history_expand">fa-angle-right</v-icon>
<v-btn :id="`history-${index}-expand`" icon small @click="expand(!isExpanded)">
<v-icon v-if="isExpanded" :alt="i18n.expand" :title="i18n.expandHelp" data-aid="detection_history_collapse">fa-angle-down</v-icon>
<v-icon v-else :alt="i18n.expand" :title="i18n.expandHelp" data-aid="detection_history_expand">fa-angle-right</v-icon>
</v-btn>
</td>
<td class="associated" data-aid="detection_history_owner_display">
<v-avatar color="primary" class="mr-2 white--text" size="28" data-aid="detection_history_avatar_display">
<div class="font-weight-bold" :title="props.item.owner">
{{ $root.getAvatar(props.item.owner) }}
<div class="font-weight-bold" :title="item.owner">
{{ $root.getAvatar(item.owner) }}
</div>
</v-avatar>
{{ props.item.owner }}
{{ item.owner }}
</td>
<td class="associated" data-aid="detection_history_timestamp_display">{{ props.item.updateTime | formatDateTime }}</td>
<td class="associated" data-aid="detection_history_timestamp_display">{{ item.updateTime | formatDateTime }}</td>
<td class="associated" data-aid="detection_history_kind_display">
<v-icon>fa-magnifying-glass</v-icon>
<span class="rounded ml-2">{{ props.item.kind }}</span>
<span class="rounded ml-2">{{ item.kind }}</span>
</td>
<td class="associated" data-aid="detection_history_operation_display">
<v-icon v-if="props.item.operation.toLowerCase() == i18n.create.toLowerCase()">fa-plus</v-icon>
<v-icon v-if="props.item.operation.toLowerCase() == i18n.delete.toLowerCase()">fa-circle-xmark</v-icon>
<v-icon v-if="props.item.operation.toLowerCase() == i18n.update.toLowerCase()">fa-pencil-alt</v-icon>
<span class="rounded ml-2">{{ props.item.operation }}</span>
<v-icon v-if="item.operation.toLowerCase() == i18n.create.toLowerCase()">fa-plus</v-icon>
<v-icon v-if="item.operation.toLowerCase() == i18n.delete.toLowerCase()">fa-circle-xmark</v-icon>
<v-icon v-if="item.operation.toLowerCase() == i18n.update.toLowerCase()">fa-pencil-alt</v-icon>
<span class="rounded ml-2">{{ item.operation }}</span>
</td>
</tr>
</template>
Expand Down
48 changes: 3 additions & 45 deletions html/js/routes/detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,16 +862,6 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
}
return b < a ? -1 : 1;
},
expand(item) {
if (this.isExpanded(item)) {
this.expanded = [];
} else {
this.expanded = [item];
}
},
isExpanded(item) {
return (this.expanded.length > 0 && this.expanded[0] === item);
},
createNewOverride() {
this.newOverride = {
type: null,
Expand Down Expand Up @@ -966,6 +956,8 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
this.detect.overrides = [];
}

this.newOverride.isEnabled = true;

this.detect.overrides.push(this.newOverride);

this.saveDetection(false);
Expand Down Expand Up @@ -1013,21 +1005,7 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
this.saveDetection(false);
},
canAddOverride() {
if (this.detect.engine === 'elastalert') {
if (this.detect.overrides && this.detect.overrides.length > 0) {
for (let i = 0; i < this.detect.overrides.length; i++) {
if (this.detect.overrides[i].type === 'custom filter') {
// elastalert detections that already have a custom filter
// cannot have any other custom filter overrides
return false;
}
}
}
} else if (this.detect.engine === 'strelka') {
return false;
}

return true;
return this.detect.engine !== 'strelka';
},
tagOverrides() {
if (this.detect.overrides) {
Expand All @@ -1038,26 +1016,6 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
this.detect.overrides = [];
}
},
isExpanded(row) {
const expanded = this.historyTableOpts.expanded;
for (var i = 0; i < expanded.length; i++) {
if (expanded[i].id == row.id) {
return true;
}
}
return false;
},
async expandRow(row) {
const expanded = this.historyTableOpts.expanded;
for (var i = 0; i < expanded.length; i++) {
if (expanded[i].id == row.id) {
expanded.splice(i, 1);
return;
}
}

expanded.push(row);
},
prepareForInput(id) {
const el = document.getElementById(id)
el.scrollIntoView()
Expand Down
6 changes: 3 additions & 3 deletions html/js/routes/detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ test('canAddOverride elastalert', () => {

comp.detect.overrides = [
{
type: 'custom filter',
type: 'customFilter',
isEnabled: 'isEnabled',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
Expand All @@ -290,7 +290,7 @@ test('canAddOverride elastalert', () => {
},
];

expect(comp.canAddOverride()).toBe(false);
expect(comp.canAddOverride()).toBe(true);
});

test('tagOverrides', () => {
Expand All @@ -305,6 +305,6 @@ test('tagOverrides', () => {
comp.tagOverrides();

for (let i = 0; i < comp.detect.overrides.length; i++) {
expect(comp.detect.overrides[0]).toStrictEqual({ index: 0 });
expect(comp.detect.overrides[i]).toStrictEqual({ index: i });
}
});
Loading