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.
I've been wanting to have greater control over how rules are loaded. Specifically, being able to load them from places other than a local directory; for example, a mongo database.
This PR creates a means to do just that. It uses a similar methodology as Enhancements and Alerters in that there is a base class
RulesLoader
which is specified in theconfig.yaml
under therules_loader
property. You can use the formatmodule.file.ClassName
to use your own loader. The default is calledFileRulesLoader
and this behaves exactly like the current way. If you don't make a change you will see no difference in the way that EA works.RulesLoaders are subclasses of
RulesLoader
, found inelastalert/loaders.py
. They are used togather rules for a particular source. Your RulesLoader needs to implement three member functions, and will look something like this:
You can import loaders by specifying the type as
module.file.RulesLoaderName
, where module is the name of a python module, and file is the name of the python file containing aRulesLoader
subclass namedRulesLoaderName
.As an example loader, let's retrieve rules from a database rather than from the local file system. First, create a
modules folder for the loader in the ElastAlert directory.
Now, in a file named
mongo_loader.py
, addFinally, you need to specify in your ElastAlert configuration file that MongoRulesLoader should be used instead of the
default FileRulesLoader, so in your
elastalert.conf
file: