Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a special value name dump_params #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pip install superhooks

```bash
$ superhooks -u http://localhost:8090/ -e STARTING,RUNNING,BACKOFF,STOPPING,FATAL,EXITED,STOPPED,UNKNOWN -d "a^b^^c^d" -H "p^q^^r^s"
# Telegram Example
$ superhooks -u https://api.telegram.org/bot$YOURBOT/sendMessage -d "chat_id^$YOURID^^text^dump_params^^disable_notifications^true" -e STARTING, RUNNING, BACKOFF, STOPPING, EXITED, STOPPED, UNKNOWN
```

### Options
Expand All @@ -22,7 +24,7 @@ $ superhooks -u http://localhost:8090/ -e STARTING,RUNNING,BACKOFF,STOPPING,FAT

Post the payload to the url with http `POST`

```-d DATA, --data=a^b^^c^d``` post body data as key value pair items are separated by `^^` and key and values are separated by `^`
```-d DATA, --data=a^b^^c^d``` post body data as key value pair items are separated by `^^` and key and values are separated by `^`, if `dump_params` is used as value `foo:dump_params` foo will dump `eventname` and all params

```-H HEADERS, --headers=p^q^^r^s``` request headers with as key value pair items are separated by `^^` and key and values are separated by `^`

Expand Down
8 changes: 6 additions & 2 deletions superhooks/superhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def _get_opt_parser(cls):

parser = OptionParser()
parser.add_option("-u", "--url", help="Web Hook URL")
parser.add_option("-d", "--data", help="data in key value pair ex: `foo:bar::goo:baz`")
parser.add_option("-d", "--data", help="data in key value pair ex: `foo:bar::goo:baz`"
" if 'dump_params' is used as value `foo:dump_params` foo will dump `eventname` and all params")
parser.add_option("-H", "--headers", help="headers in key value pair ex: `foo:bar::goo:baz`")
parser.add_option("-e", "--events",
help="Supervisor event(s). Can be any, some or all of {} as comma separated values".format(
Expand Down Expand Up @@ -125,7 +126,10 @@ def send_batch_notification(self):
for item in self.data.split("^^"):
kv = item.split("^")
if len(kv) == 2:
params[kv[0]] = kv[1]
if kv[1] == 'dump_params':
params[kv[0]] = eventname+'\n'+pheaders_all.replace(' ', '\n').replace(':', ': ')
else:
params[kv[0]] = kv[1]
headers = {}
if self.headers:
for item in self.headers.split("^^"):
Expand Down