email

package
v0.1.65 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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>&nbsp;&nbsp;&nbsp;&#34;ayy&#34;:&nbsp;&#34;lmao&#34;<br>}<br>----------------------------------------<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&#34;hello&#34;:&nbsp;&#34;world&#34;<br>}
<br>
</body>
</html>

func (*AlertMethod) Write added in v0.1.55

func (e *AlertMethod) Write(ctx context.Context, rule string, records []*alert.Record) error

Write creates an email message from the records and sends it to the email address(es) specified at the creation of the AlertMethod. If there was an error sending the email, it returns a non-nil error.

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.

Jump to

Keyboard shortcuts

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