Skip to content

Commit

Permalink
Use proxy for API key check in info page (#3012)
Browse files Browse the repository at this point in the history
Fixes #3011
  • Loading branch information
2rs2ts authored and gmmeyer committed Nov 10, 2016
1 parent 48ffba9 commit 3e09d3e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions checks/check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from utils.pidfile import PidFile
from utils.platform import Platform
from utils.profile import pretty_statistics
from utils.proxy import get_proxy


STATUS_OK = 'OK'
Expand Down Expand Up @@ -116,10 +117,14 @@ def get_ntp_info():
ntp_styles = []
return ntp_offset, ntp_styles

def validate_api_key(api_key):
def validate_api_key(config):
try:
proxy = get_proxy(agentConfig=config)
request_proxy = {}
if proxy:
request_proxy = {'https': "http://{user}:{password}@{host}:{port}".format(**proxy)}
r = requests.get("https://app.datadoghq.com/api/v1/validate",
params={'api_key': api_key}, timeout=3)
params={'api_key': config.get('api_key')}, proxies=request_proxy, timeout=3)

if r.status_code == 403:
return "API Key is invalid"
Expand Down Expand Up @@ -798,7 +803,7 @@ def body_lines(self):
"Transactions received: %s" % self.transactions_received,
"Transactions flushed: %s" % self.transactions_flushed,
"Transactions rejected: %s" % self.transactions_rejected,
"API Key Status: %s" % validate_api_key(get_config().get('api_key')),
"API Key Status: %s" % validate_api_key(config=get_config()),
"",
]

Expand Down

0 comments on commit 3e09d3e

Please sign in to comment.