-
Notifications
You must be signed in to change notification settings - Fork 25
/
import_testssl.sh_csv_to_ES.py
executable file
·39 lines (34 loc) · 1.27 KB
/
import_testssl.sh_csv_to_ES.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
# Import testssl.sh CSV to ELasticSearch
import argparse
from docTestssl import DocTestSSLResult
from elasticsearch_dsl.connections import connections
from elasticsearch_dsl import Index
from datetime import datetime
argparser = argparse.ArgumentParser(description="Import testssl.sh CSV logs into ElasticSearch")
argparser.add_argument("--elasticsearch", "-e", nargs="*", default="localhost", help="ElasticSearch host (default: %(default)s)")
argparser.add_argument("--index", "-i", default="testssl-scan", help="ElasticSearch index (default: %(default)s)")
argparser.add_argument("files", nargs="+", help="List of testssl.sh logs in CSV format")
args = argparser.parse_args()
connections.create_connection(hosts=args.elasticsearch)
idx = Index(args.index)
idx.doc_type(DocTestSSLResult)
DocTestSSLResult.init()
try:
idx.create()
except:
pass
csvFiles = args.files
for csvFile in csvFiles:
try:
csv = open(csvFile, mode="r", newline="")
except IOError as e:
print("Error while opening %s: %s" % (csvFile, e.strerror))
print("Processing '%s'" % (csvFile))
doc = DocTestSSLResult(source=csvFile)
doc.parseCSV(csv)
csv.close()
try:
doc.save()
except ValueError:
print("File %s was empty!" % (csvFile))