Skip to content

Commit

Permalink
Merge pull request #63 from sensu/js/refactor-output
Browse files Browse the repository at this point in the history
refactor annotation override output so check output is not polluted
  • Loading branch information
Jef Spaleta authored Sep 10, 2021
2 parents db43ed9 + 09930cf commit 9f59e73
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions sensu/gocheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewGoCheck(config *PluginConfig, options []*PluginConfigOption,
eventValidation: false,
readEvent: readEvent,
configurationOverrides: true,
verbose: false,
errorExitStatus: 1,
},
validationFunction: validationFunction,
Expand Down
1 change: 1 addition & 0 deletions sensu/gohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewGoHandler(config *PluginConfig, options []*PluginConfigOption,
eventMandatory: true,
eventValidation: true,
configurationOverrides: true,
verbose: true,
errorExitStatus: 1,
},
validationFunction: validationFunction,
Expand Down
1 change: 1 addition & 0 deletions sensu/gomutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewGoMutator(config *PluginConfig, options []*PluginConfigOption,
eventMandatory: true,
eventValidation: true,
configurationOverrides: true,
verbose: true,
exitFunction: os.Exit,
errorExitStatus: 1,
},
Expand Down
17 changes: 11 additions & 6 deletions sensu/goplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type basePlugin struct {
eventMandatory bool
eventValidation bool
configurationOverrides bool
verbose bool
exitStatus int
errorExitStatus int
exitFunction func(int)
Expand Down Expand Up @@ -228,7 +229,7 @@ func (p *basePlugin) cobraExecuteFunction(args []string) error {

// If there is an event process configuration overrides if necessary
if p.sensuEvent != nil && p.configurationOverrides {
err := configurationOverrides(p.config, p.options, p.sensuEvent)
err := configurationOverrides(p.config, p.options, p.sensuEvent, p.verbose)
if err != nil {
p.exitStatus = p.errorExitStatus
return err
Expand Down Expand Up @@ -282,7 +283,7 @@ func setOptionValue(opt *PluginConfigOption, valueStr string) error {
return json.Unmarshal([]byte(valueStr), &opt.Value)
}

func configurationOverrides(config *PluginConfig, options []*PluginConfigOption, event *types.Event) error {
func configurationOverrides(config *PluginConfig, options []*PluginConfigOption, event *types.Event, verbose bool) error {
if config.Keyspace == "" {
return nil
}
Expand All @@ -299,15 +300,19 @@ func configurationOverrides(config *PluginConfig, options []*PluginConfigOption,
if err != nil {
return err
}
log.Printf("Overriding default handler configuration with value of \"Check.Annotations.%s\" (\"%s\")\n",
key, event.Check.Annotations[key])
if verbose {
log.Printf("Overriding default plugin configuration with value of \"Check.Annotations.%s\" (\"%s\")\n",
key, event.Check.Annotations[key])
}
case event.Entity != nil && len(event.Entity.Annotations[key]) > 0:
err := setOptionValue(opt, event.Entity.Annotations[key])
if err != nil {
return err
}
log.Printf("Overriding default handler configuration with value of \"Entity.Annotations.%s\" (\"%s\")\n",
key, event.Entity.Annotations[key])
if verbose {
log.Printf("Overriding default plugin configuration with value of \"Entity.Annotations.%s\" (\"%s\")\n",
key, event.Entity.Annotations[key])
}
}
}
}
Expand Down

0 comments on commit 9f59e73

Please sign in to comment.