Initial commit
This commit is contained in:
commit
66cf1fc9aa
30 changed files with 2735 additions and 0 deletions
52
checker/provider.go
Normal file
52
checker/provider.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
func Provider() sdk.ObservationProvider { return &blacklistProvider{} }
|
||||
|
||||
type blacklistProvider struct{}
|
||||
|
||||
func (p *blacklistProvider) Key() sdk.ObservationKey { return ObservationKeyBlacklist }
|
||||
func (p *blacklistProvider) Definition() *sdk.CheckerDefinition { return Definition() }
|
||||
|
||||
// ExtractMetrics turns the (now uniform) per-source results into a
|
||||
// small set of generic gauges. Source-specific metrics (VT engine
|
||||
// counts, URLhaus URL count, …) live in SourceResult.Details and are
|
||||
// rendered in the HTML report; metrics here stay coarse so the
|
||||
// scheduler / Prometheus side does not have to know which sources are
|
||||
// installed.
|
||||
func (p *blacklistProvider) ExtractMetrics(ctx sdk.ReportContext, collectedAt time.Time) ([]sdk.CheckMetric, error) {
|
||||
var data BlacklistData
|
||||
if err := json.Unmarshal(ctx.Data(), &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metrics := []sdk.CheckMetric{
|
||||
{
|
||||
Name: "blacklist_total_hits", Value: float64(data.TotalHits()),
|
||||
Unit: "results", Timestamp: collectedAt,
|
||||
},
|
||||
}
|
||||
for _, r := range data.Results {
|
||||
if !r.Enabled {
|
||||
continue
|
||||
}
|
||||
v := 0.0
|
||||
if r.Listed {
|
||||
v = 1
|
||||
}
|
||||
metrics = append(metrics, sdk.CheckMetric{
|
||||
Name: "blacklist_source_listed",
|
||||
Value: v,
|
||||
Unit: "bool",
|
||||
Labels: map[string]string{"source": r.SourceID, "subject": r.Subject},
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
}
|
||||
return metrics, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue