slacknotifier

package
v0.0.0-...-98749a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EntryPoint

func EntryPoint(ctx context.Context, m *pubsub.Message) error

EntryPoint consumes a Pub/Sub message to send notification via Slack

func NewSlackWebhookMessageForCompute

func NewSlackWebhookMessageForCompute(
	projectID string,
	zone string,
	timestamp string,
	instanceName string,
	message string,
	color string,
) *slack.WebhookMessage

NewSlackWebhookMessageForCompute gets message for Slack WebHook

Types

type ComputeAPILog

type ComputeAPILog struct {
	ProtoPayload ProtoPayload `json:"protoPayload"`
	Operation    Operation    `json:"operation"`
	// contains filtered or unexported fields
}

ComputeAPILog is a JSON-style log from Compute Engine API

func NewComputeAPILog

func NewComputeAPILog(jsonPayload []byte) (*ComputeAPILog, error)

NewComputeAPILog parses JSON log from Compute Engine API and creates ComputeAPILog

func (ComputeAPILog) GetInstanceName

func (l ComputeAPILog) GetInstanceName() string

GetInstanceName returns Compute Engine instance name

func (ComputeAPILog) GetLogName

func (l ComputeAPILog) GetLogName() string

GetLogName returns name of log

func (ComputeAPILog) GetMessage

func (l ComputeAPILog) GetMessage() string

GetMessage returns Compute Engine log message

func (ComputeAPILog) GetMethodName

func (l ComputeAPILog) GetMethodName() string

GetMethodName returns Compute Engine method name

func (ComputeAPILog) GetProjectID

func (l ComputeAPILog) GetProjectID() string

GetProjectID returns GCP project ID

func (ComputeAPILog) GetTimeStamp

func (l ComputeAPILog) GetTimeStamp() string

GetTimeStamp returns timestamp of log

func (ComputeAPILog) GetZone

func (l ComputeAPILog) GetZone() string

GetZone returns GCP zone the instance locates in

type ComputeLog

type ComputeLog interface {
	GetInstanceName() string
	GetMethodName() string
	GetMessage() string
	GetProjectID() string
	GetZone() string
	GetTimeStamp() string
}

ComputeLog is a JSON-style log from Compute Engine

func NewComputeLog

func NewComputeLog(jsonPayload []byte) (ComputeLog, error)

NewComputeLog parses JSON log from any Compute Engine and creates slack webhook message

type ComputeStartupScriptLog

type ComputeStartupScriptLog struct {
	JSONPayload JSONPayload `json:"jsonPayload"`
	// contains filtered or unexported fields
}

ComputeStartupScriptLog is a JSON-style message of Compute Engine startup script on Cloud Logging

func NewComputeStartupScriptLog

func NewComputeStartupScriptLog(jsonPayload []byte) (*ComputeStartupScriptLog, error)

NewComputeStartupScriptLog parses JSON log from Compute Engine startup script and creates ComputeStartupScriptLog

func (ComputeStartupScriptLog) GetInstanceName

func (l ComputeStartupScriptLog) GetInstanceName() string

GetInstanceName returns Compute Engine instance name

func (ComputeStartupScriptLog) GetLogName

func (l ComputeStartupScriptLog) GetLogName() string

GetLogName returns name of log

func (ComputeStartupScriptLog) GetMessage

func (l ComputeStartupScriptLog) GetMessage() string

GetMessage returns Compute Engine log message

func (ComputeStartupScriptLog) GetMethodName

func (l ComputeStartupScriptLog) GetMethodName() string

GetMethodName returns Compute Engine method name

func (ComputeStartupScriptLog) GetProjectID

func (l ComputeStartupScriptLog) GetProjectID() string

GetProjectID returns GCP project ID

func (ComputeStartupScriptLog) GetTimeStamp

func (l ComputeStartupScriptLog) GetTimeStamp() string

GetTimeStamp returns timestamp of log

func (ComputeStartupScriptLog) GetZone

func (l ComputeStartupScriptLog) GetZone() string

GetZone returns GCP zone the instance locates in

type Config

type Config struct {
	Teams    map[string]string `yaml:"teams"`
	Severity []Severity        `yaml:"severity"`
	Rules    []Rule            `yaml:"rules"`
}

Config is a Slack notifier

func NewConfig

func NewConfig(configYAML []byte) (*Config, error)

NewConfig creates new Notifier from config YAML

func (Config) FindColorByMessage

func (c Config) FindColorByMessage(message string) (string, error)

FindColorByMessage returns color by maching regex with message

func (Config) FindTeamsByInstanceName

func (c Config) FindTeamsByInstanceName(target string) (map[string]struct{}, error)

FindTeamsByInstanceName returns matched URLs of target teams

func (Config) GetWebHookURLsFromTeams

func (c Config) GetWebHookURLsFromTeams(teams map[string]struct{}) (map[string]struct{}, error)

GetWebHookURLsFromTeams returns webhook URLs set from the given teams

type JSONPayload

type JSONPayload struct {
	HostName string `json:"_HOSTNAME"`
	Message  string `json:"MESSAGE"`
}

JSONPayload is a nested field of MessageBody

type Labels

type Labels struct {
	ProjectID string `json:"project_id"`
	Zone      string `json:"zone"`
}

Labels is a nested field of Resource

type Operation

type Operation struct {
	Last bool `json:"last"`
}

Operation is a nested field of Operation

type ProtoPayload

type ProtoPayload struct {
	MethodName   string `json:"methodName"`
	ResourceName string `json:"resourceName"`
}

ProtoPayload is a nested field of ProtoPayload

type Resource

type Resource struct {
	Labels Labels `json:"labels"`
	Type   string `json:"type"`
}

Resource is a nested field of MessageBody

type Rule

type Rule struct {
	Name         string   `yaml:"name"`
	Regex        string   `yaml:"regex"`
	ExcludeRegex *string  `yaml:"excludeRegex"`
	TargetTeams  []string `yaml:"targetTeams"`
}

Rule is a notification rule for Slack

type Severity

type Severity struct {
	Color string `yaml:"color"`
	Regex string `yaml:"regex"`
}

Severity represents relationships betwen color and regex

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL