diff --git a/README.md b/README.md index e6150b5..8a73159 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,13 @@ tags: ['flapper', 'notify'] # If omitted, defaults to system's hostname +# Can be list like this +# host: +# - "host1.example.com" +# - "host2.example.com" +# or this: +# host: ["host1.example.com", "host2.example.com"] +# In this case message will be sent to all hosts. host: "myhost.example.com" # Set arbitrary attributes, optional diff --git a/bin/sumd b/bin/sumd index 8d10ab6..b6971d6 100755 --- a/bin/sumd +++ b/bin/sumd @@ -3,7 +3,9 @@ # Add cwd-relative lib to path import os import sys -sys.path.append("lib") + +dirname = os.path.dirname(os.path.dirname(__file__)) +sys.path.append(os.path.join(dirname, 'lib')) # Misc standard library imports import time @@ -51,6 +53,7 @@ parser.add_option("--log-dir", dest="log_directory", default="/var/log", help="D parser.add_option("--config-dir", dest="config_directory", default="/etc/sumd", help="Root path where tasks.d and tags.d can be found") parser.add_option("--run-dir", dest="run_directory", default="/var/run", help="Directory for where pidfiles should be placed") parser.add_option("--foreground", dest="foreground", action='store_true', default=False, help="Don't daemonize.") +parser.add_option("--suspend", dest="suspend", default=0, help="Suspend time before task starting.") parser.add_option("--debug", dest="debug", action='store_true', default=False, help="Increase logger verbosity") parser.add_option("--client-key-file", dest="client_key_file", help="Path to client SSL key file") parser.add_option("--client-cert-file", dest="client_cert_file", help="Path to client SSL cert file") @@ -128,18 +131,22 @@ def load_configs(schedule): schedule.add(task) def riemann_client(): - if options.client_key_file != None and options.client_cert_file != None: - riemann = bernhard.SSLClient( - host=options.riemann_host, - port=options.riemann_port, - keyfile=options.client_key_file, - certfile=options.client_cert_file, - ca_certs=options.ca_certs_file) - else: - riemann = bernhard.Client( - host=options.riemann_host, - port=options.riemann_port, - transport=bernhard.UDPTransport) + riemann = [] + if type(options.riemann_host) not in (list, tuple): + options.riemann_host = [options.riemann_host] + for h in options.riemann_host: + if options.client_key_file != None and options.client_cert_file != None: + riemann.append(bernhard.SSLClient( + host=h, + port=options.riemann_port, + keyfile=options.client_key_file, + certfile=options.client_cert_file, + ca_certs=options.ca_certs_file)) + else: + riemann.append(bernhard.Client( + host=h, + port=options.riemann_port, + transport=bernhard.UDPTransport)) return riemann @@ -163,6 +170,11 @@ def main(): if not options.foreground: log.info("Creating pidfile with PID: %s" % (pidfile(create=True))) + if options.suspend: + log.info("Suspend tasks for {}s".format(options.suspend)) + time.sleep(float(options.suspend)) + log.info("Continue to start.") + # Create scheduler schedule = scheduler.TaskSchedule() diff --git a/lib/sender.py b/lib/sender.py index 24dbb1d..425644d 100644 --- a/lib/sender.py +++ b/lib/sender.py @@ -21,11 +21,12 @@ def send(self, events): log.debug("Sending %s events..." % (len(events))) while len(events) > 0: event = events.pop(0) - try: - log.debug("Event: %s" % (event.dict())) - self.riemann.send(event.dict()) - except socket.error: - log.error("Unable to send event '%s' to %s:%s" % (event.service, self.riemann.host, self.riemann.port)) + log.debug("Event: %s" % (event.dict())) + for r in self.riemann: + try: + r.send(event.dict()) + except socket.error: + log.error("Unable to send event '%s' to %s:%s" % (event.service, r.host, r.port)) else: log.warning("Send called with no events to send.")