Skip to content

Commit

Permalink
Several updates according to the code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renaud HAGER committed Aug 9, 2018
1 parent a8bf516 commit 70c0df2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 0 additions & 2 deletions traefik/.flake8

This file was deleted.

2 changes: 1 addition & 1 deletion traefik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ init_config:
instances:
- host: 10.1.2.3
port: "8080"
path: health
path: "/health"
```

Configuration Options:
Expand Down
2 changes: 1 addition & 1 deletion traefik/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ init_config:
instances:
- host: 10.1.2.3
port: "8080"
path: health
path: "/health"
13 changes: 6 additions & 7 deletions traefik/datadog_checks/traefik/traefik.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under a 3-clause BSD style license (see LICENSE)

import requests
import json

from datadog_checks.checks import AgentCheck
from datadog_checks.errors import CheckException
Expand All @@ -21,14 +20,14 @@ def check(self, instance):
raise CheckException("Configuration error, please fix traefik.yaml")

try:
url = "http://" + host + ":" + port + path
url = 'http://{}:{}{}'.format(host, port, path)
response = requests.get(url)
response_status_code = response.status_code

if response_status_code == 200:
self.service_check('traefik.health', self.OK, tags=None, message="")
self.service_check('traefik.health', self.OK)

payload = json.loads(response.text)
payload = response.json()

if 'total_status_code_count' in payload:
values = payload['total_status_code_count']
Expand All @@ -45,10 +44,10 @@ def check(self, instance):
self.log.warn('Field total_count not found in response.')

else:
self.service_check('traefik.health', self.CRITICAL, tags=None, message="Traefik health check return code is not 200")
self.service_check('traefik.health', self.CRITICAL, message="Traefik health check return code is not 200")

except requests.exceptions.ConnectionError:
self.service_check('traefik.health', self.CRITICAL, tags=None, message="Traefik endpoint unreachable")
self.service_check('traefik.health', self.CRITICAL, message="Traefik endpoint unreachable")

except Exception as e:
self.service_check('traefik.health', self.UNKNOW, tags=None, message="Unknow exception" + str(e))
self.service_check('traefik.health', self.UNKNOWN, message="UNKNOWN exception" + str(e))
3 changes: 2 additions & 1 deletion traefik/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ basepython = py27
envlist = unit, flake8

[testenv]
platform = linux2|darwin
platform = linux2|darwin|win32
deps =
datadog-checks-base
-rrequirements-dev.txt
Expand All @@ -26,4 +26,5 @@ commands = flake8 .

[flake8]
exclude = .eggs,.tox
ignore = W292,E226,E501,F401,E303
max-line-length = 120

0 comments on commit 70c0df2

Please sign in to comment.