Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( EnvEmailAuthUsername = "GO_ELASTICSEARCH_ALERTS_SMTP_USERNAME" EnvEmailAuthPassword = "GO_ELASTICSEARCH_ALERTS_SMTP_PASSWORD" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmailAlertMethod ¶
type EmailAlertMethod struct {
// contains filtered or unexported fields
}
func NewEmailAlertMethod ¶
func NewEmailAlertMethod(config *EmailAlertMethodConfig) (*EmailAlertMethod, error)
NewEmailAlertMethod creates a new *EmailAlertMethod or a non-nil error if there was an error.
func (*EmailAlertMethod) BuildMessage ¶ added in v0.0.22
BuildMessage creates an email message from the provided records. It will return a non-nil error if an error occurs.
Example ¶
records := []*alert.Record{ &alert.Record{ Filter: "aggregations.hostname.buckets", Text: "", Fields: []*alert.Field{ &alert.Field{ Key: "foo", Count: 10, }, &alert.Field{ Key: "bar", Count: 8, }, }, }, &alert.Record{ Filter: "aggregations.hostname.buckets.program.buckets", Text: "", Fields: []*alert.Field{ &alert.Field{ Key: "foo - bim", Count: 3, }, &alert.Field{ Key: "foo - baz", Count: 7, }, &alert.Field{ Key: "bar - hello", Count: 6, }, &alert.Field{ Key: "bar - world", Count: 2, }, }, }, &alert.Record{ Filter: "hits.hits._source", Text: "{\n \"ayy\": \"lmao\"\n}\n----------------------------------------\n{\n \"hello\": \"world\"\n}", }, } em := &EmailAlertMethod{} 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>
Click to show internal directories.
Click to hide internal directories.