/
heartbeat_cmd.go
42 lines (36 loc) · 1.02 KB
/
heartbeat_cmd.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
package command
import (
"errors"
"fmt"
"github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat"
gcli "github.com/urfave/cli"
"os"
)
func NewHeartbeatClient(c *gcli.Context) (*heartbeat.Client, error) {
heartbeatCli, cliErr := heartbeat.NewClient(getConfigurations(c))
if cliErr != nil {
message := "Can not create the heartbeat client. " + cliErr.Error()
fmt.Printf("%s\n", message)
return nil, errors.New(message)
}
printVerboseMessage("Heartbeat Client created.")
return heartbeatCli, nil
}
// HeartbeatAction sends an Heartbeat signal to Opsgenie.
func HeartbeatAction(c *gcli.Context) {
cli, err := NewHeartbeatClient(c)
if err != nil {
os.Exit(1)
}
var name string
if val, success := getVal("name", c); success {
name = val
}
printVerboseMessage("Heartbeat request prepared from flags, sending request to Opsgenie..")
response, err := cli.Ping(nil, name)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
printVerboseMessage("Ping request has received. RequestID: " + response.RequestId)
}