Documentation
¶
Index ¶
- Constants
- func GenerateMetricsGraphAndLink(detail *cw.EventDetails, cfg *Config) (string, error)
- func GetOwnerFromTags(tags cw.AlarmTags) string
- func GetPagerDutyRoutingKey(ServiceName string) string
- func GetServiceNameFromTags(tags cw.AlarmTags) string
- func GetSlackChannel(tags cw.AlarmTags) string
- func GetSlackChannelFromOwner(owner string) string
- func GetSlackChannelOverrideFromTags(tags cw.AlarmTags) string
- func HandleRequest(ctx context.Context, sqsEvent awsevents.SQSEvent) (string, error)
- func ProcessSQSEvent(d *cw.EventDetails) error
- func SetConfig(c *Config)
- func Start()
- type Config
- type ConfigOptions
- func WithCWClient(cw *cw.Client) ConfigOptions
- func WithDefaultPagerDutyRoutingKey(key string) ConfigOptions
- func WithDefaultSlackChannel(channel string) ConfigOptions
- func WithImageBucket(bucket string) ConfigOptions
- func WithImageBucketPrefix(p string) ConfigOptions
- func WithImageBucketRegion(r string) ConfigOptions
- func WithImageBucketRoleArn(r string) ConfigOptions
- func WithImageHost(host string) ConfigOptions
- func WithLogLevel(level string) ConfigOptions
- func WithPagerDutyClient(pdclient *pagerduty.Client) ConfigOptions
- func WithParameterStoreClient(psclient *parameterstore.Client) ConfigOptions
- func WithS3Client(s3c *s3.Client) ConfigOptions
- func WithSlackAlternativeURL(url string) ConfigOptions
- func WithSlackClient(sclient *slack.Client) ConfigOptions
- func WithSlackToken(token string) ConfigOptions
Constants ¶
const ( // default configuration values: // DefaultlOwnerTagKey is the AWS tag key to look for the team owner of the alarm DefaultOwnerTagKey = "owner" // DefaultServiceNameTagKey is the AWS tag key to look for the service name the alert is from DefaultServiceNameTagKey = "service" // DefaultSlackChannelOverrideTagKey is the AWS tag which specifies the slack channel these alerts should be sent to DefaultSlackChannelOverrideTagKey = "alerts:slack_channel" //PagerDutySuppressAlarmsTagKey is the AWS tag which specifies whether we should suppress alarms in PagerDuty for this alarm // must contain "true" to enable - else it will be considered false (whether empty or not) // note: the logic to handle this is actually in PagerDuty event rules - since we can inspect the tags there DefaultPagerDutySuppressAlarmsTagKey = "alerts:suppress_pagerduty" // PagerDutyRoutingKeySSMPattern is the base ssm key name where other services put their routing key DefaultPagerDutyRoutingKeySSMPattern = "/service/cw_alert_router/pagerduty/routing_keys/%s" // environment variable keys: // SlackTokenSSMKeyEnv is the environment variable key for the slack token ssm key value SlackTokenSSMKeyEnv = "SLACK_TOKEN_SSM_KEY" // DefaultSlackChannelEnv is the environment variable key for the default slack channel DefaultSlackChannelEnv = "DEFAULT_SLACK_CHANNEL" // DefaultPagerDutyRoutingKeyEnv is the environment variable key for the pagerduty routing key DefaultPagerDutyRoutingKeyEnv = "PAGERDUTY_DEFAULT_ROUTING_KEY" // ImageBucketEnv is the environment variable key for the images bucket ImageBucketEnv = "IMAGE_BUCKET" // ImageBucketRegionEnv is the environment variable key for the images bucket region ImageBucketRegionEnv = "IMAGE_BUCKET_REGION" // ImageBucketRoleArnEnv is the env var key to find the role arn to use when writing to the images bucket ImageBucketRoleArnEnv = "IMAGE_BUCKET_ROLE_ARN" // ImageBucketPrefix is the env var key to find the s3 prefix used for storing images ImageBucketPrefixEnv = "IMAGE_BUCKET_PREFIX" // LogLevelEnv is the environment variable key for setting the global log level LogLevelEnv = "LOG_LEVEL" // ImageHostEnv is the env variable key for the images host (ie: where images can be fetched externally) ImageHostEnv = "IMAGE_HOST" // OwnerTagKeyEnv is used to override the default owner tag key OwnerTagKeyEnv = "OWNER_TAG_KEY" // ServiceNameTagKey is used to override the default service name tag key ServiceNameTagKeyEnv = "SERVICE_NAME_TAG_KEY" )
Variables ¶
This section is empty.
Functions ¶
func GenerateMetricsGraphAndLink ¶
func GenerateMetricsGraphAndLink(detail *cw.EventDetails, cfg *Config) (string, error)
GenerateMetricsGraphAndLink takes the cloudwatch event and generates a graph (stored on S3) - it will then return a url based on the configured endpoint (eg: cloudfront or s3 web hosting)
func GetOwnerFromTags ¶
GetOwnerFromTags returns the owning team name from the given tags
func GetPagerDutyRoutingKey ¶
GetPagerDutyRoutingKey returns the PagerDuty routing key given the service name. 1. if ServiceName is empty, then the default pagerduty routing key is returned - ServiceName is lowercased, and hyphens replaced with underscores 2. if /service/alert-router/pagerduty/routing_keys/${service_name} exists - use that value 3. else return the default routing key
func GetServiceNameFromTags ¶
GetServiceNameFromTags returns the service name from the given tags
func GetSlackChannel ¶
GetSlackChannel determines which slack channel we send messages to based on owner or the alerts:slack_channel override (fallback = default channel via env variable)
func GetSlackChannelFromOwner ¶
GetSlackChannelFromOwner returns the slack channel name given the owner name note:
- if owner is empty, the default slack channel (stored in config) is used - owner name is converted to lowercase
- else, use "${owner}-alarms"
func GetSlackChannelOverrideFromTags ¶
GetSlackChannelOverrideFromTags returns the slack channel override from the given tags
func HandleRequest ¶
HandleRequest is the main entrypoint for the lambda
func ProcessSQSEvent ¶
func ProcessSQSEvent(d *cw.EventDetails) error
ProcessSQSEvent handles the cloudwatch event from SQS
Types ¶
type Config ¶
type Config struct { // DefaultSlackChannel is used when no owner tag is found - ie: we don't know who owns the alert. // This must be set via environment variables on the lambda DefaultSlackChannel string // ServiceNameTagKey is the AWS tag key for the name of the service (used to lookup SSM keys for the pagerduty routing key) ServiceNameTagKey string // OwnerTagKEy is the AWS tag key for the owner of the service (used to generate slack channel names) OwnerTagKey string // ImageBucket used for hosting our graph images in the slack messages ImageBucket string // ImageBucketRegion is used to specify the image bucket region when the region differs from the default ImageBucketRegion string // ImageBucketRoleArn is the role to assume when writing to the images bucket ImageBucketRoleArn string // ImageBucketPrefix is the s3 prefix to use for images ImageBucketPrefix string // ImageHost is used for actually accessing the images we write to s3. eg: https://cf-site.test.com ImageHost string // DefaultPagerDutyRoutingKey is for when an alert comes through and we cannot determine the pagerduty routing key, // we use this. The normal way to get this value is via parameter store - the default routing key should be // configured via env DefaultPagerDutyRoutingKey string // contains filtered or unexported fields }
Config holds configuration options for the lambda
func NewConfig ¶
func NewConfig(options ...ConfigOptions) (*Config, error)
NewConfig returns a new lambda Config struct
func (Config) PagerDutyClient ¶
PagerDutyClient returns the internal PagerDuty client
func (*Config) ParameterStoreClient ¶
func (c *Config) ParameterStoreClient() *parameterstore.Client
ParameterStoreClient just returns the internal parameter store client
func (*Config) SetLogLevel ¶
SetLogLevel sets the global log level
func (Config) SlackClient ¶
SlackClient returns the internal Slack client
type ConfigOptions ¶
type ConfigOptions func(*Config)
ConfigOptions provides a way to override settings in the lambda Config struct
func WithCWClient ¶
func WithCWClient(cw *cw.Client) ConfigOptions
WithCWClient allows overriding of the Alarms client
func WithDefaultPagerDutyRoutingKey ¶
func WithDefaultPagerDutyRoutingKey(key string) ConfigOptions
WithDefaultPagerDutyRoutingKey allows setting the PagerDuty default routing key during New
func WithDefaultSlackChannel ¶
func WithDefaultSlackChannel(channel string) ConfigOptions
WithDefaultSlackChannel allows setting the default slack channel during New
func WithImageBucket ¶
func WithImageBucket(bucket string) ConfigOptions
WithImageBucket allows setting the image bucket during New instead of fetching from env
func WithImageBucketPrefix ¶
func WithImageBucketPrefix(p string) ConfigOptions
WithImageBucketPrefix sets the s3 bucket prefix used for writing images
func WithImageBucketRegion ¶
func WithImageBucketRegion(r string) ConfigOptions
WithImageBucketRegion allows setting the image bucket region during New instead of fetching from env
func WithImageBucketRoleArn ¶
func WithImageBucketRoleArn(r string) ConfigOptions
WithImageBucketRoleArn allows specifying the role arn to use for s3 writes instead of fetching from env
func WithImageHost ¶
func WithImageHost(host string) ConfigOptions
WithImageHost allows setting the image host during New instead of fetching from env
func WithLogLevel ¶
func WithLogLevel(level string) ConfigOptions
WithLogLevel allows specifying log level during New
func WithPagerDutyClient ¶
func WithPagerDutyClient(pdclient *pagerduty.Client) ConfigOptions
WithPagerDutyClient allows overriding of the pagerduty client
func WithParameterStoreClient ¶
func WithParameterStoreClient(psclient *parameterstore.Client) ConfigOptions
WithParameterStoreClient allows overriding of the parameterstore client
func WithS3Client ¶
func WithS3Client(s3c *s3.Client) ConfigOptions
WithS3Client allows overriding of the S3 client
func WithSlackAlternativeURL ¶
func WithSlackAlternativeURL(url string) ConfigOptions
WithSlackAlternativeURL allows setting the slack API url during New
func WithSlackClient ¶
func WithSlackClient(sclient *slack.Client) ConfigOptions
WithSlackClient allows overriding of the slack client
func WithSlackToken ¶
func WithSlackToken(token string) ConfigOptions
WithSlackToken allows setting the slack API token during New