Use url.Parse to validate configuration params
This commit is contained in:
parent
2daa9ff260
commit
40d8aeecb0
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
// "net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
// "sync"
|
// "sync"
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ func (j *Jolokia) Description() string {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func getAttr(url string) (map[string]interface{}, error) {
|
func getAttr(requestUrl *url.URL) (map[string]interface{}, error) {
|
||||||
//make request
|
//make request
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(requestUrl.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func getAttr(url string) (map[string]interface{}, error) {
|
||||||
// Process response
|
// Process response
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
err = fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
|
err = fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
|
||||||
url,
|
requestUrl,
|
||||||
resp.StatusCode,
|
resp.StatusCode,
|
||||||
http.StatusText(resp.StatusCode),
|
http.StatusText(resp.StatusCode),
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
|
@ -167,9 +167,13 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
|
||||||
tags["port"] = server.Port
|
tags["port"] = server.Port
|
||||||
tags["host"] = server.Host
|
tags["host"] = server.Host
|
||||||
|
|
||||||
url := "http://" + server.Host + ":" + server.Port + context + jmxPath
|
// Prepare URL
|
||||||
//fmt.Println(url)
|
requestUrl, err := url.Parse("http://" + server.Host + ":" + server.Port + context + jmxPath)
|
||||||
out, _ := getAttr(url)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out, _ := getAttr(requestUrl)
|
||||||
|
|
||||||
if values, ok := out["value"]; ok {
|
if values, ok := out["value"]; ok {
|
||||||
switch values.(type) {
|
switch values.(type) {
|
||||||
|
@ -179,7 +183,7 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
|
||||||
acc.Add(measurement, values.(interface{}), tags)
|
acc.Add(measurement, values.(interface{}), tags)
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
fmt.Printf("Missing key 'value' in '%s' output response\n", url)
|
fmt.Printf("Missing key 'value' in '%s' output response\n", requestUrl.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue