site24x7

package module
v0.0.7-0...-4a53b1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 6 Imported by: 2

README

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.

Documentation

Overview

Package site24x7 provides an API client for managing web application monitors on site24x7.com.

Index

Constants

View Source
const (
	// APIBaseURL is the base url of the Site24x7 API.
	APIBaseURL = "https://www.site24x7.com/api"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	CurrentStatus() endpoints.CurrentStatus
	LocationProfiles() endpoints.LocationProfiles
	LocationTemplate() endpoints.LocationTemplate
	MonitorGroups() endpoints.MonitorGroups
	Monitors() endpoints.Monitors
	NotificationProfiles() endpoints.NotificationProfiles
	ThresholdProfiles() endpoints.ThresholdProfiles
	UserGroups() endpoints.UserGroups
	ITAutomations() endpoints.ITAutomations
}

Client is the Site24x7 API Client interface. It provides methods to get clients for resource endpoints.

func New

func New(c Config) Client

New creates a new Site24x7 API Client with Config c.

func NewClient

func NewClient(httpClient HTTPClient) Client

NewClient creates a new Site24x7 API Client from httpClient with default API base URL. This can be used to provide a custom http client for use with the API. The custom http client has to transparently handle the Site24x7 OAuth flow.

func NewClientWithBaseURL added in v0.0.6

func NewClientWithBaseURL(httpClient HTTPClient, baseURL string) Client

NewClientWithBaseURL creates a new Site24x7 API Client from httpClient and given API base URL. This can be used to provide a custom http client for use with the API. The custom http client has to transparently handle the Site24x7 OAuth flow.

type Config

type Config struct {
	// ClientID is the OAuth client ID needed to obtain an access token for API
	// usage.
	ClientID string

	// ClientSecret is the OAuth client secret needed to obtain an access token
	// for API usage.
	ClientSecret string

	// RefreshToken is a token that's used by the application
	// (as opposed to the user) to refresh the access token
	// if it expires.
	RefreshToken string

	// APIBaseURL allows overriding the default API base URL (https://www.site24x7.com/api).
	// See https://www.site24x7.com/help/api/index.html#introduction for options of data centers for top level domain.
	APIBaseURL string

	// TokenURL allows overriding the default token URL (https://accounts.zoho.com/oauth/v2/token).
	// See https://www.site24x7.com/help/api/index.html#authentication for options of data centers for top level domain.
	TokenURL string

	// RetryConfig contains the configuration of the backoff-retry behavior. If
	// nil, backoff.DefaultRetryConfig will be used.
	RetryConfig *backoff.RetryConfig
}

Config is the configuration for the Site24x7 API Client.

func (*Config) OAuthClient

func (c *Config) OAuthClient(ctx context.Context) *http.Client

OAuthClient creates a new *http.Client from c that transparently obtains and attaches OAuth access tokens to every request.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface of an http client that is compatible with *http.Client.

Directories

Path Synopsis
_examples
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL