master
Steve L. Nyemba 8 years ago
parent f29eb0d4c0
commit 1e47d041ad

@ -219,56 +219,36 @@ class FileWatch(Analysis):
def __init__(self,conf): def __init__(self,conf):
pass pass
def split(self,row): def split(self,row):
x = row.split(' ') x = row.split(' ')
r = {} r = {}
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
if x:
if 'K' in x[0]: if 'K' in x[0]:
size = x[0].replace('K','').replace('KB','') / 1000 print x
size = float(x[0].replace('K','').replace('KB','')) / 1000
elif 'M' in x[0] : elif 'M' in x[0] :
size = x[0].replace('MB','') size = x[0].replace('MB','')
elif 'G' in x[0] : elif 'G' in x[0] :
size = x[0].replace('GB','') * 1000 size = x[0].replace('GB','') * 1000
elif 'T' in x[0] : elif 'T' in x[0] :
pass pass
month = months.index(m[1]) + 1 month = months.index(x[1]) + 1
day = x[2] day = x[2]
hour,minute = x[3].split(':') print [' ** ',x[4]]
#hour,minute = x[3].split(':')
year = x[4] year = x[4]
return {"size":size,"age":age} return {"size":size,"age":age}
return None
def evaluate(self,path): def evaluate(self,path):
cmd = "find :path|xargs ls -lh |awk '{print $5,$6,$7,$8,$9}'".replace(":path",path) cmd = "find :path|xargs ls -lh |awk '{print $5,$6,$7,$8,$9}'".replace(":path",path)
print cmd
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
ostream = handler.communicate()[0].split('\n') ostream = handler.communicate()[0].split('\n')
[self.split(stream) for stream in ostream if stream.strip() != '']
pass
"""
This class attempts to retrieve information form a jmxproxy
The resulting is a dataset that will be used for mining, and detection of anomalies
"""
class Jmx (Analysis):
def __init__(self,conf):
self.conf = conf
def evaluate(self,**param):
app = param['app']
r = param['host'].split('@')
host = r[1].strip()
login = base64.b64encode("%s" % (r[0]))
uri = "".join(['http://',host,'/manager/jmxproxy/?qry=*:j2eeType=Servlet,*']) print [self.split(stream) for stream in ostream if stream.strip() != '']
pass
request = http.Request(uri)
request.add_header('Authorization','Basic '+login)
r = http.urlopen(request)
stream= r.read()
r.close()
self.parse(stream)
def parse(self,stream):
print stream
return {}
class Monitor (Thread): class Monitor (Thread):
def __init__(self,pConfig,pWriter,id='processes') : def __init__(self,pConfig,pWriter,id='processes') :

@ -1,6 +1,6 @@
from __future__ import division from __future__ import division
import unittest import unittest
from monitor import Env, DetailProcess, ProcessCounter, Sandbox, Jmx from monitor import Env, DetailProcess, ProcessCounter, Sandbox, FileWatch
import monitor import monitor
import os import os
import json import json
@ -57,9 +57,9 @@ class TestMonitorServer(unittest.TestCase):
p = Learner(CONFIG,lock) p = Learner(CONFIG,lock)
p.start() p.start()
def test_JMX(self): def test_JMX(self):
conf =CONFIG['monitor']['jmx'] conf =CONFIG['monitor']['folder']
jmx = Jmx(conf) fw = FileWatch(conf)
print jmx.evaluate(host='jmx:!mx@localhost:8080',app='teamcity') print fw.evaluate("/Users/steve/tmp")
if __name__ == '__main__' : if __name__ == '__main__' :
unittest.main() unittest.main()

Loading…
Cancel
Save