-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
new.go
41 lines (36 loc) · 912 Bytes
/
new.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
package cmd
import (
"fmt"
"log"
"strings"
uptimerobot "github.com/bitfield/uptimerobot/pkg"
"github.com/spf13/cobra"
)
var newCmd = &cobra.Command{
Use: "new",
Short: "add a new monitor",
Long: `Create a new monitor with the specified URL and friendly name`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
m := uptimerobot.Monitor{
URL: args[0],
FriendlyName: args[1],
Type: uptimerobot.TypeHTTP,
AlertContacts: contacts,
Port: 80,
}
if strings.HasPrefix(m.URL, "https") {
m.Port = 443
}
ID, err := client.CreateMonitor(m)
if err != nil {
log.Fatal(err)
}
fmt.Printf("New monitor created with ID %d\n", ID)
},
}
var contacts []string
func init() {
newCmd.Flags().StringSliceVarP(&contacts, "contacts", "c", []string{}, "Comma-separated list of contact IDs to notify")
RootCmd.AddCommand(newCmd)
}