Make AlertDown required for a Monitor
This commit is contained in:
parent
6b9edf75d7
commit
1b07059825
@ -31,7 +31,10 @@ type Monitor struct {
|
|||||||
func (monitor Monitor) IsValid() bool {
|
func (monitor Monitor) IsValid() bool {
|
||||||
atLeastOneCommand := (monitor.CommandShell != "" || monitor.Command != nil)
|
atLeastOneCommand := (monitor.CommandShell != "" || monitor.Command != nil)
|
||||||
atMostOneCommand := (monitor.CommandShell == "" || monitor.Command == nil)
|
atMostOneCommand := (monitor.CommandShell == "" || monitor.Command == nil)
|
||||||
return atLeastOneCommand && atMostOneCommand && monitor.getAlertAfter() > 0
|
return (atLeastOneCommand &&
|
||||||
|
atMostOneCommand &&
|
||||||
|
monitor.getAlertAfter() > 0 &&
|
||||||
|
monitor.AlertDown != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldCheck returns a boolean indicating if the Monitor is ready to be
|
// ShouldCheck returns a boolean indicating if the Monitor is ready to be
|
||||||
|
@ -13,16 +13,16 @@ func TestMonitorIsValid(t *testing.T) {
|
|||||||
expected bool
|
expected bool
|
||||||
name string
|
name string
|
||||||
}{
|
}{
|
||||||
{Monitor{Command: []string{"echo", "test"}}, true, "Command only"},
|
{Monitor{Command: []string{"echo", "test"}, AlertDown: []string{"log"}}, true, "Command only"},
|
||||||
{Monitor{CommandShell: "echo test"}, true, "CommandShell only"},
|
{Monitor{CommandShell: "echo test", AlertDown: []string{"log"}}, true, "CommandShell only"},
|
||||||
{Monitor{}, false, "No commands"},
|
{Monitor{Command: []string{"echo", "test"}}, false, "No AlertDown"},
|
||||||
|
{Monitor{AlertDown: []string{"log"}}, false, "No commands"},
|
||||||
{
|
{
|
||||||
Monitor{Command: []string{"echo", "test"}, CommandShell: "echo test"},
|
Monitor{Command: []string{"echo", "test"}, CommandShell: "echo test", AlertDown: []string{"log"}},
|
||||||
false,
|
false,
|
||||||
"Both commands",
|
"Both commands",
|
||||||
},
|
},
|
||||||
{Monitor{AlertAfter: -1}, false, "Invalid alert threshold, -1"},
|
{Monitor{Command: []string{"echo", "test"}, AlertDown: []string{"log"}, AlertAfter: -1}, false, "Invalid alert threshold, -1"},
|
||||||
{Monitor{AlertAfter: 0}, false, "Invalid alert threshold, 0"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
Loading…
Reference in New Issue
Block a user