mirror of
https://github.com/valitydev/botkube.git
synced 2024-11-06 08:25:19 +00:00
Merge pull request #1 from valitydev/ft/TD-74
TD-74::add filter to show pod's url in kibana
This commit is contained in:
commit
9b3a8b128f
@ -55,3 +55,6 @@ communications:
|
||||
webhook:
|
||||
enabled: false
|
||||
url: 'WEBHOOK_URL' # e.g https://example.com:80
|
||||
|
||||
podLogsDashboard:
|
||||
url: "KIBANA_URL" # url with '%s' to fill it with pod name, e.g. https://kibana-url.com/?query:(language:kuery,query:'kubernetes.pod.name:%20%22%s%22')
|
||||
|
@ -138,6 +138,7 @@ type CommunicationsConfig struct {
|
||||
Webhook Webhook
|
||||
Teams Teams
|
||||
ElasticSearch ElasticSearch
|
||||
PodLogsDashboard PodLogsDashboard
|
||||
}
|
||||
|
||||
// Slack configuration to authentication and send notifications
|
||||
@ -211,6 +212,12 @@ type Webhook struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
// PodLogsDashboard configuration containing URL template with pod name mask
|
||||
//to fill and send if errors occurred
|
||||
type PodLogsDashboard struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
// Kubectl configuration for executing commands inside cluster
|
||||
type Kubectl struct {
|
||||
Enabled bool
|
||||
|
@ -55,6 +55,7 @@ type Event struct {
|
||||
|
||||
Recommendations []string
|
||||
Warnings []string
|
||||
LogsUrlMsg string
|
||||
}
|
||||
|
||||
// LevelMap is a map of event type to Level
|
||||
|
54
pkg/filterengine/filters/deploy_errors_checker.go
Normal file
54
pkg/filterengine/filters/deploy_errors_checker.go
Normal file
@ -0,0 +1,54 @@
|
||||
package filters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/infracloudio/botkube/pkg/config"
|
||||
"github.com/infracloudio/botkube/pkg/events"
|
||||
"github.com/infracloudio/botkube/pkg/filterengine"
|
||||
"github.com/infracloudio/botkube/pkg/log"
|
||||
"github.com/infracloudio/botkube/pkg/utils"
|
||||
coreV1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
Message = "You can see your pod's errors in kibana:"
|
||||
)
|
||||
|
||||
type DeployErrorsChecker struct {
|
||||
Description string
|
||||
}
|
||||
|
||||
func (d DeployErrorsChecker) Run(object interface{}, event *events.Event) {
|
||||
if event.Kind != "Pod" || event.Type != config.ErrorEvent {
|
||||
return
|
||||
}
|
||||
commConfig, confErr := config.NewCommunicationsConfig()
|
||||
if confErr != nil {
|
||||
log.Errorf("Error in loading configuration. %s", confErr.Error())
|
||||
return
|
||||
}
|
||||
if commConfig == nil {
|
||||
log.Errorf("Error in loading configuration.")
|
||||
return
|
||||
}
|
||||
var podObj coreV1.Pod
|
||||
err := utils.TransformIntoTypedObject(object.(*unstructured.Unstructured), &podObj)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to transform object type: %v, into type: %v", reflect.TypeOf(object), reflect.TypeOf(podObj))
|
||||
}
|
||||
searchUrlTemplate := commConfig.Communications.PodLogsDashboard.URL
|
||||
event.LogsUrlMsg = fmt.Sprintf(Message+"[LOGS URL]("+searchUrlTemplate+")", podObj.Name)
|
||||
}
|
||||
|
||||
func (d DeployErrorsChecker) Describe() string {
|
||||
return d.Description
|
||||
}
|
||||
|
||||
// Register filter
|
||||
func init() {
|
||||
filterengine.DefaultFilterEngine.Register(DeployErrorsChecker{
|
||||
Description: "Checks if errors occurred while deployment and adds link to kibana for that pod.",
|
||||
})
|
||||
}
|
@ -22,12 +22,11 @@ package notify
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/infracloudio/botkube/pkg/config"
|
||||
"github.com/infracloudio/botkube/pkg/events"
|
||||
"github.com/infracloudio/botkube/pkg/log"
|
||||
"github.com/nlopes/slack"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var attachmentColor = map[config.Level]string{
|
||||
@ -317,6 +316,9 @@ func FormatShortMessage(event events.Event) (msg string) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(event.LogsUrlMsg) > 0 {
|
||||
msg += fmt.Sprintf("\n%s", event.LogsUrlMsg)
|
||||
}
|
||||
// Add message in the attachment if there is any
|
||||
if len(additionalMsg) > 0 {
|
||||
msg += fmt.Sprintf("```\n%s```", additionalMsg)
|
||||
|
Loading…
Reference in New Issue
Block a user