File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ type Conf struct {
4949 // UseNtlm specifies if HTTP requests should authenticate with NTLM.
5050 UseNtlm bool
5151
52+ // UserAgentMessage is an optional message that is appended to the User Agent
53+ UserAgentMessage string
54+
5255 HAProxy []HAProxy
5356 SNMP []SNMP
5457 MIBS map [string ]MIB
Original file line number Diff line number Diff line change @@ -103,6 +103,11 @@ Default is 500.
103103MaxQueueLen (integer): is the number of metrics keept internally.
104104Default is 200000.
105105
106+ UserAgentMessage (string): is an optional message that will be appended to the
107+ User Agent when making HTTP requests. This can be used to add contact details
108+ so external services are aware of who is making the requests.
109+ Example: Scollector/0.6.0 (UserAgentMessage added here)
110+
106111Filter (array of string): Only include collectors matching these terms. Prefix
107112with - to invert match and exclude collectors matching those terms. Use
108113*,-term,-anotherterm to include all collectors except excluded terms.
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
2727 "bosun.org/slog"
2828 "bosun.org/util"
2929 "github.com/BurntSushi/toml"
30+ "github.com/facebookgo/httpcontrol"
3031)
3132
3233var (
4647 mains []func ()
4748)
4849
50+ type scollectorHTTPTransport struct {
51+ UserAgent string
52+ http.RoundTripper
53+ }
54+
55+ func (t * scollectorHTTPTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
56+ if req .Header .Get ("User-Agent" ) == "" {
57+ req .Header .Add ("User-Agent" , t .UserAgent )
58+ }
59+ return t .RoundTripper .RoundTrip (req )
60+ }
61+
4962func main () {
5063 flag .Parse ()
5164 if * flagToToml != "" {
@@ -64,6 +77,20 @@ func main() {
6477 m ()
6578 }
6679 conf := readConf ()
80+ ua := "Scollector/" + version .ShortVersion ()
81+ if conf .UserAgentMessage != "" {
82+ ua += fmt .Sprintf (" (%s)" , conf .UserAgentMessage )
83+ }
84+ client := & http.Client {
85+ Transport : & scollectorHTTPTransport {
86+ ua ,
87+ & httpcontrol.Transport {
88+ RequestTimeout : time .Minute ,
89+ },
90+ },
91+ }
92+ http .DefaultClient = client
93+ collect .DefaultClient = client
6794 if * flagHost != "" {
6895 conf .Host = * flagHost
6996 }
You can’t perform that action at this time.
0 commit comments