Skip to content

Commit

Permalink
mysql: fix mysql logger bug
Browse files Browse the repository at this point in the history
  • Loading branch information
QianKaiLin committed Oct 9, 2024
1 parent c0a363d commit 8095542
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
25 changes: 20 additions & 5 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2387,9 +2387,6 @@
"type": "object",
"optional": true,
"properties": {
"tx_id": {
"type": "integer"
},
"version": {
"type": "string"
},
Expand All @@ -2402,8 +2399,14 @@
"affected_rows": {
"type": "integer"
},
},
"additionalProperties": false
"rows": {
"type": "array",
"optional": true,
"items": {
"type": "string"
}
}
}
},
"ldap": {
"type": "object",
Expand Down Expand Up @@ -4685,6 +4688,10 @@
"description": "Errors encountered parsing MQTT protocol",
"$ref": "#/$defs/stats_applayer_error"
},
"mysql": {
"description": "Errors encountered parsing MySQL protocol",
"$ref": "#/$defs/stats_applayer_error"
},
"nfs_tcp": {
"description": "Errors encountered parsing NFS/TCP protocol",
"$ref": "#/$defs/stats_applayer_error"
Expand Down Expand Up @@ -4860,6 +4867,10 @@
"description": "Number of flows for MQTT protocol",
"type": "integer"
},
"mysql": {
"description": "Number of flows for MySQL protocol",
"type": "integer"
},
"nfs_tcp": {
"description": "Number of flows for NFS/TCP protocol",
"type": "integer"
Expand Down Expand Up @@ -5030,6 +5041,10 @@
"description": "Number of transactions for MQTT protocol",
"type": "integer"
},
"mysql": {
"description": "Number of flows for MySQL protocol",
"type": "integer"
},
"nfs_tcp": {
"description": "Number of transactions for NFS/TCP protocol",
"type": "integer"
Expand Down
6 changes: 3 additions & 3 deletions rust/src/mysql/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::mysql::mysql::*;

fn log_mysql(tx: &MysqlTransaction, _flags: u32, js: &mut JsonBuilder) -> Result<(), JsonError> {
fn log_mysql(tx: &MysqlTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("mysql")?;
if let Some(version) = &tx.version {
js.set_string("version", version)?;
Expand Down Expand Up @@ -54,14 +54,14 @@ fn log_mysql(tx: &MysqlTransaction, _flags: u32, js: &mut JsonBuilder) -> Result

#[no_mangle]
pub unsafe extern "C" fn SCMysqlLogger(
tx: *mut std::os::raw::c_void, flags: u32, js: &mut JsonBuilder,
tx: *mut std::os::raw::c_void, js: &mut JsonBuilder,
) -> bool {
let tx_mysql = cast_pointer!(tx, MysqlTransaction);
SCLogDebug!(
"----------- MySQL rs_mysql_logger call. Tx is {:?}",
tx_mysql
);
let result = log_mysql(tx_mysql, flags, js);
let result = log_mysql(tx_mysql, js);
if let Err(ref err) = result {
SCLogError!("----------- MySQL rs_mysql_logger failed. err is {:?}", err);
}
Expand Down
6 changes: 5 additions & 1 deletion src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ void OutputRegisterRootLoggers(void)
RegisterSimpleJsonApplayerLogger(
ALPROTO_BITTORRENT_DHT, rs_bittorrent_dht_logger_log, "bittorrent_dht");
RegisterSimpleJsonApplayerLogger(
ALPROTO_MYSQL, (EveJsonSimpleTxLogFunc)SCMysqlLogger, "mysql");
ALPROTO_MYSQL, SCMysqlLogger, "mysql");

OutputPacketLoggerRegister();
OutputFiledataLoggerRegister();
Expand Down Expand Up @@ -1083,6 +1083,10 @@ void OutputRegisterLoggers(void)
OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonLdapLog", "eve-log.ldap",
OutputJsonLogInitSub, ALPROTO_LDAP, JsonGenericDirFlowLogger, JsonLogThreadInit,
JsonLogThreadDeinit);
/* MySQL JSON logger. */
OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonMySQLLog", "eve-log.mysql",
OutputJsonLogInitSub, ALPROTO_MYSQL, JsonGenericDirFlowLogger, JsonLogThreadInit,
JsonLogThreadDeinit);
/* DoH2 JSON logger. */
JsonDoh2LogRegister();
/* Template JSON logger. */
Expand Down

0 comments on commit 8095542

Please sign in to comment.