new: Add poll time span ability

Use --start and --end
pull/38/head
Hannah Ward 2018-02-06 13:35:31 +00:00
parent 6f3627e565
commit db60d29f68
No known key found for this signature in database
GPG Key ID: 6F3BAD60DE190290
1 changed files with 11 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import argparse
import os import os
import logging import logging
import sys import sys
from datetime import datetime
# Create an argument parser for our program # Create an argument parser for our program
# Will just take in a config file and logging options # Will just take in a config file and logging options
@ -13,6 +14,9 @@ parser = argparse.ArgumentParser(description='Run MISP taxii pull.')
parser.add_argument('-c', "--configdir", default="~/.misptaxii", help='Config directory') parser.add_argument('-c', "--configdir", default="~/.misptaxii", help='Config directory')
parser.add_argument("-v", "--verbose", action="store_true", help="More verbose logging") parser.add_argument("-v", "--verbose", action="store_true", help="More verbose logging")
parser.add_argument("-s", "--stdout", action="store_true", help="Log to STDOUT") parser.add_argument("-s", "--stdout", action="store_true", help="Log to STDOUT")
parser.add_argument("--start", help="Date to poll from (YYYY-MM-DD), Exclusive")
parser.add_argument("--end", help="Date to poll to (YYYY-MM-DD), Inclusive")
args = parser.parse_args() args = parser.parse_args()
# Set up a logger for logging's sake # Set up a logger for logging's sake
@ -65,6 +69,9 @@ except Exception as ex:
log.info("Connected") log.info("Connected")
poll_from = datetime.strptime(args.start, "%Y-%m-%d") if args.start else None
poll_to = datetime.strptime(args.end, "%Y-%m-%d") if args.end else datetime.now()
for server in config: for server in config:
log.info("== %s ==", server["name"]) log.info("== %s ==", server["name"])
@ -99,8 +106,11 @@ for server in config:
log.debug("Auth set.") log.debug("Auth set.")
for collection in server["collections"]: for collection in server["collections"]:
log.debug("Polling %s", collection) log.debug("Polling %s", collection)
log.debug("Within date range %s - %s", poll_from or "Beginning of time", poll_to)
try: try:
for content_block in cli.poll(collection_name=collection): for content_block in cli.poll(collection_name=collection,
begin_date=poll_from,
end_date=poll_to):
try: try:
log.debug("Pushing block %s", content_block) log.debug("Pushing block %s", content_block)
localClient.push(content_block.content.decode("utf-8"), localClient.push(content_block.content.decode("utf-8"),