summaryrefslogtreecommitdiffstats
path: root/extra/uptime-kuma-push/uptime-kuma-push.go
blob: 69cd1f8c27c8528fce4484f64a119abaac8af452 (plain)
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
package main

import (
	"fmt"
	"net/http"
	os "os"
	"time"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Fprintln(os.Stderr, "Usage: uptime-kuma-push <url> [<interval>]")
		os.Exit(1)
	}

	pushURL := os.Args[1]

	var interval time.Duration

	if len(os.Args) >= 3 {
		intervalString, err := time.ParseDuration(os.Args[2] + "s")
		interval = intervalString

		if err != nil {
			fmt.Fprintln(os.Stderr, "Error: Invalid interval", err)
			os.Exit(1)
		}

	} else {
		interval = 60 * time.Second
	}

	for {
		_, err := http.Get(pushURL)
		if err == nil {
			fmt.Print("Pushed!")
		} else {
			fmt.Print("Error: ", err)
		}

		fmt.Println(" Sleeping for", interval)
		time.Sleep(interval)
	}
}