Skip to content

Add https support for monit collector. #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/collectors/MonitCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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
scheme | http | Select scheme http or https | str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptions need to be added to the get_default_config_help method in the collector file since this doc is actually generated from that.

selfsigned | False | Use self-signed certificate | bool
send_totals | False | Send cpu and memory totals | bool

#### Example Output
Expand All @@ -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
```

18 changes: 16 additions & 2 deletions src/collectors/monit/monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import urllib2
import base64
import sys
import ssl

from xml.dom.minidom import parseString

Expand Down Expand Up @@ -40,12 +42,24 @@ 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'],
int(self.config['port']))
url = '%s://%s:%i/_status?format=xml' % (self.config['scheme'],
self.config['host'],
int(self.config['port']))

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:
request = urllib2.Request(url)

Expand Down