Skip to content

Commit 9e14a61

Browse files
Fixes #36 Support for creating/deleting/listing/enabling/disabling he… (#43)
* Fixes #36 Support for creating/deleting/listing/enabling/disabling heartbeats This PR adds support for creating/deleting/listing/enabling/disabling heartbeats and changed name of ping function adding Changelog.md updating go-sdk version * Updating ChangeLog.md Co-authored-by: pmudaiya <pmudaiya@atlassian.com>
1 parent aad7b28 commit 9e14a61

File tree

9 files changed

+335
-14
lines changed

9 files changed

+335
-14
lines changed

CHANEGLOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## 3.1.4 (July 1, 2021)
2+
* **Heartbeat:** Added create/delete/list/enable/diable functionality for heatbeart
3+
* **Go-SDK:** Updated Go-SDK version
4+
5+
## 3.1.3 (June 21, 2021)
6+
* **Github Actions** Adding github Actions for deploying all binaries in github.
7+
* **Logs:** Added Default Limit to Logs Download
8+
* **Config:** Updated Default Config File Location
9+
* **File Logging:** Added functionality to allow logging of Lamp into file
10+
* **Service:** Added Service Commands functionality
11+
* **Incident:** Added Incident Commands functionality
12+
* **Schedule:** Added Schedule Commands functionality
13+
* **Esclation:** Added Escalation Commands functionality
14+
15+
## 3.1.2 (February 27, 2020)
16+
* **Dependencies:** Updating the used Dependencies
17+
18+
## 3.1.1 (February 26, 2020)
19+
BUGFIX:
20+
* **Logs:** Stop comparing endDate if it is bigger than compared log file while downloading Logs
21+
22+
## 3.1.0 (December 18, 2010)
23+
* **GO SDK Version:** Updated Go-SDK Version

command/heartbeat_cmd.go

+170-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package command
33
import (
44
"errors"
55
"github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat"
6+
"github.com/opsgenie/opsgenie-go-sdk-v2/og"
67
gcli "github.com/urfave/cli"
78
"os"
9+
"strconv"
10+
"strings"
811
)
912

1013
func NewHeartbeatClient(c *gcli.Context) (*heartbeat.Client, error) {
@@ -19,7 +22,7 @@ func NewHeartbeatClient(c *gcli.Context) (*heartbeat.Client, error) {
1922
}
2023

2124
// HeartbeatAction sends an Heartbeat signal to Opsgenie.
22-
func HeartbeatAction(c *gcli.Context) {
25+
func PingHeartbeatAction(c *gcli.Context) {
2326
cli, err := NewHeartbeatClient(c)
2427
if err != nil {
2528
os.Exit(1)
@@ -39,3 +42,169 @@ func HeartbeatAction(c *gcli.Context) {
3942
}
4043
printMessage(DEBUG,"Ping request has received. RequestID: " + response.RequestId)
4144
}
45+
46+
func CreateHeartbeatAction(c *gcli.Context) {
47+
cli, err := NewHeartbeatClient(c)
48+
if err != nil {
49+
os.Exit(1)
50+
}
51+
52+
addRequest := heartbeat.AddRequest{}
53+
54+
if val, success := getVal("name", c); success {
55+
addRequest.Name = val
56+
}
57+
58+
if val, success := getVal("description", c); success {
59+
addRequest.Description = val
60+
}
61+
62+
if val, success := getVal("alertMessage", c); success {
63+
addRequest.AlertMessage = val
64+
}
65+
66+
if val, success := getVal("alertTag", c); success {
67+
addRequest.AlertTag = strings.Split(val, ",")
68+
}
69+
70+
if val, success := getVal("alertPriority", c); success {
71+
addRequest.AlertPriority = val
72+
}
73+
74+
if val, success := getVal("ownerTeam", c); success {
75+
addRequest.OwnerTeam = og.OwnerTeam{
76+
Name: val,
77+
}
78+
}
79+
80+
if val, success := getVal("interval", c); success {
81+
addRequest.Interval, err = strconv.Atoi(val)
82+
83+
if err != nil {
84+
printMessage(ERROR, "Please provide a valid integer for interval.")
85+
os.Exit(1)
86+
}
87+
}
88+
89+
if val, success := getVal("intervalType", c); success {
90+
if val == "m" {
91+
addRequest.IntervalUnit = heartbeat.Minutes
92+
} else if val == "h" {
93+
addRequest.IntervalUnit = heartbeat.Hours
94+
} else if val == "d" {
95+
addRequest.IntervalUnit = heartbeat.Days
96+
} else {
97+
printMessage(ERROR, "Please provide a valid interval unit.")
98+
os.Exit(1)
99+
}
100+
}
101+
102+
enabled := c.IsSet("enabled")
103+
addRequest.Enabled = &enabled
104+
105+
printMessage(DEBUG, "Heartbeat create request created from flags. Sedning to Opsgenie...")
106+
107+
response, err := cli.Add(nil, &addRequest)
108+
if err != nil {
109+
printMessage(ERROR,err.Error())
110+
os.Exit(1)
111+
}
112+
printMessage(DEBUG,"Heartbeat will be created " + response.RequestId)
113+
}
114+
115+
func DeleteHeartbeatAction(c *gcli.Context) {
116+
cli, err := NewHeartbeatClient(c)
117+
if err != nil {
118+
os.Exit(1)
119+
}
120+
121+
var name string
122+
if val, success := getVal("name", c); success {
123+
name = val
124+
}
125+
126+
printMessage(DEBUG, "Heartbeat delete request created from flags. Sending to Opsgenie...")
127+
128+
response, err := cli.Delete(nil, name)
129+
if err != nil {
130+
printMessage(ERROR,err.Error())
131+
os.Exit(1)
132+
}
133+
printMessage(DEBUG,"Heartbeat will be deleted.")
134+
printMessage(INFO, response.RequestId)
135+
}
136+
137+
func DisableHeartbeatAction(c *gcli.Context) {
138+
cli, err := NewHeartbeatClient(c)
139+
if err != nil {
140+
os.Exit(1)
141+
}
142+
143+
var name string
144+
if val, success := getVal("name", c); success {
145+
name = val
146+
}
147+
148+
printMessage(DEBUG, "Heartbeat disable request created from flags. Sending to Opsgenie...")
149+
150+
response, err := cli.Disable(nil, name)
151+
if err != nil {
152+
printMessage(ERROR,err.Error())
153+
os.Exit(1)
154+
}
155+
printMessage(DEBUG,"Heartbeat will be disabled.")
156+
printMessage(INFO, response.RequestId)
157+
}
158+
159+
func EnableHeartbeatAction(c *gcli.Context) {
160+
cli, err := NewHeartbeatClient(c)
161+
if err != nil {
162+
os.Exit(1)
163+
}
164+
165+
var name string
166+
if val, success := getVal("name", c); success {
167+
name = val
168+
}
169+
170+
printMessage(DEBUG, "Heartbeat enable request created from flags. Sending to Opsgenie...")
171+
172+
response, err := cli.Enable(nil, name)
173+
if err != nil {
174+
printMessage(ERROR,err.Error())
175+
}
176+
printMessage(DEBUG, "Heartbeat will be enabled")
177+
printMessage(INFO, response.RequestId)
178+
}
179+
180+
func ListHeartbeatAction(c *gcli.Context) {
181+
cli, err := NewHeartbeatClient(c)
182+
if err != nil {
183+
os.Exit(1)
184+
}
185+
186+
response, err := cli.List(nil)
187+
if err != nil {
188+
printMessage(ERROR,err.Error())
189+
}
190+
191+
outputFormat := strings.ToLower(c.String("output-format"))
192+
printMessage(DEBUG,"Heartbeats listed successfully, and will print as " + outputFormat)
193+
switch outputFormat {
194+
case "yaml":
195+
output, err := resultToYAML(response.Heartbeats)
196+
if err != nil {
197+
printMessage(ERROR,err.Error())
198+
os.Exit(1)
199+
}
200+
printMessage(INFO, output)
201+
default:
202+
isPretty := c.IsSet("pretty")
203+
output, err := resultToJSON(response.Heartbeats, isPretty)
204+
if err != nil {
205+
printMessage(ERROR,err.Error())
206+
os.Exit(1)
207+
}
208+
printMessage(INFO, output)
209+
}
210+
}

conf/lamp.conf

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ apiKey=your_api_key
1010

1111
############## Use following settings options for connection to OpsGenie server############
1212
##connectionTimeout=50
13-
##requestTimeout=100
13+
##requestTimeout=100
14+
15+
############## Use alternative urls for connection to EU / Sandbox server############
16+
## opsgenie.api.url=https://api.eu.opsgenie.com
17+
## opsgenie.api.url=https://api.sandbox.opsgenie.com

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
88
github.com/hashicorp/go-retryablehttp v0.5.4 // indirect
99
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
10-
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6
10+
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8
1111
github.com/urfave/cli v1.21.0
1212
gopkg.in/yaml.v2 v2.2.2
1313
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es
1313
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
1414
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
1515
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
16-
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6 h1:C3p45LH9szkt8/pbI4CXwBPkLj3pFLlCzbzm6FgG57c=
17-
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s=
16+
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8 h1:qF/rRi8GSU2mjBXfJIyMj9GGmjedsV3Gm1uYbiGlCRk=
17+
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s=
1818
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
1919
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2020
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)