-
Notifications
You must be signed in to change notification settings - Fork 7
/
jitsi.py
52 lines (44 loc) · 1.5 KB
/
jitsi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env python3
# -*- coding: utf-8; py-indent-offset: 4 -*-
#
# Author: Linuxfabrik GmbH, Zurich, Switzerland
# Contact: info (at) linuxfabrik (dot) ch
# https://www.linuxfabrik.ch/
# License: The Unlicense, see LICENSE file.
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst
"""This library collects some Jitsi related functions that are
needed by more than one Jitsi plugin."""
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2024031401'
import base64 # pylint: disable=C0413
from . import url
def get_data(args, _type='json'):
"""Calls args.URL, optionally using args.USERNAME and args.PASSWORD,
taking args.TIMEOUT into account, returning JSON (`type='json'`) or raw data (else).
"""
header = {}
if not args.USERNAME is None:
header['Authorization'] = 'Basic {}'.format(
base64.b64encode(args.USERNAME + ':' + args.PASSWORD)
)
if _type == 'json':
success, result = url.fetch_json(
args.URL,
extended=True,
header=header,
insecure=args.INSECURE,
no_proxy=args.NO_PROXY,
timeout=args.TIMEOUT,
)
else:
success, result = url.fetch(
args.URL,
extended=True,
header=header,
insecure=args.INSECURE,
no_proxy=args.NO_PROXY,
timeout=args.TIMEOUT,
)
if not success:
return (success, result, False)
return (True, result)