Commit 852ab9cc authored by Jonathan Michalon's avatar Jonathan Michalon

Prefix messages with a timestamp and support multiple verbosity levels

parent 04b27b1a
......@@ -50,6 +50,8 @@ In addition some checks have specific options, see lib/checks.py for examples.
In case you want to check lesser important services and configure very long check intervals, you may
want to have another interval, global to all checks, for error retries. This can be set with the `error_every` option.
For a full list of all available options, see the lib/__init__.py file.
Current state output
--------------------
......
......@@ -15,6 +15,9 @@ config.install_attr('base_tick', 60)
# How often we retry checks that are in error (-1 disables feature)
config.install_attr('error_every', -1)
# Verbosity level (one of CRITICAL, ERROR, WARNING, INFO, DEBUG)
config.install_attr('verb_level', 'INFO')
# Email addresses to send to when an alert is triggered
config.install_attr('emails.to', [])
# The From: address
......
from .subprocess_compat import TimeoutExpired, Popen, PIPE
import re
import logging
from . import mails
from collections import Iterable
from datetime import datetime
......@@ -61,6 +62,7 @@ class Check(object):
config.error_every < 0
else config.error_every)
if self.every_count == 0 or immediate:
logging.debug('Running ' + str(self))
self.setup()
if not self.check():
self.retry_count = min(self.retry_count + 1, self.retry)
......
import smtplib
import logging
from email.mime.text import MIMEText
from email.utils import make_msgid
from collections import defaultdict
......@@ -55,7 +56,7 @@ class ThreadedSMTP(object):
server = smtplib.SMTP(host)
server.sendmail(*args, **kwargs)
except Exception as e:
print("Couldn't send email: %s" % str(e), file=stderr)
logging.warning("Couldn't send email: %s" % str(e))
finally:
if server: # server is None on exception queue.Empty
self._queue.task_done()
......
import concurrent.futures
import signal
import argparse
import logging
from time import sleep
import config as user_config
from lib import config
......@@ -60,8 +61,17 @@ if __name__ == '__main__':
help="single run with immediate output of " +
"check results (test/debug)",
action="store_true")
parser.add_argument("-D", "--debug",
help="Set verbosity to DEBUG",
action="store_true")
args = parser.parse_args()
# Configure logging
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
level=config.verb_level)
if args.debug:
logging.getLogger().setLevel('DEBUG')
# do the actual polling
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
def runner(check):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment