plugin

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// APIKey is the key to get the NS1 API Key from the decrypted secure data.
	APIKey = "apiKey"
)

Variables

Functions

func NewPulsarDatasource

NewPulsarDatasource creates a new datasource instance.

Types

type App

type App struct {
	AppID string `json:"appid"`
	Name  string `json:"name,omitempty"`
	Jobs  []Job  `json:"jobs"`
}

App is a basic model to exchange information with the frontend.

type GetAppsResponse

type GetAppsResponse struct {
	Apps    []App
	AppsMap map[string]App
	JobsMap map[string]Job
}

GetAppsResponse holds the App and Job info in two formats: A slice to be conveyed to the UI and a couple of maps for internal caching.

type Job

type Job struct {
	JobID string `json:"jobid"`
	Name  string `json:"name"`
}

Job is a basic model to put info usable by the frontend.

type PulsarAppParameter

type PulsarAppParameter func(p *PulsarAppParameters)

func OptionAppFetchJobs

func OptionAppFetchJobs(fetchJobs bool) PulsarAppParameter

OptionAppFetchJobs indicates the GetApp function to retrieve the Job list for each Pulsar App.

func OptionJobsFetchInactive

func OptionJobsFetchInactive(fetchInactive bool) PulsarAppParameter

OptionJobsFetchInactive indicates that the API must also retrieve jobs marked as inactive along with active ones.

func PulsarAppFetchInactive

func PulsarAppFetchInactive(fetchInactive bool) PulsarAppParameter

PulsarAppFetchInactive indicates the GetApp function to retrieve Apps marked as Inactive.

type PulsarAppParameters

type PulsarAppParameters struct {
	FetchInactiveApps bool
	FetchJobs         bool
	FetchInactiveJobs bool
}

PulsarAppParameters are all the options available to retrieve Apps and Jobs. The options are dynamically provided.

type PulsarClient

type PulsarClient struct {
	// contains filtered or unexported fields
}

PulsarClient is the main Object and contain the implementation of the Query Logic.

func NewPulsarClient

func NewPulsarClient() *PulsarClient

NewPulsarClient is the default constructor for the Pulsar Client object.

func (*PulsarClient) CheckAPIKey

func (pc *PulsarClient) CheckAPIKey(apiKey string) error

CheckAPIKey verifies the provided API key against the NS1 API. It returns error if the key is invalid, meaning that the authorization was denied.

func (*PulsarClient) GetApps

func (pc *PulsarClient) GetApps(apiKey string, params ...PulsarAppParameter) (*GetAppsResponse, error)

GetApps query the NS1 API and retrieves the Pulsar Apps and optionally their Pulsar Jobs.

func (*PulsarClient) GetData

func (pc *PulsarClient) GetData(apiKey string, query *queryModel) ([]time.Time, []float64, error)

GetData queries the NS1 API to fetch the performance or availability data. It requires the actual query string and an instance of the queryModel. Returns 3 values:

  • A slice of times. This is passed to the Frame.
  • A slice of values. This is passed to the Frame.
  • An error if something goes wrong.

func (*PulsarClient) GetJobs

func (pc *PulsarClient) GetJobs(apiKey, appID string, params ...PulsarAppParameter) ([]Job, error)

GetJobs retrieves a Job slice given the appID.

type PulsarData

type PulsarData struct {
	// contains filtered or unexported fields
}

PulsarData is the data struct for caching Apps and Jobs. Given that the plugin instance can use only one API Key, these values will be the same for any user of the plugin. The ttl field it's expressed in seconds.

func NewPulsarData

func NewPulsarData(appsResponse *GetAppsResponse, ttl time.Duration) *PulsarData

NewPulsarData is the constructor for the Pulsar Data (apps and jobs).

type PulsarDatasource

type PulsarDatasource struct {
	// contains filtered or unexported fields
}

PulsarDatasource is an example datasource which can respond to data queries, reports its health and has streaming skills.

func (*PulsarDatasource) CheckHealth

CheckHealth handles health checks sent from Grafana to the plugin. The main use case for these health checks is the test button on the datasource configuration page which allows users to verify that a datasource is working as expected.

func (*PulsarDatasource) Dispose

func (p *PulsarDatasource) Dispose()

Dispose here tells plugin SDK that plugin wants to clean up resources when a new instance created. As soon as datasource settings change detected by SDK old datasource instance will be disposed and a new one will be created using NewPulsarDatasource factory function.

func (*PulsarDatasource) QueryData

QueryData handles multiple queries and returns multiple responses. req contains the queries []DataQuery (where each query contains RefID as a unique identifier). The QueryDataResponse contains a map of RefID to the response for each query, and each response contains Frames ([]*Frame).

Jump to

Keyboard shortcuts

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