82 lines
1.9 KiB
Python
Executable File
82 lines
1.9 KiB
Python
Executable File
#! /usr/bin/env python
|
|
|
|
import argparse
|
|
import sys
|
|
import time
|
|
import requests
|
|
import json
|
|
|
|
CODE_OK = 0
|
|
CODE_WARN = 1
|
|
CODE_CRITICAL = 2
|
|
CODE_UNKNOWN = 3
|
|
|
|
def main(args):
|
|
|
|
# load default values if not passed as arguments
|
|
if args.timeout:
|
|
timeout = args.timeout
|
|
else:
|
|
timeout = 10
|
|
|
|
if args.port:
|
|
port = args.port
|
|
else:
|
|
port = "3010"
|
|
|
|
if args.uripath:
|
|
path = args.uripath
|
|
else:
|
|
path = "api/v1/stats"
|
|
|
|
if args.https:
|
|
protocol="https://"
|
|
else:
|
|
protocol="http://"
|
|
|
|
url=protocol+args.hostname+':' + port+'/'+path
|
|
|
|
headers = {"authorization": args.apikey,
|
|
"Content-Type": "application/json",}
|
|
|
|
start = time.time()
|
|
|
|
try:
|
|
response = requests.get(url, headers=headers, timeout=timeout)
|
|
except:
|
|
print("MIROTALKSFU CRITICAL - Server unreachable")
|
|
sys.exit(CODE_CRITICAL)
|
|
|
|
end = time.time()
|
|
|
|
if response.status_code==502:
|
|
print("MIROTALKSFU CRITICAL - Server unavailable")
|
|
sys.exit(CODE_CRITICAL)
|
|
elif response.status_code==403:
|
|
print("MIROTALKSFU WARN - Bad API key")
|
|
sys.exit(CODE_WARN)
|
|
elif response.status_code==200:
|
|
delay = round(end-start, 3)
|
|
data=response.json()
|
|
rooms=data['totalRooms']
|
|
users=data['totalUsers']
|
|
print("MIROTALKSFU OK - %s second response time | rooms=%s users=%s" % (delay, rooms, users))
|
|
#print(json.dumps(response.json()))
|
|
else:
|
|
print("MIROTALKSFU WARN - Unknown error")
|
|
sys.exit(CODE_WARN)
|
|
|
|
sys.exit(CODE_OK)
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(\
|
|
description='MirotalkSFU server checker for Nagios')
|
|
parser.add_argument('-H', '--hostname', help='Hostname to check', required=True)
|
|
parser.add_argument('-A', '--apikey', help='API Key', required=True)
|
|
parser.add_argument('-p', '--port', help='Server port')
|
|
parser.add_argument('-t', '--timeout', help='Timeout in seconds')
|
|
parser.add_argument('-u', '--uripath', help='Path of API stats endpoint')
|
|
parser.add_argument('-S', '--https', action="store_true", help='Use HTTPS')
|
|
args = parser.parse_args()
|
|
main(args)
|