From: Calin Crisan Date: Thu, 26 Nov 2015 19:32:36 +0000 (+0200) Subject: webhook: added support for transmitting data as form and json X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=077fe04aaf0be87a58af79d906530e88709c9f64;p=motioneye-debian webhook: added support for transmitting data as form and json --- diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index 6daef16..9187ef3 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -550,7 +550,7 @@ Image File Name - ? + ? Image Quality @@ -723,9 +723,9 @@ - + - + @@ -766,7 +766,7 @@ - + @@ -780,10 +780,12 @@ - + diff --git a/motioneye/webhook.py b/motioneye/webhook.py index 2e7988a..d38fb66 100644 --- a/motioneye/webhook.py +++ b/motioneye/webhook.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import json import logging import urllib2 import urlparse @@ -41,14 +42,31 @@ def main(parser, args): logging.debug('method = %s' % options.method) logging.debug('url = %s' % options.url) + headers = {} + parts = urlparse.urlparse(options.url) + url = options.url + data = None + if options.method == 'POST': - parts = urlparse.urlparse(options.url) + headers['Content-Type'] = 'text/plain' + data = '' + + elif options.method == 'POSTf': # form url-encoded + headers['Content-Type'] = 'application/x-www-form-urlencoded' data = parts.query + url = options.url.split('?')[0] + + elif options.method == 'POSTj': # json + headers['Content-Type'] = 'application/json' + data = urlparse.parse_qs(parts.query) + data = {k: v[0] for (k, v) in data.iteritems()} + data = json.dumps(data) + url = options.url.split('?')[0] - else: - data = None + else: # GET + pass - request = urllib2.Request(options.url, data) + request = urllib2.Request(url, data, headers=headers) try: urllib2.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT) logging.debug('webhook successfully called')
Email NotificationsSend An Email ??
Email Addresses
Web Hook NotificationsCall A Web Hook ?
??