Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ Note that command line arguments are case-insensitive as of v0.9.5
# Database to connect to the clickhouse database
--clickhousedatabase=default

# Table which data will be stored on clickhouse database
--clickhousetable=DNS_LOG

# Interval between sending results to ClickHouse. If non-0, Batch size is ignored and batch delay is used
--clickhousedelay=0s

Expand Down Expand Up @@ -497,6 +500,9 @@ Note that command line arguments are case-insensitive as of v0.9.5
# Psql endpoint used. must be in uri format. example: postgres://username:password@hostname:port/database?sslmode=disable
--psqlendpoint=

# Psql table which data will be stored on database
--psqltable=DNS_LOG

# Number of PSQL workers
--psqlworkers=1

Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mosajjal/dnsmonster
go 1.23.4

require (
github.com/ClickHouse/clickhouse-go/v2 v2.30.0
github.com/ClickHouse/clickhouse-go/v2 v2.34.0
github.com/arthurkiller/rollingwriter v1.1.3
github.com/deathowl/go-metrics-prometheus v0.0.0-20221009205350-f2a1482ba35b
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
Expand All @@ -20,7 +20,7 @@ require (
)

require (
github.com/ClickHouse/ch-go v0.65.0 // indirect
github.com/ClickHouse/ch-go v0.65.1 // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
Expand Down Expand Up @@ -65,12 +65,12 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.28.0 // indirect
golang.org/x/tools v0.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ClickHouse/ch-go v0.65.0 h1:vZAXfTQliuNNefqkPDewX3kgRxN6Q4vUENnnY+ynTRY=
github.com/ClickHouse/ch-go v0.65.0/go.mod h1:tCM0XEH5oWngoi9Iu/8+tjPBo04I/FxNIffpdjtwx3k=
github.com/ClickHouse/clickhouse-go/v2 v2.30.0 h1:AG4D/hW39qa58+JHQIFOSnxyL46H6h2lrmGGk17dhFo=
github.com/ClickHouse/clickhouse-go/v2 v2.30.0/go.mod h1:i9ZQAojcayW3RsdCb3YR+n+wC2h65eJsZCscZ1Z1wyo=
github.com/ClickHouse/ch-go v0.65.1 h1:SLuxmLl5Mjj44/XbINsK2HFvzqup0s6rwKLFH347ZhU=
github.com/ClickHouse/ch-go v0.65.1/go.mod h1:bsodgURwmrkvkBe5jw1qnGDgyITsYErfONKAHn05nv4=
github.com/ClickHouse/clickhouse-go/v2 v2.34.0 h1:Y4rqkdrRHgExvC4o/NTbLdY5LFQ3LHS77/RNFxFX3Co=
github.com/ClickHouse/clickhouse-go/v2 v2.34.0/go.mod h1:yioSINoRLVZkLyDzdMXPLRIqhDvel8iLBlwh6Iefso8=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
Expand Down Expand Up @@ -95,8 +95,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
Expand Down Expand Up @@ -350,10 +350,10 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down Expand Up @@ -391,8 +391,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -484,8 +484,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
8 changes: 5 additions & 3 deletions internal/output/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"crypto/tls"
"errors"
"fmt"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
Expand All @@ -34,6 +35,7 @@ type clickhouseConfig struct {
ClickhouseUsername string `long:"clickhouseusername" ini-name:"clickhouseusername" env:"DNSMONSTER_CLICKHOUSEUSERNAME" default:"" description:"Username to connect to the clickhouse database"`
ClickhousePassword string `long:"clickhousepassword" ini-name:"clickhousepassword" env:"DNSMONSTER_CLICKHOUSEPASSWORD" default:"" description:"Password to connect to the clickhouse database"`
ClickhouseDatabase string `long:"clickhousedatabase" ini-name:"clickhousedatabase" env:"DNSMONSTER_CLICKHOUSEDATABASE" default:"default" description:"Database to connect to the clickhouse database"`
ClickhouseTable string `long:"clickhousetable" ini-name:"clickhousetable" env:"DNSMONSTER_CLICKHOUSETABLE" default:"DNS_LOG" description:"Table which data will be stored on clickhouse database"`
ClickhouseDelay time.Duration `long:"clickhousedelay" ini-name:"clickhousedelay" env:"DNSMONSTER_CLICKHOUSEDELAY" default:"0s" description:"Interval between sending results to ClickHouse. If non-0, Batch size is ignored and batch delay is used"`
ClickhouseCompress uint8 `long:"clickhousecompress" ini-name:"clickhousecompress" env:"DNSMONSTER_CLICKHOUSECOMPRESS" description:"Clickhouse connection LZ4 compression level, 0 means no compression"`
ClickhouseDebug bool `long:"clickhousedebug" ini-name:"clickhousedebug" env:"DNSMONSTER_CLICKHOUSEDEBUG" description:"Debug Clickhouse connection"`
Expand Down Expand Up @@ -145,7 +147,7 @@ func (chConfig clickhouseConfig) connectClickhouse(ctx context.Context) (driver.
return connection, nil, err
}

batch, err := connection.PrepareBatch(ctx, "INSERT INTO DNS_LOG")
batch, err := connection.PrepareBatch(ctx, fmt.Sprintf("INSERT INTO %v", chConfig.ClickhouseTable))
return connection, batch, err
}

Expand Down Expand Up @@ -240,7 +242,7 @@ func (chConfig clickhouseConfig) clickhouseOutputWorker(ctx context.Context) err
clickhouseFailed.Inc(int64(c))
}
c = 0
batch, _ = conn.PrepareBatch(ctx, "INSERT INTO DNS_LOG")
batch, _ = conn.PrepareBatch(ctx, fmt.Sprintf("INSERT INTO %v", chConfig.ClickhouseTable))
}
}
case <-ticker.C:
Expand All @@ -250,7 +252,7 @@ func (chConfig clickhouseConfig) clickhouseOutputWorker(ctx context.Context) err
clickhouseFailed.Inc(int64(c))
}
c = 0
batch, _ = conn.PrepareBatch(ctx, "INSERT INTO DNS_LOG")
batch, _ = conn.PrepareBatch(ctx, fmt.Sprintf("INSERT INTO %v", chConfig.ClickhouseTable))
case <-ctx.Done():
err := batch.Flush()
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions internal/output/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package output
import (
"context"
"errors"
"fmt"
"time"

"github.com/jackc/pgx/v4"
Expand All @@ -31,6 +32,7 @@ import (
type psqlConfig struct {
PsqlOutputType uint `long:"psqloutputtype" ini-name:"psqloutputtype" env:"DNSMONSTER_PSQLOUTPUTTYPE" default:"0" description:"What should be written to Microsoft Psql. options:\n;\t0: Disable Output\n;\t1: Enable Output without any filters\n;\t2: Enable Output and apply skipdomains logic\n;\t3: Enable Output and apply allowdomains logic\n;\t4: Enable Output and apply both skip and allow domains logic" choice:"0" choice:"1" choice:"2" choice:"3" choice:"4"`
PsqlEndpoint string `long:"psqlendpoint" ini-name:"psqlendpoint" env:"DNSMONSTER_PSQLOUTPUTENDPOINT" default:"" description:"Psql endpoint used. must be in uri format. example: postgres://username:password@hostname:port/database?sslmode=disable"`
PsqlTable string `long:"psqltable" ini-name:"psqltable" env:"DNSMONSTER_PSQLTABLE" default:"DNS_LOG" description:"Psql table which data will be stored on database"`
PsqlWorkers uint `long:"psqlworkers" ini-name:"psqlworkers" env:"DNSMONSTER_PSQLWORKERS" default:"1" description:"Number of PSQL workers"`
PsqlBatchSize uint `long:"psqlbatchsize" ini-name:"psqlbatchsize" env:"DNSMONSTER_PSQLBATCHSIZE" default:"1" description:"Psql Batch Size"`
PsqlBatchDelay time.Duration `long:"psqlbatchdelay" ini-name:"psqlbatchdelay" env:"DNSMONSTER_PSQLBATCHDELAY" default:"0s" description:"Interval between sending results to Psql if Batch size is not filled. Any value larger than zero takes precedence over Batch Size"`
Expand Down Expand Up @@ -92,10 +94,10 @@ func (psqConf psqlConfig) connectPsql() *pgxpool.Pool {
}

_, err = c.Exec(context.Background(),
`CREATE TABLE IF NOT EXISTS DNS_LOG (PacketTime timestamp, IndexTime timestamp,
fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %v (PacketTime timestamp, IndexTime timestamp,
Server text, IPVersion integer, SrcIP inet, DstIP inet, Protocol char(3),
QR smallint, OpCode smallint, Class smallint, Type integer, Edns0Present smallint,
DoBit smallint, FullQuery text, ResponseCode smallint, Question text, Size smallint);`,
DoBit smallint, FullQuery text, ResponseCode smallint, Question text, Size smallint);`, psqConf.PsqlTable),
)
if err != nil {
log.Error(err.Error())
Expand Down Expand Up @@ -130,10 +132,10 @@ func (psqConf psqlConfig) OutputWorker() {
}

batch := new(pgx.Batch)
insertQuery := `INSERT INTO DNS_LOG(
insertQuery := fmt.Sprintf(`INSERT INTO %v(
PacketTime, IndexTime, Server, IPVersion, SrcIP ,DstIP, Protocol, QR, OpCode,
Class, Type, Edns0Present, DoBit, FullQuery, ResponseCode, Question, Size)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17);`
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17);`, psqConf.PsqlTable)

timeoutContext, cancel := context.WithTimeout(context.Background(), psqConf.PsqlBatchTimeout)
defer cancel()
Expand Down