dev-make-query-performant #16
@ -23,41 +23,19 @@ client_id = "eft-event-generator-confidential"
|
|||||||
secret = ""
|
secret = ""
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
|
overrideEmbeddedquery = false
|
||||||
driver = "ODBC Driver 18 for SQL Server"
|
driver = "ODBC Driver 18 for SQL Server"
|
||||||
server = "192.168.x.x"
|
server = "192.168.x.x"
|
||||||
database = "EFTDB"
|
database = "EFTDB"
|
||||||
user = "a"
|
user = "a"
|
||||||
password = "a"
|
password = "a"
|
||||||
query = """DECLARE @stopTime DATETIME2
|
query = """DECLARE @stopTime DATETIME2
|
||||||
SET @stopTime = DATEADD(DAY, -30, GETDATE())
|
SET @stopTime=DATEADD(DAY, -30, GETDATE())
|
||||||
SELECT p.[ProtocolCommandID]
|
SELECT p.ProtocolCommandID, t.Time_stamp, p.RemoteIP, p.RemotePort, p.LocalIP, p.LocalPort, p.Protocol, p.SiteName, p.Command, p.FileName, p.VirtualFolderName, p.FileSize, p.TransferTime, p.BytesTransferred, p.Description, p.ResultID, t.TransactionID, p.Actor, t.TransactionObject, t.NodeName, t.TransactionGUID, a.Protocol user_type
|
||||||
,t.[Time_stamp]
|
FROM tbl_Transactions t
|
||||||
,p.[RemoteIP]
|
Full JOIN tbl_ProtocolCommands p ON(t.TransactionID=p.TransactionID)
|
||||||
,p.[RemotePort]
|
Full JOIN tbl_Authentications a ON(t.TransactionID=a.TransactionID)
|
||||||
,p.[LocalIP]
|
WHERE p.Time_stamp>@stopTime AND p.Command IS NOT NULL"""
|
||||||
,p.[LocalPort]
|
|
||||||
,p.[Protocol]
|
|
||||||
,p.[SiteName]
|
|
||||||
,p.[Command]
|
|
||||||
,p.[CommandParameters]
|
|
||||||
,p.[FileName]
|
|
||||||
,p.[VirtualFolderName]
|
|
||||||
,p.[PhysicalFolderName]
|
|
||||||
,p.[IsInternal]
|
|
||||||
,p.[FileSize]
|
|
||||||
,p.[TransferTime]
|
|
||||||
,p.[BytesTransferred]
|
|
||||||
,p.[ResultID]
|
|
||||||
,t.[TransactionID]
|
|
||||||
,p.[Description]
|
|
||||||
,p.[Actor]
|
|
||||||
,t.ParentTransactionID
|
|
||||||
,t.TransactionObject
|
|
||||||
,t.NodeName
|
|
||||||
,t.TransactionGUID
|
|
||||||
,a.Protocol user_type
|
|
||||||
FROM [EFTDB].[dbo].[tbl_Transactions] t Full JOIN tbl_ProtocolCommands p ON (t.TransactionID = p.TransactionID) Full join tbl_Authentications a ON (t.TransactionID = a.TransactionID)
|
|
||||||
WHERE p.Time_stamp > @stopTime"""
|
|
||||||
|
|
||||||
[immutables]
|
[immutables]
|
||||||
prd_instance_id = 1
|
prd_instance_id = 1
|
||||||
|
11
inex.py
11
inex.py
@ -10,6 +10,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
import inexEncoder
|
import inexEncoder
|
||||||
import inexSqlquery
|
import inexSqlquery
|
||||||
|
|
||||||
class Inex:
|
class Inex:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initilize config, calls functions from inex-connect.py and inex-logging.py"""
|
"""Initilize config, calls functions from inex-connect.py and inex-logging.py"""
|
||||||
@ -30,6 +31,8 @@ class Inex:
|
|||||||
self.config = self.tl.load(c)
|
self.config = self.tl.load(c)
|
||||||
|
|
||||||
# set config
|
# set config
|
||||||
|
try:
|
||||||
|
if self.config:
|
||||||
self.dbDriver = self.config["database"]["driver"]
|
self.dbDriver = self.config["database"]["driver"]
|
||||||
self.dbServer = self.config["database"]["server"]
|
self.dbServer = self.config["database"]["server"]
|
||||||
self.dbDatabase = self.config["database"]["database"]
|
self.dbDatabase = self.config["database"]["database"]
|
||||||
@ -48,6 +51,10 @@ class Inex:
|
|||||||
self.selectedPlatform = self.config["fortraPlatform"]["selectedPlatform"]
|
self.selectedPlatform = self.config["fortraPlatform"]["selectedPlatform"]
|
||||||
self.writeJsonfile = self.config["output"]["dumpTojson"]
|
self.writeJsonfile = self.config["output"]["dumpTojson"]
|
||||||
self.pushToplatform = self.config["output"]["pushToplatform"]
|
self.pushToplatform = self.config["output"]["pushToplatform"]
|
||||||
|
self.queryOverride = self.config["database"]["overrideEmbeddedquery"]
|
||||||
|
except:
|
||||||
|
print("No config.toml. Please use example file and configure appropriately")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
if "dev" in self.selectedPlatform.lower():
|
if "dev" in self.selectedPlatform.lower():
|
||||||
self.platformConfig = self.config["fortraPlatform"]["dev"]
|
self.platformConfig = self.config["fortraPlatform"]["dev"]
|
||||||
@ -55,7 +62,6 @@ class Inex:
|
|||||||
self.platformConfig = self.config["fortraPlatform"]["stage"]
|
self.platformConfig = self.config["fortraPlatform"]["stage"]
|
||||||
if "prod" in self.selectedPlatform.lower():
|
if "prod" in self.selectedPlatform.lower():
|
||||||
self.platformConfig = self.config["fortraPlatform"]["prod"]
|
self.platformConfig = self.config["fortraPlatform"]["prod"]
|
||||||
# print(self.platformConfig)
|
|
||||||
|
|
||||||
#Setup logging
|
#Setup logging
|
||||||
inexLog(self)
|
inexLog(self)
|
||||||
@ -63,9 +69,8 @@ class Inex:
|
|||||||
# create the connection to the database
|
# create the connection to the database
|
||||||
self.cursor = self.ic.inexSql.connectDatabase(self, self.db, self.dbDriver, self.dbServer, self.dbDatabase, self.dbUser, self.dbPassword)
|
self.cursor = self.ic.inexSql.connectDatabase(self, self.db, self.dbDriver, self.dbServer, self.dbDatabase, self.dbUser, self.dbPassword)
|
||||||
|
|
||||||
# self.data = self.ic.inexSql.databaseQuery(self, self.cursor, self.dbQuery)
|
|
||||||
|
|
||||||
self.data = self.ic.inexSql.databaseQuery(self, self.cursor, self.sq.sqlQuerymodel.queryData())
|
self.data = self.ic.inexSql.databaseQuery(self, self.cursor, self.sq.sqlQuerymodel.queryData(self.queryOverride,self.dbQuery))
|
||||||
|
|
||||||
self.modifiedData = processData(self.data, dataTemplate, prd_instance_id=self.prdInstanceID,\
|
self.modifiedData = processData(self.data, dataTemplate, prd_instance_id=self.prdInstanceID,\
|
||||||
product_guid=self.productGUID,product_name=self.productName,product_version=self.productVersion)
|
product_guid=self.productGUID,product_name=self.productName,product_version=self.productVersion)
|
||||||
|
@ -35,7 +35,7 @@ def dataTemplate(transactionType,**kwargs):
|
|||||||
"tenant_name":"GlobalScape",
|
"tenant_name":"GlobalScape",
|
||||||
"time": kwargs.get('time'),
|
"time": kwargs.get('time'),
|
||||||
"status_code": kwargs.get('status_code'),
|
"status_code": kwargs.get('status_code'),
|
||||||
"status_detail": kwargs.get('status_detail'),
|
"status_detail": kwargs.get('description'),
|
||||||
"user": {
|
"user": {
|
||||||
"home_directory": kwargs.get('user_home_directory'),
|
"home_directory": kwargs.get('user_home_directory'),
|
||||||
"uuid": kwargs.get('guid'),
|
"uuid": kwargs.get('guid'),
|
||||||
@ -123,5 +123,7 @@ def dataTemplate(transactionType,**kwargs):
|
|||||||
template = fileDeleted
|
template = fileDeleted
|
||||||
if transactionType == "user_logged_on":
|
if transactionType == "user_logged_on":
|
||||||
template = logon
|
template = logon
|
||||||
|
if transactionType == "other":
|
||||||
|
template = {}
|
||||||
|
|
||||||
return template
|
return template
|
@ -7,7 +7,7 @@ def processData(data, template, **kwargs):
|
|||||||
# print(f'Row: {row}')
|
# print(f'Row: {row}')
|
||||||
if row.get('Command') == None:
|
if row.get('Command') == None:
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
processedData.append(template(identifyUtype(row.get('Command')),\
|
processedData.append(template(identifyUtype(row.get('Command')),\
|
||||||
prd_ext_tenant_id='',\
|
prd_ext_tenant_id='',\
|
||||||
status_code=row.get('ResultID'),\
|
status_code=row.get('ResultID'),\
|
||||||
@ -36,9 +36,15 @@ def processData(data, template, **kwargs):
|
|||||||
user_domain=row.get('SiteName'),\
|
user_domain=row.get('SiteName'),\
|
||||||
user_name=row.get('Actor'),\
|
user_name=row.get('Actor'),\
|
||||||
user_home_directory=row.get('VirtualFolderName'),\
|
user_home_directory=row.get('VirtualFolderName'),\
|
||||||
|
description=row.get('Description'),\
|
||||||
utype=identifyUtype(row.get('Command'))))
|
utype=identifyUtype(row.get('Command'))))
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(f'Problem row GUID:{row.get("TransactionGUID")} ::: TransactionObject:{row.get("TransactionObject")} Command: {row.get("Command")}')
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
if row.get('TransactionGUID') not in transactionLoginid:
|
if row.get('TransactionGUID') not in transactionLoginid:
|
||||||
|
try:
|
||||||
processedData.append(template(identifyUtype(row.get('TransactionObject')),\
|
processedData.append(template(identifyUtype(row.get('TransactionObject')),\
|
||||||
guid=row.get('TransactionGUID'),\
|
guid=row.get('TransactionGUID'),\
|
||||||
prd_instance_id=kwargs.get('prd_instance_id'),\
|
prd_instance_id=kwargs.get('prd_instance_id'),\
|
||||||
@ -62,6 +68,9 @@ def processData(data, template, **kwargs):
|
|||||||
utype=identifyUtype(row.get('TransactionObject'))\
|
utype=identifyUtype(row.get('TransactionObject'))\
|
||||||
))
|
))
|
||||||
transactionLoginid.append(row.get('TransactionGUID'))
|
transactionLoginid.append(row.get('TransactionGUID'))
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(f'Problem row GUID:{row.get("TransactionGUID")} ::: TransactionObject:{row.get("TransactionObject")} Command: {row.get("Command")}')
|
||||||
|
continue
|
||||||
|
|
||||||
return processedData
|
return processedData
|
||||||
|
|
||||||
@ -88,4 +97,4 @@ def identifyUtype(obj):
|
|||||||
if obj in file_downloaded:
|
if obj in file_downloaded:
|
||||||
return "file_downloaded"
|
return "file_downloaded"
|
||||||
else:
|
else:
|
||||||
return None
|
return "other"
|
@ -1,11 +1,11 @@
|
|||||||
class sqlQuerymodel:
|
class sqlQuerymodel:
|
||||||
def queryData():
|
def queryData(overRideflag, configQuery):
|
||||||
"""Embedded query data"""
|
"""Embedded query data"""
|
||||||
q ="""DECLARE @stopTime DATETIME2
|
q ="""DECLARE @stopTime DATETIME2
|
||||||
SET @stopTime=DATEADD(DAY, -30, GETDATE())
|
SET @stopTime=DATEADD(DAY, -30, GETDATE())
|
||||||
SELECT p.ProtocolCommandID, t.Time_stamp, p.RemoteIP, p.RemotePort, p.LocalIP, p.LocalPort, p.Protocol, p.SiteName, p.Command, p.CommandParameters, p.FileName, p.VirtualFolderName, p.PhysicalFolderName, p.IsInternal, p.FileSize, p.TransferTime, p.BytesTransferred, p.ResultID, t.TransactionID, p.Description, p.Actor, t.ParentTransactionID, t.TransactionObject, t.NodeName, t.TransactionGUID, a.Protocol user_type
|
SELECT p.ProtocolCommandID, t.Time_stamp, p.RemoteIP, p.RemotePort, p.LocalIP, p.LocalPort, p.Protocol, p.SiteName, p.Command, p.FileName, p.VirtualFolderName, p.FileSize, p.TransferTime, p.BytesTransferred, p.Description, p.ResultID, t.TransactionID, p.Actor, t.TransactionObject, t.NodeName, t.TransactionGUID, a.Protocol user_type
|
||||||
FROM tbl_Transactions t
|
FROM tbl_Transactions t
|
||||||
Full JOIN tbl_ProtocolCommands p ON(t.TransactionID=p.TransactionID)
|
Full JOIN tbl_ProtocolCommands p ON(t.TransactionID=p.TransactionID)
|
||||||
Full join tbl_Authentications a ON(t.TransactionID=a.TransactionID)
|
Full join tbl_Authentications a ON(t.TransactionID=a.TransactionID)
|
||||||
WHERE p.Time_stamp>@stopTime"""
|
WHERE p.Time_stamp>@stopTime AND p.Command IS NOT NULL"""
|
||||||
return q
|
return configQuery if overRideflag else q
|
Loading…
x
Reference in New Issue
Block a user