email

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

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

func (e *EmailAlertMethod) BuildMessage(rule string, records []*alert.Record) (string, error)

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>&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 (*EmailAlertMethod) Write

func (e *EmailAlertMethod) 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 EmailAlertMethod. If there was an error sending the email, it returns a non-nil error.

type EmailAlertMethodConfig

type EmailAlertMethodConfig 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"`
}

Jump to

Keyboard shortcuts

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