-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 1.07 KB
/
main.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
53
54
55
56
57
package main
import (
"crypto/tls"
"fmt"
"log"
"os"
"strings"
"time"
alerts "github.com/opsgenie/opsgenie-go-sdk/alertsv2"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
)
func triggerAlert(domain string) {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(os.Getenv("OPSGENIE_API_KEY"))
alertCli, _ := cli.AlertV2()
request := alerts.CreateAlertRequest{
Message: "SSL certificate expired",
Description: fmt.Sprintf("Certificate of %s expired", domain),
Priority: alerts.P1,
}
_, err := alertCli.Create(request)
if err != nil {
log.Println(err.Error())
}
}
func main() {
domains := strings.Split(os.Getenv("DOMAINS"), ",")
for {
for i := range domains {
site := fmt.Sprintf("%s:443", domains[i])
log.Println("Checking", site)
conn, err := tls.Dial("tcp", site, nil)
if err != nil {
log.Println(err)
triggerAlert(domains[i])
continue
}
err = conn.VerifyHostname(domains[i])
if err != nil {
log.Println(err)
continue
}
}
log.Println("Sleeping for next 24 hours...")
time.Sleep(24 * time.Hour)
}
}