generated from sensu/handler-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
67 lines (58 loc) · 1.49 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
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"log"
"os"
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-plugin-sdk/sensu"
)
// Config represents the check 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: "CHECK_EXAMPLE",
Argument: "example",
Shorthand: "e",
Default: "",
Usage: "An example string configuration option",
Value: &plugin.Example,
},
}
)
func main() {
useStdin := false
fi, err := os.Stdin.Stat()
if err != nil {
fmt.Printf("Error check stdin: %v\n", err)
panic(err)
}
//Check the Mode bitmask for Named Pipe to indicate stdin is connected
if fi.Mode()&os.ModeNamedPipe != 0 {
log.Println("using stdin")
useStdin = true
}
check := sensu.NewGoCheck(&plugin.PluginConfig, options, checkArgs, executeCheck, useStdin)
check.Execute()
}
func checkArgs(event *corev2.Event) (int, error) {
if len(plugin.Example) == 0 {
return sensu.CheckStateWarning, fmt.Errorf("--example or CHECK_EXAMPLE environment variable is required")
}
return sensu.CheckStateOK, nil
}
func executeCheck(event *corev2.Event) (int, error) {
log.Println("executing check with --example", plugin.Example)
return sensu.CheckStateOK, nil
}