diff --git a/CHANEGLOG.md b/CHANEGLOG.md new file mode 100644 index 0000000..ff44d64 --- /dev/null +++ b/CHANEGLOG.md @@ -0,0 +1,23 @@ +## 3.1.4 (July 1, 2021) +* **Heartbeat:** Added create/delete/list/enable/diable functionality for heatbeart +* **Go-SDK:** Updated Go-SDK version + +## 3.1.3 (June 21, 2021) +* **Github Actions** Adding github Actions for deploying all binaries in github. +* **Logs:** Added Default Limit to Logs Download +* **Config:** Updated Default Config File Location +* **File Logging:** Added functionality to allow logging of Lamp into file +* **Service:** Added Service Commands functionality +* **Incident:** Added Incident Commands functionality +* **Schedule:** Added Schedule Commands functionality +* **Esclation:** Added Escalation Commands functionality + +## 3.1.2 (February 27, 2020) +* **Dependencies:** Updating the used Dependencies + +## 3.1.1 (February 26, 2020) +BUGFIX: +* **Logs:** Stop comparing endDate if it is bigger than compared log file while downloading Logs + +## 3.1.0 (December 18, 2010) +* **GO SDK Version:** Updated Go-SDK Version \ No newline at end of file diff --git a/command/heartbeat_cmd.go b/command/heartbeat_cmd.go index 30f0511..1a16ec1 100644 --- a/command/heartbeat_cmd.go +++ b/command/heartbeat_cmd.go @@ -3,8 +3,11 @@ package command import ( "errors" "github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat" + "github.com/opsgenie/opsgenie-go-sdk-v2/og" gcli "github.com/urfave/cli" "os" + "strconv" + "strings" ) func NewHeartbeatClient(c *gcli.Context) (*heartbeat.Client, error) { @@ -19,7 +22,7 @@ func NewHeartbeatClient(c *gcli.Context) (*heartbeat.Client, error) { } // HeartbeatAction sends an Heartbeat signal to Opsgenie. -func HeartbeatAction(c *gcli.Context) { +func PingHeartbeatAction(c *gcli.Context) { cli, err := NewHeartbeatClient(c) if err != nil { os.Exit(1) @@ -39,3 +42,169 @@ func HeartbeatAction(c *gcli.Context) { } printMessage(DEBUG,"Ping request has received. RequestID: " + response.RequestId) } + +func CreateHeartbeatAction(c *gcli.Context) { + cli, err := NewHeartbeatClient(c) + if err != nil { + os.Exit(1) + } + + addRequest := heartbeat.AddRequest{} + + if val, success := getVal("name", c); success { + addRequest.Name = val + } + + if val, success := getVal("description", c); success { + addRequest.Description = val + } + + if val, success := getVal("alertMessage", c); success { + addRequest.AlertMessage = val + } + + if val, success := getVal("alertTag", c); success { + addRequest.AlertTag = strings.Split(val, ",") + } + + if val, success := getVal("alertPriority", c); success { + addRequest.AlertPriority = val + } + + if val, success := getVal("ownerTeam", c); success { + addRequest.OwnerTeam = og.OwnerTeam{ + Name: val, + } + } + + if val, success := getVal("interval", c); success { + addRequest.Interval, err = strconv.Atoi(val) + + if err != nil { + printMessage(ERROR, "Please provide a valid integer for interval.") + os.Exit(1) + } + } + + if val, success := getVal("intervalType", c); success { + if val == "m" { + addRequest.IntervalUnit = heartbeat.Minutes + } else if val == "h" { + addRequest.IntervalUnit = heartbeat.Hours + } else if val == "d" { + addRequest.IntervalUnit = heartbeat.Days + } else { + printMessage(ERROR, "Please provide a valid interval unit.") + os.Exit(1) + } + } + + enabled := c.IsSet("enabled") + addRequest.Enabled = &enabled + + printMessage(DEBUG, "Heartbeat create request created from flags. Sedning to Opsgenie...") + + response, err := cli.Add(nil, &addRequest) + if err != nil { + printMessage(ERROR,err.Error()) + os.Exit(1) + } + printMessage(DEBUG,"Heartbeat will be created " + response.RequestId) +} + +func DeleteHeartbeatAction(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 + } + + printMessage(DEBUG, "Heartbeat delete request created from flags. Sending to Opsgenie...") + + response, err := cli.Delete(nil, name) + if err != nil { + printMessage(ERROR,err.Error()) + os.Exit(1) + } + printMessage(DEBUG,"Heartbeat will be deleted.") + printMessage(INFO, response.RequestId) +} + +func DisableHeartbeatAction(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 + } + + printMessage(DEBUG, "Heartbeat disable request created from flags. Sending to Opsgenie...") + + response, err := cli.Disable(nil, name) + if err != nil { + printMessage(ERROR,err.Error()) + os.Exit(1) + } + printMessage(DEBUG,"Heartbeat will be disabled.") + printMessage(INFO, response.RequestId) +} + +func EnableHeartbeatAction(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 + } + + printMessage(DEBUG, "Heartbeat enable request created from flags. Sending to Opsgenie...") + + response, err := cli.Enable(nil, name) + if err != nil { + printMessage(ERROR,err.Error()) + } + printMessage(DEBUG, "Heartbeat will be enabled") + printMessage(INFO, response.RequestId) +} + +func ListHeartbeatAction(c *gcli.Context) { + cli, err := NewHeartbeatClient(c) + if err != nil { + os.Exit(1) + } + + response, err := cli.List(nil) + if err != nil { + printMessage(ERROR,err.Error()) + } + + outputFormat := strings.ToLower(c.String("output-format")) + printMessage(DEBUG,"Heartbeats listed successfully, and will print as " + outputFormat) + switch outputFormat { + case "yaml": + output, err := resultToYAML(response.Heartbeats) + if err != nil { + printMessage(ERROR,err.Error()) + os.Exit(1) + } + printMessage(INFO, output) + default: + isPretty := c.IsSet("pretty") + output, err := resultToJSON(response.Heartbeats, isPretty) + if err != nil { + printMessage(ERROR,err.Error()) + os.Exit(1) + } + printMessage(INFO, output) + } +} diff --git a/conf/lamp.conf b/conf/lamp.conf index 63a9822..a4caba4 100644 --- a/conf/lamp.conf +++ b/conf/lamp.conf @@ -10,4 +10,8 @@ apiKey=your_api_key ############## Use following settings options for connection to OpsGenie server############ ##connectionTimeout=50 -##requestTimeout=100 \ No newline at end of file +##requestTimeout=100 + +############## Use alternative urls for connection to EU / Sandbox server############ +## opsgenie.api.url=https://api.eu.opsgenie.com +## opsgenie.api.url=https://api.sandbox.opsgenie.com diff --git a/go.mod b/go.mod index 2c86f09..e9ee761 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.1 // indirect github.com/hashicorp/go-retryablehttp v0.5.4 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect - github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6 + github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8 github.com/urfave/cli v1.21.0 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 79f5b42..f0b29ed 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6 h1:C3p45LH9szkt8/pbI4CXwBPkLj3pFLlCzbzm6FgG57c= -github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8 h1:qF/rRi8GSU2mjBXfJIyMj9GGmjedsV3Gm1uYbiGlCRk= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/lamp.go b/lamp.go index ef4508b..095fb7a 100644 --- a/lamp.go +++ b/lamp.go @@ -959,7 +959,7 @@ func deleteAlertCommand() gcli.Command { return cmd } -func heartbeatCommand() gcli.Command { +func pingHeartbeatCommand() gcli.Command { commandFlags := []gcli.Flag{ gcli.StringFlag{ Name: "name", @@ -967,11 +967,131 @@ func heartbeatCommand() gcli.Command { }, } flags := append(commonFlags, commandFlags...) - cmd := gcli.Command{Name: "heartbeat", + cmd := gcli.Command{Name: "pingHeartbeat", Flags: flags, Usage: "Sends heartbeat to Opsgenie", Action: func(c *gcli.Context) error { - command.HeartbeatAction(c) + command.PingHeartbeatAction(c) + return nil + }} + return cmd +} + +func createHeartbeatCommand() gcli.Command { + commandFlags := []gcli.Flag{ + gcli.StringFlag{ + Name: "name", + Usage: "Name of the heartbeat to be created", + }, + gcli.StringFlag{ + Name: "description", + Usage: "Description for the heartbeat to be created", + }, + gcli.IntFlag{ + Name: "interval", + Usage: "Interval after which hearbeat will expire", + }, + gcli.StringFlag{ + Name: "intervalType", + Usage: "Type of interval : 'm' (minute), 'h' (hours), 'd' (days)", + }, + gcli.BoolFlag{ + Name: "enabled", + Usage: "If present, heartbaat will be enabled", + }, + gcli.StringFlag{ + Name: "ownerTeam", + Usage: "Owner team for the heartbeat", + }, + gcli.StringFlag{ + Name: "alertMessage", + Usage: "Heartbeat alert nessage", + }, + gcli.StringFlag{ + Name: "alertTag", + Usage: "Tag for the heartbeat alert", + }, + gcli.StringFlag{ + Name: "alertPriority", + Usage: "Priority of the alert created by Heartbeat", + }, + } + + flags := append(commonFlags, commandFlags...) + cmd := gcli.Command{Name: "createHeartbeat", + Flags: flags, + Usage: "Creates a new opsgenie heartbeat", + Action: func(c *gcli.Context) error { + command.CreateHeartbeatAction(c) + return nil + }} + return cmd +} + +func deleteHeartbeatCommand() gcli.Command { + commandFlags := []gcli.Flag{ + gcli.StringFlag{ + Name: "name", + Usage: "Name of the heartbeat to be deleted", + }, + } + + flags := append(commonFlags, commandFlags...) + cmd := gcli.Command{Name: "deleteHeartbeat", + Flags: flags, + Usage: "Deletes opsgenie heartbeat", + Action: func(c *gcli.Context) error { + command.DeleteHeartbeatAction(c) + return nil + }} + return cmd +} + +func disableHeartbeatCommand() gcli.Command { + commandFlags := []gcli.Flag{ + gcli.StringFlag{ + Name: "name", + Usage: "Name of the heartbeat to be disabled", + }, + } + + flags := append(commonFlags, commandFlags...) + cmd := gcli.Command{Name: "disableHeartbeat", + Flags: flags, + Usage: "Disabled opsgenie heartbeat", + Action: func(c *gcli.Context) error { + command.DisableHeartbeatAction(c) + return nil + }} + return cmd +} + +func enableHeartbeatCommand() gcli.Command { + commandFlags := []gcli.Flag{ + gcli.StringFlag{ + Name: "name", + Usage: "Name of the heartbeat to be Enabled", + }, + } + + flags := append(commonFlags, commandFlags...) + cmd := gcli.Command{Name: "enableHeartbeat", + Flags: flags, + Usage: "Enable opsgenie heartbeat", + Action: func(c *gcli.Context) error { + command.EnableHeartbeatAction(c) + return nil + }} + return cmd +} + +func listHeartbeatCommand() gcli.Command { + flags := append(commonFlags, renderingFlags...) + cmd := gcli.Command{Name: "listHeartbeat", + Flags: flags, + Usage: "List opsgenie heartbeats", + Action: func(c *gcli.Context) error { + command.ListHeartbeatAction(c) return nil }} return cmd @@ -2979,7 +3099,12 @@ func initCommands(app *gcli.App) { executeActionCommand(), closeAlertCommand(), deleteAlertCommand(), - heartbeatCommand(), + pingHeartbeatCommand(), + createHeartbeatCommand(), + deleteHeartbeatCommand(), + disableHeartbeatCommand(), + enableHeartbeatCommand(), + listHeartbeatCommand(), enableCommand(), disableCommand(), listAlertsCommand(), diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/request.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/request.go index e062136..fc66efc 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/request.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/request.go @@ -34,7 +34,7 @@ type CreateNotificationPolicyRequest struct { MainFields AutoRestartAction *AutoRestartAction `json:"autoRestartAction,omitempty"` AutoCloseAction *AutoCloseAction `json:"autoCloseAction,omitempty"` - DeDuplicationAction *DeDuplicationAction `json:"deduplicationActionAction,omitempty"` + DeDuplicationAction *DeDuplicationAction `json:"deduplicationAction,omitempty"` DelayAction *DelayAction `json:"delayAction,omitempty"` Suppress *bool `json:"suppress,omitempty"` } @@ -271,7 +271,7 @@ type UpdateNotificationPolicyRequest struct { MainFields AutoRestartAction *AutoRestartAction `json:"autoRestartAction,omitempty"` AutoCloseAction *AutoCloseAction `json:"autoCloseAction,omitempty"` - DeDuplicationAction *DeDuplicationAction `json:"deduplicationActionAction,omitempty"` + DeDuplicationAction *DeDuplicationAction `json:"deduplicationAction,omitempty"` DelayAction *DelayAction `json:"delayAction,omitempty"` Suppress *bool `json:"suppress,omitempty"` Id string @@ -546,7 +546,7 @@ type AutoCloseAction struct { } type DeDuplicationAction struct { - DeDuplicationActionType DeDuplicationActionType `json:"deduplicationType,omitempty"` + DeDuplicationActionType DeDuplicationActionType `json:"deduplicationActionType,omitempty"` Duration *Duration `json:"duration,omitempty"` Count int `json:"count,omitempty"` } diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/result.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/result.go index 6927163..6b5edfa 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/result.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/policy/result.go @@ -38,7 +38,7 @@ type GetNotificationPolicyResult struct { MainFields AutoRestartAction *AutoRestartAction `json:"autoRestartAction,omitempty"` AutoCloseAction *AutoCloseAction `json:"autoCloseAction,omitempty"` - DeDuplicationActionAction *DeDuplicationAction `json:"deduplicationActionAction,omitempty"` + DeDuplicationAction *DeDuplicationAction `json:"deduplicationAction,omitempty"` DelayAction *DelayAction `json:"delayAction,omitempty"` Suppress bool `json:"suppress,omitempty"` } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0f056a2..356e4bf 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,7 +6,7 @@ github.com/hashicorp/go-cleanhttp github.com/hashicorp/go-retryablehttp # github.com/konsorten/go-windows-terminal-sequences v1.0.2 github.com/konsorten/go-windows-terminal-sequences -# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.6 +# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8 github.com/opsgenie/opsgenie-go-sdk-v2/alert github.com/opsgenie/opsgenie-go-sdk-v2/client github.com/opsgenie/opsgenie-go-sdk-v2/escalation