-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (38 loc) · 1006 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"strings"
"time"
)
const (
siteUpCheckTimeInterval = 10 * time.Second
siteUrl = "https://google.com"
webhookURL = "https://discord.com/api/webhooks/WEBHOOK_ID/WEBHOOK_TOKEN"
)
func main() {
for range time.Tick(siteUpCheckTimeInterval) {
resp, err := http.Get(siteUrl)
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != http.StatusOK {
fmt.Println("Website Response Is:", resp.StatusCode, http.StatusText(resp.StatusCode))
sendWebhook("Website is down!")
} else {
fmt.Println("All Good Chef!")
}
resp.Body.Close()
}
}
func sendWebhook(message string) {
payload := `{"content":"` + message + `"}`
resp, err := http.Post(webhookURL, "application/json", strings.NewReader(payload))
if err != nil {
log.Println("Failed to send webhook:", err)
} else {
defer resp.Body.Close()
fmt.Println("Webhook notification sent successfully")
}
}