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.
Pull request #6 ("Generalized mail parsing") introduced mail handlers, which inspired extending the same idea to other contexts. Specifically, this pull request introduces transformation handlers that can be run as XMPP bots like any
abusehelper.core.transformation
, but can also be reused as command line tools and in automated tests.This pull request also adds
abusehelper.core.cymruwhois.Handler
, a transformation handler that adds Cymru ASN lookup data to the input events. By default it watches all event keys for values that look like IP addresses but it can be configured to watch only a certain limited set of keys with e.g.{"type": "abusehelper.core.cymruwhois.Handler", "ip_keys": ["ip", "netblock"]}
.Writing a Transformation Handler
Writing a new transformation handler is very similar to writing a mail handler. Let's put this to
myhandler.py
:Running from Command Line
abusehelper.core.transformation.tester
allows us to run a handler as a command line tool:Outputs should look like this:
Also configuring the handler works:
Output:
Running as a XMPP Bot
$ python -m abusehelper.core.transformation.bot [email protected] lobby.room myhandler.MyHandler
The launched bot behaves like any
abusehelper.core.transformation
bot. Session parameterssrc_room
anddst_room
control where the input events are read from and where the output events are delivered to.Note that currently session parameters aren't routed to the handler, and the only way to configure a handler is to pass in startup parameters:
$ python -m abusehelper.core.transformation.bot [email protected] lobby.room '{"type": "myhandler.MyHandler", "extras": {"abc": "123"}}'
Creating Automated Tests
The following
test_myhandler.py
is an example howabusehelper.core.transformation.tester.handle
takes in a handler and a list of input events and returns a list of output events: