-
Notifications
You must be signed in to change notification settings - Fork 291
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
Add events bus when inserting or updating new object in arangodb #1144
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
udgover
added
enhancement
dependencies
Pull requests that update a dependency file
code health
Changes about syntax, code health, etc.
noteworthy
PRs that are noteworthy / introduce new features
core
labels
Oct 17, 2024
Closed
tomchop
requested changes
Oct 17, 2024
…de access to timestamp for example
will this eventually enable us to check if an observable overlaps with different feeds or analytics? |
Hello, if you create an EventTask that acts on There's no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
code health
Changes about syntax, code health, etc.
core
dependencies
Pull requests that update a dependency file
enhancement
noteworthy
PRs that are noteworthy / introduce new features
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds support for an events bus when inserting or updating new objects in arangodb.
The system relies on Kombu messaging library which is the underlying system to handle message passing in celery.
It aims to keep it simple, stupid by providing an event producer that will publish new message in
events
orlogs
queues and consumers that will call relevant tasks of type EventTask or LogTask accordingly.Implementation details
Messages
Messages format are validated by relying on pydantic models defined in
core.events.message.py
:YetiObjectTypes
supports all defined schemas in Yeti (even private ones). For example, withObjectEvent
message data,yeti_object
could be a campaign (entity), an ipv4 (observable), a regex (indicator), ...Producer
To publish an event message, producer must be called with
publish_event
method with the event message argument that can be of typeObjectEvent
,LinkEvent
orTagLinkEvent
:To publish a log message, producer must be called with
publish_log
method which supports eitherstr
ordict
as arguments:The call to publish method is non-blocking and just sends the message to the configured queue and exchange, events and logs respectively.
Consumers
In order to receive messages and process them, consumers must be created by defining from which queue they must receive the messages.
To handle events messages:
To handle logs messages:
By default, the consumer will spawn several
multiprocessing.Process
based on the number of available CPU by usingmultiprocessing.cpu_count()
.If the number of spawned processes must be changed,
--concurrency
argument can be used, followed by the number of processes to spawn.Events Message routing
Plugins of type
EventTask
can defineacts_on
attribute which represents a regex to match an event. For every event message,EventWorker
callsmatch
method implemented byEventTypes
classes withacts_on
.As example, the following
acts_on
can be set to precisely define when a task must be called on events messages:Global events -> ObjectEvent, LinkEvent, TagEvent
""
new
events:"new"
"(new|update)"
Yeti objects specialisation -> ObjectEvent
"(new|update|delete):(observable|entity)"
"(new|update|delete):observable"
"(new|update|delete):observable:url"
"(new|update|delete):observable:(ipv4|ipv6)"
"new:entity:(campaign|vulnerability)"
"(new|update|delete):tag"
Link events specialisation -> LinkEvent
"(new|update|delete):link"
"(new|update|delete):link:source:observable"
"(new|update|delete):link:target:observable"
Tagged event specialisation -> TagEvent
"(new|update|delete):tagged:(malware|c2)"
EventTask implementation
In order to create task to be called based on events, the following example is provided:
The task must inherit
task.EventTask
and define_defaults
dictionary to define its name, description and the events to acts onWhen a consumer matches a task based on its acts_on, task
run
method will be called with the event as argument.In the example, this task will always receive an
EventMessage
with event of typeObjectEvent
because the consumer will precisely match onacts_on
which is based onObjectEvent
.When implementing a task with a more generic
acts_on
, the task is responsible for handling the different event types it can receive.Testing
Producer / Consumer
For now, you have to spawn a new python shell to execute the consumer:
Then in another shell to trigger producer when saving an observable
New plugins
This PR also adds two new plugins:
new.observables.url
. It will extract hostname or ipv4 from a newly inserted Url observablelogging.info
for all received events.