Giter VIP home page Giter VIP logo

opsgenie-nodejs-sdk's Introduction

OpsGenie Node.js SDK

npm version Dependency Status

This is the repository for Node.js SDK of OpsGenie.

Aim and Scope

OpsGenie Node.js SDK aims to access OpsGenie Web API through HTTP calls from Node.js applications.

OpsGenie Node.js SDK covers:

  • Alert API v2
  • User API
  • User API v2
  • Group API
  • Team API
  • Heartbeat API
  • Incident API
  • Escalation API (TODO: will be available soon)
  • Schedule API (TODO: will be available soon)
  • Schedule Override API (TODO: will be available soon)
  • Forwarding Rule API (TODO: will be available soon)
  • Integration API (TODO: will be available soon)
  • Policy API (TODO: will be available soon)

Future releases are subject to be delivered for packing more APIs soon.

Installation

Node.js version >=0.6.x is required.

npm install opsgenie-sdk

Getting Started

var opsgenie = require("opsgenie-sdk");

opsgenie.configure({
  api_key: "your_api_key",
});

Those using the European Service Region should set the EU endpooint in the configuration along with the API key.

opsgenie.configure({
    'api_key': 'your_api_key',
    'host': 'https://api.eu.opsgenie.com',
});
var get_alert_identifier = {
  identifier: "alert_id",
  identifierType: "id",
};

opsgenie.alertV2.get(get_alert_identifier, function (error, alert) {
  if (error) {
    // handle error
  } else {
    console.log("Alert data received", alert);
  }
});

Samples

More samples can be found under /samples directory

Also, checkout "Node.js SDK page" for detailed documentation

opsgenie-nodejs-sdk's People

Contributors

ayhanyunt12 avatar bakatz avatar brksfsrt avatar dependabot[bot] avatar hisener avatar insanicly avatar mumblemaker avatar mustafanacar avatar prakhar-mudaiya avatar serhatcan avatar trabab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opsgenie-nodejs-sdk's Issues

Alerts V2 callback receives a string response instead of an object

The following code prints: "string"

opsgenie.alertV2.list(activeAlertsParams, function (error, alerts) {
    if(!error) console.log(typeof(alerts))
}

This is mildly annoying because, in order to reference any properties on alerts, I have to manually call JSON.parse(alerts) myself

Shouldn't the callback be called with the result obtained from JSON.parse(...) instead of just passing the raw response string to the callback?

EDIT: also, my package.json includes this version of the SDK - "opsgenie-sdk": "^0.4.1"

requestretry vulnerability

The requestretry v1.13.0 has a cookie exposure vulnerability.

To reproduce:

$ npm audit

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Cookie exposure in requestretry                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ requestretry                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=7.0.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ opsgenie-sdk                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ opsgenie-sdk > requestretry                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-hjp8-2cm3-cc45            │
└───────────────┴──────────────────────────────────────────────────────────────┘

Environment:

  • Node version: 14.19.0
  • opsgenie-sdk: 1.13.0

Could you be able to update requestretry to 7.0.0?

Version 0.4.4 not working at all

version 0.4.4 deleted alert file /resources/alert.js,
but it's still in use in opsgenie.js

image

The following error will popup when I'm trying to import this package in my code

image

Unable to require ../package in configure.js

I am on Node 8.9.4. I have received the following error:

Cannot find module '../package' from 'configure.js'

I believe the issue is related to trying to require package without the .json extension. When I changed require('../package') to require('../package.json') in lib/configure.js the issue was resolved.

Might be related to the newer version of Node.

devDependencies is outdated

The badge on README.md shows only dependencies. devDependencies is outdated.

devDependencies Status

Also, Greenkeeper is a great tool for automatic dependency updates and free for open source projects.

Travis CI is not active

.travis.yml exists but Travis CI is not active.

I've run npm test on my local machine, it aborted due to jshint warnings.

Cannot set property 'response_stringified' of null

            err.response_stringified = JSON.stringify(response);
                                     ^
TypeError: Cannot set property 'response_stringified' of null
    at handleResponse (/mnt/Code/node_modules/opsgenie-sdk/lib/restApi.js:124:38)
    at Request.<anonymous> (/mnt/Code/node_modules/opsgenie-sdk/lib/restApi.js:110:9)
    at Request._callback (/mnt/Code/node_modules/opsgenie-sdk/node_modules/requestretry/node_modules/lodash/lodash.js:10067:25)
    at Request.requestRetryReply [as reply] (/mnt/Code/node_modules/opsgenie-sdk/node_modules/requestretry/index.js:105:19)
    at Request.<anonymous> (/mnt/Code/node_modules/opsgenie-sdk/node_modules/requestretry/index.js:133:10)
    at Request.self.callback (/mnt/Code/node_modules/request/request.js:188:22)
    at Request.emit (events.js:110:17)
    at Request.<anonymous> (/mnt/Code/node_modules/request/request.js:1171:10)
    at Request.emit (events.js:107:17)
    at IncomingMessage.<anonymous> (/mnt/Code/node_modules/request/request.js:1091:12)
    at IncomingMessage.g (events.js:199:16)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

The error is in this part:

    if (response.statusCode < 200 || response.statusCode >= 300) {
        if (process.env.NODE_ENV === 'development') {
            err.response_stringified = JSON.stringify(response);
        }```

Alerts V2 List API throws 500 errors when createdAt is passed as a decimal value

For example, the following params causes a 500 error to be returned from the server:


var activeAlertsParams = {
        query: 'status != closed createdAt >=151003410.486',
        offset: 0,
        limit: 1,
        sort: 'alias',
        order: 'desc'
      }

...while the following works fine:

var activeAlertsParams = {
        query: 'status != closed createdAt >=151003410',
        offset: 0,
        limit: 1,
        sort: 'alias',
        order: 'desc'
      }

I would expect a 422 / 400 status code in this case, not a 500.

heartbeat.ping appears to have extra parameter

Hello,

I noticed that the ping function in lib/heartbeat/Heartbeat.js takes 4 parameters and is passing 4 parameters to restApi.get. However, restApi.get appears to only accept 3 parameters. Should the data parameter be removed from the heartbeat ping function?

image

image

TypeScript Support

It would be great if we could use this SDK with Typescript via a @types/opsgenie-sdk npm package

opsgenie.configure() doesn't change the default retryDelay

    opsgenie.configure({
      retryDelay: 3, //     <--- doesn't change anything
    });
    
    const createAlertRequest = {...};
    
    opsgenie.alertV2.create(createAlertRequest, (requestStatus) => {
          this.logger.info(`Created Opsgenie alert`, requestStatus, createAlertRequest);
          const requestId = requestStatus?.requestId;
          resolve({ requestId });
        });

will still use the default 5s delay

Return alertId for all operations (like in the case of create)

When a create request is made the result contains also the newly created alertId:

{
    "took": 84,
    "code": 200,
    "alertId": "8faa119e-3d24-4878-abba-c69d7fee8c8b",
    "message": "alert created",
    "status": "successful",
    "httpStatusCode": 200
}

It would be very practical if other operations as well would return the alertId. For example the close operation, where one can close alerts based on an alias as well (and hence not having the alertId). Currently the close operation returns:

POST /v1/json/alert/close
{
    "alias": "myalias"
}
{
    "took": 54,
    "code": 200,
    "status": "successful",
    "httpStatusCode": 2
}

Here, the alertID would avoid us doing an extra request to get the alert with the given alias.

For the delete operation this might not make much sense from the OpsGenie point of view. But when correlating these alert IDs with external systems, it would be nice to always return the ID.

(I know this is an extension that should be added to the underlying WebAPI)

can't get a list of users

var opsgenie = require('opsgenie-sdk')

opsgenie.configure({
  api_key: ''
})

async function main() {
  const a = await opsgenie.user.list({})
  console.log(a)
}

main()

undefined
undefined:1
No handler found for url /v1/json/user/
^

SyntaxError: Unexpected token N in JSON at position 0
at JSON.parse ()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.