summaryrefslogtreecommitdiffstats
path: root/api.py
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2020-08-27 18:10:23 +0200
committernico <nico@magicbroccoli.de>2020-08-27 18:10:23 +0200
commit893b93379fffd91c18a21315dc0b5c5d7285494c (patch)
treef17f35d763fa069ea6cec46ed199eb8e4a2fe6aa /api.py
Initial working releaseHEADmaster
TeamSpeak InfluxDB exporter base of ejabberd-tools framework + implement TeamSpeak REST api call to gather statistics + implement metrics logic to omit unnecessary data points + add systemd service file + implement pre-commit framework
Diffstat (limited to 'api.py')
-rw-r--r--api.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/api.py b/api.py
new file mode 100644
index 0000000..9cfb820
--- /dev/null
+++ b/api.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import requests
+
+
+class TeamSpeakApi:
+ """
+ class to interact with the teamspeak rest api
+ """
+
+ def __init__(self, apikey: str, url: str):
+ # variables
+ self._apikey = apikey
+ self._url = url
+
+ # define api handler
+ self.cmd = self._rest
+
+ self.session = requests.Session()
+
+ @property
+ def _auth(self):
+ if self._apikey is not None:
+ return {"x-api-key": self._apikey}
+
+ def _rest(self, command: str) -> dict:
+ # add authentication header to the session obj
+ auth_header = self._auth
+
+ # build get request
+ r = self.session.get("/".join([self._url, command]), headers=auth_header, verify=False)
+
+ # proceed if response is ok
+ if r.ok:
+ return r.json()
+
+ return {}