diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-08-06 18:34:57 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-08-06 18:34:57 -0500 |
commit | ebd393e56ba21f8a84571dff499e6d6fb6852042 (patch) | |
tree | 8087df81be6a63e0bbc27e19360bda65d59ec9b5 /cloudinit/reporting | |
parent | 6fdb23b6cbc8de14ebcffc17e9e49342b7bf193d (diff) | |
download | vyos-cloud-init-ebd393e56ba21f8a84571dff499e6d6fb6852042.tar.gz vyos-cloud-init-ebd393e56ba21f8a84571dff499e6d6fb6852042.zip |
tests pass
Diffstat (limited to 'cloudinit/reporting')
-rw-r--r-- | cloudinit/reporting/handlers.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cloudinit/reporting/handlers.py b/cloudinit/reporting/handlers.py index 86cbe3c3..d8f69641 100644 --- a/cloudinit/reporting/handlers.py +++ b/cloudinit/reporting/handlers.py @@ -34,5 +34,33 @@ class LogHandler(ReportingHandler): logger.info(event.as_string()) +class WebHookHandler(ReportingHandler): + def __init__(self, endpoint, consumer_key=None, token_key=None, + token_secret=None, consumer_secret=None, timeout=None, + retries=None): + super(WebHookHandler, self).__init__() + + if any(consumer_key, token_key, token_secret, consumer_secret): + self.oauth_helper = url_helper.OauthHelper( + consumer_key=consumer_key, token_key=token_key, + token_secret=token_secret, consumer_secret=consumer_secret) + else: + self.oauth_helper = None + self.endpoint = endpoint + self.timeout = timeout + self.retries = retries + self.ssl_details = util.fetch_ssl_details() + + def publish_event(self, event): + if self.oauth_helper: + readurl = self.oauth_helper.readurl + else: + readurl = url_helper.readurl + return readurl( + self.endpoint, data=event.as_dict(), + timeout=self.timeout, + retries=self.retries, ssl_details=self.ssl_details) + + available_handlers = DictRegistry() available_handlers.register_item('log', LogHandler) |