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. ...@@ -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 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. 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 Current state output
-------------------- --------------------
......
...@@ -15,6 +15,9 @@ config.install_attr('base_tick', 60) ...@@ -15,6 +15,9 @@ config.install_attr('base_tick', 60)
# How often we retry checks that are in error (-1 disables feature) # How often we retry checks that are in error (-1 disables feature)
config.install_attr('error_every', -1) 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 # Email addresses to send to when an alert is triggered
config.install_attr('emails.to', []) config.install_attr('emails.to', [])
# The From: address # The From: address
......
from .subprocess_compat import TimeoutExpired, Popen, PIPE from .subprocess_compat import TimeoutExpired, Popen, PIPE
import re import re
import logging
from . import mails from . import mails
from collections import Iterable from collections import Iterable
from datetime import datetime from datetime import datetime
...@@ -61,6 +62,7 @@ class Check(object): ...@@ -61,6 +62,7 @@ class Check(object):
config.error_every < 0 config.error_every < 0
else config.error_every) else config.error_every)
if self.every_count == 0 or immediate: if self.every_count == 0 or immediate:
logging.debug('Running ' + str(self))
self.setup() self.setup()
if not self.check(): if not self.check():
self.retry_count = min(self.retry_count + 1, self.retry) self.retry_count = min(self.retry_count + 1, self.retry)
......
import smtplib import smtplib
import logging
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import make_msgid from email.utils import make_msgid
from collections import defaultdict from collections import defaultdict
...@@ -55,7 +56,7 @@ class ThreadedSMTP(object): ...@@ -55,7 +56,7 @@ class ThreadedSMTP(object):
server = smtplib.SMTP(host) server = smtplib.SMTP(host)
server.sendmail(*args, **kwargs) server.sendmail(*args, **kwargs)
except Exception as e: except Exception as e:
print("Couldn't send email: %s" % str(e), file=stderr) logging.warning("Couldn't send email: %s" % str(e))
finally: finally:
if server: # server is None on exception queue.Empty if server: # server is None on exception queue.Empty
self._queue.task_done() self._queue.task_done()
......
import concurrent.futures import concurrent.futures
import signal import signal
import argparse import argparse
import logging
from time import sleep from time import sleep
import config as user_config import config as user_config
from lib import config from lib import config
...@@ -60,8 +61,17 @@ if __name__ == '__main__': ...@@ -60,8 +61,17 @@ if __name__ == '__main__':
help="single run with immediate output of " + help="single run with immediate output of " +
"check results (test/debug)", "check results (test/debug)",
action="store_true") action="store_true")
parser.add_argument("-D", "--debug",
help="Set verbosity to DEBUG",
action="store_true")
args = parser.parse_args() 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 # do the actual polling
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
def runner(check): 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