"""
SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
"""

import sys
import json
import logging as log

import pyaml
import requests

#from device import Devices

PROMETHEUS = "https://rancher.aetherproject.org/k8s/clusters/c-xp25p/api/v1/namespaces/cattle-monitoring-system" \
             "/services/http:rancher-monitoring-prometheus:9090/proxy/api/v1/query"
AUTH = ('token-m44n6', 'sgnxmckznp5kl6wqqxxk5pzd5ptc8qx9bqtfkfqxfx29qvqr8gld2f')


class Prometheus(object):

    def __init__(self, key, token):
        self.key = key
        self.token = token

    def get_ips(self):
        ips = {}
        params = (
            ('query', 'subscribers_info>0'),
        )
        try:
            response = requests.get(PROMETHEUS, params=params, auth=(self.key, self.token), timeout=10)
        except requests.ReadTimeout as e:
            log.error("Rancher/Prometheus request timeout, error={}".format(e))
            sys.exit()
        if response.status_code != 200:
            log.error("get_subscriberinfo() failed, status_code: {}".format(response.status_code))
            return None
        metrics = json.loads(response.text)['data']['result']
        for metric in metrics:
            device = metric['metric']
            if 'imsi' in device and 'mobile_ip' in device:
                ips[device['imsi']] = device['mobile_ip']
        return ips

    def update_devices(self, devices):
        params = (
            ('query', 'subscribers_info'),
        )

        try:
            response = requests.get(PROMETHEUS, params=params, auth=(self.key, self.token), timeout=10)
        except requests.ReadTimeout as e:
            log.error("Rancher/Prometheus request timeout, error={}".format(e))
            sys.exit()
        if response.status_code != 200:
            log.error("get_subscriberinfo() failed, status_code: {}".format(response.status_code))
            sys.exit()
            #return None

        metrics = json.loads(response.text)['data']['result']

        # log.debug(pyaml.dump(metrics))

        for elem in metrics:
            metric = elem['metric']
            if 'imsi' in metric and 'mobile_ip' in metric:
                imsi = metric['imsi']
                for k in devices:
                    if devices[k].imsi == imsi:
                        devices[k].ip = metric['mobile_ip']
            else:
                log.error("Ignoring device as imsi or mobile-ip not found - {}".format(metric))

        return devices

    def dump(self):
        print(pyaml.dump(self.get_ips()))


if __name__ == '__main__':
    log.basicConfig()
    log.getLogger().setLevel(log.DEBUG)
    requests_log = log.getLogger("requests.packages.urllib3")
    requests_log.setLevel(log.DEBUG)
    requests_log.propagate = True

    # use Rancher secret-key:bearer-token
    prom = Prometheus("secret-key", "bearer-token")

    # prom.get_ips()
    prom.dump()
