~dricottone/huttese-apk

7c54a212f5f87e19b1f5f80d84722aecfcc04d3e — Drew DeVault 4 years ago 44ba1a8
alertmanager: add Message-ID patch
A sr.ht/alertmanager/0001-email-generate-message-ID-headers.patch => sr.ht/alertmanager/0001-email-generate-message-ID-headers.patch +83 -0
@@ 0,0 1,83 @@
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


M sr.ht/alertmanager/APKBUILD => sr.ht/alertmanager/APKBUILD +9 -2
@@ 1,7 1,7 @@
# Maintainer: Drew DeVault <sir@cmpwn.com>
pkgname=alertmanager
pkgver=0.19.0
pkgrel=5
pkgrel=6
pkgdesc="Prometheus Alertmanager"
url="https://github.com/prometheus/alertmanager"
arch="all"


@@ 12,11 12,17 @@ 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

prepare() {
	default_prepare
	go mod vendor
}

build() {
	go build \
		-trimpath \


@@ 52,4 58,5 @@ package() {

sha512sums="2c21bfbb1001e07e81b1115439ad15e7c0e7089839e56a19c445177e322b8ef9aa2b85e96478f3c3d709cbbd3a5447662a8c55da370b84aa4b6b24f83848744b  alertmanager-0.19.0.tar.gz
58420cf10ed51ec389d21ffdd5b4a0e588f0dc78b1069e32d0db1e0215f64c1c980d8f539ae902839f2f9342090b50ce1db756839f3676ee18b77548ce8f99c8  alertmanager.confd
def36c9933e91a38d863c06679efd840952ba003a839afe5b5c6423fa6ee8f229755f758c5363564b433756af34509fef282b81dea2532500f1287c47c426787  alertmanager.initd"
def36c9933e91a38d863c06679efd840952ba003a839afe5b5c6423fa6ee8f229755f758c5363564b433756af34509fef282b81dea2532500f1287c47c426787  alertmanager.initd
7df6fb27a22b12f006f2f0ba0b6b807c07611a1c63fecee67de04d0899f4ba9924b62281f43289e4519ae6313a0b1bf47bce7a3401c91ef6f49e943638e84ae1  0001-email-generate-message-ID-headers.patch"