Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package cli

import (
"crypto/tls"
"net/http"
"net/url"
"os"
"path"
Expand All @@ -31,10 +33,11 @@ import (
)

var (
verbose bool
alertmanagerURL *url.URL
output string
timeout time.Duration
verbose bool
alertmanagerURL *url.URL
output string
timeout time.Duration
tlsInsecureSkipVerify bool

configFiles = []string{os.ExpandEnv("$HOME/.config/amtool/config.yml"), "/etc/amtool/config.yml"}
legacyFlags = map[string]string{"comment_required": "require-comment"}
Expand Down Expand Up @@ -78,6 +81,13 @@ func NewAlertmanagerClient(amURL *url.URL) *client.Alertmanager {

cr := clientruntime.New(address, path.Join(amURL.Path, defaultAmApiv2path), schemes)

if tlsInsecureSkipVerify {
transport := http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
cr.Transport = &transport
}

if amURL.User != nil {
password, _ := amURL.User.Password()
cr.DefaultAuthentication = clientruntime.BasicAuth(amURL.User.Username(), password)
Expand All @@ -98,6 +108,7 @@ func Execute() {
app.Flag("alertmanager.url", "Alertmanager to talk to").URLVar(&alertmanagerURL)
app.Flag("output", "Output formatter (simple, extended, json)").Short('o').Default("simple").EnumVar(&output, "simple", "extended", "json")
app.Flag("timeout", "Timeout for the executed command").Default("30s").DurationVar(&timeout)
app.Flag("tls.insecure.skip.verify", "Skip TLS certificate verification").BoolVar(&tlsInsecureSkipVerify)

app.Version(version.Print("amtool"))
app.GetFlag("help").Short('h')
Expand Down Expand Up @@ -151,5 +162,9 @@ static configuration:

date.format
Sets the output format for dates. Defaults to "2006-01-02 15:04:05 MST"

tls.insecure.skip.verify
Skips TLS certificate verification for all HTTPS requests.
Defaults to false.
`
)