-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This Commit - adds `NodeEventsChecker` filter to send notifs on node level critical events like `NodeNotReady` and `NodeReady`
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// NodeEventsChecker filter to send notifications on critical node events | ||
|
||
package filters | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/infracloudio/botkube/pkg/events" | ||
"github.com/infracloudio/botkube/pkg/filterengine" | ||
apiV1 "k8s.io/api/core/v1" | ||
|
||
log "github.com/infracloudio/botkube/pkg/logging" | ||
) | ||
|
||
const ( | ||
// NodeNotReady reason indicates Node is NotReady state | ||
NodeNotReady string = "NodeNotReady" | ||
// NodeReady reason indicates Node is Ready state | ||
NodeReady string = "NodeReady" | ||
) | ||
|
||
// NodeEventsChecker checks job status and adds message in the events structure | ||
type NodeEventsChecker struct { | ||
Description string | ||
} | ||
|
||
// Register filter | ||
func init() { | ||
filterengine.DefaultFilterEngine.Register(NodeEventsChecker{ | ||
Description: "Sends notifications on node level critical events.", | ||
}) | ||
} | ||
|
||
// Run filers and modifies event struct | ||
func (f NodeEventsChecker) Run(object interface{}, event *events.Event) { | ||
|
||
// Run filter only on Node events | ||
if event.Kind != "Node" { | ||
return | ||
} | ||
|
||
eventObj, ok := object.(*apiV1.Event) | ||
if !ok { | ||
return | ||
} | ||
|
||
// update event details | ||
switch event.Reason { | ||
case NodeNotReady: | ||
event.Level = events.Critical | ||
case NodeReady: | ||
event.Level = events.Info | ||
event.Messages = []string{fmt.Sprintf("%s\n", eventObj.Message)} | ||
default: | ||
// skip events with least significant reasons | ||
event.Skip = true | ||
} | ||
|
||
log.Logger.Debug("Node Critical Event filter successful!") | ||
} | ||
|
||
// Describe filter | ||
func (f NodeEventsChecker) Describe() string { | ||
return f.Description | ||
} |