github.com/netdata/go.d.plugin@v0.58.1/modules/whoisquery/whoisquery.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package whoisquery 4 5 import ( 6 _ "embed" 7 "time" 8 9 "github.com/netdata/go.d.plugin/agent/module" 10 "github.com/netdata/go.d.plugin/pkg/web" 11 ) 12 13 //go:embed "config_schema.json" 14 var configSchema string 15 16 func init() { 17 module.Register("whoisquery", module.Creator{ 18 JobConfigSchema: configSchema, 19 Defaults: module.Defaults{ 20 UpdateEvery: 60, 21 }, 22 Create: func() module.Module { return New() }, 23 }) 24 } 25 26 func New() *WhoisQuery { 27 return &WhoisQuery{ 28 Config: Config{ 29 Timeout: web.Duration{Duration: time.Second * 5}, 30 DaysUntilWarn: 90, 31 DaysUntilCrit: 30, 32 }, 33 } 34 } 35 36 type Config struct { 37 Source string 38 Timeout web.Duration `yaml:"timeout"` 39 DaysUntilWarn int64 `yaml:"days_until_expiration_warning"` 40 DaysUntilCrit int64 `yaml:"days_until_expiration_critical"` 41 } 42 43 type WhoisQuery struct { 44 module.Base 45 Config `yaml:",inline"` 46 47 charts *module.Charts 48 49 prov provider 50 } 51 52 func (w *WhoisQuery) Init() bool { 53 if err := w.validateConfig(); err != nil { 54 w.Errorf("config validation: %v", err) 55 return false 56 } 57 58 prov, err := w.initProvider() 59 if err != nil { 60 w.Errorf("init whois provider: %v", err) 61 return false 62 } 63 w.prov = prov 64 65 w.charts = w.initCharts() 66 67 return true 68 } 69 70 func (w *WhoisQuery) Check() bool { 71 return len(w.Collect()) > 0 72 } 73 74 func (w *WhoisQuery) Charts() *module.Charts { 75 return w.charts 76 } 77 78 func (w *WhoisQuery) Collect() map[string]int64 { 79 mx, err := w.collect() 80 if err != nil { 81 w.Error(err) 82 } 83 84 if len(mx) == 0 { 85 return nil 86 } 87 return mx 88 } 89 90 func (w *WhoisQuery) Cleanup() {}