-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
54 lines (46 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"log"
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-plugin-sdk/sensu"
)
// Config represents the handler plugin config.
type Config struct {
sensu.PluginConfig
Example string
}
var (
plugin = Config{
PluginConfig: sensu.PluginConfig{
Name: "{{ .GithubProject }}",
Short: "{{ .Description }}",
Keyspace: "sensu.io/plugins/{{ .GithubProject }}/config",
},
}
options = []sensu.ConfigOption{
&sensu.PluginConfigOption[string]{
Path: "example",
Env: "HANDLER_EXAMPLE",
Argument: "example",
Shorthand: "e",
Default: "",
Usage: "An example string configuration option",
Value: &plugin.Example,
},
}
)
func main() {
handler := sensu.NewGoHandler(&plugin.PluginConfig, options, checkArgs, executeHandler)
handler.Execute()
}
func checkArgs(event *corev2.Event) error {
if len(plugin.Example) == 0 {
return fmt.Errorf("--example or HANDLER_EXAMPLE environment variable is required")
}
return nil
}
func executeHandler(event *corev2.Event) error {
log.Println("executing handler with --example", plugin.Example)
return nil
}