forked from jordan-wright/dumpmon
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdumpmon.py
More file actions
91 lines (72 loc) · 2.47 KB
/
dumpmon.py
File metadata and controls
91 lines (72 loc) · 2.47 KB
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
83
84
85
86
87
88
89
90
91
# dumpmon.py
# Author: Jordan Wright
# Version: 0.0 (in dev)
# ---------------------------------------------------
# To Do:
#
# - Refine Regex
# - Create/Keep track of statistics
from lib.regexes import regexes
from lib.Pastebin import Pastebin, PastebinPaste
from lib.Slexy import Slexy, SlexyPaste
from lib.Pastie import Pastie, PastiePaste
from lib.HaveIBeen import HaveIBeen, HaveIBeenPaste
from lib.helper import log, createThread
from lib.TwitterBot import TwitterBot
from lib.RegexMgr import RegexMgr
from lib.Stats import Stats
from time import sleep
from settings import log_file
import threading
import logging
from logging.handlers import RotatingFileHandler
def monitor():
'''
monitor() - Main function... creates and starts threads
'''
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"-v", "--verbose", help="more verbose", action="store_true")
args = parser.parse_args()
level = logging.INFO
if args.verbose:
level = logging.DEBUG
logging.basicConfig(
format='%(asctime)s [%(levelname)s][%(module)s][%(funcName)s] %(message)s', filename=log_file, level=level)
handler = RotatingFileHandler(log_file, maxBytes=20*1000,
backupCount=5)
#logging.addHandler(handler)
logging.info('Monitoring...')
regexMgr = RegexMgr()
bot = TwitterBot(regexMgr)
# Create lock for output log
log_lock = threading.Lock()
#create an event to tell threads to keep running
isRunning = threading.Event()
isRunning.set()
#array to keep a handle on threads
workers = []
#these next 2 workers don't need to be joined when termd
createThread(bot.monitor)
createThread(Stats().monitor,bot)
#these workers need to be shut down gracefully
workers.append(createThread(HaveIBeen().monitor,bot,isRunning))
workers.append(createThread(Pastebin().monitor,bot,isRunning))
workers.append(createThread(Slexy().monitor,bot,isRunning))
workers.append(createThread(Pastie().monitor,bot,isRunning))
# Let threads run
try:
while(1):
sleep(5)
except KeyboardInterrupt:
#signal threads to shutdown
isRunning.clear()
print 'stopping'
#wait for threads to join
for t in workers:
t.join()
print 'stopped'
logging.warn('Stopped.')
if __name__ == "__main__":
monitor()