From fa3eb473fb132a99343e9d0da2b0cbb09e1968f3 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 13 Oct 2017 14:32:34 +0900 Subject: [PATCH] ing --- auth/auth.go | 4 ---- collector/collector.go | 15 ++++++++++----- config.json | 20 ++++++++++---------- main.go | 29 +++++++++++++++-------------- noauthprobe.json | 3 +++ probe/probe.go | 12 +++++++++--- 6 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 noauthprobe.json diff --git a/auth/auth.go b/auth/auth.go index 2f0d561..169514d 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -72,10 +72,6 @@ func (a *auth) EndableStart(endded chan<- error) error { } func (a *auth) start() error { - if nil != config.CFG.Probe.Key || "" != *config.CFG.Probe.Key { - return nil - } - if nil != a.noAuthConfig.DenyDate { return fmt.Errorf("Cannot start because this probe have been denied from overFlow at %s", a.noAuthConfig.DenyDate.String()) } diff --git a/collector/collector.go b/collector/collector.go index 75702f8..64b744c 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -1,6 +1,11 @@ package collector type Collector interface { + StartSensor() error + StopSensor() error + AddSensor() error + RemoveSensor() error + UpdateSensor() error } type collector struct { @@ -13,18 +18,18 @@ func New() (Collector, error) { return c, nil } -func (c *collector) Start() error { +func (c *collector) StartSensor() error { return nil } -func (c *collector) Stop() error { +func (c *collector) StopSensor() error { return nil } -func (c *collector) Add() error { +func (c *collector) AddSensor() error { return nil } -func (c *collector) Remove() error { +func (c *collector) RemoveSensor() error { return nil } -func (c *collector) Update() error { +func (c *collector) UpdateSensor() error { return nil } diff --git a/config.json b/config.json index d1123d1..35c3cc6 100644 --- a/config.json +++ b/config.json @@ -1,11 +1,11 @@ { - "central": { - "url": "ws://127.0.0.1:19190", - "apikey": "52abd6fd57e511e7ac52080027658d13", - "readBufferSize": 8192, - "writeBufferSize": 8192 - }, - "probe": { - "key": "" - } -} + "central": { + "url": "ws://127.0.0.1:19190", + "apiKey": "52abd6fd57e511e7ac52080027658d13", + "readBufferSize": 8192, + "writeBufferSize": 8192 + }, + "probe": { + "key": "52abd6fd57e511e7ac52080027658d13" + } +} \ No newline at end of file diff --git a/main.go b/main.go index 284c9c5..0ff9d24 100644 --- a/main.go +++ b/main.go @@ -78,21 +78,22 @@ func main() { } go func() { - if instance, err = auth.New(); nil != err { - logging.Logger.Error(fmt.Sprintf("Auth error: %v", err)) - return + if nil == config.CFG.Probe.Key || "" == *config.CFG.Probe.Key { + if instance, err = auth.New(); nil != err { + 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 { logging.Logger.Error(fmt.Sprintf("Probe error: %v", err)) return diff --git a/noauthprobe.json b/noauthprobe.json new file mode 100644 index 0000000..8e02e65 --- /dev/null +++ b/noauthprobe.json @@ -0,0 +1,3 @@ +{ + "tempKey": "aecae27c-11ef-4c0b-b3ee-d711681b2e8c" +} \ No newline at end of file diff --git a/probe/probe.go b/probe/probe.go index 675fb75..c295ea9 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -98,9 +98,9 @@ func (p *probe) connectToCentral() error { p.probeClient.OnNotify(p.onNotify) - if _, err = client.ConnectToCentralAsProbe(p.metricClient, p.metricEntryURL); nil != err { - return err - } + // if _, err = client.ConnectToCentralAsProbe(p.metricClient, p.metricEntryURL); nil != err { + // return err + // } return nil } @@ -123,4 +123,10 @@ func (p *probe) Shutdown(ctx context.Context) error { func (p *probe) stop(err error) { 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)) + } + }