Last active
May 21, 2019 19:09
-
-
Save thenoid/09bee74000c3332f809f2e4ef9dbb6bb to your computer and use it in GitHub Desktop.
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
import urllib2 | |
import simplejson | |
import socket | |
try: | |
# first, try to import the base class from old versions of the Agent... | |
from checks import AgentCheck | |
except ImportError: | |
# ...if the above failed, the check is running in Agent version 6 or later | |
from datadog_checks.checks import AgentCheck | |
__version__ = '19.5.1' | |
class CustomVault(AgentCheck): | |
def check(self, instance): | |
token = instance.get('token', "") | |
hostname = instance.get('host', socket.gethostname()) | |
port = instance.get('port', 8200) | |
ssl = 'https' if instance.get('ssl', True) else 'http' | |
lburl = "{}://{}:{}".format(ssl, hostname, port) | |
fullurl = "{}/v1/sys/internal/counters/requests".format(lburl) | |
req = urllib2.Request(fullurl, headers={'X-Vault-Token': token}) | |
try: | |
response = urllib2.urlopen(req) | |
data = simplejson.load(response) | |
except urllib2.HTTPError, error: | |
data = {} | |
value = data.get("data", {}).get("counters", [{}])[-1].get("total", 0) | |
self.gauge('custom_vault.counters.requests', value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment