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

Get processing timeline events #3241

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion timesketch/api/v1/resources/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def post(self, sketch_id):
sketch_indices = {
t.searchindex.index_name
for t in sketch.timelines
if t.get_status.status.lower() == "ready"
if t.get_status.status.lower() in ["ready", "processing"]
}

aggregation_dsl = form.aggregation_dsl.data
Expand Down
8 changes: 6 additions & 2 deletions timesketch/api/v1/resources/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def post(self, sketch_id):
query_filter = request.json.get("filter", {})
parent = request.json.get("parent", None)
incognito = request.json.get("incognito", False)

include_processing_timelines = request.json.get(
"includeProcessingTimelines", False
)
return_field_string = form.fields.data
if return_field_string:
return_fields = [x.strip() for x in return_field_string.split(",")]
Expand All @@ -163,7 +165,9 @@ def post(self, sketch_id):

# Make sure that the indices in the filter are part of the sketch.
# This will also remove any deleted timeline from the search result.
indices, timeline_ids = get_validated_indices(indices, sketch)
indices, timeline_ids = get_validated_indices(
indices, sketch, include_processing_timelines
)

# Remove indices that don't exist from search.
indices = utils.validate_indices(indices, self.datastore)
Expand Down
30 changes: 30 additions & 0 deletions timesketch/frontend-ng/src/components/Explore/EventList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ limitations under the License.
-->
<template>
<div>
<v-alert
v-model="showBanner"
dense
dismissible
type="info"
>
Processing timelines can be enabled but their events may be incomplete.
</v-alert>

<v-dialog v-model="exportDialog" width="700">
<v-card flat class="pa-5">
<v-progress-circular indeterminate size="20" width="1"></v-progress-circular>
Expand Down Expand Up @@ -581,6 +590,7 @@ export default {
showHistogram: false,
branchParent: null,
sortOrderAsc: true,
showBanner: false,
}
},
computed: {
Expand Down Expand Up @@ -681,6 +691,9 @@ export default {
activeContext() {
return this.$store.state.activeContext
},
settings() {
return this.$store.state.settings
},
filterChips: function () {
return this.currentQueryFilter.chips.filter((chip) => chip.type === 'label' || chip.type === 'term')
},
Expand Down Expand Up @@ -864,10 +877,13 @@ export default {
formData['facet'] = this.activeContext.facetId
formData['question'] = this.activeContext.questionId

formData['includeProcessingTimelines'] = this.settings.showProcessingTimelineEvents

ApiClient.search(this.sketch.id, formData)
.then((response) => {
this.eventList.objects = response.data.objects
this.eventList.meta = response.data.meta
this.updateShowBanner()
this.searchInProgress = false
EventBus.$emit('updateCountPerTimeline', response.data.meta.count_per_timeline)
this.$emit('countPerTimeline', response.data.meta.count_per_timeline)
Expand Down Expand Up @@ -1021,6 +1037,15 @@ export default {
})
.catch((e) => {})
},
updateShowBanner: function() {
// Show banner only when processing timelines are enabled and at
// least one enabled timeline is the "processing" state.
this.showBanner =
this.settings.showProcessingTimelineEvents &&
this.$store.state.sketch.active_timelines
.filter(tl => this.$store.state.enabledTimelines.includes(tl.id))
.some(tl => tl.status && tl.status[0].status === 'processing')
},
},
watch: {
tableOptions: {
Expand Down Expand Up @@ -1060,6 +1085,11 @@ export default {
},
deep: true,
},
'settings.showProcessingTimelineEvents': {
handler() {
this.updateShowBanner()
},
},
},
created() {
if (Object.keys(this.queryRequest).length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ limitations under the License.
<template v-slot:activator="{ on: onTooltip, attrs }">
<span
class="timeline-name-ellipsis"
:class="{ disabled: !isSelected && slotProps.timelineStatus === 'ready' }"
:class="{ disabled: !isSelected && (slotProps.timelineStatus === 'processing' || slotProps.timelineStatus === 'ready') }"
v-bind="attrs"
v-on="onTooltip"
>{{ timeline.name }}</span
Expand Down Expand Up @@ -88,7 +88,7 @@ export default {
},
methods: {
timelineStyle(timelineStatus) {
const greyOut = timelineStatus === 'ready' && !this.isSelected
const greyOut = (timelineStatus === 'processing' || timelineStatus === 'ready') && !this.isSelected
return {
opacity: greyOut ? '50%' : '100%',
backgroundColor: this.$vuetify.theme.dark ? '#303030' : '#f5f5f5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
-->
<template>
<span>
<v-dialog v-if="timelineStatus === 'processing'" v-model="dialogStatus" width="600">
<v-dialog v-if="!timelineAvailable" v-model="dialogStatus" width="600">
<template v-slot:activator="{ on, attrs }">
<slot
name="processing"
Expand Down Expand Up @@ -155,7 +155,7 @@ limitations under the License.
</v-card>
</v-dialog>

<v-list-item v-if="timelineStatus === 'ready'" @click="$emit('toggle', timeline)">
<v-list-item v-if="timelineAvailable" @click="$emit('toggle', timeline)">
<v-list-item-action>
<v-icon v-if="isSelected">mdi-eye-off</v-icon>
<v-icon v-else>mdi-eye</v-icon>
Expand All @@ -164,7 +164,7 @@ limitations under the License.
<v-list-item-subtitle v-else>Re-enable</v-list-item-subtitle>
</v-list-item>

<v-list-item v-if="timelineStatus === 'ready'" @click="$emit('disableAllOtherTimelines', timeline)">
<v-list-item v-if="timelineAvailable" @click="$emit('disableAllOtherTimelines', timeline)">
<v-list-item-action>
<v-icon>mdi-checkbox-marked-circle-minus-outline</v-icon>
</v-list-item-action>
Expand Down Expand Up @@ -245,7 +245,7 @@ limitations under the License.
<v-list-item-subtitle>Run Analyzers</v-list-item-subtitle>
</v-list-item>

<v-list-item style="cursor: pointer" @click="deleteConfirmation = true">
<v-list-item v-if="timelineAvailable" style="cursor: pointer" @click="deleteConfirmation = true">
<v-list-item-action>
<v-icon>mdi-trash-can-outline</v-icon>
</v-list-item-action>
Expand Down Expand Up @@ -399,12 +399,18 @@ export default {
timelineFailed() {
return this.timelineStatus === 'fail'
},
timelineAvailable() {
return this.timelineStatus === 'ready' || (this.showProcessingTimelineEvents && this.timelineStatus === 'processing')
},
timelineChipColor() {
if (!this.timeline.color.startsWith('#')) {
return '#' + this.timeline.color
}
return this.timeline.color
},
showProcessingTimelineEvents() {
return this.$store.state.settings.showProcessingTimelineEvents
},
},
methods: {
openDialog() {
Expand Down
22 changes: 18 additions & 4 deletions timesketch/frontend-ng/src/components/LeftPanel/TimelinesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ export default {
return a.name.localeCompare(b.name)
})
},
settings() {
return this.$store.state.settings
},
},
watch: {
'settings.showProcessingTimelineEvents': function () {
this.updateEnabledTimelines()
},
},
methods: {
isEnabled(timeline) {
Expand All @@ -206,6 +214,15 @@ export default {
disableAllOtherTimelines(timeline) {
this.$store.dispatch('updateEnabledTimelines', [timeline.id])
},
updateEnabledTimelines() {
this.$store.dispatch(
'updateEnabledTimelines',
this.activeTimelines
.filter((tl) => this.$store.state.enabledTimelines.includes(tl.id))
.filter((tl) => this.settings.showProcessingTimelineEvents || tl.status[0].status !== 'processing')
.map((tl) => tl.id)
)
},
timelineStyle(timelineStatus, isSelected) {
const greyOut = timelineStatus === 'ready' && !isSelected
return {
Expand Down Expand Up @@ -237,10 +254,7 @@ export default {
}
},
created() {
this.$store.dispatch(
'updateEnabledTimelines',
this.activeTimelines.map((tl) => tl.id)
)
this.updateEnabledTimelines()
},
mounted() {
EventBus.$on('updateCountPerTimeline', this.updateCountPerTimeline)
Expand Down
13 changes: 13 additions & 0 deletions timesketch/frontend-ng/src/components/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ limitations under the License.
>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-action>
<v-switch v-model="settings.showProcessingTimelineEvents" color="primary" @change="saveSettings()"></v-switch>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>Show processing timeline events</v-list-item-title>
<v-list-item-subtitle
>Select to include events from timelines in <strong>processing</strong> state</v-list-item-subtitle
>
</v-list-item-content>
</v-list-item>
</v-list>
</v-card>
</template>
Expand All @@ -49,6 +60,7 @@ import ApiClient from '../utils/RestApiClient'

const DEFAULT_SETTINGS = {
showLeftPanel: true,
showProcessingTimelineEvents: false,
}

export default {
Expand All @@ -57,6 +69,7 @@ export default {
settings: {
showLeftPanel: true,
generateQuery: true,
showProcessingTimelineEvents: false,
},
}
},
Expand Down
10 changes: 8 additions & 2 deletions timesketch/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,21 +526,27 @@ def read_and_validate_jsonl(
)


def get_validated_indices(indices, sketch):
def get_validated_indices(indices, sketch, include_processing_timelines=False):
"""Exclude any deleted search index references.

Args:
indices: List of indices from the user
sketch: A sketch object (instance of models.sketch.Sketch).
include_processing_timelines: True to include processing
timelines, Flase otherwise.

Returns:
Tuple of two items:
List of indices with those removed that is not in the sketch
List of timeline IDs that should be part of the output.
"""
allowed_statuses = ["ready"]
if include_processing_timelines:
allowed_statuses.append("processing")

sketch_structure = {}
for timeline in sketch.timelines:
if timeline.get_status.status.lower() != "ready":
if timeline.get_status.status.lower() not in allowed_statuses:
continue
index_ = timeline.searchindex.index_name
sketch_structure.setdefault(index_, [])
Expand Down
4 changes: 2 additions & 2 deletions timesketch/models/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_view_urls(self):

@property
def active_timelines(self):
"""List timelines that are ready for analysis.
"""List timelines that are being processed or ready for analysis.

Returns:
List of instances of timesketch.models.sketch.Timeline
Expand All @@ -144,7 +144,7 @@ def active_timelines(self):
for timeline in self.timelines:
timeline_status = timeline.get_status.status
index_status = timeline.searchindex.get_status.status
if (timeline_status or index_status) in ("processing", "fail", "archived"):
if (timeline_status or index_status) in ("fail", "archived"):
continue
_timelines.append(timeline)
return _timelines
Expand Down