diff --git a/README.md b/README.md index 4f34385fcbbe66303d9f8d719e30fdcc668ec5c0..d6e52d5c8a3bcb36e8f0aad19e1a96330eac1495 100644 --- a/README.md +++ b/README.md @@ -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 -------------------- diff --git a/lib/__init__.py b/lib/__init__.py index 52d271d52599bcb63e6c55ccd9528c2fbb9da9ef..1d799dca8d4e16a0233fb8cd4e0a05236f172015 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -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 diff --git a/lib/checks.py b/lib/checks.py index ad07f84bd48f5c32b2b4a92b0fe14ddf9f4edee7..209a6718fd296281423f3bde8c7cf832f6a662dc 100644 --- a/lib/checks.py +++ b/lib/checks.py @@ -1,5 +1,6 @@ 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) diff --git a/lib/mails.py b/lib/mails.py index d08f27f3dfb5d0f6f941f63a4d5674149885c15a..1951eb23aba282bb1af1046f583d517834bfa16f 100644 --- a/lib/mails.py +++ b/lib/mails.py @@ -1,4 +1,5 @@ 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() diff --git a/picomon.py b/picomon.py index 553dd6669ab73984260881019f3868145465d877..ff0e57e952f3f953b0a013e2a9c7ff379876222c 100644 --- a/picomon.py +++ b/picomon.py @@ -1,6 +1,7 @@ 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):