2023-10-03 17:54:57 +00:00
|
|
|
package pancheri
|
|
|
|
|
2023-10-03 22:46:12 +00:00
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"slices"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
blockedDomains = promauto.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "pancheri_blackhole_blocked_domains_total",
|
|
|
|
Help: "Number of blocked domains on the blackhole blocklist",
|
|
|
|
})
|
|
|
|
blockHits = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Name: "pancheri_blackhole_block_hits_total",
|
|
|
|
Help: "Number of requests that have hit the blocklist",
|
|
|
|
})
|
|
|
|
blockMisses = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Name: "pancheri_blackhole_misses_total",
|
|
|
|
Help: "Number of requests that have missed the blocklist",
|
|
|
|
})
|
|
|
|
)
|
2023-10-03 17:54:57 +00:00
|
|
|
|
|
|
|
type BlackholeFile struct {
|
|
|
|
DenyDomains []string `yaml:"deny_domains"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Blackholer struct {
|
|
|
|
DenyDomains []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Blackholer) ShouldBlock(domain string) bool {
|
2023-10-03 22:46:12 +00:00
|
|
|
blockedDomains.Set(float64(len(b.DenyDomains)))
|
|
|
|
blocked := slices.Contains(b.DenyDomains, domain)
|
|
|
|
if blocked {
|
|
|
|
blockHits.Inc()
|
|
|
|
} else {
|
|
|
|
blockMisses.Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
return blocked
|
2023-10-03 17:54:57 +00:00
|
|
|
}
|