Skip to content

Commit

Permalink
Chore: refactor rbl code into a pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed May 14, 2022
1 parent 50590f5 commit 879507d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sync"

"github.com/Luzilla/dnsbl_exporter/pkg/dns"
"github.com/Luzilla/dnsbl_exporter/pkg/rbl"
x "github.com/miekg/dns"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -85,10 +86,10 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {

log.Debugln("Checking ...", host)

rbl := NewRbl(dns.New(new(x.Client), c.resolver))
rbl.Update(host, c.rbls)
r := rbl.New(dns.New(new(x.Client), c.resolver))
r.Update(host, c.rbls)

for _, result := range rbl.Results {
for _, result := range r.Results {
// this is an "error" from the RBL
if result.Error {
log.Errorln(result.Text)
Expand Down
4 changes: 2 additions & 2 deletions collector/rbl.go → pkg/rbl/rbl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package collector
package rbl

import (
"fmt"
Expand Down Expand Up @@ -28,7 +28,7 @@ type Rbl struct {
}

// NewRbl ... factory
func NewRbl(util *dns.DNSUtil) Rbl {
func New(util *dns.DNSUtil) Rbl {
var results []Rblresult

rbl := Rbl{
Expand Down
11 changes: 6 additions & 5 deletions collector/rbl_test.go → pkg/rbl/rbl_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package collector
package rbl_test

import (
"os"
"testing"

"github.com/Luzilla/dnsbl_exporter/pkg/dns"
"github.com/Luzilla/dnsbl_exporter/pkg/rbl"
x "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
)
Expand All @@ -15,10 +16,10 @@ func TestUpdate(t *testing.T) {

d := dns.New(new(x.Client), "0.0.0.0:53")

rbl := NewRbl(d)
rbl.Update("this.is.not.an.ip", []string{"cbl.abuseat.org"})
r := rbl.New(d)
r.Update("this.is.not.an.ip", []string{"cbl.abuseat.org"})

if len(rbl.Results) > 0 {
t.Errorf("Got a result, but shouldn't have: %v", rbl.Results)
if len(r.Results) > 0 {
t.Errorf("Got a result, but shouldn't have: %v", r.Results)
}
}

0 comments on commit 879507d

Please sign in to comment.