Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix foo #118

Merged
merged 4 commits into from
May 14, 2022
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GO_VERSION:=0.16

.PHONY: build
build:
goreleaser r --snapshot --rm-dist
goreleaser build --snapshot --single-target --rm-dist

.PHONY: test
test:
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ $ dnsbl-exporter -h

Go to http://127.0.0.1:9211/ in your browser.

#### Quering

The individual configured servers and their status are represented by a **gauge**:

```sh
luzilla_rbls_ips_blacklisted{hostname="mail.gmx.net",ip="212.227.17.168",rbl="ix.dnsbl.manitu.net"} 0
```

This represent the server's hostname and the DNSBL in question. `0` for unlisted and `1` for listed. Requests to the DNSBL happen in real-time and are not cached. Take this into account and use accordingly.

### Caveat

In order to use this, a _proper_ DNS resolver is needed. Proper means: not Google, not Cloudflare, OpenDNS, etc..
Instead use a resolver like Unbound.
Instead use a resolver like [Unbound](https://github.com/NLnetLabs/unbound).

To test on OSX, follow these steps:

Expand Down
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ func (app *DNSBLApp) Bootstrap() {

http.Handle(ctx.String("web.telemetry-path"), handler)

log.Infoln("Starting on: ", ctx.String("web.listen-address"))
err = http.ListenAndServe(ctx.String("web.listen-address"), nil)
if err != nil {
return err
}

log.Infoln("Listening on", ctx.String("web.listen-address"))

return nil
}
}
Expand Down
26 changes: 17 additions & 9 deletions collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collector

import (
"sync"

"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -73,9 +75,10 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {
float64(len(c.rbls)),
)

// this should be a map of blacklist and a counter
listed := 0
// this should be a map of blacklist and a counter (for listings)
var listed sync.Map

// iterate over hosts -> resolve to ip, check
for _, host := range hosts {

log.Debugln("Checking ...", host)
Expand All @@ -91,9 +94,10 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {

metricValue := 0

val, _ := listed.LoadOrStore(result.Rbl, 0)
if result.Listed {
metricValue = 1
listed = +1
listed.Store(result.Rbl, val.(int)+1)
}

labelValues := []string{result.Rbl, result.Address, host}
Expand All @@ -116,10 +120,14 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {
}
}

ch <- prometheus.MustNewConstMetric(
c.listedMetric,
prometheus.GaugeValue,
float64(listed),
[]string{"foo"}...,
)
for _, rbl := range c.rbls {
val, _ := listed.LoadOrStore(rbl, 0)
ch <- prometheus.MustNewConstMetric(
c.listedMetric,
prometheus.GaugeValue,
float64(val.(int)),
[]string{rbl}...,
)
}

}