diff --git a/plugins/outputs/instrumental/instrumental.go b/plugins/outputs/instrumental/instrumental.go index 199069377..2fcc28cc0 100644 --- a/plugins/outputs/instrumental/instrumental.go +++ b/plugins/outputs/instrumental/instrumental.go @@ -28,9 +28,10 @@ type Instrumental struct { } const ( - DefaultHost = "collector.instrumentalapp.com" - HelloMessage = "hello version go/telegraf/1.1\n" - AuthFormat = "authenticate %s\n" + DefaultHost = "collector.instrumentalapp.com" + HelloMessage = "hello version go/telegraf/1.1\n" + AuthFormat = "authenticate %s\n" + HandshakeFormat = HelloMessage + AuthFormat ) var ( @@ -59,12 +60,6 @@ func (i *Instrumental) Connect() error { return err } - err = i.hello(connection) - if err != nil { - i.conn = nil - return err - } - err = i.authenticate(connection) if err != nil { i.conn = nil @@ -175,39 +170,19 @@ func (i *Instrumental) SampleConfig() string { return sampleConfig } -func (i *Instrumental) hello(conn net.Conn) error { - _, err := fmt.Fprintf(conn, HelloMessage) - if err != nil { - return err - } - - response := make([]byte, 512) - if _, err = conn.Read(response); err != nil { - fmt.Println("hello err", err) - return err - } - - if string(response)[:3] != "ok\n" { - return fmt.Errorf("Hello failed: %s", response) - } - - return nil -} - func (i *Instrumental) authenticate(conn net.Conn) error { - _, err := fmt.Fprintf(conn, AuthFormat, i.ApiToken) + _, err := fmt.Fprintf(conn, HandshakeFormat, i.ApiToken) if err != nil { return err } - // The response here will either be an "ok" or an error message. + // The response here will either be two "ok"s or an error message. responses := make([]byte, 512) if _, err = conn.Read(responses); err != nil { - fmt.Println("err was not nil: ", err) return err } - if string(responses)[:3] != "ok\n" { + if string(responses)[:6] != "ok\nok\n" { return fmt.Errorf("Authentication failed: %s", responses) } diff --git a/plugins/outputs/instrumental/instrumental_test.go b/plugins/outputs/instrumental/instrumental_test.go index dbab355d6..9708a2590 100644 --- a/plugins/outputs/instrumental/instrumental_test.go +++ b/plugins/outputs/instrumental/instrumental_test.go @@ -79,10 +79,9 @@ func TCPServer(t *testing.T, wg *sync.WaitGroup) { hello, _ := tp.ReadLine() assert.Equal(t, "hello version go/telegraf/1.1", hello) - conn.Write([]byte("ok\n")) auth, _ := tp.ReadLine() assert.Equal(t, "authenticate abc123token", auth) - conn.Write([]byte("ok\n")) + conn.Write([]byte("ok\nok\n")) data1, _ := tp.ReadLine() assert.Equal(t, "gauge my.prefix.192_168_0_1.mymeasurement.myfield 3.14 1289430000", data1) @@ -96,11 +95,9 @@ func TCPServer(t *testing.T, wg *sync.WaitGroup) { hello, _ = tp.ReadLine() assert.Equal(t, "hello version go/telegraf/1.1", hello) - conn.Write([]byte("ok\n")) - auth, _ = tp.ReadLine() assert.Equal(t, "authenticate abc123token", auth) - conn.Write([]byte("ok\n")) + conn.Write([]byte("ok\nok\n")) data3, _ := tp.ReadLine() assert.Equal(t, "increment my.prefix.192_168_0_1.my_histogram 3.14 1289430000", data3)