Permalink
Browse files

averez-19-samples: move json2Mozdef.py to /benchmarking/workers/

  • Loading branch information...
netantho committed Apr 22, 2014
1 parent 6519d8d commit 8b7db3e42beb8aad1d115189611c55dc6917b3d4
Showing with 7 additions and 7 deletions.
  1. +7 −7 {test → benchmarking/workers}/json2Mozdef.py
@@ -36,12 +36,12 @@
logger = logging.getLogger(sys.argv[0])
logger.level=logging.DEBUG
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
def postLogs(logcache):
#post logs asynchronously with requests workers and check on the results
#expects a queue object from the multiprocessing library
posts=[]
try:
try:
while not logcache.empty():
postdata=logcache.get_nowait()
if len(postdata)>0:
@@ -64,7 +64,7 @@ def postLogs(logcache):
except Exception as e:
logger.fatal("exception posting to %s %r %r [will not retry]\n"%(url,e,postdata))
sys.exit(1)
if __name__ == '__main__':
parser=OptionParser()
parser.add_option("-u", dest='url' , default='http://localhost:8080/events/', help="mozdef events URL to use when posting events")
@@ -74,9 +74,9 @@ def postLogs(logcache):
logger.addHandler(sh)
#create a list of logs we can append json to and call for a post when we want.
logcache=Queue()
try:
try:
for i in range(0,10):
print(i)
alog=dict(eventtime=pytz.timezone('US/Pacific').localize(datetime.now()).isoformat(),\
hostname=socket.gethostname(),\
@@ -89,7 +89,7 @@ def postLogs(logcache):
details=[])
alog['details']=dict(success=True,username='mozdef')
alog['tags']=['mozdef','stresstest']
logcache.put(json.dumps(alog))
if not logcache.empty():
time.sleep(.001)
@@ -102,7 +102,7 @@ def postLogs(logcache):
pass
else:
logger.error('%r'%e)
while not logcache.empty():
try:
postingProcess=Process(target=postLogs,args=(logcache,),name="json2MozdefStressTest")

0 comments on commit 8b7db3e

Please sign in to comment.