Add https proxy support for a hipchat/slack plugin

Monasca notification will be running in a controller. There
are two way to add proxy, either via system proxy or via application
settings. The problem with system settings is that we need to add
no_proxy for all the other connections which is more difficult if there
are more number of outgoing connection which doesn't require proxy. Since
hipchat/slack most probably need proxy settings, it is easy to add
proxy settings only for hipchat/slack rather than changing the system-wide
environmental settings. Operators can also use system wide setting instead
of application specific settings by not using the proxy confifg option. This
gives a choice for the operator dependening on the complexity of the
installation.

Change-Id: Id5b7000d49c6824cf78b10299fcf7a707dec501e
This commit is contained in:
Haneef Ali 2016-08-12 15:25:33 -07:00 committed by haali1
parent 9ee7f5c6fe
commit facf67edb3
3 changed files with 12 additions and 0 deletions

View File

@ -92,12 +92,17 @@ class HipChatNotifier(AbstractNotifier):
if (self._config.get("ca_certs")):
verify = self._config.get("ca_certs")
proxyDict = None
if (self._config.get("proxy")):
proxyDict = {"https": self._config.get("proxy")}
try:
# Posting on the given URL
result = requests.post(url=url,
data=hipchat_message,
verify=verify,
params=query_params,
proxies=proxyDict,
timeout=self._config['timeout'])
if result.status_code in range(200, 300):

View File

@ -88,6 +88,10 @@ class SlackNotifier(AbstractNotifier):
if (self._config.get("ca_certs")):
verify = self._config.get("ca_certs")
proxyDict = None
if (self._config.get("proxy")):
proxyDict = {"https": self._config.get("proxy")}
try:
# Posting on the given URL
self._log.debug("Sending to the url {0} , with query_params {1}".format(url, query_params))
@ -95,6 +99,7 @@ class SlackNotifier(AbstractNotifier):
data=slack_message,
verify=verify,
params=query_params,
proxies=proxyDict,
timeout=self._config['timeout'])
if result.status_code not in range(200, 300):

View File

@ -56,11 +56,13 @@ notification_types:
timeout: 5
ca_certs: "/etc/ssl/certs/ca-certificates.crt"
insecure: False
proxy: https://myproxy.corp.com:8080
slack:
timeout: 5
ca_certs: "/etc/ssl/certs/ca-certificates.crt"
insecure: False
proxy: https://myproxy.corp.com:8080
processors:
alarm: