forked from mperham/inspeqtor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.go
60 lines (50 loc) · 1.09 KB
/
events.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
package inspeqtor
import (
"fmt"
"os"
)
/*
There are several different types of Events:
* Process disappeared (or did not exist when we started up)
* Process appeared
* Rule failed check
* Rule has recovered
*/
type EventType string
const (
ProcessDoesNotExist EventType = "ProcessDoesNotExist"
ProcessExists EventType = "ProcessExists"
RuleFailed EventType = "RuleFailed"
RuleRecovered EventType = "RuleRecovered"
)
var (
Events = []EventType{ProcessDoesNotExist, ProcessExists, RuleFailed, RuleRecovered}
)
func (s EventType) String() string {
return string(s)
}
type Event struct {
Type EventType
Checkable
*Rule
}
func (e *Event) Service() *Service {
return e.Checkable.(*Service)
}
func (e *Event) Hostname() string {
hostname, err := os.Hostname()
if err != nil {
return err.Error()
}
return hostname
}
func (e *Event) Target() string {
switch x := e.Checkable.(type) {
case *Service:
return fmt.Sprintf("%s[%s]", e.Hostname(), x.Name())
case *Host:
return fmt.Sprintf("%s", x.Name())
default:
return fmt.Sprintf("Unknown: %s", e.Checkable)
}
}