forked from bannsec/NetTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetTK.py
executable file
·76 lines (55 loc) · 1.62 KB
/
netTK.py
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
#!/usr/bin/python -u
__builtins__.VERSION = "0.1"
import sys
sys.path.append("monitor")
from ping import ping
from database import startHandler
import threading
from Queue import Queue
import signal
import ConfigParser
CONFIGFILE = "netTK.cfg"
def cleanExit():
"""
Take care of telling threads to exit and then exiting.
"""
# Tell threads we're leaving
shouldExit.set()
# Exit cleanly
sys.exit(0)
def signal_handler(signal, frame):
"""
Handle when the user presses ctl-C to exit.
"""
# Perform clean exit
cleanExit()
# Register new abilities here to be callable
dispatcher = {
'sqlitedb': startHandler,
'ping': ping
}
# Register our SIGINT handler
signal.signal(signal.SIGINT, signal_handler)
# Define an addRecord queue
__builtins__.addRecord = Queue()
# Define our exit event to allow threads to cleanly exit
__builtins__.shouldExit = threading.Event()
# Open up our config file
config = ConfigParser.ConfigParser()
# Read the config
config.read(CONFIGFILE)
# Loop through the config, starting up whatever we need to.
for section in config._sections:
# Generate the tag for the module to use
kargs = dict(config._sections[section])
kargs["tag"] = kargs["module"].lower()
if kargs.has_key("ctag") and kargs["ctag"] != "":
kargs["tag"] += "_" + kargs["ctag"]
# Generic thread call. Looks up the "test" paramter (case insensitive) in dispatcher to know what to call.
t = threading.Thread(target=dispatcher[config._sections[section]["module"].lower()], kwargs=kargs)
t.start()
# Wait for the user to want to exit
print "Press Enter To Exit\n"
raw_input()
# Let the threads know we should be exiting
shouldExit.set()