Script Proxy for Marid

Marid is an open source tool provided by OpsGenie, it supports Groovy & Ruby scripting. Normally OpsGenie Java API methods can be directly used within Marid scripts. OpsGenie also provides a special proxy to easily execute actions against OpsGenie Web API :  

  • A special variable named opsgenie is available to Marid scripts
  • Calls to opsgenie is converted to Java API calls, Java API calls communicate with Web API
  • Using opsgenie is much easier then using Java API methods, less code more work
  • Almost all Web API features available in ScriptProxy 
  • opsgenie can be used by both Groovy & Ruby scripts.
  • opsgenie variable is an instance of com.ifountain.opsgenie.client.script.util.ScriptProxy
  • ScriptProxy source code can be found at OpsGenieClient Github pages
  • To store in memory shared data, use static methods of com.ifountain.opsgenie.client.marid.MemoryStore class. To get more information, please refer to Memory Store section.
apiKey parameter is optional in when using script proxy, if not provided it uses the apiKey in conf file
user parameter is optional in when using script proxy, if not provided it uses the user in conf file
 

Alert API Requests

Other API Requests

Create Alert Request

Create alert request is used to create alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
message Alert text limited to 130 characters

Optional Parameters

Parameter
teams List of team names which will be responsible for the alert. Team escalation policies are run to calculate which users will receive notifications.
alias A user defined identifier for the alert and there can be only one alert with open status with the same alias. Provides ability to assign a known id and later use this id to perform additional actions such as log, close, attach for the same alert.
description To provide detailed information about the alert, limited to 15000 characters
recipients The user names of individual users or groups
actions A comma separated list of actions that can be executed. Custom actions can be defined to enable users to execute actions for each alert. If action callback URL is specified on Settings page of customer, that callback URL will be called when action is executed.
source Field to specify source of alert. By default, it will be assigned to IP address of incoming request
tags A comma separated list of labels attached to the alert. You can overwrite Quiet Hours setting for urgent alerts by adding OverwriteQuietHours tag.
details Set of user defined properties. This will be specified as a nested map such as "details" : { "prop1":"prop1Value" "prop2":"prop2Value" }
entity The entity the alert is related to.
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
Sample Request
opsgenie.createAlert(["message":"Sample Alert","recipients":"all"])
Sample Advanced Request
def response = opsgenie.createAlert([
        "message":"Sample Alert",
        "teams":["ops_team"],
        "recipients":["user1@yourdomain.com","user2@yourdomain.com"],
        "description":"for demo usage",
        "alias":"demo",
        "tags":["demo","sample"],
        "actions":["ping"]
])
logger.warn("Alert is created with id ${response.id}");

Close Alert Request

Close alert request is used to close open alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be closed. Either id or alias must be provided
alias Alias of the alert that will be closed. Either id or alias must be provided. Alias option can only be used for open alerts
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
notify Comma separated list of user and groups which will be notified. Also special values "all", "recipients" and "owner" is accepted.
source User defined field to specify source of close action.
Sample Request
opsgenie.closeAlert(["id":"123"])
Advanced Request
opsgenie.closeAlert(["alias":"demo","user":"user1@yourdomain.com","note":"closing demo alert"])

Delete Alert Request

Delete alert request is used to delete closed alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be deleted.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
source User defined field to specify source of delete action.
Sample Request
opsgenie.deleteAlert(["id":"123"])

Get Alert Request

Get alert request is used to search and retrieve alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
apiKey API key is used for authenticating API requests
id Id of alert to be retrieved
alias Alias of alert to be retrieved
tinyId short id assigned to the alert
One of id, alias or tinyId parameters should be specified with get alert request.
Sample request to retrieve a single alert
opsgenie.getAlert(["id":"123"])
opsgenie.getAlert(["alias":"demo"])
Response ( Groovy Map ) :
[
    "tags": [ ],
    "message": "WebServer3 is down",
    "id": "ac463592-dbd2-4ca3-a333d-48fhf5j5c871",
    "details": [
        "ip": "192.168.1.87"
    ],
    "tinyId": "324",
    "source": "fili@opsgenie.com",
    "status": "open",
    "alias": "host_down",
    "teams": [
        "ops_team",
        "dev_team"
    ],
    "recipients": [
        "kili@opsgenie.com"
    ],
    "description": "WebServer3 is down due to failure in WAN-1 connection.",
    "createdAt": 1349698149317,
    "updatedAt": 1349698149317,
    "entity": "",
    "isSeen":true,
    "acknowledged":false,
    "owner":"kili@opsgenie.com",
    "actions": [ ]
}

List Alerts Request

List alerts request is used to list alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
There is no mandatory parameter

Optional Parameters

Parameter
createdAfter Unix timestamp value which is converted to nano second. Request will return all alerts which are created after specified time.
createdBefore Unix timestamp value which is converted to nano second. Request will return all alerts which are created before specified time.
updatedAfter Unix timestamp value which is converted to nano second. Request will return all alerts which are updated after specified time.
updatedBefore Unix timestamp value which is converted to nano second. Request will return all alerts which are updated before specified time.
limit Page size. Default is 20. Max value for this parameter is 100.
status Used to query alerts with specified status. May take one of open, acked, unacked, seen, notseen, closed
sortBy createdAt, updatedAt, default is createdAt
order asc/desc, default : desc
Sample requests to retrieve list of alerts
retrieve the last 20 alerts (20 is the default for limit, 100 is the max for limit)
opsgenie.listAlerts([:]).each{ alert ->
    logger.warn("Found alert ${alert.message}");
}
retrieve the last 10 closed alerts
opsgenie.listAlerts(["status":"closed","limit":10])
Response ( Groovy List of Map ) :
[
    [
        "id" : "ac463592-dbd2-4ca3-a651d-48fhf5j5c871",
        "alias" : "host_down",
        "message" : "Host 192.168.1.1 is down",
        "status" : "open",
        "isSeen" : false,
        "acknowledged" : false,
        "createdAt" : "1351634560000000",
        "updatedAt" : "1351634560000000",
        "tinyId" : "111"
    ],
    [
        "id" : "cf463592-emt2-4ca3-a651d-56hhf5j5c132",
        "alias" : "app_down",
        "message" : "Web server Web_Server1 is down",
        "status" : "closed",
        "isSeen" : true,
        "acknowledged" : false,
        "createdAt" : "1351634560000000",
        "updatedAt" : "1351634560000000",
        "tinyId" : "66"
    ],
]

List Alert Logs Request

List alert logs request is used to retrieve alert logs in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of alert to be retrieved
alias Alias of alert to be retrieved
tinyId tinyId of alert

Optional Parameters

Parameter
limit Page size. Default is 100.
order asc/desc, default : desc
lastKey Key which will be used in pagination.
Sample request to retrieve a single alert 
opsgenie.listAlertLogs(["id":"123"])
Response:
[ 
    "lastKey": "13099992234_1309999223432245566",
    "logs": [ 
        ["log": "log message", "logType":"comment", "owner":"user1@xyz.com", "createdAt":13099992234] 
    ]
]

List Alert Recipients Request

List alert recipients request is used to retrieve alert recipeints in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of alert to be retrieved
alias Alias of alert to be retrieved
tinyId tinyId of alert
Sample request to retrieve a single alert
opsgenie.listAlertRecipients(["id":"123"])
Response:
[
    "users": [
        ["username": "user1@xyz.com", "state":"pending", "method":"sms", "stateChangedAt":13999878445]
    ],
    "groups": [
        "group1":[
               ["username": "user2@xyz.com", "state":"sent", "method":"email", "stateChangedAt":13997878445]
        ]
    ]
]

List Alert Notes Request

List alert notes request is used to retrieve alert notes in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert to be retrieved
alias Alias of alert to be retrieved
tinyId short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
One of id, alias or tinyId parameters should be specified with list alert notes request. Alias option can only be used for open alerts.

Optional Parameters

Parameter
limit Page size. Default is 100.
order asc/desc, default : desc
lastKey Key which will be used in pagination.
Sample Request
opsgenie.listAlertNotes(["id" : "123"])
Response:

Timestamps are Unix Epoch as nanoseconds

[
    "lastKey": "13099992234_1309999223432245566",
    "notes": [
        [
            "note": "comment message",
            "owner":"user1@xyz.com",
            "createdAt":13099992234
        ]
    ]
]

Acknowledge Request

Acknowledge request is used to acknowledge alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be acknowledged. Either id or alias must be provided
alias Alias of the alert that will be acknowledged. Either id or alias must be provided. Alias option can only be used for open alerts
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of acknowledge action.
Sample Request
opsgenie.acknowledge(["id":"123", "user":"user1@yourdomain.com"])

UnAcknowledge Request

UnAcknowledge request is used to revert back the alert state to un-acknowledged. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be un-acknowledged.
alias Alias of the alert that will be un-acknowledged.
tinyId Short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
One of idalias or tinyId parameters should be specified with un-acknowledge alert request.

Optional Parameters

 
Parameter
user Default owner of the execution. If user is not specified, the system becomes owner of the execution.
note Additional alert note
source User defined field to specify source of unacknowledge action.
Sample Request
opsgenie.unAcknowledge(["id" : "123"])

Snooze Request

Snooze request is used to snooze alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be snoozed.
alias Alias of the alert that will be snoozed.
tinyId short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
endDate The date and time snooze will end.
One of id, alias or tinyId parameters should be specified with snooze alert request. Alias option can only be used for open alerts.

Optional Parameters

 
Parameter
timezone Timezone of endDate parameter. Please look at /docs/miscellaneous/supported-timezone-ids for available timezones. Defaults to Root Timezone, explained in Time Constraints and Timezones document.
user Default owner of the execution. If user is not specified, the system becomes owner of the execution.
note Additional alert note
source User defined field to specify source of snooze action.
Sample Request
opsgenie.snooze(["id" : "123", "endDate" : new Date("11/16/2016 08:00")])
    

Renotify Request

Renotifyrequest is used to renotify recipients about specified alert in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be acknowledged. Either id or alias must be provided
alias Alias of the alert that will be acknowledged. Either id or alias must be provided. Alias option can only be used for open alerts
Optional Parameters
Parameter
recipients The user names of individual users or groups. If not specified alert recipients will be renotified.
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of renotify action.
Sample Request
opsgenie.renotify(["id":"123"])

Take Ownership Request

Take ownership request is used to take the ownership of the alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert whose ownership will be taken. Either id or alias must be provided
alias Alias of the alert whose ownership will be taken. Either id or alias must be provided. Alias option can only be used for open alerts
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of takeownership action.
Sample Request
opsgenie.takeOwnership(["id":"123", "user":"user2@yourdomain.com"])

Assign Request

Assign request is used to assign the ownership of the alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that will be assigned. Either id or alias must be provided
alias Alias of the alert that will be assigned Either id or alias must be provided. Alias option can only be used for open alerts/td>
owner The user who will be the owner of the alert after the execution.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of assign action.
Sample Request
opsgenie.assign(["id":"123", "owner":"otherUser@yourdomain.com"])

Add Team Request

Add team request is used to add a new team to alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that the new team will be added. Either id or alias must be provided
alias Alias of the alert that the new team will be added. Either id or alias must be provided. Alias option can only be used for open alerts
team Name of the new team that will be added.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of add team action.
Sample Request
opsgenie.addTeam(["id":"123", "team":"ops_team"])

Add Recipient Request

Add recipient request is used to add new recipients(user or group) to alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that the new recipient will be added. Either id or alias must be provided
alias Alias of the alert that the new recipient will be added. Either id or alias must be provided. Alias option can only be used for open alerts
recipient The new recipient that will be added.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of add recipient action.
Sample Request
opsgenie.addRecipient(["id":"123", "recipient":"newRecipient@yourdomain.com"])

Add Tags Request

Add Tags request is used to add new tags to alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that new tags will be added. Either id or alias must be provided
alias Alias of the alert that new tags will be added. Either id or alias must be provided. Alias option can only be used for open alerts
tags List of tags will be added to the alert.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of add tags action.
Sample Request
opsgenie.addTags(["id":"123", "tags":["autoClose", "support"]])

Remove Tags Request

Remove Tags request is used to remove tags from alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert given tags will be removed. Either id or alias must be provided.
alias Alias of the alert given tags will be removed. Either id or alias must be provided. Alias option can only be used for open alerts.
tags List of tags will be removed from the alert.
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used.
note Additional alert note.
source User defined field to specify source of remove tags action.
Sample Request
opsgenie.removeTags(["id":"123", "tags":["autoClose", "support"]])

Add Details Request

Add details request is used to add properties to alert details in OpsGenie. If you send an existing alert property's key, it overwrites the existing one. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that details will be added.
alias Alias of the alert that details will be added.
tinyId Short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
details Set of properties to be added to alert details.
One of id, alias or tinyId parameters should be specified with add details request. Alias option can only be used for open alerts.

Optional Parameters

Parameter
user Default owner of the execution. If user is not specified, the system becomes owner of the execution.
source User defined field to specify source of add details action.
note Additional alert note.
Sample Request
opsgenie.addDetails(["id" : "123", "details" : ["prop1" : "val1", "prop2" : "val2"]])

Remove Details Request

Remove details request is used to remove properties from alert details in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that details properties will be removed from.
alias Alias of the alert that details properties will be removed from.
tinyId short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
keys List of keys of alert details properties.
One of id, alias or tinyId parameters should be specified with remove details request. Alias option can only be used for open alerts.

Optional Parameters

Parameter
user Default owner of the execution. If user is not specified, the system becomes owner of the execution.
source User defined field to specify source of remove details action.
note Additional alert note
Sample Request
opsgenie.removeDetails(["id" : "123", "keys" : ["key1", "key2"]])

Add Note Request

Add note request is used to add notes to alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that note will be added. Either id or alias must be provided
alias Alias of the alert that note will be added. Either id or alias must be provided. Alias option can only be used for open alerts
note Note text
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
source User defined field to specify source of add note action.
Sample Request
opsgenie.addNote(["id":"123", "note":"Sample Note"]);

Execute Action Request

Execute action request is used to execute predefined actions on alerts in OpsGenie. It takes the following parameters:

Mandatory Parameters

Parameter
id Id of the alert that action will be executed for. Either id or alias must be provided
alias Alias of the alert that action will be executed for. Either id or alias must be provided. Alias option can only be used for open alerts
action Action to execute
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
note Additional alert note
source User defined field to specify source of action execution.
Sample Request
opsgenie.executeAlertAction(["id":"123", "action":"ping"])

Attach File Request

Attach file request is used to attach files to alerts in OpsGenie. It should be sent as multipart HTTP request. It takes the following parameters:

Mandatory Parameters

Parameter
apiKey API key is used for authenticating API requests
id Id of the alert that attachment will be added. Either id or alias must be provided
alias Alias of the alert that attachment will be added. Either id or alias must be provided. Alias option can only be used for open alerts
attachment Attachment file content
Optional Parameters
Parameter
user Default owner of the execution. If user is not specified owner of account will be used
source User defined field to specify source of attach action.
indexFile Name of html file which will be shown when attachment clicked on UI.
If it is not specified, following rules will be applied by order to determine index file name
  1. if it is not a zip file,  it will be assigned to attachment file name 
  2. If it is a zip file, it will be assigned to
    1. HTML file whose name equals attachment file name
    2. index.htm or index.html file
    3. the first HTML file found in the ZIP
    4. If no HTML file exists, it will be assigned to attachment zip file name and zip file will be downloaded from OpsGenie web site directly when clicked on attachment.
note Additional alert note
Sample Request
opsgenie.attach(["id":"123", "attachment":"sample.txt"])

Escalate To Next Request

Escalate to Next request is used to immediately process the next available available rule in the specified escalation. It takes the following parameters:

For more details see Escalate to Next documentation page

Mandatory Parameters

Parameter
id Id of the alert that details will be added.
alias Alias of the alert that details will be added.
tinyId short id assigned to the alert. All requests supports tinyId but using this field is not recommended because it rolls.
escalationId Id of the escalation that will be escalated to the next level.
escalationName Name of the escalation that will be escalated to the next level.
One of id, alias or tinyId parameters should be specified with escalate to next request. Alias option can only be used for open alerts.
One of escalationId or escalationName parameters should be specified with escalate to next request.

Optional Parameters

 
Parameter
user Default owner of the execution. If user is not specified, the system becomes owner of the execution.
note Additional alert note
source User defined field to specify source of unacknowledge action.
Sample Request
opsgenie.escalateToNext(["id" : "123", "escalationId" : "123"])

Memory Store

You may need to load data to memory and use it later action executions. OpsGenie Marid provides com.ifountain.opsgenie.client.marid.MemoryStore class to meet these needs.
Memory Store class has following helper methods:

Store

Store method adds data as key,value pair into the memory.

Example Usage
import com.ifountain.opsgenie.client.marid.MemoryStore

MemoryStore.store("prop1","val1")

Lookup

Lookup method checks the memory and retrieves the data with the given key if exists.

Example Usage
import com.ifountain.opsgenie.client.marid.MemoryStore

def prop = MemoryStore.lookup("prop1")

Remove

Remove method removes the data with the given key, if exists.

Example Usage
import com.ifountain.opsgenie.client.marid.MemoryStore

MemoryStore.remove("prop1")

Reset

Reset method clears the in memory data store.

Example Usage
import com.ifountain.opsgenie.client.marid.MemoryStore

MemoryStore.reset()