diff --git a/README.md b/README.md index ea41665..171452c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 `^` diff --git a/superhooks/superhooks.py b/superhooks/superhooks.py index 3ca7e9c..e0dd874 100644 --- a/superhooks/superhooks.py +++ b/superhooks/superhooks.py @@ -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( @@ -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("^^"):