Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // EnvEmailAuthUsername sets the username with which to // authenticate to the SMTP server. EnvEmailAuthUsername = "GO_ELASTICSEARCH_ALERTS_SMTP_USERNAME" // EnvEmailAuthPassword set the password with which to // authenticate to the SMTP server. EnvEmailAuthPassword = "GO_ELASTICSEARCH_ALERTS_SMTP_PASSWORD" )
Variables ¶
This section is empty.
Functions ¶
func NewAlertMethod ¶ added in v0.1.55
func NewAlertMethod(config *AlertMethodConfig) (alert.Method, error)
NewAlertMethod creates a new *AlertMethod or a non-nil error if there was an error.
Types ¶
type AlertMethod ¶ added in v0.1.55
type AlertMethod struct {
// contains filtered or unexported fields
}
AlertMethod implements the alert.Method interface for writing new alerts to email.
Example (BuildMessage) ¶
records := []*alert.Record{ { Filter: "aggregations.hostname.buckets", Text: "", Fields: []*alert.Field{ { Key: "foo", Count: 10, }, { Key: "bar", Count: 8, }, }, }, { Filter: "aggregations.hostname.buckets.program.buckets", Text: "", Fields: []*alert.Field{ { Key: "foo - bim", Count: 3, }, { Key: "foo - baz", Count: 7, }, { Key: "bar - hello", Count: 6, }, { Key: "bar - world", Count: 2, }, }, }, { Filter: "hits.hits._source", Text: "{\n \"ayy\": \"lmao\"\n}\n----------------------------------------\n{\n \"hello\": \"world\"\n}", }, } em := &AlertMethod{} msg, _ := em.buildMessage("Test Rule", records) fmt.Println(msg)
Output: Content-Type: text/html Subject: Go Elasticsearch Alerts: Test Rule <!DOCTYPE html> <html> <head> <style> table { font-family: arial, sans-serif; border-collapse: collapse; } td, th { border: 1px solid #dddddd; text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #dddddd; } </style> </head> <body> <h4>Filter path: aggregations.hostname.buckets</h4> <table> <tr> <th>Key</th> <th>Count</th> </tr> <tr> <td>foo</td> <td>10</td> </tr> <tr> <td>bar</td> <td>8</td> </tr> </table> <br><h4>Filter path: aggregations.hostname.buckets.program.buckets</h4> <table> <tr> <th>Key</th> <th>Count</th> </tr> <tr> <td>foo - bim</td> <td>3</td> </tr> <tr> <td>foo - baz</td> <td>7</td> </tr> <tr> <td>bar - hello</td> <td>6</td> </tr> <tr> <td>bar - world</td> <td>2</td> </tr> </table> <br><h4>Filter path: hits.hits._source</h4> {<br> "ayy": "lmao"<br>}<br>----------------------------------------<br>{<br> "hello": "world"<br>} <br> </body> </html>
type AlertMethodConfig ¶ added in v0.1.55
type AlertMethodConfig struct { Host string `mapstructure:"host"` Port int `mapstructure:"port"` From string `mapstructure:"from"` To []string `mapstructure:"to"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` }
AlertMethodConfig is used to configure where email alerts should be sent.
Click to show internal directories.
Click to hide internal directories.