OpsGenie Node.js API

The OpsGenie SDK for Node.js provides a set of Node.js API for OpsGenie services, making it easier for Node.js developers to build applications that integrate with OpsGenie. Developers can build Node.js applications on top of APIs that take the complexity out of coding directly against a web service interface. The library provides APIs that hide much of the lower-level plumbing, including authentication, request retries, and error handling.

Before you begin, you must sign up for OpsGenie service, create an API Integration and get your API key. In order to use the OpsGenie Node.js SDK, you will need the API key from the API Integration you created. The API key is used to authenticate requests to the service and identify yourself as the sender of a request.

Node.js SDK Installation

Opsgenie Node.js SDK requires Node.js (version > 0.6) to be installed. You can install from Node.js website. Following that the API can be installed using npm install opsgenie-sdk (add --save option if you want it to be added to package.json automatically). The command will automatically download and install necessary package files and dependencies.

OpsGenie Node.js Sdk source code is available at GitHub OpsGenie Node.js Sdk repository.

Client Initialization

Opsgenie client is the basic data structure on which all operations and actions are taken. A client variable can be created as following.

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

    opsgenie.configure({
        'api_key': 'your_api_key'
    });
          

It is required to set the API key parameter to execute Opsgenie Web Api calls using client. Otherwise the authentication will fail and the API is going to raise an exception.

Alert API

Create Alert

        var create_alert_json = {
            "message": "Hello world my alert :)"
        };

        opsgenie.alert.create(create_alert_json, function (error, alert) {
            if (error) {
                console.error(error);
            } else {
                console.log(alert);
            }
        });
          

Close Alert

            var close_alert_json = {
                id: "alert_id"
            };

            opsgenie.alert.close(close_alert_json, function (error, alert) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Close Alert Response");
                }
            });
          

Delete Alert

            var delete_alert_json = {
                "id": "alert_id"
            };

            opsgenie.alert.delete(delete_alert_json, function (error, alert) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Delete Alert Response");
                }
            });
          

Get Alert

            var get_alert_json = {
                id: "alert_id"
            };

            opsgenie.alert.get(get_alert_json, function (error, alert) {
                if (error) {
                    console.log("Error status: " + error.httpStatusCode);
                } else {
                    console.log("Get Alert Response");
                }
            });
          

List Alerts

           var list_alert_json = {};

            opsgenie.alert.list(list_alert_json, function (error, alerts) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("List Alert Response: ", alerts);
                }
            });
          

Count Alerts

            var count_alert_json = {};

            opsgenie.alert.count(count_alert_json, function (error, alert) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Count Alerts Response");
                }
            });
          

List Alert Logs

            opsgenie.alert.listAlertLogs({id: alertId}, function (error, listAlertLogsSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("List Alert Logs Success: ", listAlertLogsSuccess);
                }
            });
          

List Alert Notes

            opsgenie.alert.listAlertNotes({id: alertId}, function (error, listAlertNotesSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("List Alert Notes Success: ", listAlertNotesSuccess);
                }
            });
          

List Alert Recipients

            opsgenie.alert.listAlertRecipients({"id": alertId}, function (error, listAlertRecipientSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("List Alert Recipient Success: ", listAlertRecipientSuccess);
                }
            });
          

Acknowledge

            opsgenie.alert.acknowledge({id: alertId}, function (error, acknowledgeSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Acknowledge Success: ", acknowledgeSuccess);
                }
            });
          

Snooze

            var snooze_json = {
                "id": alertId
            };

            opsgenie.alert.snooze(snooze_json, function (error, snoozeSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Snooze Success: ", snoozeSuccess);
                }
            });
          

Renotify

            var renotify_json = {
                "id": alertId,
                "recipients": "user1@opsgenie.com"
            };

            opsgenie.alert.renotify(renotify_json, function (error, renotifySuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Renotify Success: ", renotifySuccess);
                }
            });
          

Take Ownership

            opsgenie.alert.takeOwnership({"id": alertId}, function (error, takeOwnershipSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Take Ownership Success: ", takeOwnershipSuccess);
                }
            });
          

Assign Owner

            var assign_json = {
                "id": alertId,
                "owner": "user1@opsgenie.com"
            };

            opsgenie.alert.assign(assign_json, function (error, assignSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Assign Success: ", assignSuccess);
                }
            });
          

Add Team

            var add_team = {
                "id": alertId,
                "team": "team1"
            };

            opsgenie.alert.addTeam(add_team, function (error, addTeamSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Add Team Success: ", addTeamSuccess);
                }
            });
          

Add Recipient

            var add_recipient = {
                "id": alertId,
                "recipient": "user1@opsgenie.com"
            };

            opsgenie.alert.addRecipient(add_recipient, function (error, addRecipientSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Add Recipient: ", addRecipientSuccess);
                }
            });
          

Add Note

            var add_note_json = {
                "id": alertId,
                "note": "custom note"
            };

            opsgenie.alert.addNote(add_note_json, function (error, addNoteSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Add Note: ", addNoteSuccess);
                }
            });
          

Add Tags

            var add_tags_json = {
                "id": alertId,
                "tags": "tag1, tag2"
            };

            opsgenie.alert.addTags(add_tags_json, function (error, addTagsSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Add Tags: ", addTagsSuccess);
                }
            });
          

Remove Tags

            var remove_tags_json = {
                "id": alertId,
                "tags": "tag1, tag2"
            };

            opsgenie.alert.removeTags(remove_tags_json, function (error, removeTagsSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Remove Tags: ", removeTagsSuccess);
                }
            });
          

Add Details

            var add_details_json = {
                "id": alertId,
                "details": {"prop1" : "val1", "prop2" : "val2"}
            };

            opsgenie.alert.addDetails(add_details_json, function (error, addDetailsSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Add Details: ", addDetailsSuccess);
                }
            });
          

Remove Details

            var remove_details_json = {
                "id": alertId,
                "details": {"prop1" : "val1", "prop2" : "val2"}
            };

            opsgenie.alert.removeDetails(remove_details_json, function (error, removeDetailsSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Remove Details: ", removeDetailsSuccess);
                }
            });
          

Execute Action

            var execute_action_json = {
                "action": "acknowledge"
            };

            opsgenie.alert.executeAction(execute_action_json, function (error, executeActionSuccess) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Execute Action Success: ", executeActionSuccess);
                }
            });
          

User API

Available actions:

  • opsgenie.user.create(json, error, success)
  • opsgenie.user.get(json, error, success)
  • opsgenie.user.update(json, error, success)
  • opsgenie.user.list(json, error, success)
  • opsgenie.user.delete(json, error, success)
  • opsgenie.user.deleteById(json, error, success)

Group API

Available actions:

  • opsgenie.group.create(json, error, success)
  • opsgenie.group.get(json, error, success)
  • opsgenie.group.update(json, error, success)
  • opsgenie.group.list(json, error, success)
  • opsgenie.group.delete(json, error, success)
  • opsgenie.group.deleteById(json, error, success)
  • opsgenie.group.addMember(json, error, success)
  • opsgenie.group.removeMember(json, error, success)

Team API

Available actions:

  • opsgenie.user.create(json, error, success)
  • opsgenie.user.get(json, error, success)
  • opsgenie.user.update(json, error, success)
  • opsgenie.user.list(json, error, success)
  • opsgenie.user.delete(json, error, success)
  • opsgenie.user.deleteById(json, error, success)
  • opsgenie.group.addMember(json, error, success)
  • opsgenie.group.removeMember(json, error, success)
  • opsgenie.group.listLogs(json, error, success)

Heartbeat API

(Will be avaliable soon)

Policy API

(Will be avaliable soon)

Integration API

(Will be avaliable soon)