Skip to content

Commit 4ecd5ef

Browse files
author
Remi Hakim
authored
[status] Display api key status in the info page (#2947)
1 parent 4a1fca0 commit 4ecd5ef

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

checks/check_status.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# 3p
2121
import ntplib
22+
import requests
2223
import yaml
2324

2425
# project
@@ -115,6 +116,21 @@ def get_ntp_info():
115116
ntp_styles = []
116117
return ntp_offset, ntp_styles
117118

119+
def validate_api_key(api_key):
120+
try:
121+
r = requests.get("https://app.datadoghq.com/api/v1/validate",
122+
params={'api_key': api_key}, timeout=3)
123+
124+
if r.status_code == 403:
125+
return "API Key is invalid"
126+
127+
r.raise_for_status()
128+
129+
except Exception:
130+
log.exception("Unable to validate API Key")
131+
return "Unable to validate API Key. Please try again later"
132+
133+
return "API Key is valid"
118134

119135
class AgentStatus(object):
120136
"""
@@ -782,7 +798,8 @@ def body_lines(self):
782798
"Transactions received: %s" % self.transactions_received,
783799
"Transactions flushed: %s" % self.transactions_flushed,
784800
"Transactions rejected: %s" % self.transactions_rejected,
785-
""
801+
"API Key Status: %s" % validate_api_key(get_config().get('api_key')),
802+
"",
786803
]
787804

788805
return lines

0 commit comments

Comments
 (0)