Skip to content

Commit

Permalink
#1838 Use Query API to list artifact jobs and refresh the list only o…
Browse files Browse the repository at this point in the history
…n events related to the right observable
  • Loading branch information
nadouani committed Mar 16, 2021
1 parent 2ea4414 commit 38df9fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.thp.thehive.services.CaseOps._
import org.thp.thehive.services.ObservableOps._
import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.{AttachmentSrv, ObservableSrv, ObservableTypeSrv, ReportTagSrv}
import play.api.libs.json.Json
import play.api.libs.json.{JsObject, JsString, Json}

import java.nio.file.Files
import java.util.{Date, Map => JMap}
Expand Down Expand Up @@ -92,7 +92,13 @@ class JobSrv @Inject() (
create(fromCortexOutputJob(cortexOutputJob).copy(cortexId = cortexId), observable.observable)
})
_ <- Future.fromTry(db.tryTransaction { implicit graph =>
auditSrv.job.create(createdJob.job, observable.observable, createdJob.toJson)
auditSrv
.job
.create(
createdJob.job,
observable.observable,
createdJob.toJson.as[JsObject] + ("objectType" -> JsString("Observable")) + ("objectId" -> JsString(observable._id.toString))
)
})
_ = cortexActor ! CheckJob(Some(createdJob._id), cortexOutputJob.id, None, cortexClient.name, authContext)
} yield createdJob
Expand Down Expand Up @@ -171,7 +177,14 @@ class JobSrv @Inject() (
.update(_.endDate, endDate)
.getOrFail("Job")
observable <- get(job).observable.getOrFail("Observable")
_ <- auditSrv.job.update(job, observable, Json.obj("status" -> status, "endDate" -> endDate))
_ <-
auditSrv
.job
.update(
job,
observable,
Json.obj("status" -> status, "endDate" -> endDate, "objectType" -> "Observable", "objectId" -> observable._id.toString)
)
} yield job
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
})
.finally(function () {
if($scope.analysisEnabled) {
$scope.jobs = CortexSrv.list($scope, $scope.caseId, observableId, $scope.onJobsChange);
$scope.jobs = CortexSrv.listJobs($scope, $scope.caseId, observableId, $scope.onJobsChange);
}
});

Expand Down
29 changes: 16 additions & 13 deletions frontend/app/scripts/services/api/CortexSrv.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
(function() {
'use strict';
angular.module('theHiveServices').service('CortexSrv', function($q, $http, $rootScope, $uibModal, QuerySrv, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv, ModalUtilsSrv) {
angular.module('theHiveServices').service('CortexSrv', function($q, $http, $rootScope, $uibModal, QuerySrv, PaginatedQuerySrv, StreamSrv, AnalyzerSrv, PSearchSrv, ModalUtilsSrv) {
var self = this;
var baseUrl = './api/connector/cortex';

this.list = function(scope, caseId, observableId, callback) {
return PSearchSrv(undefined, 'connector/cortex/job', {
this.listJobs = function(scope, caseId, observableId, callback) {
return new PaginatedQuerySrv({
name: 'observable-jobs-' + observableId,
version: 'v1',
scope: scope,
sort: ['-startDate'],
streamObjectType: 'case_artifact_job',
loadAll: false,
sort: ['-startDate'],
pageSize: 200,
onUpdate: callback || angular.noop,
streamObjectType: 'case_artifact_job',
filter: {
_parent: {
_type: 'observable',
_query: {
_id: observableId
}
}
operations: [
{ '_name': 'getObservable', 'idOrName': observableId },
{ '_name': 'jobs' }
],
guard: function(updates) {
return _.find(updates, function(item) {
return (item.base.details.objectType === 'Observable') && (item.base.details.objectId === observableId);
}) !== undefined;
}
});
};
}

this.getJobs = function(caseId, observableId, analyzerId, limit) {

Expand Down

0 comments on commit 38df9fd

Please sign in to comment.