Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to standard project strcuture
Browse files Browse the repository at this point in the history
mosajjal committed Jan 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 223519d commit 02e9b01
Showing 45 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ jobs:
go get -v
- name: Build
run: go build -v .
run: go build -v ./...

- name: Test
run: go test -v .
run: go test -v ./...

- name: generate sample config file
run: ./dnsmonster --writeConfig=config-sample.ini
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
dnsmonster
/dnsmonster

#generated docker-composee
docker-compose.yml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ RUN git clone https://${REPO}.git /opt/dnsmonster --depth 1 \
&& cd /opt/dnsmonster \
&& git fetch --tags \
&& export LATEST_TAG=`git describe --tags --always` \
&& go build --ldflags "-L /usr/lib/libcap.a -linkmode external -X ${REPO}/util.releaseVersion=${LATEST_TAG} -extldflags \"-static\""
&& go build --ldflags "-L /usr/lib/libcap.a -linkmode external -X ${REPO}/util.releaseVersion=${LATEST_TAG} -extldflags \"-static\"" ./...

FROM scratch
COPY --from=0 /opt/dnsmonster/dnsmonster /dnsmonster
2 changes: 1 addition & 1 deletion Dockerfile-crossplatform
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ RUN mkdir /${PROJECT} && mkdir ${OUTDIR}
COPY . /${PROJECT}
WORKDIR /${PROJECT}

env GOBUILD="go build -ldflags=-s -tags ${GOTAG} -o ${OUTDIR}/${PROJECT}_${GOTAG}"
env GOBUILD="go build -ldflags=-s -tags ${GOTAG} -o ${OUTDIR}/${PROJECT}_${GOTAG}" ./...

# Linux
RUN echo "Building Linux binaries"
4 changes: 2 additions & 2 deletions Dockerfile-release
Original file line number Diff line number Diff line change
@@ -10,12 +10,12 @@ RUN git clone https://${REPO}.git /opt/dnsmonster --depth 1 \
&& cd /opt/dnsmonster \
&& git fetch --tags \
&& export LATEST_TAG=`git describe --tags $(git rev-list --tags --max-count=1)` \
&& go build --ldflags "-L /usr/lib/libcap.a -linkmode external -X ${REPO}/util.releaseVersion=${LATEST_TAG} -extldflags \"-static\"" -o /tmp/dnsmonster-linux-amd64.bin
&& go build --ldflags "-L /usr/lib/libcap.a -linkmode external -X ${REPO}/util.releaseVersion=${LATEST_TAG} -extldflags \"-static\"" -o /tmp/dnsmonster-linux-amd64.bin ./...

ENV CGO_ENABLED=1
ENV GOOS=windows
ENV GOARCH=amd64
RUN sh -c 'cd /opt/dnsmonster && go build -o /tmp/dnsmonster-windows-amd64.exe'
RUN sh -c 'cd /opt/dnsmonster && go build -o /tmp/dnsmonster-windows-amd64.exe' ./...

WORKDIR /opt/dnsmonster

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -86,13 +86,13 @@ sudo docker run --rm -it --net=host --cap-add NET_RAW --cap-add NET_ADMIN --name
### Build manually

- with `libpcap`:
Make sure you have `go`, `libpcap-devel` and `linux-headers` packages installed. The name of the packages might differ based on your distribution. After this, simply clone the repository and run `go build .`
Make sure you have `go`, `libpcap-devel` and `linux-headers` packages installed. The name of the packages might differ based on your distribution. After this, simply clone the repository and run `go build ./...`

```sh
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster
go get
go build -o dnsmonster .
go build -o dnsmonster ./...
```

- without `libpcap`:
@@ -102,7 +102,7 @@ go build -o dnsmonster .
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster
go get
go build -o dnsmonster -tags nolibpcap .
go build -o dnsmonster -tags nolibpcap ./...
```

The above build also works on ARMv7 (RPi4) and AArch64.
@@ -115,14 +115,14 @@ If you have a copy of `libpcap.a`, you can build the statically link it to `dnsm
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster/
go get
go build --ldflags "-L /root/libpcap-1.9.1/libpcap.a -linkmode external -extldflags \"-I/usr/include/libnl3 -lnl-genl-3 -lnl-3 -static\"" -a -o dnsmonster
go build --ldflags "-L /root/libpcap-1.9.1/libpcap.a -linkmode external -extldflags \"-I/usr/include/libnl3 -lnl-genl-3 -lnl-3 -static\"" -a -o dnsmonster ./...
```

For more information on how the statically linked binary is created, take a look at [this](Dockerfile) Dockerfile.

## Windows

Bulding on Windows is much the same as Linux. Just make sure that you have `npcap`. Clone the repository (`--history 1` works), and run `go get` and `go build .`
Bulding on Windows is much the same as Linux. Just make sure that you have `npcap`. Clone the repository (`--history 1` works), and run `go get` and `go build ./...`

As mentioned, Windows release of the binary depends on [npcap](https://nmap.org/npcap/#download) to be installed. After installation, the binary should work out of the box. It's been tested in a Windows 10 environment and it executed without an issue. To find interface names to give `--devName` parameter and start sniffing, you'll need to do the following:

@@ -143,7 +143,7 @@ Much the same as Linux and Windows, make sure you have `git`, `libpcap` and `go`
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster
go get
go build -o dnsmonster .
go build -o dnsmonster ./...
```

# Architecture
2 changes: 1 addition & 1 deletion clickhouse/tables.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS DNS_LOG (
PacketTime DateTime,
PacketTime DateTime64,
IndexTime DateTime64,
Server LowCardinality(String),
IPVersion UInt8,
4 changes: 2 additions & 2 deletions main.go → cmd/dnsmonster/main.go
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ import (
"syscall"
"time"

"github.com/mosajjal/dnsmonster/capture"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/capture"
"github.com/mosajjal/dnsmonster/internal/util"
"github.com/pkg/profile"
"github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
4 changes: 2 additions & 2 deletions outputs.go → cmd/dnsmonster/outputs.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ import (
"context"
"time"

_ "github.com/mosajjal/dnsmonster/output" // this will automatically set up all the outputs
"github.com/mosajjal/dnsmonster/util"
_ "github.com/mosajjal/dnsmonster/internal/output" // this will automatically set up all the outputs
"github.com/mosajjal/dnsmonster/internal/util"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)
6 changes: 3 additions & 3 deletions docs/content/en/docs/Getting started/installation.md
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ Check out the configuration section to understand the provided command line argu
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster
go get
go build -o dnsmonster .
go build -o dnsmonster ./...
```

- without `libpcap`:
@@ -47,7 +47,7 @@ go build -o dnsmonster .
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster
go get
go build -o dnsmonster -tags nolibpcap .
go build -o dnsmonster -tags nolibpcap ./...
```

The above build also works on ARMv7 (RPi4) and AArch64.
@@ -60,7 +60,7 @@ If you have a copy of `libpcap.a`, you can build the statically link it to `dnsm
git clone https://github.com/mosajjal/dnsmonster --depth 1 /tmp/dnsmonster
cd /tmp/dnsmonster/
go get
go build --ldflags "-L /root/libpcap-1.9.1/libpcap.a -linkmode external -extldflags \"-I/usr/include/libnl3 -lnl-genl-3 -lnl-3 -static\"" -a -o dnsmonster
go build --ldflags "-L /root/libpcap-1.9.1/libpcap.a -linkmode external -extldflags \"-I/usr/include/libnl3 -lnl-genl-3 -lnl-3 -static\"" -a -o dnsmonster ./...
```

For more information on how the statically linked binary is created, take a look at Dockerfiles in the root of the repository responsible for generating the published binaries.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion capture/capture.go → internal/capture/capture.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import (
"github.com/gopacket/gopacket"
"github.com/gopacket/gopacket/layers"
"github.com/gopacket/gopacket/tcpassembly/tcpreader"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
)

type captureConfig struct {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion capture/dnstap.go → internal/capture/dnstap.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
"github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion capture/nondnstap.go → internal/capture/nondnstap.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
"github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
2 changes: 1 addition & 1 deletion capture/packet.go → internal/capture/packet.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"github.com/gopacket/gopacket"
"github.com/gopacket/gopacket/layers"
mkdns "github.com/miekg/dns"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion output/clickhouse.go → internal/output/clickhouse.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
2 changes: 1 addition & 1 deletion output/elastic.go → internal/output/elastic.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"net/http"
"time"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"

2 changes: 1 addition & 1 deletion output/file.go → internal/output/file.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"os"

"github.com/jessevdk/go-flags"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)
2 changes: 1 addition & 1 deletion output/influx.go → internal/output/influx.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"time"

influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)
2 changes: 1 addition & 1 deletion output/kafka.go → internal/output/kafka.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"net"
"time"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"

File renamed without changes.
2 changes: 1 addition & 1 deletion output/postgres.go → internal/output/postgres.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"github.com/jackc/pgx/v4/pgxpool"
metrics "github.com/rcrowley/go-metrics"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
log "github.com/sirupsen/logrus"
)

2 changes: 1 addition & 1 deletion output/sentinel.go → internal/output/sentinel.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
"strings"
"time"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)
2 changes: 1 addition & 1 deletion output/splunk.go → internal/output/splunk.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/mosajjal/Go-Splunk-HTTP/splunk/v2"
"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
)

type splunkConfig struct {
2 changes: 1 addition & 1 deletion output/stdout.go → internal/output/stdout.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)
2 changes: 1 addition & 1 deletion output/syslog.go → internal/output/syslog.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (

syslog "github.com/hashicorp/go-syslog"

"github.com/mosajjal/dnsmonster/util"
"github.com/mosajjal/dnsmonster/internal/util"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 02e9b01

Please sign in to comment.