Skip to content

Commit

Permalink
Move create table outside trigger object
Browse files Browse the repository at this point in the history
  • Loading branch information
dogoncouch committed Aug 24, 2017
1 parent 2668d7e commit 9441208
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions siemstress/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ def watch_rule(self):
if not '-' in self.tzone:
self.tzone = '+' + self.tzone

# Create table if it doesn't exist:
con = mdb.connect(self.server, self.user, self.password,
self.database)
with con:
cur = con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS ' + self.rule['OutTable'] + \
'(Id INT PRIMARY KEY AUTO_INCREMENT, ' + \
'DateStamp TIMESTAMP, ' + \
'TZone NVARCHAR(5), ' + \
'SourceRule NVARCHAR(25), ' + \
'Severity TINYINT UNSIGNED, ' + \
'SourceTable NVARCHAR(25), ' + \
'EventLimit INT, EventCount INT, ' + \
'TimeInt INT, ' + \
'Message NVARCHAR(1000), ' + \
'SourceIDs NVARCHAR(2000))')
cur.close()
con.close()

while True:

# Check the rule:
Expand Down Expand Up @@ -149,6 +130,25 @@ def check_rule(self):
def start_rule(server, user, password, database, rule, oneshot):
"""Initialize trigger object and start watching"""

# Create table if it doesn't exist:
con = mdb.connect(self.server, self.user, self.password,
self.database)
with con:
cur = con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS ' + rule['OutTable'] + \
'(Id INT PRIMARY KEY AUTO_INCREMENT, ' + \
'DateStamp TIMESTAMP, ' + \
'TZone NVARCHAR(5), ' + \
'SourceRule NVARCHAR(25), ' + \
'Severity TINYINT UNSIGNED, ' + \
'SourceTable NVARCHAR(25), ' + \
'EventLimit INT, EventCount INT, ' + \
'TimeInt INT, ' + \
'Message NVARCHAR(1000), ' + \
'SourceIDs NVARCHAR(2000))')
cur.close()
con.close()

sentry = SiemTrigger(server, user, password, database, rule)

if oneshot:
Expand Down

0 comments on commit 9441208

Please sign in to comment.