File indexing completed on 2026-04-10 08:39:00
0001 import json
0002 import os
0003 import time
0004 from urllib.parse import urlparse
0005
0006 import requests
0007
0008 from pandaserver.config import panda_config
0009
0010 GB = 1024**3
0011 PROD_INPUT = "Production Input"
0012 PROD_OUTPUT = "Production Output"
0013 EXPRESS = "Express"
0014 FILES = "files"
0015 MBPS = "mbps"
0016 LATENCY = "latency"
0017 PACKETLOSS = "packetloss"
0018 DONE = "done"
0019 QUEUED = "queued"
0020 LATEST = "latest"
0021 H1 = "1h"
0022 H6 = "6h"
0023 D1 = "1d"
0024 W1 = "1w"
0025 TIMESTAMP = "timestamp"
0026
0027 REQUESTS_TIMEOUT = 30
0028
0029
0030 def get_dump(url):
0031 """
0032 Retrieves a json file from the given URL and loads it into memory
0033 """
0034
0035 p = urlparse(url)
0036 if not p.scheme or p.scheme == "file":
0037 try:
0038 with open(p.path) as f:
0039 return json.load(f)
0040 except Exception:
0041 return None
0042 if panda_config.configurator_use_cert:
0043 key_file = os.environ["X509_USER_PROXY"]
0044 cert_file = os.environ["X509_USER_PROXY"]
0045 ca_certs = os.environ["X509_CERT_DIR"]
0046 cert = (cert_file, key_file)
0047 else:
0048 cert = None
0049 ca_certs = False
0050 for _ in range(1, 4):
0051 try:
0052 r = requests.get(url, cert=cert, verify=ca_certs, timeout=REQUESTS_TIMEOUT)
0053 if r.status_code == requests.codes.ok:
0054 return r.json()
0055 except Exception:
0056 time.sleep(1)
0057 return None
0058
0059
0060 def query_grafana_proxy(query, bearer_token):
0061 headers = {
0062 "Content-Type": "application/x-ndjson",
0063 "Authorization": f"Bearer {bearer_token}",
0064 }
0065 grafana_proxy_url = "https://monit-grafana.cern.ch/api/datasources/proxy/10349/_msearch"
0066 for _ in range(1, 4):
0067 try:
0068 r = requests.post(grafana_proxy_url, data=query, headers=headers)
0069 if r.status_code == requests.codes.ok:
0070 return r.json()
0071 except Exception:
0072 time.sleep(1)
0073 return None