Update Splunk support

This commit is contained in:
Sean Whalen committed 2018-09-25 13:06:27 -04:00
1 parent a1a4cbbf28
commit 861ee7d247
4 files changed
+41 -8

No files matched your search

+1 -1
View File
@@ -83,7 +83,7 @@ CLI help
collector (HEC) collector (HEC)
--hec-index HEC_INDEX --hec-index HEC_INDEX
The index to use when sending events to the Splunk The index to use when sending events to the Splunk
HTTP Events (Default: dmarc) HTTP Events
--save-aggregate Save aggregate reports to search indexes --save-aggregate Save aggregate reports to search indexes
--save-forensic Save forensic reports to search indexes --save-forensic Save forensic reports to search indexes
-O OUTGOING_HOST, --outgoing-host OUTGOING_HOST -O OUTGOING_HOST, --outgoing-host OUTGOING_HOST
+1 -1
View File
@@ -90,7 +90,7 @@ CLI help
collector (HEC) collector (HEC)
--hec-index HEC_INDEX --hec-index HEC_INDEX
The index to use when sending events to the Splunk The index to use when sending events to the Splunk
HTTP Events (Default: dmarc) HTTP Events
--save-aggregate Save aggregate reports to search indexes --save-aggregate Save aggregate reports to search indexes
--save-forensic Save forensic reports to search indexes --save-forensic Save forensic reports to search indexes
-O OUTGOING_HOST, --outgoing-host OUTGOING_HOST -O OUTGOING_HOST, --outgoing-host OUTGOING_HOST
+5 -2
View File
@@ -101,8 +101,7 @@ def _main():
"(HEC)") "(HEC)")
arg_parser.add_argument("--hec-index", help="The index to use when " arg_parser.add_argument("--hec-index", help="The index to use when "
"sending events to the " "sending events to the "
"Splunk HTTP Events " "Splunk HTTP Events")
"(Default: dmarc)")
arg_parser.add_argument("--save-aggregate", action="store_true", arg_parser.add_argument("--save-aggregate", action="store_true",
default=False, default=False,
help="Save aggregate reports to search indexes") help="Save aggregate reports to search indexes")
@@ -160,6 +159,10 @@ def _main():
elastic.set_hosts(args.elasticsearch_host) elastic.set_hosts(args.elasticsearch_host)
elastic.create_indexes() elastic.create_indexes()
if args.hec: if args.hec:
if args.hec_token is None or args.hec_index is None:
logger.error("HEC token and HEC index are required when "
"using HEC URL")
exit(1)
hec_client = splunk.HECClient(args.hec, args.hec_token, hec_client = splunk.HECClient(args.hec, args.hec_token,
index=args.hec_index) index=args.hec_index)
except ElasticsearchException as error: except ElasticsearchException as error:
+34 -4
View File
@@ -17,7 +17,7 @@ class HECClient(object):
# http://docs.splunk.com/Documentation/Splunk/latest/Data/AboutHEC # http://docs.splunk.com/Documentation/Splunk/latest/Data/AboutHEC
# http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTinput#services.2Fcollector # http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTinput#services.2Fcollector
def __init__(self, url, access_token,index="dmarc", def __init__(self, url, access_token, index,
source="parsedmarc", verify=True): source="parsedmarc", verify=True):
""" """
Initializes the HECClient Initializes the HECClient
@@ -50,18 +50,48 @@ class HECClient(object):
Saves aggregate DMARC reports to Splunk Saves aggregate DMARC reports to Splunk
Args: Args:
aggregate_reports (list): A list of aggregate report dictionaries aggregate_reports: A list of aggregate report dictionaries
to save in Splunk to save in Splunk
""" """
if type(aggregate_reports) == dict: if type(aggregate_reports) == dict:
aggregate_reports = [aggregate_reports] aggregate_reports = [aggregate_reports]
data = self._common_data.copy()
json_str = "" json_str = ""
for report in aggregate_reports: for report in aggregate_reports:
data = self._common_data.copy() for record in report["records"]:
new_report = dict()
for metadata in report["report_metadata"]:
new_report[metadata] = report["report_metadata"][metadata]
new_report["policy_published"] = report["policy_published"]
new_report["source_ip_address"] = record["source"][
"ip_address"]
new_report["source_country"] = record["source"]["country"]
new_report["source_reverse_dns"] = record["source"][
"reverse_dns"]
new_report["source_base_domain"] = record["source"][
"base_domain"]
new_report["message_count"] = record["count"]
new_report["disposition"] = record["policy_evaluated"][
"disposition"
]
new_report["spf_aligned"] = record["alignment"]["spf"]
new_report["dkim_aligned"] = record["alignment"]["dkim"]
new_report["passed_dmarc"] = record["alignment"]["dmarc"]
new_report["header_from"] = record["identifiers"][
"header_from"]
new_report["envelope_from"] = record["identifiers"][
"envelope_from"]
if "dkim" in record["auth_results"]:
new_report["dkim_results"] = record["auth_results"][
"dkim"]
if "spf" in record["spf_results"]:
new_report["spf_results"] = record["auth_results"][
"spf"]
data["sourcetype"] = "dmarc:aggregate" data["sourcetype"] = "dmarc:aggregate"
data["event"] = report.copy() data["event"] = new_report.copy()
json_str += "{0}\n".format(json.dumps(data)) json_str += "{0}\n".format(json.dumps(data))
try: try: