-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalert_expiring_certs.go
52 lines (45 loc) · 1.13 KB
/
alert_expiring_certs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"time"
)
func alertExpiringCerts(certs []Cert, t time.Time) error {
message := SlackMessage{}
// group our certs by their fingerprint
groupedCerts := groupCerts(certs, t)
title := ""
if groupedCerts[0].ExpiresInDays < 1 {
title = fmt.Sprintf("You have EXPIRED CERTIFICATES")
if environmentString != "" {
title += fmt.Sprintf(" in %s", environmentString)
}
title += "!"
} else {
days := "days"
if groupedCerts[0].ExpiresInDays == 1 {
days = "day"
}
title = fmt.Sprintf("You have certificates expiring within %v %s", groupedCerts[0].ExpiresInDays, days)
if environmentString != "" {
title += fmt.Sprintf(" in %s", environmentString)
}
}
message.Blocks = append(message.Blocks, SlackSection{
Type: "header",
Text: SlackBlock{
Type: "plain_text",
Text: title,
},
})
// Add our divider block
message.Blocks = append(message.Blocks, SlackBlock{
Type: "divider",
})
// Add each cert to our message
for _, group := range groupedCerts {
if len(group.Certs) > 0 {
message.Blocks = append(message.Blocks, group.ToSlackMessage())
}
}
return sendToSlack(message)
}