new: added connection test to local server
parent
79dc58a0af
commit
12a51ff9e9
|
@ -7,29 +7,57 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# Create an argument parser for our program
|
||||||
|
# Will just take in a config file and logging options
|
||||||
parser = argparse.ArgumentParser(description='Run MISP taxii pull.')
|
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")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Set up a logger for logging's sake
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
|
log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
|
||||||
|
|
||||||
|
# If we want, print the output to stdout
|
||||||
if args.stdout:
|
if args.stdout:
|
||||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
ch = logging.StreamHandler(sys.stdout)
|
ch = logging.StreamHandler(sys.stdout)
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
log.addHandler(ch)
|
log.addHandler(ch)
|
||||||
|
|
||||||
configFile = "{}/servers.yml".format(os.path.expanduser(args.configdir))
|
# Read in the remote server configurations
|
||||||
|
configFile = "{}/remote-servers.yml".format(os.path.expanduser(args.configdir))
|
||||||
log.debug("Opening config file %s", configFile)
|
log.debug("Opening config file %s", configFile)
|
||||||
with open(configFile, "r") as f:
|
with open(configFile, "r") as f:
|
||||||
config = yaml.load(f.read())
|
config = yaml.load(f.read())
|
||||||
|
|
||||||
log.debug("Config read %s", config)
|
log.debug("Config read %s", config)
|
||||||
|
|
||||||
|
# Read in the local server configuration
|
||||||
|
localConfig = "{}/local-server.yml".format(os.path.expanduser(args.configdir))
|
||||||
|
log.debug("Reading local server config")
|
||||||
|
with open(localConfig, "r") as f:
|
||||||
|
localConfig = yaml.load(f.read())
|
||||||
|
|
||||||
|
# Attempt to make contact with the local server
|
||||||
|
log.info("Connecting to local server...")
|
||||||
|
localClient = create_client(host = localConfig["host"],
|
||||||
|
port = localConfig["port"],
|
||||||
|
discovery_path = localConfig["discovery_path"],
|
||||||
|
use_https = localConfig["use_https"],
|
||||||
|
version = localConfig["taxii_version"],
|
||||||
|
headers = localConfig["headers"])
|
||||||
|
localClient.username = localConfig["auth"]["username"]
|
||||||
|
localClient.password = localConfig["auth"]["password"]
|
||||||
|
|
||||||
|
# Check that we're all good and authenticated
|
||||||
|
try:
|
||||||
|
list(localClient.discover_services())
|
||||||
|
except Exception as ex:
|
||||||
|
log.fatal("Could not connect to local server")
|
||||||
|
log.fatal(ex)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
for server in config:
|
for server in config:
|
||||||
log.info("== %s ==", server["name"])
|
log.info("== %s ==", server["name"])
|
||||||
cli = create_client(host = server["host"],
|
cli = create_client(host = server["host"],
|
||||||
|
@ -42,4 +70,6 @@ for server in config:
|
||||||
cli.username = server["auth"]["username"]
|
cli.username = server["auth"]["username"]
|
||||||
cli.password = server["auth"]["password"]
|
cli.password = server["auth"]["password"]
|
||||||
|
|
||||||
log.info(list(cli.poll("collection")))
|
for collection in server["collections"]:
|
||||||
|
for content_block in cli.poll(collection):
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue