visio.chapril.org-tools/statistiques/check_jitsi_room.py

75 lines
1.9 KiB
Python
Executable File

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Imports
import os
import sys
import requests
import time
import datetime
import argparse
# Constantes
api_url = 'http://localhost:8080/colibri/stats'
# Classes
class JitsiStats:
def __init__(self):
self.datas = requests.get(api_url,timeout=1)
def getTimestamp(self):
return self.datas.json()['current_timestamp']
def getVal(self,index):
for (key,value) in self.datas.json().items():
if key.lower() == index.lower():
return value
def getStatsList(self):
liste = []
for (key,value) in self.datas.json().items():
t = (key,value)
liste.append(t)
return liste
# Fonctions
def runMain():
retStatus = 3
restString = 'UNKNOWN serveur jitsi meet, champs inconnu(s)'
parser = argparse.ArgumentParser( prog = 'getJistiStats', description = 'Sonde pour les salons jitsi-meet',)
parser.add_argument('-l,--liste', dest="liste", action='store_true')
parser.add_argument('-f,--field', dest='fields', action='append')
args = parser.parse_args()
stats = JitsiStats()
if args.liste is True:
champs = stats.getStatsList()
for c in champs:
print(c)
sys.exit(0)
perfs = ''
if len(args.fields) == 1:
fields = []
for f in args.fields[0].split(','):
fields.append(f)
else:
fields = args.fields
for field in fields:
if stats.getVal(field) is not None:
#print(f"{field}: {stats.getVal(field)}")
perfs = f"{perfs} {field}={stats.getVal(field)}"
if perfs != '':
#perfs = perfs.replace(' ',';')
restString = f"OK statistiques jitsi-meet {perfs} | {perfs}"
retStatus = 0
return (retStatus,restString)
# Principal
if __name__ == '__main__':
retStatus,restString = runMain()
print(restString)
sys.exit(retStatus)