added support for http proxy in salesforce plugin

Change-Id: Ia7aa4d423dcecb46aa31e69d9570562fa86f13f1
diff --git a/sensu/files/handlers/sfdc.json b/sensu/files/handlers/sfdc.json
index e683bdb..d331442 100644
--- a/sensu/files/handlers/sfdc.json
+++ b/sensu/files/handlers/sfdc.json
@@ -21,6 +21,12 @@
     "sfdc_username": "{{ handler.sfdc_username }}",
     "sfdc_password": "{{ handler.sfdc_password }}",
     "sfdc_auth_url": "{{ handler.sfdc_auth_url }}",
+    {%- if handler.sfdc_http_proxy is defined %}
+    "sfdc_http_proxy": "{{ handler.sfdc_http_proxy }}",
+    {%- endif %}
+    {%- if handler.sfdc_https_proxy is defined %}
+    "sfdc_https_proxy": "{{ handler.sfdc_https_proxy }}",
+    {%- endif %}
     "environment": "{{ handler.environment }}",
     "sfdc_organization_id": "{{ handler.sfdc_organization_id }}"
 {%- if token_cache_file %}
diff --git a/sensu/files/plugins/handlers/notification/salesforce.py b/sensu/files/plugins/handlers/notification/salesforce.py
index dc31a1c..6df0934 100644
--- a/sensu/files/plugins/handlers/notification/salesforce.py
+++ b/sensu/files/plugins/handlers/notification/salesforce.py
@@ -25,7 +25,7 @@
 LOG = logging.getLogger()
 
 class OAuth2(object):
-    def __init__(self, client_id, client_secret, username, password, auth_url=None, organizationId=None):
+    def __init__(self, client_id, client_secret, username, password, auth_url=None, http_proxy=None, https_proxy=None, organizationId=None):
         if not auth_url:
             auth_url = 'https://login.salesforce.com'
 
@@ -35,6 +35,8 @@
         self.username = username
         self.password = password
         self.organizationId = organizationId
+        self.http_proxy = http_proxy
+        self.https_proxy = https_proxy
 
     def getUniqueElementValueFromXmlString(self, xmlString, elementName):
         """
@@ -85,9 +87,16 @@
             'SOAPAction': 'login'
         }
 
+        proxies = {
+          'http': self.http_proxy,
+          'https': self.http_proxy,
+        }
+
         response = requests.post(soap_url,
-                             login_soap_request_body,
-                             headers=login_soap_request_headers)
+                     login_soap_request_body,
+                     headers=login_soap_request_headers,
+                     proxies=proxies)
+
         LOG.debug(response)
         LOG.debug(response.status_code)
         LOG.debug(response.text)
@@ -114,8 +123,13 @@
             'password': self.password,
         }
 
+        proxies = {
+          'http': self.http_proxy,
+          'https': self.http_proxy,
+        }
+
         url = '{}/services/oauth2/token'.format(self.auth_url)
-        response = requests.post(url, data=data)
+        response = requests.post(url, data=data, proxies=proxies)
         response.raise_for_status()
         return response.json()
 
@@ -136,9 +150,14 @@
     def __init__(self, oauth2):
         self.oauth2 = oauth2
 
+        self.http_proxy = oauth2.http_proxy
+        self.https_proxy = oauth2.https_proxy
+
         self.access_token = None
         self.instance_url = None
 
+
+
     def ticket(self, id):
         try:
             return self.get('/services/data/v36.0/sobjects/proxyTicket__c/{}'.format(id)).json()
@@ -189,7 +208,6 @@
     def update_case(self, id, data):
         return self.patch('/services/data/v36.0/sobjects/Case/{}'.format(id), data=json.dumps(data), headers={"content-type": "application/json"})
 
-
     def update_comment(self, id, data):
         return self.patch('/services/data/v36.0/sobjects/proxyTicketComment__c/{}'.format(id), data=json.dumps(data), headers={"content-type": "application/json"})
 
@@ -252,7 +270,13 @@
         url = self.instance_url + url
         print "URL", url
         print "KWARGS", kwargs
-        response = requests.request(method, url, headers=headers, **kwargs)
+
+        proxies = {
+          'http': self.http_proxy,
+          'https': self.http_proxy,
+        }
+
+        response = requests.request(method, url, headers=headers, proxies=proxies, **kwargs)
         print "RESPONSE", response
 # Debug only
         LOG.debug("Response code: {}".format(response.status_code))
diff --git a/sensu/files/plugins/handlers/notification/sfdc.py b/sensu/files/plugins/handlers/notification/sfdc.py
index e02f76b..9b0e48c 100755
--- a/sensu/files/plugins/handlers/notification/sfdc.py
+++ b/sensu/files/plugins/handlers/notification/sfdc.py
@@ -50,18 +50,22 @@
         username = self.settings.get('sfdc', {}).get('sfdc_username')
         password = self.settings.get('sfdc', {}).get('sfdc_password')
         auth_url = self.settings.get('sfdc', {}).get('sfdc_auth_url')
+        http_proxy = self.settings.get('sfdc', {}).get('sfdc_http_proxy')
+        https_proxy = self.settings.get('sfdc', {}).get('sfdc_https_proxy')
         organization_id = self.settings.get('sfdc', {}).get('sfdc_organization_id')
         environment = self.settings.get('sfdc', {}).get('environment')
         token_cache_file = self.settings.get('sfdc', {}).get('token_cache_file', None)
 
         print self.event
         print "client_id: ", client_id
-        print "client_secrete: ", client_secret
+        #print "client_secrete: ", client_secret
         print "auth_url: ", auth_url
+        print "http_proxy: ", http_proxy
+        print "https_proxy: ", https_proxy
         print "organization: ", organization_id
         print "username: ", username
         sfdc_oauth2 = OAuth2(client_id, client_secret, username, password,
-                             auth_url, organization_id)
+                             auth_url, http_proxy, https_proxy, organization_id)
 
         data = self.event
         client_host = data.get('client', {}).get('name')