Skip to content

Commit

Permalink
NO-ENDPOINT: update notifier to look at doc_type
Browse files Browse the repository at this point in the history
  • Loading branch information
darmstrong-r7 committed Jun 4, 2024
1 parent 3c18ec4 commit 797db60
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions services/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"www.velocidex.com/golang/cloudvelo/schema/api"
cvelo_services "www.velocidex.com/golang/cloudvelo/services"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
velo_json "www.velocidex.com/golang/velociraptor/json"
"www.velocidex.com/golang/velociraptor/logging"
)

Expand All @@ -26,6 +27,30 @@ func (self Nofitier) ListenForNotification(id string) (chan bool, func()) {
logger := logging.GetLogger(self.config_obj, &logging.GUIComponent)
ctx, cancel := context.WithCancel(context.Background())

var notifications_query = `
{
"query": {
"bool": {
"must": [
{
"match": {"key": %q}
}, {
"match": {"doc_type": "notifications"}
}
]
}
},
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"size": 1
}
`

go func() {
defer close(output_chan)

Expand All @@ -37,8 +62,10 @@ func (self Nofitier) ListenForNotification(id string) (chan bool, func()) {
return

case <-time.After(self.poll):
serialized, err := cvelo_services.GetElasticRecord(
ctx, self.config_obj.OrgId, "persisted", id)

serialized, err := cvelo_services.GetElasticRecordByQuery(ctx,
self.config_obj.OrgId, "persisted",
velo_json.Format(notifications_query, id))
if err != nil {
continue
}
Expand Down Expand Up @@ -66,7 +93,7 @@ func (self Nofitier) NotifyListener(
config_obj *config_proto.Config, id, tag string) error {
return cvelo_services.SetElasticIndex(
context.Background(), self.config_obj.OrgId,
"persisted", id,
"persisted", cvelo_services.DocIdRandom,
&api.NotificationRecord{
Key: id,
Timestamp: time.Now().Unix(),
Expand Down

0 comments on commit 797db60

Please sign in to comment.