Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for hashed directories #8

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ LogFile = ./log/certstreammonitor.log

[REPORTING]
# Alerts reporting directory for scanhost.py
Alerts_dir = ./alerts
Alerts_dir = ./alerts/%%Y/%%m/%%d
27 changes: 25 additions & 2 deletions scanhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import socket
from ipwhois import IPWhois
import warnings
import time


def create_connection(db_file):
Expand Down Expand Up @@ -75,7 +76,7 @@ def args_parse():
sys.exit(1)
else:
assert False, "Unhandled Option"
return
return


def usage():
Expand All @@ -90,6 +91,28 @@ def usage():
sys.exit(0)


def generate_alert_dir(path):
"""
Generate the hashed directory path based on current date
"""
# %m -> month
# %d -> day
# %Y -> year
# %H -> hour
# %M -> minute
t_hour = time.strftime("%H")
t_minute = time.strftime("%M")
t_day = time.strftime("%d")
t_month = time.strftime("%m")
t_year = time.strftime("%Y")
path = path.replace('%H', t_hour)
path = path.replace('%M', t_minute)
path = path.replace('%d', t_day)
path = path.replace('%m', t_month)
path = path.replace('%Y', t_year)
return path


def ConfAnalysis(ConfFile):
"""
configuration file analysis. Load global variables with parameters found
Expand All @@ -113,7 +136,7 @@ def ConfAnalysis(ConfFile):
LogFile = CONF.LogFile
Proxy = CONF.Proxy
UA = CONF.http_UA
Alerts_dir = CONF.Alerts_dir
Alerts_dir = generate_alert_dir(CONF.Alerts_dir)
UAFILE = CONF.UAfile

except Exception as err:
Expand Down