Bug fix, for got to update new files

data-collector
Steve L. Nyemba 7 years ago
parent 9509c66973
commit a9574f741c

@ -19,7 +19,6 @@ import re
from monitor import ProcessCounter from monitor import ProcessCounter
from utils.transport import QueueListener, QueueWriter, QueueReader from utils.transport import QueueListener, QueueWriter, QueueReader
from utils.params import PARAMS from utils.params import PARAMS
from ngram import NGram as ng
import smtplib import smtplib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -80,6 +79,7 @@ class Apps(Actor) :
def isValid(self,**args): def isValid(self,**args):
""" """
We insure that the provided application exists and that the payload is correct We insure that the provided application exists and that the payload is correct
The class will only respond to reboot,kill,start actions
p validate the payload p validate the payload
q validate the app can be restarted q validate the app can be restarted
@ -100,27 +100,11 @@ class Apps(Actor) :
""" """
self.action = action self.action = action
self.params = params self.params = params
# self.ng = ng(self.config.keys())
# def can_start(self,name):
# """
# This function is intended to determine if it is possible to boot an application
# """
# items = self.ng.search(name) if self.ng is not None else []
# if len(items) == 0 :
# return False
# else:
# return items[0][1] > 0.01
def startup(self,cmd) : def startup(self,cmd) :
""" """
This function is intended to start a program given the configuration This function is intended to start a program given the configuration
""" """
# items = self.ng.search(name)[0]
# app = items[0]
# args = self.config[app]
try: try:
os.system(cmd +" &") os.system(cmd +" &")
except Exception, e: except Exception, e:
@ -132,36 +116,42 @@ class Apps(Actor) :
@NOTE: Make sure the reference to the app is not ambiguous @NOTE: Make sure the reference to the app is not ambiguous
""" """
try: try:
args = "".join(['ps -eo pid,command|grep -E -i "',name.lower(),'"|grep -E "^ {0,}[0-9]+" -o|xargs kill -9']) args = "".join(['ps -eo pid,command|grep -Ei "',name.lower(),'"|grep -E "^ {0,}[0-9]+" -o|xargs kill -9'])
#self.execute([args]) #self.execute([args])
subprocess.call([args],shell=True) subprocess.call([args],shell=True)
except Exception,e: except Exception,e:
print e print e
def run(self): def run(self):
__action = str(self.action) __action = str(self.action).strip()
__params = dict(self.params) __params = dict(self.params)
if self.action == 'reboot' : pointer = None
if __action == 'reboot' :
def pointer(): def pointer():
self.kill(__params['label']) self.kill(__params['label'])
self.startup(__params['cmd']) self.startup(__params['cmd'])
else: elif __action == 'kill':
def pointer():
self.kill(__params['label'])
elif __action =='start':
def pointer() : def pointer() :
self.startup(__params['cmd']) self.startup(__params['cmd'])
print __action,__params if pointer :
print pointer thread = Thread(target=pointer)
pointer() thread.start()
# thread = Thread(target=pointer) # pointer()
# thread.start()
def analyze(self,logs) : def analyze(self,logs) :
""" """
This function is designed to analyze a few logs and take appropriate action This function is designed to analyze a few logs and take appropriate action
@param logs logs of application/process data; folder analysis or sandbox analysis @param logs logs of application/process data; folder analysis or sandbox analysis
""" """
for item in logs : pass
name = item['label'] # for item in logs :
if self.can_start(name) : # name = item['label']
self.startup(name) # if self.can_start(name) :
# # self.startup(name)
# #
class Mailer (Actor): class Mailer (Actor):
@ -297,8 +287,8 @@ class Folders(Actor):
def analyze(self,logs): def analyze(self,logs):
r = {'clean':self.clean,'archive':self.archive} r = {'clean':self.clean,'archive':self.archive}
self.lfolders = [ folder['label'] for folder in logs] self.lfolders = [ folder['label'] for folder in logs]
for item in logs : #for item in logs :
if self.can_clean(item) : # if self.can_clean(item) :
self.archive(item) # self.archive(item)
# self.clean(item) # self.clean(item)

@ -13,7 +13,7 @@ from datetime import datetime
from utils.transport import * from utils.transport import *
import monitor import monitor
import requests import requests
from threading import Thread
class Manager() : class Manager() :
def version(self): def version(self):
return 1.1 return 1.1
@ -44,7 +44,10 @@ class Manager() :
self.qlistener = self.factory.instance(type="QueueListener",args=_args) self.qlistener = self.factory.instance(type="QueueListener",args=_args)
self.qlistener.callback = self.callback self.qlistener.callback = self.callback
self.qlistener.init(self.id) self.qlistener.init(self.id)
self.qlistener.read()
# self.qlistener.read()
thread = (Thread(target=self.qlistener.read))
thread.start()
def update(self) : def update(self) :
""" """
This method inspect the plans for the current account and makes sure it can/should proceed This method inspect the plans for the current account and makes sure it can/should proceed
@ -190,7 +193,7 @@ class Manager() :
if type(row)==list and len(row) == 0 : if type(row)==list and len(row) == 0 :
continue continue
print get.getName(),len(row)
# #
# #
index = self.agents.index(agent) index = self.agents.index(agent)

Loading…
Cancel
Save