diff options
author | nico <nico@magicbroccoli.de> | 2020-08-27 18:10:23 +0200 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2020-08-27 18:10:23 +0200 |
commit | 893b93379fffd91c18a21315dc0b5c5d7285494c (patch) | |
tree | f17f35d763fa069ea6cec46ed199eb8e4a2fe6aa /api.py |
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.py | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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 {} |