-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheceld_service
executable file
·82 lines (71 loc) · 3.17 KB
/
eceld_service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import Pyro4
from engine.engine import Engine
import time
import logging
import os
import sys, traceback
from subprocess import Popen
@Pyro4.expose
class ECELDaemon(object):
def __init__(self, *args, **kwargs):
logging.debug("Initializing ECELDaemon()")
#get the engine object
self.engine = Engine()
logging.debug("Completed initializing ECELDaemon()")
def start_collectors(self):
logging.debug("Instantiating start_collectors()")
collectors = self.engine.get_all_collectors()
for i, collector in enumerate(collectors):
if collector.name != 'manualscreenshot':
logging.info("Starting Collector: " + collector.name)
self.engine.start_collector(collector)
logging.debug("Completed start_collectors()")
return "Collectors started"
def stop_collectors(self):
logging.debug("Instantiating stop_collectors()")
#collectors = self.engine.get_all_collectors()
#for i, collector in enumerate(collectors):
# if collector.name != 'manualscreenshot':
# logging.info("Starting Collector: " + collector.name)
# self.engine.stop_collector(collector)
self.engine.stop_all_collectors()
logging.debug("Completed stop_collectors()")
return "Collectors stopped"
def parse_data_all(self):
logging.debug("Instantiating parse_data_all()")
collectors = self.engine.get_all_collectors()
for i, collector in enumerate(collectors):
logging.error("PARSER: " + str(collector.name))
self.engine.parser(collector)
logging.debug("Completed parse_data_all()")
def is_parser_running(self):
return self.engine.parsersRunning()
def export_data(self, path=None):
logging.debug("Instantiating export_data()")
if path == None or os.path.exists(path) == False:
logging.warning("Valid path was not provided: " + str(path) + ". Writing to /tmp/")
path = "/tmp/"
logging.debug("Exporting data to: " + str(path))
self.engine.export(path)
logging.debug("Completed export_data()")
def remove_data(self):
logging.debug("Instantiating remove_data()")
self.engine.delete_all()
logging.debug("Completed remove_data()")
if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
os.chdir(os.path.dirname(sys.argv[0]))
daemon = Pyro4.Daemon() # make a Pyro daemon
try:
output = Popen("pyro4-ns")
time.sleep(8)
except:
logging.error("Pyro name server already running or could not be started")
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback)
ns = Pyro4.locateNS() # find the name server
uri = daemon.register(ECELDaemon) # register the greeting maker as a Pyro object
ns.register("ecel.service", uri) # register the object with a name in the name server
logging.info("ECELd Engine Started")
daemon.requestLoop() # start the event loop of the server to wait for calls