From fd2d5093a900af512d6f4e29824df023c22565f3 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Tue, 9 Oct 2018 11:48:31 -0400 Subject: [PATCH] More logging when --debug is used --- parsedmarc/__init__.py | 1 + parsedmarc/elastic.py | 7 +++++++ parsedmarc/splunk.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index 7e65715..04cd65c 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -1587,6 +1587,7 @@ def email_results(results, host, mail_from, mail_to, port=0, message: Override the default plain text body ssl_context: SSL context options """ + logging.debug("Emailing report to: {0}".format(",".join(mail_to))) date_string = datetime.now().strftime("%Y-%m-%d") if attachment_filename: if not attachment_filename.lower().endswith(".zip"): diff --git a/parsedmarc/elastic.py b/parsedmarc/elastic.py index c426755..1a781ed 100644 --- a/parsedmarc/elastic.py +++ b/parsedmarc/elastic.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import logging from collections import OrderedDict import parsedmarc @@ -7,6 +8,9 @@ from elasticsearch_dsl.search import Q from elasticsearch_dsl import connections, Object, Document, Index, Nested, \ InnerDoc, Integer, Text, Boolean, DateRange, Ip, Date +logger = logging.getLogger(__name__) +logger.setLevel(logging.WARNING) + class _PolicyOverride(InnerDoc): type = Text() @@ -179,6 +183,7 @@ def create_indexes(names=None, settings=None): settings (dict): Index settings """ + logger.debug("Creating elasticsearch indexes") if names is None: names = ["dmarc_aggregate", "dmarc_forensic"] for name in names: @@ -201,6 +206,7 @@ def save_aggregate_report_to_elasticsearch(aggregate_report, Raises: AlreadySaved """ + logger.debug("Saving aggregate report to Elasticsearch") aggregate_report = aggregate_report.copy() metadata = aggregate_report["report_metadata"] org_name = metadata["org_name"] @@ -299,6 +305,7 @@ def save_forensic_report_to_elasticsearch(forensic_report, AlreadySaved """ + logger.debug("Saving forensic report to Elasticsearch") forensic_report = forensic_report.copy() sample_date = forensic_report["parsed_sample"]["date"] sample_date = parsedmarc.human_timestamp_to_datetime(sample_date) diff --git a/parsedmarc/splunk.py b/parsedmarc/splunk.py index 714f2d4..5c1bd1a 100644 --- a/parsedmarc/splunk.py +++ b/parsedmarc/splunk.py @@ -1,3 +1,4 @@ +import logging from urllib.parse import urlparse import socket import json @@ -9,6 +10,9 @@ from parsedmarc import __version__, human_timestamp_to_timestamp urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +logger = logging.getLogger(__name__) +logger.setLevel(logging.WARNING) + class SplunkError(RuntimeError): """Raised when a Splunk API error occurs"""