diff options
author | Rahiel Kasim <rahielkasim@gmail.com> | 2017-06-21 12:31:58 +0200 |
---|---|---|
committer | Rahiel Kasim <rahielkasim@gmail.com> | 2017-06-21 12:31:58 +0200 |
commit | e23b83f82f9c47ca0a1feb90a8807fe718c5bbbe (patch) | |
tree | eddb45cc18a06b239af18ac22607bbadeed1db3d | |
parent | fed303fc98579b8dd027da837dffab9cf630e149 (diff) |
fix sending over Telegram
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | supervisor_alert.py | 21 |
3 files changed, 18 insertions, 12 deletions
@@ -1,13 +1,16 @@ # supervisor-alert +[](https://pypi.python.org/pypi/supervisor-alert) +[](https://pypi.python.org/pypi/supervisor-alert) [](https://github.com/rahiel/supervisor-alert/blob/master/LICENSE.txt) Are you using [Supervisor](http://supervisord.org) to manage processes on a server? With supervisor-alert you can receive messages when the state of your processes change. Be the first to know when your services die! -To send messages on Telegram you need to install and set up [telegram-send][] -first. You can also use any shell command to send the notifications. +With the default configuration supervisor-alert sends messages over Telegram. +For this to work you need to install [telegram-send][] system-wide first. You +can also use any shell command to send the notifications. [telegram-send]: https://github.com/rahiel/telegram-send @@ -17,7 +17,7 @@ except: setup( name="supervisor-alert", version=__version__, - description="Receive notifications for supervisor process events", + description="Receive notifications for Supervisor process events.", long_description=long_description, url="https://github.com/rahiel/supervisor-alert", license="Apache-2.0", diff --git a/supervisor_alert.py b/supervisor_alert.py index fc3e8db..18ac265 100644 --- a/supervisor_alert.py +++ b/supervisor_alert.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# supervisor-alert - Receive notifications for supervisor process events -# Copyright 2016 Rahiel Kasim +# supervisor-alert - Receive notifications for Supervisor process events +# Copyright 2016-2017 Rahiel Kasim # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,17 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse +import shlex from functools import partial -import os from os.path import expanduser from pwd import getpwnam -import shlex -from subprocess import check_call, CalledProcessError +from subprocess import CalledProcessError, check_call from supervisor.childutils import listener, get_headers -__version__ = "0.3" +__version__ = "0.4" + +telegram_conf_args = ["--config", "/etc/telegram-send.conf"] def main(): parser = argparse.ArgumentParser(description="Supervisor event listener to notify on process events.", @@ -64,11 +65,11 @@ def main(): def telegram(message): """Send message with telegram-send.""" try: - check_call(["telegram-send", message]) + check_call(["telegram-send", message] + telegram_conf_args) listener.ok() except OSError: # command not found cmd = expanduser("~/.local/bin/telegram-send") - check_call([cmd, message]) + check_call([cmd, message] + telegram_conf_args) listener.ok() except CalledProcessError: listener.fail() @@ -96,7 +97,7 @@ user=supervisor_alert """ try: - with open(conf, 'w') as f: + with open(conf, "w") as f: f.write(config) except IOError: raise Exception("Can't save config, please execute as root: sudo supervisor-alert --configure") @@ -114,6 +115,8 @@ user=supervisor_alert raise Exception("Please retry as root or configure manually: " "https://github.com/rahiel/supervisor-alert#manual-configuration") + print("Setting up telegram-send...") + check_call(["telegram-send", "--configure"] + telegram_conf_args) print("Supervisor-alert has been set up successfully!") |