1.0.0 • Published 3 years ago

splunk-oncall-client v1.0.0

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
3 years ago

Splunk On-Call Client npm version Build Status Coverage Status codecov

The splunk-oncall-client library contains a simple and convenient HTTP client for making requests to the Splunk On-Call (VictorOps) REST API.

Table of contents

Installation

Using NPM:

$ npm install splunk-oncall-client

Using Yarn:

$ yarn add splunk-oncall-client

Usage

Initialize the client

The library exports a SplunkOnCallClient class. All you need to do is instantiate it, and you're ready to go. You'll need an API ID and API key provided by the Splunk On-Call service. You can provide these values as apiId and apiKey options or set these values as environment variables using SPLUNK_ONCALL_API_ID and SPLUNK_ONCALL_API_KEY. By default, the client will use the SPLUNK_ONCALL_API_ID and SPLUNK_ONCALL_API_KEY environment variables if apiId and apiKey are not provided in the options.

Example import methods:

const SplunkOnCallClient = require('splunk-oncall-client');

const client = new SplunkOnCallClient({
  apiId: 'API-ID',
  apiKey: 'API-KEY'
});
import SplunkOnCallClient from 'splunk-oncall-client';

const client = new SplunkOnCallClient({
  apiId: 'API-ID',
  apiKey: 'API-KEY'
});

It is required to set the API ID and API key parameters as either environment variables or as options when instantiating the client. These parameters are necessary to execute SplunkOnCallClient calls. If these parameters are not provided or cannot be determined, then an error is thrown.

Using environment variables in an application:

const SplunkOnCallClient = require('splunk-oncall-client');

// Set the API ID and key as environment variables.
process.env.SPLUNK_ONCALL_API_ID = 'SOME-API-ID';
process.env.SPLUNK_ONCALL_API_KEY = 'SOME-API-KEY';

const client = new SplunkOnCallClient();

Setting environment variables before running an application:

Linux:

$ SPLUNK_ONCALL_API_ID=SOME-API-ID SPLUNK_ONCALL_API_KEY=SOME-API-KEY node app.js

Windows:

> cmd /C "set SPLUNK_ONCALL_API_ID=SOME-API-ID && set SPLUNK_ONCALL_API_KEY=SOME-API-KEY && node app.js"

Options

These are the available options for creating a SplunkOnCallClient instance. If the apiId and apiKey options are not provided, then the SPLUNK_ONCALL_API_ID and SPLUNK_ONCALL_API_KEY environment variables will be used instead.

NameDefaultDescription
apiIdundefinedSplunk On-Call API ID
apiKeyundefinedSplunk On-Call API Key
timeout5000Number of milliseconds before the request times out
baseUrlhttps://api.victorops.comThe base URL for the Splunk On-Call REST API
fullResponsefalseGet the full response instead of just the body
maxContentLength10000The max size of the HTTP response content in bytes
maxBodyLength2000The max allowed size of the HTTP request body in bytes

Examples

Create an instance:

const SplunkOnCallClient = require('splunk-oncall-client');

const client = new SplunkOnCallClient({
  apiId: 'API-ID',
  apiKey: 'API-KEY'
});

Get a list of users:

async function getUsers() {
  try {
    const users = await client.users.getUsers();
    return users;
  } catch(err) {
    console.error(err);
  }
}

Get a list of incidents:

async function getIncidents() {
  try {
    const incidents = await client.incidents.getIncidents();
    return incidents;
  } catch(err) {
    console.error(err);
  }
}

Create a new incident:

async function createIncident() {
  try {
    const resp = await client.incidents.createIncident({
      summary: 'Test incident',
      details: 'Something bad happened!!!',
      userName: 'johndoe',
      targets: [
        {
          type: 'User',
          slug: 'johndoe'
        }
      ],
      isMultiResponder: true
    });
    return resp;
  } catch(err) {
    console.error(err);
  }
}

Get a list of teams:

async function getTeams() {
  try {
    const teams = await client.teams.getTeams();
    return teams;
  } catch(err) {
    console.error(err);
  }
}

Documentation

The client instance has a named property for each of the public endpoints in the Splunk On-Call (VictorOps) REST API. Each endpoint property contains methods that correspond to the operations associated with the endpoint (according to the Splunk On-Call API). All named endpoint methods return a Promise which resolves with the response data or rejects with an error. Below are the endpoints and operations included with the client.

Any endpoint operation that takes a query argument expects the value to be an Object that contains the query parameters for that particular endpoint operation. Please refer to the endpoint operation's documentation for the correct query parameters.

On-Call

Incidents

Alerts

Reporting

Users

User Contact Methods

User Paging Policies

Personal Paging Policy Values

Personal Paging Policies

Teams

Escalation Policies

Routing Keys

Scheduled Overrides

Rotations

Webhooks

Chat

Notes

Maintenance Mode

Change Log

The CHANGELOG contains descriptions of notable changes.

License

This software is licensed under the Apache 2 license.