mpeltonen / site24x7-go

Golang API Client for https://www.site24x7.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

site24x7-go

Build Status Go Report Card GoDoc

An API client for Site24x7 written in go. Currently the following endpoints are implemented:

  • Current Status
  • IT Automations
  • Location Profiles
  • Location Template
  • Monitor Groups
  • Monitors
  • Notification Profiles
  • Threshold Profiles
  • User Groups

If you want to add support for other endpoints as well or want to add missing fields to an existing endpoint, we are happy to accept Pull Requests.

Site24x7 OAuth Scopes

The following Site24x7 OAuth Scopes are required for using the implemented endpoints:

  • Monitors, Monitor Groups, Location Profiles, Notification Profiles, Threshold Profiles, User Groups
    • Create: Site24x7.Admin.Create
    • Get/List: Site24x7.Admin.Read
    • Update: Site24x7.Admin.Update
    • Delete: Site24x7.Admin.Delete
  • IT Automations
    • Create: Site24x7.Operations.Create
    • Get/List: Site24x7.Operations.Read
    • Update: Site24x7.Operations.Update
    • Delete: Site24x7.Operations.Delete
  • Current Status
    • Get/List: Site24x7.Reports.Read

Installation

go get -u github.com/Bonial-International-GmbH/site24x7-go

Usage Example

The API client needs the OAuth2 client ID, client secret and refresh token to authenticate against Site24x7 and obtain OAuth access tokens. Refer to the official documentation for instructions on how to obtain these credentials.

Here is a very simple example of creating a website monitor:

package main

import (
	"fmt"
	"os"
	"time"

	site24x7 "github.com/Bonial-International-GmbH/site24x7-go"
	"github.com/Bonial-International-GmbH/site24x7-go/api"
	apierrors "github.com/Bonial-International-GmbH/site24x7-go/api/errors"
	"github.com/Bonial-International-GmbH/site24x7-go/backoff"
)

func main() {
	config := site24x7.Config{
		ClientID:     os.Getenv("CLIENT_ID"),
		ClientSecret: os.Getenv("CLIENT_SECRET"),
		RefreshToken: os.Getenv("REFRESH_TOKEN"),

		// RetryConfig is optional. If omitted, backoff.DefaultRetryConfig will
		// be used.
		RetryConfig: &backoff.RetryConfig{
			MinWait:    1 * time.Second,
			MaxWait:    30 * time.Second,
			MaxRetries: 4,
			CheckRetry: backoff.DefaultRetryPolicy,
			Backoff:    backoff.DefaultBackoff,
		},
	}

	client := site24x7.New(config)

	monitor := &api.Monitor{
		DisplayName: "my monitor",
		Website:     "https://example.com",
	}

	monitor, err := client.Monitors().Create(monitor)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Monitor %q created (ID: %s)\n", monitor.DisplayName, monitor.MonitorID)
	fmt.Printf("%+v\n\n", monitor)

	monitorID := "123"

	monitor, err = client.Monitors().Get(monitorID)
	if apierrors.IsNotFound(err) {
		fmt.Printf("monitor %s not found\n", monitorID)
	} else if err != nil {
		panic(err)
	} else {
		fmt.Printf("%+v\n\n", monitor)
	}
}

Refer to the godoc for all available endpoints and API types.

Also check out the other usage examples in the _examples/ subdirectory.

License

The source code of site24x7-go is released under the MIT License. See the bundled LICENSE file for details.

About

Golang API Client for https://www.site24x7.com

License:MIT License


Languages

Language:Go 98.6%Language:Shell 0.8%Language:Makefile 0.6%