cw

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//MetricNamesKey is the map[string]string key used for the metric names in MetricList()
	MetricNamesKey = "names"
	//MetricDimensionsKey is the map[string]string key used for the metric dimensions in MetricList()
	MetricDimensionsKey = "dimensions"
	//MetricNamespacesKey is the map[string]string key used for the metric namespaces in MetricList()
	MetricNamespacesKey = "namespaces"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlarmConfiguration

type AlarmConfiguration struct {
	Metrics []AlarmMetric `json:"metrics"`
}

AlarmConfiguration wraps cloudwatch alarm config from the event payload

type AlarmEventDetail

type AlarmEventDetail struct {
	State         AlarmState         `json:"state"`
	PreviousState AlarmState         `json:"previousState"`
	Configuration AlarmConfiguration `json:"configuration"`
	AlarmName     string             `json:"alarmName"`
	// Tags is not actually present in the event payload.  We need to inject this ourselves
	Tags AlarmTags `json:"tags"`
}

AlarmEventDetail wraps the cloudwatch alarm detail as sent via Eventbridge -> SQS -> Lambda

type AlarmMetric

type AlarmMetric struct {
	ReturnData bool            `json:"returnData"`
	ID         string          `json:"id"`
	MetricStat AlarmMetricStat `json:"metricStat"`
}

AlarmMetric wraps the cloudwatch alarm metric config

type AlarmMetricDetail

type AlarmMetricDetail struct {
	Namespace  string            `json:"namespace"`
	Name       string            `json:"name"`
	Dimensions map[string]string `json:"dimensions"`
}

AlarmMetricDetail wraps the individual alarm metric

func (AlarmMetricDetail) AWSDimensions

func (d AlarmMetricDetail) AWSDimensions() []*cloudwatch.Dimension

AWSDimensions returns our map[string]string dimensions in aws formatted cloudwatch.Dimension

type AlarmMetricStat

type AlarmMetricStat struct {
	Stat   string            `json:"stat"`
	Period int64             `json:"period"`
	Metric AlarmMetricDetail `json:"metric"`
}

AlarmMetricStat wraps the cloudwatch alarm metric stat config

type AlarmState

type AlarmState struct {
	Value      string `json:"value"`
	Timestamp  string `json:"timestamp"`
	ReasonData string `json:"reasonData"`
	Reason     string `json:"reason"`
}

AlarmState contains the cloudwatch alarm state details

type AlarmTags

type AlarmTags map[string]string

AlarmTags is an AWS tag list converted to a map[string]string

type Client

type Client struct {
	CWClient cloudwatchiface.CloudWatchAPI
}

Client provides methods to get information on a specific cloudwatch alarm.

func New

func New() (*Client, error)

New returns a new cw Client

func (*Client) GetAlarmTags

func (c *Client) GetAlarmTags(alarmARN string) (AlarmTags, error)

GetAlarmTags returns a list of alarm tags from the given alarm ARN

type EventDetails

type EventDetails struct {
	Account    string           `json:"account"`
	Version    string           `json:"version"`
	Time       string           `json:"time"`
	Source     string           `json:"source"`
	Resources  []string         `json:"resources"`
	Region     string           `json:"region"`
	ID         string           `json:"id"`
	DetailType string           `json:"detail-type"`
	Detail     AlarmEventDetail `json:"detail"`
	// contains filtered or unexported fields
}

EventDetails contains the actual event details as received by SQS

func (*EventDetails) AlarmARN

func (d *EventDetails) AlarmARN() (string, error)

AlarmARN returns the arn for the alarm that sent this event

func (d *EventDetails) AlarmConsoleLink() string

AlarmConsoleLink provides a URL straight to the AWS console so users can view the alarm details

func (*EventDetails) GetMetricDataRequestForHrs

func (d *EventDetails) GetMetricDataRequestForHrs(hrs ...int) (*cloudwatch.MetricDataResult, error)

GetMetricDataForHrs returns metric data for the given event over the last N hours (default is 1 hour)

func (*EventDetails) InjectTags

func (d *EventDetails) InjectTags() error

InjectTags adds the AWS tags on the related cloudwatch alarm

func (*EventDetails) MetricList

func (d *EventDetails) MetricList() map[string][]string

MetricList returns a map[string]string with all metric names & namespaces for this alarm (it will stick all namespaces, dimensions and names under the respective keys... if there are more than 1 of each)

func (*EventDetails) SetCWClient

func (d *EventDetails) SetCWClient(c *Client)

SetCWClient sets the cloudwatch client to use for internal operations

Jump to

Keyboard shortcuts

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