-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLogs.py
executable file
·44 lines (34 loc) · 1.26 KB
/
getLogs.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
import pika
import sqlite3
from utility import *
import pprint
import sys, os, signal
def callback(ch, method, properties, body):
result = cleanData(body)
# rsldata = json.loads(result)
# pprint.pprint(rsldata)
# print('----------------------------------------------------------------------\n')
database = konstantes('LOGDB', 'database')
con = sqlite3.connect (database)
cur = con.cursor()
stmt = 'insert into servicelog(log) values (?)'
cur.execute (stmt, (result,))
con.commit()
def handleSIGCHLD(param1, param2):
os.waitpid(-1, os.WNOHANG)
npid = os.fork()
if npid != 0:
sys.exit(0)
signal.signal(signal.SIGCHLD, handleSIGCHLD)
connectURL = konstantes('PIKA', 'url')
parametros = pika.URLParameters(connectURL)
connect = pika.BlockingConnection(parametros)
channel = connect.channel()
exchange = konstantes('PIKA', 'exchange_fanout')
channel.exchange_declare(exchange=exchange, exchange_type='fanout')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange=exchange, queue=queue_name)
print(' [*] Waiting for logs.')
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()