Giter VIP home page Giter VIP logo

opsgenie-go-sdk's Introduction

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.

Documentation:

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 and GOPATH 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.

opsgenie-go-sdk's People

Contributors

tubaozturk avatar tubaozturk92 avatar victortrac avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.