Skip to content

Commit

Permalink
Add option to produce output to a file for environments w/o mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Piet Mens committed Jan 27, 2015
1 parent 446b45a commit d6f446a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
9 changes: 5 additions & 4 deletions README
@@ -1,16 +1,17 @@
Public version of the DNSSEC key rollover monitor and checker.

The tool has been described in a paper released at the SATIN conference
<http://conferences.npl.co.uk/satin/>. See the paper at
The tool has been described in a paper released at the SATIN conference
<http://conferences.npl.co.uk/satin/>. See the paper at
<http://conferences.npl.co.uk/satin/papers/satin2011-Bortzmeyer.pdf>.


Basic instructions:

1) sqlite3 dnssec.sqlite < create.sql

2) Edit ~/.key-report.ini may be using key-report.ini.sample as a
starting point.
2) Edit ~/.key-report.ini; you can use key-report.ini.sample as a
starting point. Set fileonly to a file which is appended to if
you don't want to (or can't) send e-mail.

3) while true:
key-store-and-report.py $YOURDOMAIN $YOURSERVER
Expand Down
1 change: 1 addition & 0 deletions key-report.ini.sample
Expand Up @@ -3,3 +3,4 @@ mailserver: smtp.example.net
prefix: DNSSEC Check of my zones
maintainer: John.Foo@bar.example
output: false
fileonly: /path/to/file
33 changes: 27 additions & 6 deletions key-store-and-report.py
Expand Up @@ -25,6 +25,7 @@
maintainer_address = "foo@bar"
output = True
syslog = False
file_only = False
SECTION = "default"
version = sys.argv[0] + " $Revision: 10774 $ (Python %s)" % \
re.sub ("\n", " ", sys.version)
Expand All @@ -35,6 +36,7 @@
# prefix: DNSSEC Check at AFNIC
# maintainer: Stephane.Bortzmeyer+dnssec-key-check@nic.fr
# timeout: 10
# fileonly: xxxx.out # append output to file; no mail is sent

class DNSerror(Exception):
pass
Expand All @@ -49,10 +51,23 @@ def sendemail(subject, content):
(maintainer_address, maintainer_address, ("[%s] " % email_prefix) + subject,
version))
msg = msg + content + "\r\n"
server = smtplib.SMTP(mail_server)
server.set_debuglevel(0)
server.sendmail(maintainer_address, maintainer_address, msg)
server.quit()

if file_only:
timestr = time.strftime("%Y-%m-%d %H:%M:%S %z")
msg = ("%s -- %s\n" % (timestr, subject))
msg = msg + content + "\n"
try:
f = open(file_only, 'a')
f.write(msg)
f.close()
except Exception, e:
print "Cannot open output file {0}: {1}".format(file_only, str(e))
sys.exit(2)
else:
server = smtplib.SMTP(mail_server)
server.set_debuglevel(0)
server.sendmail(maintainer_address, maintainer_address, msg)
server.quit()

def get_rr(zone, rrtype, ns_address, handler=None):
""" rrtype must be a character _string_. handler is a function
Expand Down Expand Up @@ -135,8 +150,12 @@ def update_zones(set):
if len(sys.argv) != 3:
raise Exception("Usage: dnssec.py zonename nameserver-address")

config = ConfigParser.SafeConfigParser()
config.readfp(open(os.path.expanduser("~/.key-report.ini")))
try:
config = ConfigParser.SafeConfigParser()
config.readfp(open(os.path.expanduser("~/.key-report.ini")))
except:
print "Cannot open config file {0}".format(os.path.expanduser("~/.key-report.ini"))
sys.exit(2)

if config.has_option(SECTION, 'mailserver'):
mail_server = config.get(SECTION, 'mailserver')
Expand All @@ -152,6 +171,8 @@ def update_zones(set):
output = config.getboolean(SECTION, 'output')
if config.has_option(SECTION, 'syslog'):
syslog = config.getboolean(SECTION, 'syslog')
if config.has_option(SECTION, 'fileonly'):
file_only = config.get(SECTION, 'fileonly')

generator = random.Random()
formatter_long = logging.Formatter('%(name)s: %(asctime)s %(levelname)s %(message)s', '%Y-%m-%d %H:%M:%S')
Expand Down

0 comments on commit d6f446a

Please sign in to comment.