This commit is contained in:
crusader 2017-10-13 14:32:34 +09:00
parent caaed69010
commit fa3eb473fb
6 changed files with 47 additions and 36 deletions

View File

@ -72,10 +72,6 @@ func (a *auth) EndableStart(endded chan<- error) error {
} }
func (a *auth) start() error { func (a *auth) start() error {
if nil != config.CFG.Probe.Key || "" != *config.CFG.Probe.Key {
return nil
}
if nil != a.noAuthConfig.DenyDate { if nil != a.noAuthConfig.DenyDate {
return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", a.noAuthConfig.DenyDate.String()) return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", a.noAuthConfig.DenyDate.String())
} }

View File

@ -1,6 +1,11 @@
package collector package collector
type Collector interface { type Collector interface {
StartSensor() error
StopSensor() error
AddSensor() error
RemoveSensor() error
UpdateSensor() error
} }
type collector struct { type collector struct {
@ -13,18 +18,18 @@ func New() (Collector, error) {
return c, nil return c, nil
} }
func (c *collector) Start() error { func (c *collector) StartSensor() error {
return nil return nil
} }
func (c *collector) Stop() error { func (c *collector) StopSensor() error {
return nil return nil
} }
func (c *collector) Add() error { func (c *collector) AddSensor() error {
return nil return nil
} }
func (c *collector) Remove() error { func (c *collector) RemoveSensor() error {
return nil return nil
} }
func (c *collector) Update() error { func (c *collector) UpdateSensor() error {
return nil return nil
} }

View File

@ -1,11 +1,11 @@
{ {
"central": { "central": {
"url": "ws://127.0.0.1:19190", "url": "ws://127.0.0.1:19190",
"apikey": "52abd6fd57e511e7ac52080027658d13", "apiKey": "52abd6fd57e511e7ac52080027658d13",
"readBufferSize": 8192, "readBufferSize": 8192,
"writeBufferSize": 8192 "writeBufferSize": 8192
}, },
"probe": { "probe": {
"key": "" "key": "52abd6fd57e511e7ac52080027658d13"
} }
} }

29
main.go
View File

@ -78,21 +78,22 @@ func main() {
} }
go func() { go func() {
if instance, err = auth.New(); nil != err { if nil == config.CFG.Probe.Key || "" == *config.CFG.Probe.Key {
logging.Logger.Error(fmt.Sprintf("Auth error: %v", err)) if instance, err = auth.New(); nil != err {
return logging.Logger.Error(fmt.Sprintf("Auth error: %v", err))
return
}
endded := make(chan error)
defer close(endded)
if err := instance.(commons.EndableStarter).EndableStart(endded); err != nil {
logging.Logger.Error(fmt.Sprintf("Auther error: %v", err))
return
}
if err := <-endded; nil != err {
logging.Logger.Error(fmt.Sprintf("Auther error: %v", err))
return
}
} }
endded := make(chan error)
defer close(endded)
if err := instance.(commons.EndableStarter).EndableStart(endded); err != nil {
logging.Logger.Error(fmt.Sprintf("Auther error: %v", err))
return
}
if err := <-endded; nil != err {
logging.Logger.Error(fmt.Sprintf("Auther error: %v", err))
return
}
if instance, err = probe.New(); nil != err { if instance, err = probe.New(); nil != err {
logging.Logger.Error(fmt.Sprintf("Probe error: %v", err)) logging.Logger.Error(fmt.Sprintf("Probe error: %v", err))
return return

3
noauthprobe.json Normal file
View File

@ -0,0 +1,3 @@
{
"tempKey": "aecae27c-11ef-4c0b-b3ee-d711681b2e8c"
}

View File

@ -98,9 +98,9 @@ func (p *probe) connectToCentral() error {
p.probeClient.OnNotify(p.onNotify) p.probeClient.OnNotify(p.onNotify)
if _, err = client.ConnectToCentralAsProbe(p.metricClient, p.metricEntryURL); nil != err { // if _, err = client.ConnectToCentralAsProbe(p.metricClient, p.metricEntryURL); nil != err {
return err // return err
} // }
return nil return nil
} }
@ -123,4 +123,10 @@ func (p *probe) Shutdown(ctx context.Context) error {
func (p *probe) stop(err error) { func (p *probe) stop(err error) {
defer close(p.shutdown) defer close(p.shutdown)
ctx := context.Background()
if err := p.probeClient.Shutdown(ctx); nil != err {
logging.Logger.Error(fmt.Sprintf("Client of Probe: %v", err))
}
} }