package probe import ( "fmt" "net/http" "git.loafle.net/commons_go/logging" "git.loafle.net/overflow/overflow_probes/central/api/module" "git.loafle.net/overflow/overflow_probes/central/client" "git.loafle.net/overflow/overflow_probes/collector" "git.loafle.net/overflow/overflow_probes/commons" "git.loafle.net/overflow/overflow_probes/config" opuu "git.loafle.net/overflow/overflow_probes/util/url" ) const ( probeEntryPoint = "/probe" fileEntryPoint = "/file" ) type probe struct { *commons.Handlers probeEntryURL string fileEntryURL string metricEntryURL string probeClient client.Client fileClient client.Client metricClient client.Client collector collector.CollectorHandler } func New() (ProbeHandler, error) { p := &probe{} p.Handlers = commons.NewHandlers() var err error if p.probeEntryURL, err = opuu.Join(config.CFG.Central.URL, probeEntryPoint); nil != err { return nil, err } if p.fileEntryURL, err = opuu.Join(config.CFG.Central.URL, fileEntryPoint); nil != err { return nil, err } if c.metricEntryURL, err = opuu.Join(config.CFG.Central.URL, metricEntryPoint); nil != err { return nil, err } p.probeClient = client.New() p.fileClient = client.New() c.metricClient = client.New() if p.collector, err = collector.New(); nil != err { return nil, err } return p, nil } func (p *probe) connectToCentralProbe() error { var err error var res *http.Response if res, err = p.ConnectToCentralAsProbe(p.probeClient, p.probeEntryURL); nil != err { return err } encryptionKey := res.Header.Get(module.ProbeHeader_Probe_EncryptionKey) config.EncryptionKey = &encryptionKey p.probeClient.OnNotify(p.onNotify) if _, err = p.ConnectToCentralAsProbe(p.metricClient, p.metricEntryURL); nil != err { return err } return nil } func (p *probe) sendNotifyToCentral(method string, params ...string) { if err := p.probeClient.Notify(method, params); nil != err { logging.Logger.Error(fmt.Sprintf("Probe notify error: [%v]", err)) } }