Last active
September 27, 2021 20:24
-
-
Save mikegreen/4c6be71e37f6b5bdc19fe0e017367209 to your computer and use it in GitHub Desktop.
DataDog Vault Status Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# drafty custom-vault.py | |
# needs a corresponding /etc/datadog-agent/conf.d/custom-vault.yaml with `instances: [{}]` only | |
# see https://datadoghq.dev/integrations-core/base/api/#datadog_checks.base.checks.base.AgentCheck.count | |
# https://github.com/DataDog/integrations-core/tree/master/vault/datadog_checks/vault | |
import requests | |
# the following try/except block will make the custom check compatible with any Agent version | |
try: | |
# first, try to import the base class from new versions of the Agent... | |
from datadog_checks.base import AgentCheck | |
except ImportError: | |
# ...if the above failed, the check is running in Agent version < 6.6.0 | |
from checks import AgentCheck | |
# content of the special variable __version__ will be shown in the Agent status page | |
__version__ = "1.0.0" | |
try: | |
r = requests.head("https://localhost:8200/v1/sys/health", verify=False) | |
print(r.status_code) | |
httpCode = r.status_code | |
print("http code: ", httpCode) | |
# prints the int of the status code. Find more at httpstatusrappers.com :) | |
except requests.ConnectionError: | |
print("failed to connect") | |
exit() | |
if httpCode == 200: | |
codeMessage = "initialized, unsealed, and active" | |
elif httpCode == 429: | |
codeMessage = "unsealed and standby"; | |
elif httpCode == 472: | |
codeMessage = "data recovery mode replication secondary and active"; | |
elif httpCode == 473: | |
codeMessage = "performance standby"; | |
elif httpCode == 501: | |
codeMessage = "not initialized"; | |
elif httpCode == 503: | |
codeMessage = "sealed"; | |
else: | |
codeMessage = "Invalid HTTP response"; | |
print("http translated:", codeMessage ) | |
class HelloCheck(AgentCheck): | |
def check(self, instance): | |
self.gauge('hello.world', httpCode, tags=self.instance.get('tags', [])) | |
self.gauge('vault.status', httpCode, tags=self.instance.get('tags', [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment