updating haven notify
This commit is contained in:
@@ -9,4 +9,5 @@ FROM busybox:latest
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/haven-notify .
|
COPY --from=builder /app/haven-notify .
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
ENV WEBHOOK_URL=""
|
||||||
ENTRYPOINT ["/app/haven-notify"]
|
ENTRYPOINT ["/app/haven-notify"]
|
||||||
|
@@ -20,6 +20,12 @@ spec:
|
|||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: WEBHOOK_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: discord-webhook
|
||||||
|
key: HAVEN_WEBHOOK_URL
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
kubernetes.io/arch: amd64
|
kubernetes.io/arch: amd64
|
||||||
---
|
---
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Notification payload
|
// Notification payload
|
||||||
@@ -47,11 +48,14 @@ func notifyHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendDiscordNotification(title, message string) error {
|
func sendDiscordNotification(title, message string) error {
|
||||||
const webhookURL = ""
|
webhookURL := os.Getenv("WEBHOOK_URL")
|
||||||
|
if webhookURL == "" {
|
||||||
|
return fmt.Errorf("WEBHOOK_URL environment variable not set")
|
||||||
|
}
|
||||||
|
|
||||||
// Discord webhook payload
|
// Discord webhook payload
|
||||||
type discordPayload struct {
|
type discordPayload struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
content := "**" + title + "**\n" + message
|
content := "**" + title + "**\n" + message
|
||||||
@@ -59,17 +63,17 @@ func sendDiscordNotification(title, message string) error {
|
|||||||
|
|
||||||
jsonData, err := json.Marshal(payload)
|
jsonData, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData))
|
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
return fmt.Errorf("Discord webhook returned status: %s", resp.Status)
|
return fmt.Errorf("Discord webhook returned status: %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user