fixes, activity monitor module
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Fri, 8 Aug 2014 15:49:10 +0000 (17:49 +0200)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Fri, 8 Aug 2014 15:49:10 +0000 (17:49 +0200)
rest/monitor.py [new file with mode: 0644]

diff --git a/rest/monitor.py b/rest/monitor.py
new file mode 100644 (file)
index 0000000..ad11037
--- /dev/null
@@ -0,0 +1,53 @@
+from sfa.client.sfaserverproxy import SfaServerProxy
+from sfa.client.return_value import ReturnValue
+from django.http import HttpResponse
+from rest import error
+import os,json
+import ConfigParser
+
+def sfaGetVersion(url):
+    cert = os.getcwd() + "/myslice/sfa.cert"
+    pkey = os.getcwd() + "/myslice/sfa.pkey"
+
+    server = SfaServerProxy(url, pkey, cert)
+    try:
+        version = server.GetVersion()
+    except Exception, e:
+        return False
+    
+    return version
+
+def servicesStatus(request):
+    Config = ConfigParser.ConfigParser()
+    Config.read(os.getcwd() + "/myslice/monitor.ini")
+    
+    result = {}
+    
+    services = Config.sections()
+    for s in services :
+        if Config.has_option(s, 'url') :
+            result[s] = {}
+
+            if Config.has_option(s, 'name') :
+                result[s]['name'] = Config.get(s, 'name')
+            
+            if Config.has_option(s, 'description') :
+                result[s]['description'] = Config.get(s, 'description')
+            
+            if Config.has_option(s, 'type') :
+                result[s]['type'] = Config.get(s, 'type')
+                
+            ret = sfaGetVersion(Config.get(s, 'url'))
+            
+            if ret :
+                result[s]['status'] = 'ok'
+                
+                if 'interface' in ret : # registry
+                    result[s]['version'] = ret['sfa']
+                else :
+                    result[s]['version'] = ret['geni_api']
+            else :
+                result[s]['status'] = 'ko'
+                
+        
+    return HttpResponse(json.dumps(result), content_type="application/json")
\ No newline at end of file