From f0cc2a4736f85bd34b500c1bba775235ece02fcf Mon Sep 17 00:00:00 2001 From: Andrey Kolesnikov Date: Wed, 5 Oct 2016 11:01:24 +0300 Subject: [PATCH 1/3] Add https support for monit collector. --- src/collectors/monit/monit.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/collectors/monit/monit.py b/src/collectors/monit/monit.py index c3bbd5936..15350fcb4 100644 --- a/src/collectors/monit/monit.py +++ b/src/collectors/monit/monit.py @@ -11,6 +11,8 @@ import urllib2 import base64 +import sys +import ssl from xml.dom.minidom import parseString @@ -40,12 +42,19 @@ def get_default_config(self): 'path': 'monit', 'byte_unit': ['byte'], 'send_totals': False, + 'scheme': 'http', + 'selfsigned': False, }) return config def collect(self): - url = 'http://%s:%i/_status?format=xml' % (self.config['host'], + url = '%s://%s:%i/_status?format=xml' % (self.config['scheme'], + self.config['host'], int(self.config['port'])) + + if self.config['selfsigned'] and sys.hexversion >= 0x020709f0 and hasattr(ssl, '_create_unverified_context'): + ssl._create_default_https_context = ssl._create_unverified_context + try: request = urllib2.Request(url) From 12c53acdd541286bf2bd42864667c3942a5e9400 Mon Sep 17 00:00:00 2001 From: Andrey Kolesnikov Date: Thu, 6 Oct 2016 11:36:53 +0300 Subject: [PATCH 2/3] Monit module: More compliance PEP8 format source code. Domumentation update. --- docs/collectors/MonitCollector.md | 3 ++- src/collectors/monit/monit.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/collectors/MonitCollector.md b/docs/collectors/MonitCollector.md index 3c433980c..3ab1ed4d8 100644 --- a/docs/collectors/MonitCollector.md +++ b/docs/collectors/MonitCollector.md @@ -21,6 +21,8 @@ measure_collector_time | False | Collect the collector run time in ms | bool metrics_blacklist | None | Regex to match metrics to block. Mutually exclusive with metrics_whitelist | NoneType metrics_whitelist | None | Regex to match metrics to transmit. Mutually exclusive with metrics_blacklist | NoneType send_totals | False | Send cpu and memory totals | bool +scheme | http | Select scheme http or https | str +selfsigned | False | Use self-signed certificate | bool #### Example Output @@ -46,4 +48,3 @@ servers.hostname.monit.rsyslogd.memory.kilobyte_usage 2664 servers.hostname.monit.sshd.cpu.percent 0.0 servers.hostname.monit.sshd.memory.kilobyte_usage 2588 ``` - diff --git a/src/collectors/monit/monit.py b/src/collectors/monit/monit.py index 15350fcb4..6bfbb316a 100644 --- a/src/collectors/monit/monit.py +++ b/src/collectors/monit/monit.py @@ -50,10 +50,11 @@ def get_default_config(self): def collect(self): url = '%s://%s:%i/_status?format=xml' % (self.config['scheme'], self.config['host'], - int(self.config['port'])) + int(self.config['port'])) - if self.config['selfsigned'] and sys.hexversion >= 0x020709f0 and hasattr(ssl, '_create_unverified_context'): - ssl._create_default_https_context = ssl._create_unverified_context + # 0x020709f0 exactly equal python 2.7.9 final + if (self.config['selfsigned'] and sys.hexversion >= 0x020709f0 and hasattr(ssl, '_create_unverified_context')): + ssl._create_default_https_context = ssl._create_unverified_context try: request = urllib2.Request(url) From 19aa8761609976b4918a3e2153c6b8e25d0388e2 Mon Sep 17 00:00:00 2001 From: Andrey Kolesnikov Date: Fri, 14 Oct 2016 20:46:57 +0300 Subject: [PATCH 3/3] Fix pep8 mistake and alphabetize docs. --- docs/collectors/MonitCollector.md | 2 +- src/collectors/monit/monit.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/collectors/MonitCollector.md b/docs/collectors/MonitCollector.md index 3ab1ed4d8..4748fc628 100644 --- a/docs/collectors/MonitCollector.md +++ b/docs/collectors/MonitCollector.md @@ -20,9 +20,9 @@ enabled | False | Enable collecting these metrics | bool measure_collector_time | False | Collect the collector run time in ms | bool metrics_blacklist | None | Regex to match metrics to block. Mutually exclusive with metrics_whitelist | NoneType metrics_whitelist | None | Regex to match metrics to transmit. Mutually exclusive with metrics_blacklist | NoneType -send_totals | False | Send cpu and memory totals | bool scheme | http | Select scheme http or https | str selfsigned | False | Use self-signed certificate | bool +send_totals | False | Send cpu and memory totals | bool #### Example Output diff --git a/src/collectors/monit/monit.py b/src/collectors/monit/monit.py index 6bfbb316a..aa1457a60 100644 --- a/src/collectors/monit/monit.py +++ b/src/collectors/monit/monit.py @@ -52,8 +52,12 @@ def collect(self): self.config['host'], int(self.config['port'])) - # 0x020709f0 exactly equal python 2.7.9 final - if (self.config['selfsigned'] and sys.hexversion >= 0x020709f0 and hasattr(ssl, '_create_unverified_context')): + if ( + self.config['selfsigned'] + # 0x020709f0 exactly equal python 2.7.9 final + and sys.hexversion >= 0x020709f0 + and hasattr(ssl, '_create_unverified_context') + ): ssl._create_default_https_context = ssl._create_unverified_context try: