This commit is contained in:
Ali Alrahahleh 2016-05-24 15:53:46 -07:00
parent 6f7dac6023
commit c35ab80893
2 changed files with 18 additions and 20 deletions

View File

@ -1,18 +1,18 @@
package graylog
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strconv"
"bytes"
"regexp"
"io/ioutil"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"sync"
"time"
"encoding/json"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
@ -21,11 +21,11 @@ import (
)
type GrayLog struct {
Name string
Servers []string
TagKeys []string
Metrics []string
Headers map[string]string
Name string
Servers []string
TagKeys []string
Metrics []string
Headers map[string]string
// Path to CA file
SSLCA string `toml:"ssl_ca"`
@ -55,7 +55,7 @@ type HTTPClient interface {
}
type Messagebody struct {
Metrics []string `json:"metrics"`
Metrics []string `json:"metrics"`
}
type RealHTTPClient struct {
@ -222,10 +222,10 @@ func (h *GrayLog) gatherServer(
for k, v := range metric.Fields() {
re, _ := regexp.Compile(`metrics_([0-9]+)`)
match := re.FindAllStringSubmatch(k, -1)
if(match != nil) {
if match != nil {
i, _ := strconv.Atoi(match[0][1])
fields[name_list[i]] = v
}
}
}
fields["response_time"] = responseTime
acc.AddFields(metric.Name(), fields, metric.Tags())

View File

@ -244,15 +244,13 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {
}
}
// Create + send request
body := data.Encode()
body_attr := data.Get('__body')
if body_attr != "" {
list := strings.Split(data.Encode(), '=')
body = list[1]
}
body_attr := data.Get("__body")
http_body := data.Encode()
if body_attr != "" {
http_body = body_attr
}
req, err := http.NewRequest(h.Method, requestURL.String(),
strings.NewReader(body))
strings.NewReader(http_body))
if err != nil {
return "", -1, err
}