Skip to content

Commit

Permalink
[check_marathon] Add marathon disable_ssl_validation and group support (
Browse files Browse the repository at this point in the history
#3140)

* Add marathon disable_ssl_validation and group support

* Fix marathon_test for #3140

* Fix indentation for #3140
  • Loading branch information
Carles-Figuerola authored and masci committed Jan 24, 2017
1 parent f5c15e3 commit cee209d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 11 additions & 4 deletions checks.d/marathon.py
Expand Up @@ -12,6 +12,7 @@

# project
from checks import AgentCheck
from config import _is_affirmative


class Marathon(AgentCheck):
Expand Down Expand Up @@ -43,13 +44,19 @@ def check(self, instance):
auth = (user,password)
else:
auth = None
ssl_verify = not _is_affirmative(instance.get('disable_ssl_validation', False))
group = instance.get('group', None)

instance_tags = instance.get('tags', [])
default_timeout = self.init_config.get('default_timeout', self.DEFAULT_TIMEOUT)
timeout = float(instance.get('timeout', default_timeout))

# Marathon apps
response = self.get_json(urljoin(url, "v2/apps"), timeout, auth)
if group is None:
marathon_path = urljoin(url, "v2/apps")
else:
marathon_path = urljoin(url, "v2/groups/{}".format(group))
response = self.get_json(marathon_path, timeout, auth, ssl_verify)
if response is not None:
self.gauge('marathon.apps', len(response['apps']), tags=instance_tags)
for app in response['apps']:
Expand All @@ -59,13 +66,13 @@ def check(self, instance):
self.gauge('marathon.' + attr, app[attr], tags=tags)

# Number of running/pending deployments
response = self.get_json(urljoin(url, "v2/deployments"), timeout, auth)
response = self.get_json(urljoin(url, "v2/deployments"), timeout, auth, ssl_verify)
if response is not None:
self.gauge('marathon.deployments', len(response), tags=instance_tags)

def get_json(self, url, timeout, auth):
def get_json(self, url, timeout, auth, verify):
try:
r = requests.get(url, timeout=timeout, auth=auth)
r = requests.get(url, timeout=timeout, auth=auth, verify=verify)
r.raise_for_status()
except requests.exceptions.Timeout:
# If there's a timeout
Expand Down
6 changes: 6 additions & 0 deletions conf.d/marathon.yaml.example
Expand Up @@ -9,3 +9,9 @@ instances:
# if marathon is protected by basic auth
# user: "username"
# password: "password"
#
# to disable ssl validation
# disable_ssl_validation: true
#
# to get metrics from just one application group:
# group: product
4 changes: 2 additions & 2 deletions tests/checks/mock/test_marathon.py
Expand Up @@ -32,7 +32,7 @@ class MarathonCheckTest(AgentCheckTest):
CHECK_NAME = 'marathon'

def test_default_configuration(self):
def side_effect(url, timeout, auth):
def side_effect(url, timeout, auth, verify):
if "v2/apps" in url:
return Fixtures.read_json_file("apps.json")
elif "v2/deployments" in url:
Expand All @@ -46,7 +46,7 @@ def side_effect(url, timeout, auth):


def test_empty_responses(self):
def side_effect(url, timeout, auth):
def side_effect(url, timeout, auth, verify):
if "v2/apps" in url:
return {"apps": []}
elif "v2/deployments" in url:
Expand Down

0 comments on commit cee209d

Please sign in to comment.