Skip to content
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

Use proxy for API key check in info page #3012

Merged
merged 1 commit into from
Nov 10, 2016
Merged
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
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