diff --git a/README.md b/README.md index 8ee7b0b9c1e827feabc4297104509d37179b74cc..44ff7bc19de7a7b64d16d2f7babfce79a5ca8250 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,19 @@ easy to get it working again. Install dependencies: +```console pip install -r requirements.txt +``` + +## Standalone usage with command line arguments + +```bash +./query_alertmanager.py https://alertmanager.example.net my_password +``` -## Configuration +## Standalone usage config file + +### Configuration Config file example (`~/.config/alertmanager_status/config.yml`): @@ -31,17 +41,17 @@ user: admin password: 123 ``` - -## Standalone usage - -Start the indicator: +### Usage ```bash -./alertmanager_status.py +./query_alertmanager.py https://alertmanager.example.net my_password ``` ## Waybar integration +Additional requirement if you want waybar to parse the `on-right-click` URL +for the config file: [yq](https://github.com/mikefarah/yq) + ```json "custom/alertmanager": { "return-type": "json", @@ -53,10 +63,10 @@ Start the indicator: "snafu": "🟢", "error": "🚫" }, - "exec": "/bin/bash -c 'cd /home/varac/projects/monitoring/indicator_alertmanager/ && . ./.direnv/*/bin/activate && ./alertmanager_status.py'", + "exec": "/bin/bash -c 'cd /tmp/alertmanager_status/ && . ./.direnv/*/bin/activate && ./alertmanager_status.py'", "signal": 21, "on-click": "pkill -RTMIN+21 waybar", - "on-click-right": "xdg-open https://alertmanager.oas.varac.net", + "on-click-right": "xdg-open $(yq .url < ~/.config/alertmanager_status/config.yml)", } ``` diff --git a/alertmanager_status.py b/alertmanager_status.py index e612ba9f9ab33dc2091658b88131f236800442ba..be27b67e655c0bbabba47a15658db283441f28cc 100755 --- a/alertmanager_status.py +++ b/alertmanager_status.py @@ -39,8 +39,8 @@ def show_alerts(opts): @plac.opt('configpath', "Path to alertmanager config", type=Path) -@plac.opt('mode', "Mode: wayland or indicator (not working)", type=str) -@plac.flg('debug', "Enable debug mode") +@plac.opt('mode', "Mode", type=str, choices=['waybar', 'indicator']) +# plac.flg('debug', "Enable debug mode") def main(configpath='~/.config/alertmanager_status/config.yml', mode="wayland"): """Main function.""" diff --git a/query_alertmanager.py b/query_alertmanager.py index c9cbe586b70f6228dee7b61f8007a1861594f338..63fb710932f59f285d845ecef9f4593f8b16ee3e 100755 --- a/query_alertmanager.py +++ b/query_alertmanager.py @@ -56,10 +56,10 @@ def get_alerts(url, password, port=443, user='admin'): return return_data -@plac.opt('url', "URL of alertmanager instance", type=str, abbrev='U') +@plac.pos('url', "URL of alertmanager instance", type=str) +@plac.pos('password', "Password", type=str) @plac.opt('port', "Port of alertmanager instance", type=int, abbrev='P') @plac.opt('user', "User name", type=str) -@plac.opt('password', "Password", type=str) def main(url, password, port=443, user='admin'): """Main function.""" alerts = get_alerts(url=url, password=password, port=port, user=user)