self-signed certificate support for UrlService added
Ilya committed
Feb 25, 2017 at 21:45 UTC
ca5fe161303a4b2464634ab0c8e4c3e0b9587f13
1 file changed
+13
-2
python.d/python_modules/base.py
+13
-2
@@ -31,6 +31,7 @@ from subprocess import Popen, PIPE
31
32
import threading
33
import msg
34
+import ssl
35
36
try:
37
PATH = os.getenv('PATH').split(':')
@@ -460,7 +461,17 @@ class UrlService(SimpleService):
461
462
def __add_openers(self):
463
# TODO add error handling
463
- self.opener = urllib2.build_opener()
464
+ if self.ss_cert:
465
+ try:
466
+ ctx = ssl.create_default_context()
467
+ ctx.check_hostname = False
468
+ ctx.verify_mode = ssl.CERT_NONE
469
+ self.opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ctx))
470
+ except Exception as error:
471
+ self.error(str(error))
472
+ self.opener = urllib2.build_opener()
473
+ else:
474
+ self.opener = urllib2.build_opener()
475
476
# Proxy handling
477
# TODO currently self.proxies isn't parsed from configuration file
@@ -535,7 +546,7 @@ class UrlService(SimpleService):
546
self.password = str(self.configuration['pass'])
547
except (KeyError, TypeError):
548
pass
538
-
549
+ self.ss_cert = self.configuration.get('ss_cert')
550
self.__add_openers()
551
552
test = self._get_data()