docker-collabora-online/install/etc/zabbix/zabbix_agentd.conf.d/scripts/check-cool.py

42 lines
1.2 KiB
Python
Raw Normal View History

2018-09-17 14:33:41 +02:00
#!/usr/bin/python3
import requests
from websocket import create_connection,WebSocket
2021-12-15 17:00:32 +01:00
import datetime
2018-09-17 14:33:41 +02:00
import sys
import os
requests.packages.urllib3.disable_warnings()
def get_token_value(url,username,password):
r = requests.get(url,auth=(username,password),verify=False)
token_value = r.cookies['jwt']
return token_value
def get_doc_info(socket_url,token_value):
data = {}
2019-07-16 23:04:47 +02:00
ws = create_connection(socket_url)
2018-09-17 14:33:41 +02:00
"""Authenticating with Server """
ws.send('auth '+'jwt='+token_value)
"""Now fetching information """
word = ['active_users_count', 'active_docs_count', 'mem_consumed', 'sent_bytes', 'recv_bytes']
for i in word:
ws.send(i)
result = ws.recv()
result = result.split()
data[result[0]] = result[1]
ws.close()
return data
if __name__ == '__main__':
2021-12-03 04:26:38 +01:00
url = "http://localhost:9980/browser/dist/admin/admin.html"
2018-09-17 14:33:41 +02:00
username = os.getenv('ADMIN_USER')
password = os.getenv('ADMIN_PASS')
token_value = get_token_value(url,username,password)
2021-12-03 04:26:38 +01:00
socket_url = "ws://localhost:9980/cool/adminws"
2018-09-17 14:33:41 +02:00
data = get_doc_info(socket_url,token_value)
2021-12-15 17:00:32 +01:00
now = datetime.datetime.now()
print (now.strftime('%Y-%m-%d %H:%M:%S')+" Collabora Online Monitoring")
2018-09-17 14:33:41 +02:00
for key,value in data.items() :
2021-12-15 17:00:32 +01:00
print("cool."+key, value)