Skip to content

Commit e596843

Browse files
committed
Introduce schemav1#IcingaState
1 parent be1e77e commit e596843

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pkg/schema/v1/icinga_state.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package v1
2+
3+
import (
4+
"database/sql/driver"
5+
"fmt"
6+
)
7+
8+
type IcingaState uint8
9+
10+
const (
11+
Ok IcingaState = iota
12+
Warning
13+
Critical
14+
Unknown
15+
Pending IcingaState = 99
16+
)
17+
18+
func (s IcingaState) String() string {
19+
switch s {
20+
case Ok:
21+
return "ok"
22+
case Warning:
23+
return "warning"
24+
case Critical:
25+
return "critical"
26+
case Unknown:
27+
return "unknown"
28+
case Pending:
29+
return "pending"
30+
default:
31+
panic(fmt.Sprintf("invalid Icinga state %d", s))
32+
}
33+
}
34+
35+
// Value implements the driver.Valuer interface.
36+
func (s IcingaState) Value() (driver.Value, error) {
37+
return s.String(), nil
38+
}
39+
40+
// Assert interface compliance.
41+
var (
42+
_ fmt.Stringer = (*IcingaState)(nil)
43+
_ driver.Valuer = (*IcingaState)(nil)
44+
)

0 commit comments

Comments
 (0)