- /* Generating final SQL */
- snprintf(sql_query, OS_SIZE_2048,
- "INSERT INTO "
- "alert(id,server_id,rule_id,timestamp,location_id,src_ip) "
- "VALUES ('%u', '%u', '%u','%u', '%u', '%lu')",
- db_config->alert_id, db_config->server_id, al_data->rule,
- (unsigned int)time(0), *loc_id, (unsigned long)ntohl(s_ip));
+ /* Generate final SQL */
+ switch (db_config->db_type) {
+ case MYSQLDB:
+ snprintf(sql_query, OS_SIZE_8192,
+ "INSERT INTO "
+ "alert(server_id,rule_id,level,timestamp,location_id,src_ip,src_port,dst_ip,dst_port,alertid,user,full_log,tld) "
+ "VALUES ('%u', '%u','%u','%u', '%u', '%s', '%u', '%s', '%u', '%s', '%s', '%s','%.2s')",
+ db_config->server_id, al_data->rule,
+ al_data->level,
+ (unsigned int)time(0), *loc_id,
+ al_data->srcip,
+ (unsigned short)s_port,
+ al_data->dstip,
+ (unsigned short)d_port,
+ al_data->alertid,
+ al_data->user, fulllog, al_data->srcgeoip);
+ break;
+
+ case POSTGDB:
+ snprintf(sql_query, OS_SIZE_8192,
+ "INSERT INTO "
+ "alert(server_id,rule_id,level,timestamp,location_id,src_ip,src_port,dst_ip,dst_port,alertid,\"user\",full_log) "
+ "VALUES ('%u', '%u','%u','%u', '%u', '%s', '%u', '%s', '%u', '%s', '%s', '%s')",
+ db_config->server_id, al_data->rule,
+ al_data->level,
+ (unsigned int)time(0), *loc_id,
+ al_data->srcip != NULL ? al_data->srcip : "NULL",
+ (unsigned short)s_port,
+ al_data->dstip != NULL ? al_data->dstip : "NULL",
+ (unsigned short)d_port,
+ al_data->alertid,
+ al_data->user != NULL ? al_data->user : "NULL",
+ fulllog);
+ break;
+ }