sensu / sensu-plugin-sdk

A framework for creating Sensu plugins
MIT License
7 stars 8 forks source link

Create abstraction for Sensu mutators #2

Closed fguimond closed 5 years ago

fguimond commented 5 years ago

Create an abstraction to execute Sensu Mutators (https://docs.sensu.io/sensu-go/5.5/reference/mutators/). Mutators accept a Sensu event, transform the event and returns the output JSON.

The first version of this repository contains an abstraction for the common Sensu handles logic. The abstraction is responsible to

We want to implement something similar for mutators.

The similarities and differences are:

How to implement

  1. See the way options are defined at https://github.com/sensu-skunkworks/sensu-aws-ec2-deregistration-handler/blob/sensu-auth/main.go#L31. Very similar approach but no need to have the Path property since it defines where to look in the Sensu Event. Dependent on the support of configuration overrides
  2. Create a new sensu.NewGoMutator method instead of sensu.NewGoHandler https://github.com/sensu-skunkworks/sensu-aws-ec2-deregistration-handler/blob/sensu-auth/main.go#L31
  3. The validation method signature should be the same - https://github.com/sensu-skunkworks/sensu-aws-ec2-deregistration-handler/blob/sensu-auth/main.go#L31
  4. The execution method should return an interface object with JSON annotations, or an error - https://github.com/sensu-skunkworks/sensu-aws-ec2-deregistration-handler/blob/sensu-auth/main.go#L31 Signature might be something like func(event *types.Event) (*types.Event, error)
  5. If no error is present the exit status code is automatically set to 0, otherwise it is set to 1

Unit tests are required.

fguimond commented 5 years ago

Sensu Go Plugin Library

fguimond commented 5 years ago

This has been implemented in https://github.com/sensu/sensu-plugins-go-library/pull/5.