Skip to content

Commit

Permalink
Fix/8314 (#8322)
Browse files Browse the repository at this point in the history
* add default tiemstamp in radius_audit_log, fixes #8314

* Add created_at on Insert

---------

Co-authored-by: Darren+Satkunas <[email protected]>
Co-authored-by: James Rouzier <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent ad3eac9 commit 87c8faa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db/pf-schema-X.Y.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ CREATE TABLE pf_version (`id` INT NOT NULL PRIMARY KEY, `version` VARCHAR(11) NO

CREATE TABLE radius_audit_log (
`id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`created_at` TIMESTAMP NOT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`mac` char(17) NOT NULL,
`ip` varchar(255) NULL,
`computer_name` varchar(255) NULL,
Expand Down
3 changes: 3 additions & 0 deletions db/upgrade-X.X-X.Y.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ALTER TABLE `pki_certs`
DROP INDEX IF EXISTS `subject`,
ADD UNIQUE KEY IF NOT EXISTS `cn_serial` (`cn`,`serial_number`) USING HASH;

\! echo "Adding default timestamp to RADIUS audit logs";
ALTER TABLE radius_audit_log MODIFY created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

\! echo "Incrementing PacketFence schema version...";
INSERT IGNORE INTO pf_version (id, version, created_at) VALUES (@VERSION_INT, CONCAT_WS('.', @MAJOR_VERSION, @MINOR_VERSION), NOW());

Expand Down
4 changes: 2 additions & 2 deletions go/cron/flush_radius_audit_log_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (j *FlushRadiusAuditLogJob) buildQuery(entries [][]interface{}) (string, []
sql := `
INSERT INTO radius_audit_log
(
mac, ip, computer_name,
created_at, mac, ip, computer_name,
user_name, stripped_user_name, realm, event_type,
switch_id, switch_mac, switch_ip_address,
radius_source_ip_address, called_station_id, calling_station_id,
Expand All @@ -175,7 +175,7 @@ INSERT INTO radius_audit_log
radius_reply, request_time, radius_ip
)
VALUES `
bind := "(?" + strings.Repeat(",?", RADIUS_AUDIT_LOG_COLUMN_COUNT-1) + ")"
bind := "(NOW(), ?" + strings.Repeat(",?", RADIUS_AUDIT_LOG_COLUMN_COUNT-1) + ")"
sql += bind + strings.Repeat(","+bind, len(entries)-1)
args := make([]interface{}, 0, len(entries)*RADIUS_AUDIT_LOG_COLUMN_COUNT)
for _, e := range entries {
Expand Down

0 comments on commit 87c8faa

Please sign in to comment.