Skip to content

Commit

Permalink
fixed error logging, insecure skip verify, go mod
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Porter <portertech@gmail.com>
  • Loading branch information
portertech committed Feb 11, 2020
1 parent bb94c9d commit a9add56
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.10.x
- 1.13.x
install:
- go get gopkg.in/alecthomas/gometalinter.v1
- go get github.com/gordonklaus/ineffassign
Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/sensu/sensu-prometheus-collector

go 1.13

require (
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
github.com/davecgh/go-spew v1.1.1
github.com/golang/protobuf v1.2.0
github.com/kelseyhightower/envconfig v1.3.0
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v0.8.0
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a
github.com/stretchr/testify v1.2.2
golang.org/x/net v0.0.0-20181207154023-610586996380
)
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/kelseyhightower/envconfig v1.3.0 h1:IvRS4f2VcIQy6j4ORGIf9145T/AsUB+oY8LyvN8BXNM=
github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/net v0.0.0-20181207154023-610586996380 h1:zPQexyRtNYBc7bcHmehl1dH6TB3qn8zytv8cBGLDNY0=
golang.org/x/net v0.0.0-20181207154023-610586996380/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -158,8 +160,11 @@ func QueryPrometheus(promURL string, queryString string) (model.Vector, error) {
return nil, errors.New("unexpected response type")
}

func QueryExporter(exporterURL string, auth ExporterAuth) (model.Vector, error) {
client := &http.Client{}
func QueryExporter(exporterURL string, auth ExporterAuth, insecureSkipVerify bool) (model.Vector, error) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify},
}
client := &http.Client{Transport: tr}
req, err := http.NewRequest("GET", exporterURL, nil)

if err != nil {
Expand Down Expand Up @@ -235,6 +240,7 @@ func main() {
queryString := flag.String("prom-query", "up", "Prometheus API query string.")
outputFormat := flag.String("output-format", "influx", "The check output format to use for metrics {influx|graphite|json}.")
metricPrefix := flag.String("metric-prefix", "", "Metric name prefix, only supported by line protocol output formats.")
insecureSkipVerify := flag.Bool("insecure-skip-verify", false, "Skip TLS peer verification.")
flag.Parse()

var samples model.Vector
Expand All @@ -244,30 +250,30 @@ func main() {
auth, err := setExporterAuth(*exporterUser, *exporterPassword, *exporterAuthorizationHeader)

if err != nil {
_ = fmt.Errorf("%v", err)
log.Fatal(err)
os.Exit(2)
}

samples, err = QueryExporter(*exporterURL, auth)
samples, err = QueryExporter(*exporterURL, auth, *insecureSkipVerify)

if err != nil {
_ = fmt.Errorf("%v", err)
log.Fatal(err)
os.Exit(2)
}

} else {
samples, err = QueryPrometheus(*promURL, *queryString)

if err != nil {
_ = fmt.Errorf("%v", err)
log.Fatal(err)
os.Exit(2)
}
}

err = OutputMetrics(samples, *outputFormat, *metricPrefix)

if err != nil {
_ = fmt.Errorf("%v", err)
_ = fmt.Errorf("error %v", err)
os.Exit(2)
}
}

0 comments on commit a9add56

Please sign in to comment.