05d00a93ce
* Importing the OpsGenie SDK * Adding the goreq dependency * Initial commit of the OpsGenie / User provider * Refactoring to return a single client * Adding an import test / fixing a copy/paste error * Adding support for OpsGenie docs * Scaffolding the user documentation for OpsGenie * Adding a TODO * Adding the User data source * Documentation for OpsGenie * Adding OpsGenie to the internal plugin list * Adding support for Teams * Documentation for OpsGenie Team's * Validation for Teams * Removing Description for now * Optional fields for a User: Locale/Timezone * Removing an implemented TODO * Running makefmt * Downloading about half the internet Someone witty might simply sign this commit with "npm install" * Adding validation to the user object * Fixing the docs * Adding a test creating multple users * Prompting for the API Key if it's not specified * Added a test for multiple users / requested changes * Fixing the linting |
||
---|---|---|
.. | ||
alerts | ||
client | ||
escalation | ||
heartbeat | ||
integration | ||
logging | ||
policy | ||
schedule | ||
team | ||
user | ||
CONTRIBUTING.md | ||
LICENSE | ||
NOTICE | ||
README.md |
README.md
opsgenie-go-sdk
Aim and Scope
OpsGenie GO SDK aims to access OpsGenie Web API through HTTP calls from a client application purely written in Go language.
OpsGenie Go SDK covers the Alert API, the Heartbeat API, the Integration API and the Policy API. Future releases are subject to be delivered for packing more APIs soon.
For more information about OpsGenie Go SDK, please refer to OpsGenie Go API document.
Pre-requisites
-
The API is built using Go 1.4.2. Some features may not be available or supported unless you have installed a relevant version of Go. Please click https://golang.org/dl/ to download and get more information about installing Go on your computer.
-
Make sure you have properly set both
GOROOT
andGOPATH
environment variables. -
Before you can begin, you need to sign up OpsGenie if you don't have a valid account yet. Create an API Integration and get your API key.
Installation
To download all packages in the repo with their dependencies, simply run
go get github.com/opsgenie/opsgenie-go-sdk/...
Getting Started
One can start using OpsGenie Go SDK by initializing client and making a request. Example shown below demonstrates how to initialize an OpsGenie Alert client and make a create alert request.
package main
import (
"fmt"
alerts "github.com/opsgenie/opsgenie-go-sdk/alerts"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
)
func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey("YOUR_API_KEY")
alertCli, cliErr := cli.Alert()
if cliErr != nil {
panic(cliErr)
}
// create the alert
req := alerts.CreateAlertRequest{Message: "Hello from OpsGenie Go Sdk"}
response, alertErr := alertCli.Create(req)
if alertErr != nil {
panic(alertErr)
}
fmt.Printf("message: %s\n", response.Message)
fmt.Printf("alert id: %s\n", response.AlertId)
fmt.Printf("status: %s\n", response.Status)
fmt.Printf("code: %d\n", response.Code)
}
There are many useful sample code snippets under samples
directory for packages.
Handling Zero value problem with 'omitempty' option in Json
Every golang type has a zero value. AddHeartbeat and UpdateHeartbeat requests have a boolean "Enabled" field to determine a heartbeat is enabled or disabled. enabled is not a mandatory field in both requests so, it has "omitempty" flag.
When JSON is unmarshalling the requests, it omits the fields contains zero value of its type when this option is set.
The problem starts here: When you want to set the Enabled field as false, JSON does not unmarshal it because it contains boolean zero value and has option omitempty. This problem occurs with strings; when you want to reset a heartbeat's description. To set heartbeat's description as empty string, you should make the request with Description :"". But JSON does not unmarshal it either.
So, to solve this we followed go-github's solution as mentioned here. We used pointers just for booleans, if you want to set a string's value to empty. please use " ", or "-" as new string value.
The Web API
Please follow the links below for more information and details about the Web API.
Bug Reporting and Feature Requests
If you like to report a bug, or a feature request; please open an issue.