Skip to content

A Node.js library for interacting with the Splunk On-Call REST API.

License

Notifications You must be signed in to change notification settings

pauldenver/splunk-oncall-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Name Default Description
apiId undefined Splunk On-Call API ID
apiKey undefined Splunk On-Call API Key
timeout 5000 Number of milliseconds before the request times out
baseUrl https://api.victorops.com The base URL for the Splunk On-Call REST API
fullResponse false Get the full response instead of just the body
maxContentLength 10000 The max size of the HTTP response content in bytes
maxBodyLength 2000 The 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.

About

A Node.js library for interacting with the Splunk On-Call REST API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published