-
Notifications
You must be signed in to change notification settings - Fork 7
Creating Custom Input Generators and Parsers
Gustavo Silva edited this page Mar 8, 2023
·
2 revisions
If you need a new input generator or a new result parser, create a new app named scanner_YOURSCANNER
.
In this app, define the new input generator and/or parser in a file named scanners.py
, it will be auto-discovered and imported by this app.
To define an input generator simply write a generator function and register it as scanner input:
from scanners.parsers._input_registry import register
@register('TYPE_OF_RECORD', 'Hostnames with some criteria')
def list_my_stuff():
"""
:return: iterator with all Hosts/DNS Records that obey this criteria
"""
for something in SomeModel.objects.filter(field=criteria):
yield something.hostname
To define a parser create the following class, also in scanners.py
inside your scanner_MYSCANNER
app:
from scanners.parsers._parser_registry import register as parser_register
from scanners.parsers.base import BaseParser
@parser_register('CHOOSE_A_KEY_NAME_FOR_PARSER', 'My Scanner Parser')
class MyScanner(BaseParser):
def parse(self, rootbox, scanner, timestamp, filepath):
# filepath will point to a temporary directory holding copies from scanner /output/ files
# do whatever you please with them
- Uncomment/run
dockerd
from thedev/docker-compose.yaml
stack - Run
dev/add_test_rootbox_and_scanner.py
(or add rootbox/scanner manually) - Run
manage.py run_scanner YOUR_SCANNER_NAME
and this should start the scanner in your test dockerd - Run
manage.py resync_rootbox -r YOUR_ROOTBOX
(if it wasn't running already) and it will retrieve the files and process them (checkScannerResult
if your scanner does not have a specificparser
, otherwise check your result tables for them)