@@ 1,83 0,0 @@
From 5bea8e8c73511f90aa7c8b80fe49357862a84b92 Mon Sep 17 00:00:00 2001
From: Drew DeVault <sir@cmpwn.com>
Date: Mon, 6 Jan 2020 10:49:48 -0500
Subject: [PATCH] email: generate message ID headers
This GenerateMessageId is taken from go-message:
https://github.com/emersion/go-message/blob/master/mail/mail.go
I am the original author of this file; I agree to distribute it in
alertmanager regardless of the original license.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
---
notify/email/email.go | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/notify/email/email.go b/notify/email/email.go
index 73fcf577..529e4333 100644
--- a/notify/email/email.go
+++ b/notify/email/email.go
@@ -16,7 +16,9 @@ package email
import (
"bytes"
"context"
+ "crypto/rand"
"crypto/tls"
+ "encoding/binary"
"fmt"
"mime"
"mime/multipart"
@@ -25,11 +27,13 @@ import (
"net/mail"
"net/smtp"
"net/textproto"
+ "os"
"strings"
"time"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
+ "github.com/martinlindhe/base36"
"github.com/pkg/errors"
commoncfg "github.com/prometheus/common/config"
@@ -241,6 +245,7 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
fmt.Fprintf(buffer, "Date: %s\r\n", time.Now().Format(time.RFC1123Z))
fmt.Fprintf(buffer, "Content-Type: multipart/alternative; boundary=%s\r\n", multipartWriter.Boundary())
+ fmt.Fprintf(buffer, "Message-ID: %s\r\n", generateMessageID())
fmt.Fprintf(buffer, "MIME-Version: 1.0\r\n\r\n")
// TODO: Add some useful headers here, such as URL of the alertmanager
@@ -314,6 +319,26 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
return false, nil
}
+// Generates an RFC 2822-compliant Message-Id based on the informational draft
+// "Recommendations for generating Message IDs", for lack of a better
+// authoritative source.
+func generateMessageID() string {
+ var (
+ now bytes.Buffer
+ nonce []byte = make([]byte, 8)
+ )
+ binary.Write(&now, binary.BigEndian, time.Now().UnixNano())
+ rand.Read(nonce)
+ hostname, err := os.Hostname()
+ if err != nil {
+ hostname = "localhost"
+ }
+ return fmt.Sprintf("<%s.%s@%s>",
+ base36.EncodeBytes(now.Bytes()),
+ base36.EncodeBytes(nonce),
+ hostname)
+}
+
type loginAuth struct {
username, password string
}
--
2.24.1
@@ 1,7 1,7 @@
# Maintainer: Drew DeVault <sir@cmpwn.com>
pkgname=alertmanager
-pkgver=0.19.0
-pkgrel=6
+pkgver=0.20.0
+pkgrel=0
pkgdesc="Prometheus Alertmanager"
url="https://github.com/prometheus/alertmanager"
arch="all"
@@ 12,11 12,10 @@ source="
$pkgname-$pkgver.tar.gz::https://github.com/prometheus/alertmanager/archive/v$pkgver.tar.gz
alertmanager.confd
alertmanager.initd
- 0001-email-generate-message-ID-headers.patch
"
subpackages="$pkgname-openrc"
builddir="$srcdir/$pkgname-$pkgver"
-options="!check" # timing-dependent upstream failures
+options="!check" # Requires us to use their weird build system
prepare() {
default_prepare
@@ 56,7 55,6 @@ package() {
"$pkgdir"/etc/alertmanager/alertmanager.yml
}
-sha512sums="2c21bfbb1001e07e81b1115439ad15e7c0e7089839e56a19c445177e322b8ef9aa2b85e96478f3c3d709cbbd3a5447662a8c55da370b84aa4b6b24f83848744b alertmanager-0.19.0.tar.gz
+sha512sums="4bb9353e6ce9b149c5f22a2c305829112dfdf87f9b74e6075a45be0e07fe0f17e869ef9be4bb5e9c53d215dd1f534b1b5a707dd981efce8c5bcae4c1d6ce18bb alertmanager-0.20.0.tar.gz
58420cf10ed51ec389d21ffdd5b4a0e588f0dc78b1069e32d0db1e0215f64c1c980d8f539ae902839f2f9342090b50ce1db756839f3676ee18b77548ce8f99c8 alertmanager.confd
-def36c9933e91a38d863c06679efd840952ba003a839afe5b5c6423fa6ee8f229755f758c5363564b433756af34509fef282b81dea2532500f1287c47c426787 alertmanager.initd
-7df6fb27a22b12f006f2f0ba0b6b807c07611a1c63fecee67de04d0899f4ba9924b62281f43289e4519ae6313a0b1bf47bce7a3401c91ef6f49e943638e84ae1 0001-email-generate-message-ID-headers.patch"
+def36c9933e91a38d863c06679efd840952ba003a839afe5b5c6423fa6ee8f229755f758c5363564b433756af34509fef282b81dea2532500f1287c47c426787 alertmanager.initd"