Documentation ¶
Index ¶
- Constants
- Variables
- func ExpressionToString(expr hcl.Expression, evalCtx *hcl.EvalContext) (string, error)
- func GenerateInitialConfig(sqsQueueName string, orgName string) ([]byte, error)
- func RunCLI(ctx context.Context, args []string, setLogLevel func(string)) error
- type Alert
- type App
- func (app *App) Backend() Backend
- func (app *App) CheckBasicAuth(r *http.Request) bool
- func (app *App) Close() error
- func (app *App) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
- func (app *App) EnableBasicAuth() bool
- func (app *App) EnableWebhookServer() bool
- func (app *App) Exec(ctx context.Context, opts *ExecOptions) error
- func (app *App) ExecuteRules(ctx context.Context, body *WebhookBody) error
- func (app *App) Init(ctx context.Context, outputPath string) error
- func (app *App) LoadConfig(dir string, optFns ...func(*LoadConfigOptions)) error
- func (app *App) LoadPlugin(ctx context.Context, cfg *LoadPluginConfig) error
- func (app *App) MackerelService() *MackerelService
- func (app *App) NewEvalContext(body *WebhookBody) (*hcl.EvalContext, error)
- func (app *App) NewRule(ruleName string) *Rule
- func (app *App) ProviderList() []string
- func (app *App) QueryList() []string
- func (app *App) RetryPolicy() *RetryPolicy
- func (app *App) Rules() []*Rule
- func (app *App) Run(ctx context.Context, opts *RunOptions) error
- func (app *App) SQSQueueName() string
- func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *App) SetMackerelClient(client MackerelClient) *App
- func (app *App) SetupS3Buckend(body hcl.Body) hcl.Diagnostics
- func (app *App) UnwrapAndDumpDiagnoctics(err error) error
- func (app *App) WebhookServerIsReady() bool
- func (app *App) WithPrepalertFunctions(evalCtx *hcl.EvalContext) *hcl.EvalContext
- func (app *App) WorkerIsReady() bool
- type Backend
- type CLI
- type DiscardBackend
- type ErrorHandling
- type ExecOptions
- type Host
- type LoadConfigOptions
- type LoadPluginConfig
- type MackerelClient
- type MackerelService
- func (svc *MackerelService) GetAlertWithCache(ctx context.Context, alertID string) (*mackerel.Alert, error)
- func (svc *MackerelService) GetMonitorByAlertID(ctx context.Context, alertID string) (mackerel.Monitor, error)
- func (svc *MackerelService) GetMonitorWithCache(ctx context.Context, monitorID string) (mackerel.Monitor, error)
- func (svc *MackerelService) NewEmulatedWebhookBody(ctx context.Context, alertID string) (*WebhookBody, error)
- func (svc *MackerelService) NewExampleWebhookBody() *WebhookBody
- func (svc *MackerelService) NewMackerelUpdater(body *WebhookBody, backend Backend) *MackerelUpdater
- func (svc *MackerelService) PostGraphAnnotation(ctx context.Context, params *mackerel.GraphAnnotation) error
- func (svc *MackerelService) UpdateAlertMemo(ctx context.Context, alertID string, memo string) error
- type MackerelUpdater
- func (u *MackerelUpdater) AddAdditionalDescription(service string, text string)
- func (u *MackerelUpdater) AddMemoSectionText(sectionName string, text string, sizeLimit *int)
- func (u *MackerelUpdater) AddService(service string)
- func (u *MackerelUpdater) Flush(ctx context.Context, evalCtx *hcl.EvalContext) error
- type PostGraphAnnotationAction
- func (action *PostGraphAnnotationAction) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
- func (action *PostGraphAnnotationAction) DependsOnQueries() []string
- func (action *PostGraphAnnotationAction) Enable() bool
- func (action *PostGraphAnnotationAction) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
- type RequestIDGenerator
- type RetryPolicy
- type Role
- type Rule
- func (rule *Rule) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
- func (rule *Rule) DependsOnQueries() []string
- func (rule *Rule) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
- func (rule *Rule) Match(evalCtx *hcl.EvalContext) bool
- func (rule *Rule) Name() string
- func (rule *Rule) PostGraphAnnotationAction() *PostGraphAnnotationAction
- func (rule *Rule) Priority() int
- func (rule *Rule) UpdateAlertAction() *UpdateAlertAction
- type RunOptions
- type S3Backend
- func (b *S3Backend) EnableGoogleAuth() bool
- func (b *S3Backend) IsEmpty() bool
- func (b *S3Backend) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *S3Backend) String() string
- func (b *S3Backend) Upload(ctx context.Context, evalCtx *hcl.EvalContext, name string, body io.Reader) (string, bool, error)
- type S3Client
- type Service
- type UpdateAlertAction
- func (action *UpdateAlertAction) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
- func (action *UpdateAlertAction) DependsOnQueries() []string
- func (action *UpdateAlertAction) Enable() bool
- func (action *UpdateAlertAction) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
- type WebhookBody
Constants ¶
View Source
const (
HeaderRequestID = "Prepalert-Request-ID"
)
Variables ¶
View Source
var ( GraphAnnotationDescriptionMaxSize = 1024 AlertMemoMaxSize = 80 * 1000 CacheDuration = 1 * time.Minute )
View Source
var Version = "v1.0.2"
Functions ¶
func ExpressionToString ¶ added in v0.12.0
func GenerateInitialConfig ¶ added in v0.12.0
Types ¶
type Alert ¶
type Alert struct { OpenedAt int64 `json:"openedAt" cty:"opened_at"` ClosedAt *int64 `json:"closedAt" cty:"closed_at"` CreatedAt int64 `json:"createdAt" cty:"created_at"` CriticalThreshold *float64 `json:"criticalThreshold,omitempty" cty:"critical_threshold,omitempty"` Duration int64 `json:"duration" cty:"duration"` IsOpen bool `json:"isOpen" cty:"is_open"` MetricLabel string `json:"metricLabel" cty:"metric_label"` MetricValue float64 `json:"metricValue" cty:"metric_value"` MonitorName string `json:"monitorName" cty:"monitor_name"` MonitorOperator string `json:"monitorOperator" cty:"monitor_operator"` Status string `json:"status" cty:"status"` Trigger string `json:"trigger" cty:"trigger"` ID string `json:"id" cty:"id"` URL string `json:"url" cty:"url"` WarningThreshold *float64 `json:"warningThreshold,omitempty" cty:"warning_threshold,omitempty"` }
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) DecodeBody ¶ added in v0.12.0
func (app *App) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
func (*App) EnableBasicAuth ¶
func (*App) EnableWebhookServer ¶ added in v0.12.0
func (*App) Exec ¶ added in v0.5.0
func (app *App) Exec(ctx context.Context, opts *ExecOptions) error
func (*App) ExecuteRules ¶ added in v0.12.0
func (app *App) ExecuteRules(ctx context.Context, body *WebhookBody) error
func (*App) LoadConfig ¶ added in v0.12.0
func (app *App) LoadConfig(dir string, optFns ...func(*LoadConfigOptions)) error
func (*App) LoadPlugin ¶ added in v0.12.0
func (app *App) LoadPlugin(ctx context.Context, cfg *LoadPluginConfig) error
func (*App) MackerelService ¶ added in v0.12.0
func (app *App) MackerelService() *MackerelService
func (*App) NewEvalContext ¶ added in v0.12.0
func (app *App) NewEvalContext(body *WebhookBody) (*hcl.EvalContext, error)
func (*App) ProviderList ¶ added in v0.12.0
func (*App) RetryPolicy ¶ added in v1.0.0
func (app *App) RetryPolicy() *RetryPolicy
func (*App) SQSQueueName ¶ added in v0.12.0
func (*App) SetMackerelClient ¶ added in v0.12.0
func (app *App) SetMackerelClient(client MackerelClient) *App
func (*App) SetupS3Buckend ¶ added in v0.12.0
func (app *App) SetupS3Buckend(body hcl.Body) hcl.Diagnostics
func (*App) UnwrapAndDumpDiagnoctics ¶ added in v0.12.0
func (*App) WebhookServerIsReady ¶ added in v0.12.0
func (*App) WithPrepalertFunctions ¶ added in v0.12.0
func (app *App) WithPrepalertFunctions(evalCtx *hcl.EvalContext) *hcl.EvalContext
func (*App) WorkerIsReady ¶ added in v0.12.0
type CLI ¶ added in v0.10.0
type CLI struct { LogLevel string `help:"output log-level" env:"PREPALERT_LOG_LEVEL" default:"info"` MackerelAPIKey string `name:"mackerel-apikey" help:"for access mackerel API" env:"MACKEREL_APIKEY"` ErrorHandling ErrorHandling `help:"error handling" env:"PREPALERT_ERROR_HANDLING" default:"continue" enum:"continue,return"` Config string `help:"config path" env:"PREPALERT_CONFIG" default:"."` Run *RunOptions `cmd:"" help:"run server (default command)" default:""` Init struct{} `cmd:"" help:"create initial config"` Validate struct{} `cmd:"" help:"validate the configuration"` Exec *ExecOptions `cmd:"" help:"Generate a virtual webhook from past alert to execute the rule"` Version struct{} `cmd:"" help:"Show version"` }
type DiscardBackend ¶ added in v0.12.0
type DiscardBackend struct{}
func NewDiscardBackend ¶ added in v0.12.0
func NewDiscardBackend() *DiscardBackend
func (*DiscardBackend) ServeHTTP ¶ added in v0.12.0
func (b *DiscardBackend) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*DiscardBackend) String ¶ added in v0.12.0
func (b *DiscardBackend) String() string
type ErrorHandling ¶ added in v0.12.0
type ErrorHandling int
const ( ContinueOnError ErrorHandling = iota // if load config on error, continue run ReturnOnError // if load config on error, return error )
func (ErrorHandling) String ¶ added in v0.12.0
func (e ErrorHandling) String() string
func (*ErrorHandling) UnmarshalText ¶ added in v0.12.0
func (e *ErrorHandling) UnmarshalText(text []byte) error
type ExecOptions ¶ added in v0.10.0
type ExecOptions struct {
AlertID string `arg:"" name:"alert-id" help:"Mackerel AlertID" required:""`
}
type Host ¶
type Host struct { ID string `json:"id" cty:"id"` Name string `json:"name" cty:"name"` URL string `json:"url" cty:"url"` Type string `json:"type,omitempty" cty:"type"` Status string `json:"status" cty:"status"` Memo string `json:"memo" cty:"memo"` IsRetired bool `json:"isRetired" cty:"is_retired"` Roles []*Role `json:"roles" cty:"roles,omitempty"` }
type LoadConfigOptions ¶ added in v0.12.0
type LoadPluginConfig ¶ added in v0.12.0
type MackerelClient ¶ added in v0.12.0
type MackerelClient interface { UpdateAlert(alertID string, param mackerel.UpdateAlertParam) (*mackerel.UpdateAlertResponse, error) FindGraphAnnotations(service string, from int64, to int64) ([]*mackerel.GraphAnnotation, error) UpdateGraphAnnotation(annotationID string, annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error) CreateGraphAnnotation(annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error) GetOrg() (*mackerel.Org, error) GetAlert(string) (*mackerel.Alert, error) GetMonitor(string) (mackerel.Monitor, error) FindHost(id string) (*mackerel.Host, error) }
type MackerelService ¶ added in v0.12.0
type MackerelService struct {
// contains filtered or unexported fields
}
func NewMackerelService ¶ added in v0.12.0
func NewMackerelService(client MackerelClient) *MackerelService
func (*MackerelService) GetAlertWithCache ¶ added in v0.12.0
func (svc *MackerelService) GetAlertWithCache(ctx context.Context, alertID string) (*mackerel.Alert, error)
func (*MackerelService) GetMonitorByAlertID ¶ added in v0.12.0
func (svc *MackerelService) GetMonitorByAlertID(ctx context.Context, alertID string) (mackerel.Monitor, error)
func (*MackerelService) GetMonitorWithCache ¶ added in v0.12.0
func (svc *MackerelService) GetMonitorWithCache(ctx context.Context, monitorID string) (mackerel.Monitor, error)
func (*MackerelService) NewEmulatedWebhookBody ¶ added in v0.12.0
func (svc *MackerelService) NewEmulatedWebhookBody(ctx context.Context, alertID string) (*WebhookBody, error)
func (*MackerelService) NewExampleWebhookBody ¶ added in v0.12.0
func (svc *MackerelService) NewExampleWebhookBody() *WebhookBody
func (*MackerelService) NewMackerelUpdater ¶ added in v0.12.0
func (svc *MackerelService) NewMackerelUpdater(body *WebhookBody, backend Backend) *MackerelUpdater
func (*MackerelService) PostGraphAnnotation ¶ added in v0.12.0
func (svc *MackerelService) PostGraphAnnotation(ctx context.Context, params *mackerel.GraphAnnotation) error
func (*MackerelService) UpdateAlertMemo ¶ added in v0.12.0
type MackerelUpdater ¶ added in v0.12.0
type MackerelUpdater struct {
// contains filtered or unexported fields
}
func (*MackerelUpdater) AddAdditionalDescription ¶ added in v0.12.0
func (u *MackerelUpdater) AddAdditionalDescription(service string, text string)
func (*MackerelUpdater) AddMemoSectionText ¶ added in v0.12.0
func (u *MackerelUpdater) AddMemoSectionText(sectionName string, text string, sizeLimit *int)
func (*MackerelUpdater) AddService ¶ added in v0.12.0
func (u *MackerelUpdater) AddService(service string)
type PostGraphAnnotationAction ¶ added in v0.12.0
type PostGraphAnnotationAction struct {
// contains filtered or unexported fields
}
func (*PostGraphAnnotationAction) DecodeBody ¶ added in v0.12.0
func (action *PostGraphAnnotationAction) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
func (*PostGraphAnnotationAction) DependsOnQueries ¶ added in v0.12.0
func (action *PostGraphAnnotationAction) DependsOnQueries() []string
func (*PostGraphAnnotationAction) Enable ¶ added in v0.12.0
func (action *PostGraphAnnotationAction) Enable() bool
func (*PostGraphAnnotationAction) Execute ¶ added in v0.12.0
func (action *PostGraphAnnotationAction) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
type RequestIDGenerator ¶ added in v0.12.0
var DefaultRequestIDGeneartor RequestIDGenerator = must(katsubushi.NewGenerator(1))
type RetryPolicy ¶ added in v1.0.0
type RetryPolicy struct { Interval float64 `hcl:"interval,optional"` Jitter float64 `hcl:"jitter,optional"` MaxInterval float64 `hcl:"max_interval,optional"` BackoffFactor float64 `hcl:"backoff_factor,optional"` // contains filtered or unexported fields }
func (*RetryPolicy) DecodeAttributes ¶ added in v1.0.0
func (rp *RetryPolicy) DecodeAttributes(attrs hcl.Attributes, evalCtx *hcl.EvalContext) hcl.Diagnostics
func (*RetryPolicy) SetRetryAfter ¶ added in v1.0.0
func (rp *RetryPolicy) SetRetryAfter(w http.ResponseWriter, r *http.Request)
func (*RetryPolicy) String ¶ added in v1.0.0
func (rp *RetryPolicy) String() string
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
func (*Rule) DecodeBody ¶ added in v0.12.0
func (rule *Rule) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
func (*Rule) DependsOnQueries ¶ added in v0.12.0
func (*Rule) Execute ¶ added in v0.12.0
func (rule *Rule) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
func (*Rule) PostGraphAnnotationAction ¶ added in v0.12.0
func (rule *Rule) PostGraphAnnotationAction() *PostGraphAnnotationAction
func (*Rule) UpdateAlertAction ¶ added in v0.12.0
func (rule *Rule) UpdateAlertAction() *UpdateAlertAction
type RunOptions ¶
type RunOptions struct { Mode string `help:"run mode" env:"PREPALERT_MODE" default:"all" enum:"all,http,worker,webhook"` Address string `help:"run local address" env:"PREPALERT_ADDRESS" default:":8080"` Prefix string `help:"run server prefix" env:"PREPALERT_PREFIX" default:"/"` BatchSize int `help:"run local sqs batch size" env:"PREPALERT_BATCH_SIZE" default:"1"` }
type S3Backend ¶ added in v0.12.0
type S3Backend struct { BucketName string ObjectKeyPrefix *string ObjectKeyTemplate *hcl.Expression ViewerBaseURLString string ViewerGoogleClientID *string ViewerGoogleClientSecret *string ViewerSessionEncryptKeyString *string Allowed []string Denied []string ViewerBaseURL *url.URL ViewerSessionEncryptKey []byte // contains filtered or unexported fields }
func (*S3Backend) EnableGoogleAuth ¶ added in v0.12.0
type S3Client ¶ added in v0.12.0
type S3Client interface { manager.UploadAPIClient ls3viewer.S3Client }
var GlobalS3Client S3Client
type UpdateAlertAction ¶ added in v0.12.0
type UpdateAlertAction struct {
// contains filtered or unexported fields
}
func (*UpdateAlertAction) DecodeBody ¶ added in v0.12.0
func (action *UpdateAlertAction) DecodeBody(body hcl.Body, evalCtx *hcl.EvalContext) hcl.Diagnostics
func (*UpdateAlertAction) DependsOnQueries ¶ added in v0.12.0
func (action *UpdateAlertAction) DependsOnQueries() []string
func (*UpdateAlertAction) Enable ¶ added in v0.12.0
func (action *UpdateAlertAction) Enable() bool
func (*UpdateAlertAction) Execute ¶ added in v0.12.0
func (action *UpdateAlertAction) Execute(ctx context.Context, evalCtx *hcl.EvalContext, u *MackerelUpdater) error
type WebhookBody ¶
type WebhookBody struct { OrgName string `json:"orgName" cty:"org_name"` Text string `json:"text" cty:"-"` Event string `json:"event" cty:"event"` ImageURL *string `json:"imageUrl" cty:"image_url"` Memo string `json:"memo" cty:"memo"` Host *Host `json:"host,omitempty" cty:"host,omitempty"` Service *Service `json:"service,omitempty" cty:"service,omitempty"` Alert *Alert `json:"alert" cty:"alert,omitempty"` }
func WebhookFromEvalContext ¶ added in v0.12.0
func WebhookFromEvalContext(evalCtx *hcl.EvalContext) (*WebhookBody, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.