From 6619c75e33d2cc829c1dab725d5e83de8f31357c Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Sun, 29 Jan 2017 20:11:15 -0600 Subject: [PATCH] Added status interface updated testcases --- src/api/index.py | 25 ++++++++++++++++++++++--- test/TestML.py | 11 ++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/api/index.py b/src/api/index.py index 21e8f79..b60a9ba 100644 --- a/src/api/index.py +++ b/src/api/index.py @@ -189,14 +189,33 @@ def learn(): return json.dumps(r) - +""" + This function returns anomalies for a given context or group of processes + The information returned is around precision/recall and f-score and parameters +""" @app.route('/anomalies/status') def anomalies_status(): - pass + global CONFIG + p = CONFIG['store']['args'] + class_read = CONFIG['store']['class']['read'] + gReader = factory.instance(type=class_read,args=p) + d = gReader.read() + if 'learn' in d : + info = d['learn'] + + del d['learn'] + else : + info = [] + print info + r = [] + if 'id' in request.args: + id = request.args['id'] + r = info + return json.dumps(r) if __name__== '__main__': - ThreadManager.start(CONFIG) +# ThreadManager.start(CONFIG) app.run(host='0.0.0.0',debug=True,threaded=True) diff --git a/test/TestML.py b/test/TestML.py index d4cc8cf..32c7f85 100644 --- a/test/TestML.py +++ b/test/TestML.py @@ -30,14 +30,17 @@ class TestML(unittest.TestCase): # app = CONFIG['monitor']['processes']['config']['apps'][0] x = ML.Filter('label',app,r) - for row in x: + app = ML.CleanupName(app) + for row in x: self.assertTrue(row['label'] == app) def test_Extract(self): r = self.greader.read() r = r['apps'] app = CONFIG['monitor']['processes']['config']['apps'][0] x = ML.Filter('label',app,r) - x_ = ML.Extract(['cpu_usage','memory_usage'], x) + features = CONFIG['learner']['anomalies']['features'] + self.assertTrue(features) + x_ = ML.Extract(features, x) self.assertTrue (len (x) == len(x_)) pass @@ -49,9 +52,11 @@ class TestML(unittest.TestCase): data = greader.read() data = data['apps'] - app = CONFIG['monitor']['processes']['config']['apps'][1] + app = CONFIG['monitor']['processes']['config']['apps'][0] lhandler = AnomalyDetection() features = CONFIG['learner']['anomalies']['features'] + print features + print app label = CONFIG['learner']['anomalies']['label'] x = lhandler.learn(data,'label',app,features,label) print x