Basic ping test

Change-Id: Ib61ebd3963db46118a0d8f5c4cea0e002f48aa9a
diff --git a/prom.py b/prom.py
new file mode 100644
index 0000000..9a517e1
--- /dev/null
+++ b/prom.py
@@ -0,0 +1,84 @@
+"""
+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'),
+        )
+        response = requests.get(PROMETHEUS, params=params, auth=(self.key, self.token))
+        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'),
+        )
+
+        response = requests.get(PROMETHEUS, params=params, auth=(self.key, self.token))
+        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']
+                if imsi in devices:
+                    # log.info("{} added to list of monitored devices".format(imsi))
+                    devices[imsi].ip = metric['mobile_ip']
+                else:
+                    log.error("Ignoring device as it was not reported by ROC - {}".format(metric))
+            else:
+                log.error("Ignoring device as imsi or mobile-ip not found - {}".format(metric))
+
+    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()