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

View File

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