File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1919
2020# 3p
2121import ntplib
22+ import requests
2223import 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
119135class 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
You can’t perform that action at this time.
0 commit comments