Skip to content

Commit

Permalink
fix_sendbatch
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Aug 22, 2024
1 parent f739621 commit 86a0e1d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions api/methods/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func UpdateMwanSeries(c *gin.Context) {
batch.Queue("INSERT INTO mwan_events (time, unit_id, wan, event, interface) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING", time.Unix(event.Timestamp, 0), unit_id, event.Wan, event.Event, event.Interface)
}
if batch.Len() != 0 {
_, err := dbpool.SendBatch(dbctx, batch).Exec()
err := dbpool.SendBatch(dbctx, batch).Close()
if err != nil {
logs.Logs.Println("[ERR][MWANEVENTS] error inserting data: " + err.Error())
c.JSON(http.StatusInternalServerError, structs.Map(response.StatusInternalServerError{
Expand Down Expand Up @@ -133,7 +133,7 @@ func UpdateTsAttacks(c *gin.Context) {
batch.Queue("INSERT INTO ts_attacks (time, unit_id, ip) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING", time.Unix(attack.Timestamp, 0), unit_id, attack.Ip)
}
if batch.Len() != 0 {
_, err := dbpool.SendBatch(dbctx, batch).Exec()
err := dbpool.SendBatch(dbctx, batch).Close()
if err != nil {
logs.Logs.Println("[ERR][TSATTACKS] error inserting data: " + err.Error())
c.JSON(http.StatusInternalServerError, structs.Map(response.StatusInternalServerError{
Expand Down Expand Up @@ -188,7 +188,7 @@ func UpdateTsMalware(c *gin.Context) {
batch.Queue("INSERT INTO ts_malware (time, unit_id, src, dst, category, chain) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT DO NOTHING", time.Unix(malware.Timestamp, 0), unit_id, malware.Src, malware.Dst, malware.Category, malware.Chain)
}
if batch.Len() != 0 {
_, err := dbpool.SendBatch(dbctx, batch).Exec()
err := dbpool.SendBatch(dbctx, batch).Close()
if err != nil {
logs.Logs.Println("[ERR][TSMALWARE] error inserting data: " + err.Error())
c.JSON(http.StatusInternalServerError, structs.Map(response.StatusInternalServerError{
Expand Down Expand Up @@ -243,7 +243,7 @@ func UpdateOvpnConnections(c *gin.Context) {
batch.Queue("INSERT INTO ovpnrw_connections (time, unit_id, instance, common_name, virtual_ip_addr, remote_ip_addr, start_time, duration, bytes_received, bytes_sent) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (time, unit_id, instance, common_name) DO UPDATE SET duration=EXCLUDED.duration, bytes_received=EXCLUDED.bytes_received, bytes_sent=EXCLUDED.bytes_sent", time.Unix(connection.Timestamp, 0), unit_id, connection.Instance, connection.CommonName, connection.VirtualIpAddr, connection.RemoteIpAddr, connection.StartTime, connection.Duration, connection.BytesReceived, connection.BytesSent)
}
if batch.Len() != 0 {
_, err := dbpool.SendBatch(dbctx, batch).Exec()
err := dbpool.SendBatch(dbctx, batch).Close()
if err != nil {
logs.Logs.Println("[ERR][OVPNCONNECTIONS] error inserting data: " + err.Error())
c.JSON(http.StatusInternalServerError, structs.Map(response.StatusInternalServerError{
Expand Down Expand Up @@ -299,7 +299,7 @@ func UpdateDpiStats(c *gin.Context) {
batch.Queue("INSERT INTO dpi_stats (time, unit_id, client_address, client_name, protocol, host, application, bytes) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (time, unit_id, client_address, protocol, host, application) DO UPDATE SET bytes = EXCLUDED.bytes", time.Unix(dpi.Timestamp, 0), unit_id, dpi.ClientAddress, dpi.ClientName, dpi.Protocol, dpi.Host, dpi.Application, dpi.Bytes)
}
if batch.Len() != 0 {
_, err := dbpool.SendBatch(dbctx, batch).Exec()
err := dbpool.SendBatch(dbctx, batch).Close()
if err != nil {
logs.Logs.Println("[ERR][DPISTATS] error inserting data: " + err.Error())
c.JSON(http.StatusInternalServerError, structs.Map(response.StatusInternalServerError{
Expand Down

0 comments on commit 86a0e1d

Please sign in to comment.