Skip to content

Commit a3ab00a

Browse files
committed
version 2.1.4 - add import_device table
1 parent 8ba6735 commit a3ab00a

File tree

6 files changed

+355
-242
lines changed

6 files changed

+355
-242
lines changed

.github/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@
7474
- [2.1.3] modify `access_log` and `error_log` TABLES reordering COLUMNS to improve database design readability.
7575
- [2.1.3] modify `normalize_useragent` to removed first parameter restriction. Any string 8 characters are more can be passed.
7676
- [2.1.3] modify `apacheLogs2MySQL.py` add `completed` COLUMN to UPDATE statement to fix processing `process_access_import` and `process_error_import` with `ALL` parameter.
77-
- [2.1.3] modify `call_processes.sql` adding more comments to better describe options and parameters and overall processing.
77+
- [2.1.3] modify `call_processes.sql` adding more comments to better describe options and parameters and overall processing.
78+
- [2.1.4] add `import_device` TABLE to separate `import_client` TABLE columns to resolve software login, IP address and software version change information creating new record.
79+
- [2.1.4] add `importdeviceid` COLUMN to `import_file` TABLE to resolve Client Modules with identical FILE NAMES and PATHS. Application detected file already imported.
80+
- [2.1.4] modify `import_client` and `import_device` COLUMN widths and created UNIQUE INDEX for combined columns for each table.
81+
- [2.1.4] modify `importfileexists` and `importfileID` FUNCTIONS with new parameter for `importdeviceid`.

.github/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ comment of `call_processes.sql` are included to help check, validate and update
263263
Database normalization is the process of organizing data in a relational database to improve data integrity and reduce redundancy.
264264
Normalization ensures that data is organized in a way that makes sense for the data model and attributes, and that the database functions efficiently.
265265

266-
MySQL `apache_logs` Schema has 48 Tables, 849 Columns, 149 Indexes, 66 Views, 7 Stored Procedures and 42 Functions to process Apache Access log in 4 formats
266+
MySQL `apache_logs` Schema currently has 49 Tables, 853 Columns, 168 Indexes, 66 Views, 7 Stored Procedures and 43 Functions to process Apache Access log in 4 formats
267267
& Apache Error log in 2 formats. Database normalization at work!
268268
## MySQL Access Log View by URI
269269
MySQL View - apache_logs.access_requri_list - data from LogFormat: combined & csv2mysql
94.4 KB
Loading

apacheLogs2MySQL.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
#
13-
# version 2.1.3 - 12/27/2024 - process improvements - see changelog
13+
# version 2.1.4 - 01/02/2025 - add import_device table - see changelog
1414
#
1515
# Copyright 2024 Will Raymond <[email protected]>
1616
#
@@ -114,16 +114,28 @@ def processLogs():
114114
start_time = time.time()
115115
print("ProcessLogs start: " + str(datetime.datetime.now()))
116116
conn = pymysql.connect(**db_params)
117+
getImportDeviceID = ("SELECT apache_logs.importDeviceID('" + deviceid +
118+
"', '" + platformSystem +
119+
"', '" + platformMachine +
120+
"', '" + platformProcessor + "');")
121+
importDeviceCursor = conn.cursor()
122+
try:
123+
importDeviceCursor.execute( getImportDeviceID )
124+
except:
125+
processError += 1
126+
print(bcolors.ERROR + "ERROR - Function apache_logs.importDeviceID() failed" + bcolors.ENDC)
127+
showWarnings = conn.show_warnings()
128+
print(showWarnings)
129+
importDeviceCursor.callproc("errorLoad",["Function apache_logs.importDeviceID()",str(showWarnings[0][1]),showWarnings[0][2],str(importLoadID)])
130+
importDeviceTupleID = importDeviceCursor.fetchall()
131+
importDeviceID = importDeviceTupleID[0][0]
117132
getImportClientID = ("SELECT apache_logs.importClientID('" + ipaddress +
118-
"', '" + deviceid +
119133
"', '" + login +
120134
"', '" + expandUser +
121-
"', '" + platformSystem +
122135
"', '" + platformNode +
123136
"', '" + platformRelease +
124137
"', '" + platformVersion +
125-
"', '" + platformMachine +
126-
"', '" + platformProcessor + "');")
138+
"', '" + str(importDeviceID) + "');")
127139
importClientCursor = conn.cursor()
128140
try:
129141
importClientCursor.execute( getImportClientID )
@@ -177,7 +189,7 @@ def processLogs():
177189
for errorFile in glob.glob(errorlog_path, recursive=errorlog_recursive):
178190
errorFileCount += 1
179191
errorLoadFile = errorFile.replace(os.sep, os.sep+os.sep)
180-
errorExistsSQL = "SELECT apache_logs.importFileExists('" + errorLoadFile + "');"
192+
errorExistsSQL = "SELECT apache_logs.importFileExists('" + errorLoadFile + "', '" + str(importDeviceID) + "');"
181193
try:
182194
errorExistsCursor.execute( errorExistsSQL )
183195
except:
@@ -201,7 +213,9 @@ def processLogs():
201213
"', '" + errorLoadSize +
202214
"', '" + errorLoadCreated +
203215
"', '" + errorLoadModified +
204-
"', '" + str(importLoadID) + "', '5' );")
216+
"', '" + str(importDeviceID) +
217+
"', '" + str(importLoadID) +
218+
"', '5' );")
205219
try:
206220
errorInsertCursor.execute( errorInsertSQL )
207221
except:
@@ -273,7 +287,7 @@ def processLogs():
273287
for combinedFile in glob.glob(combined_path, recursive=combined_recursive):
274288
combinedFileCount += 1
275289
combinedLoadFile = combinedFile.replace(os.sep, os.sep+os.sep)
276-
combinedExistsSQL = "SELECT apache_logs.importFileExists('" + combinedLoadFile + "');"
290+
combinedExistsSQL = "SELECT apache_logs.importFileExists('" + combinedLoadFile + "', '" + str(importDeviceID) + "');"
277291
try:
278292
combinedExistsCursor.execute( combinedExistsSQL )
279293
except:
@@ -297,7 +311,9 @@ def processLogs():
297311
"', '" + combinedLoadSize +
298312
"', '" + combinedLoadCreated +
299313
"', '" + combinedLoadModified +
300-
"', '" + str(importLoadID) + "', '2' );")
314+
"', '" + str(importDeviceID) +
315+
"', '" + str(importLoadID) +
316+
"', '2' );")
301317
try:
302318
combinedInsertCursor.execute( combinedInsertSQL )
303319
except:
@@ -369,7 +385,7 @@ def processLogs():
369385
for vhostFile in glob.glob(vhost_path, recursive=vhost_recursive):
370386
vhostFileCount += 1
371387
vhostLoadFile = vhostFile.replace(os.sep, os.sep+os.sep)
372-
vhostExistsSQL = "SELECT apache_logs.importFileExists('" + vhostLoadFile +"');"
388+
vhostExistsSQL = "SELECT apache_logs.importFileExists('" + vhostLoadFile + "', '" + str(importDeviceID) + "');"
373389
try:
374390
vhostExistsCursor.execute( vhostExistsSQL )
375391
except:
@@ -393,7 +409,9 @@ def processLogs():
393409
"', '" + vhostLoadSize +
394410
"', '" + vhostLoadCreated +
395411
"', '" + vhostLoadModified +
396-
"', '" + str(importLoadID) + "', '3' );")
412+
"', '" + str(importDeviceID) +
413+
"', '" + str(importLoadID) +
414+
"', '3' );")
397415
try:
398416
vhostInsertCursor.execute( vhostInsertSQL )
399417
except:
@@ -460,7 +478,7 @@ def processLogs():
460478
for csv2mysqlFile in glob.glob(csv2mysql_path, recursive=csv2mysql_recursive):
461479
csv2mysqlFileCount += 1
462480
csv2mysqlLoadFile = csv2mysqlFile.replace(os.sep, os.sep+os.sep)
463-
csv2mysqlExistsSQL = "SELECT apache_logs.importFileExists('" + csv2mysqlLoadFile + "');"
481+
csv2mysqlExistsSQL = "SELECT apache_logs.importFileExists('" + csv2mysqlLoadFile + "', '" + str(importDeviceID) + "');"
464482
try:
465483
csv2mysqlExistsCursor.execute( csv2mysqlExistsSQL )
466484
except:
@@ -484,7 +502,9 @@ def processLogs():
484502
"', '" + csv2mysqlLoadSize +
485503
"', '" + csv2mysqlLoadCreated +
486504
"', '" + csv2mysqlLoadModified +
487-
"', '" + str(importLoadID) + "', '4' );")
505+
"', '" + str(importDeviceID) +
506+
"', '" + str(importLoadID) +
507+
"', '4' );")
488508
try:
489509
csv2mysqlInsertCursor.execute( csv2mysqlInsertSQL )
490510
except:

0 commit comments

Comments
 (0)