diff --git a/main.go b/main.go index 7413cd4..373973c 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,13 @@ package main -// A wrapper for "puppet agent -t" that enforces rules about setting silences, disable messages, and so on. +// A wrapper for "puppet agent -t" that enforces rules about disable messages and so on. import ( "fmt" "os" - "github.com/urfave/cli" "github.com/StackExchange/pat/version" + "github.com/urfave/cli" ) // preprocessArgs inserts a "--disable-message" flag in front of a bare message. @@ -45,7 +45,7 @@ func preprocessArgs(items []string) []string { func main() { pat := cli.NewApp() pat.Name = "pat" - pat.Usage = "A wrapper for \"puppet agent -t\" (hence the name: P... A... T) that enforces rules about setting silences, disable messages, and so on" + pat.Usage = "A wrapper for \"puppet agent -t\" (hence the name: P... A... T) that enforces rules about disable messages and so on" pat.Version = version.GetVersionInfo() pat.UsageText = fmt.Sprintf("%s [flags] [additional puppet commands]", os.Args[0]) pat.Authors = []cli.Author{ @@ -78,10 +78,6 @@ func main() { Name: "once", Usage: "Run puppet. If puppet was disabled, re-disable when done", }, - cli.BoolFlag{ - Name: "nosilence, S", - Usage: "Do not set a silence when disabling puppet", - }, cli.BoolFlag{ Name: "status", Usage: "Report disable status", @@ -114,11 +110,6 @@ func main() { Name: "facts", Usage: "Run puppet facts instead of puppet agent", }, - cli.StringFlag{ - Name: "s", - Value: "1h", - Usage: "Set the silence duration to [value]", - }, } cli.AppHelpTemplate = fmt.Sprintf(`%s @@ -138,9 +129,6 @@ SAMPLE USAGE: if left blank. Silences puppet.left.disabled for 1h or the value set by -s. - pat --nosilence --disable - Runs 'puppet --disable' but does not silence bosun. - pat --enable Runs 'puppet --enable' @@ -156,7 +144,6 @@ SAMPLE USAGE: NOTES: * %s * If you want to add regular "puppet agent" flags, add them after '--'. - * No silence it set if --noop set. `, cli.AppHelpTemplate, osRootMessage) pat.Action = doPat diff --git a/pat.go b/pat.go index f85d095..fe517b6 100644 --- a/pat.go +++ b/pat.go @@ -10,12 +10,10 @@ import ( "strings" "time" - silence "github.com/StackExchange/pat/addsilence" "github.com/urfave/cli" ) var ( - enableSilence = true additionalArguments = []string{} isDebug = false isTimestamp = false @@ -27,7 +25,6 @@ var ( func doPat(pat *cli.Context) error { //Throw these as globals as they're used all over the place. Saves us from passing pat through everywhere. additionalArguments = pat.Args() - enableSilence = !pat.Bool("nosilence") //We need some additional arguments for dealing with things like the verbose and debug flags additionalArguments = pat.Args() @@ -71,7 +68,6 @@ func doPat(pat *cli.Context) error { tsLn("DEBUG: disable:", pat.String("disable")) tsLn("DEBUG: enable:", pat.Bool("enable")) tsLn("DEBUG: once:", pat.Bool("once")) - tsLn("DEBUG: nosilence:", pat.Bool("nosilence")) tsLn("DEBUG: status:", pat.Bool("status")) tsLn("DEBUG: noop:", pat.Bool("noop")) tsLn("DEBUG: debug:", pat.Bool("debug")) @@ -90,7 +86,6 @@ func doPat(pat *cli.Context) error { tsLn("DEBUG: -- PROGRAM --") tsLn("DEBUG: puppetDisabled:", puppetDisabled) tsLn("DEBUG: additionalArgs:", additionalArguments) - tsLn("DEBUG: enableSilence:", enableSilence) } var err error @@ -132,7 +127,7 @@ func doPat(pat *cli.Context) error { //If puppet was disabled; disable it again if puppetWasDisabled { - err = disablePuppet(disabledMessage, pat.String("s")) + err = disablePuppet(disabledMessage) if err != nil { return err } @@ -144,7 +139,7 @@ func doPat(pat *cli.Context) error { // CMD: --disable [message] if pat.IsSet("disable") { - err = disablePuppet(pat.String("disable-message"), pat.String("s")) + err = disablePuppet(pat.String("disable-message")) return err } @@ -169,7 +164,7 @@ func enablePuppet() error { } // Disable puppet. If puppet is already disabled, will return an error -func disablePuppet(message, silenceduration string) error { +func disablePuppet(message string) error { if puppetDisabled { return fmt.Errorf("Puppet is already disabled") } @@ -201,10 +196,6 @@ func disablePuppet(message, silenceduration string) error { if err != nil { return err } - err = silenceBosun(silenceduration, message) - if err != nil { - return err - } return nil } @@ -275,31 +266,6 @@ func execPuppet(args ...string) error { return err } -func silenceBosun(duration, message string) error { - // If silencing is disabled, or we're doing a noop - if !enableSilence || isNoop { - if isDebug { - tsLn("DEBUG: Skipping silence, as silence is disabled or we're doing a noop") - } - return nil - } - - //Call silence here - hostName, err := os.Hostname() - if err != nil { - return err - } - hosts := []string{hostName} - silence, err := silence.EasySilence("puppet.left.disabled", duration, message, hosts) - if silence != "" { - tsLn(silence) - } - if err != nil { - return err - } - return nil -} - //Create a form message to use when disabling puppet if no message is specified func defaultPuppetDisableMessage() string { currentUser, err := user.Current() //Get the current user for the form message