• Products
  • Get started
  • Documentation
  • Resources

Attach a file to an alert through Marid

Marid is deprecated and will be permanently retired on November 21st, 2022. Read the community post for more details.

If you never used our extensibility platform before, visit Opsgenie Edge Connector as an extensibility platform to find out how to run it with your Opsgenie account.

If you're using Marid and want to migrate to Opsgenie Edge Connector, visit Why should you migrate to Opsgenie Edge Connector.

Marid can subscribe to Opsgenie user actions and execute a script for each user action. A common usage of this feature is by subscribing "Create Action" and attaching a file to the newly created alert via the script. To get more information about action execution, please refer to Marid Integration support document.

This document demonstrates how to download a file from Amazon S3, and then attach it to the alert via Marid with a "Groovy" script. The sample script uses OpsgenieHttpClient object to receive the file from S3 and then uses "opsgenie" script variable to attach the received file to the alert.

Script first constructs OpsfenieHttpClient object by using the "createHttpClient" method. Then OpsfenieHttpClient sends a "GET" request by using the specified URL. If receives file from s3 successfully; attaches the file to the alert.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 import com.ifountain.opsgenie.client.http.OpsGenieHttpClient import com.ifountain.opsgenie.client.util.ClientConfiguration //Creates OpsGenieHttpClient. OpsGenieHttpClient HTTP_CLIENT = createHttpClient() // S3 url of the file that will be attached to the alert. def url = "https://s3.amazonaws.com/yourbucket/yourfile.png" //Sending request to retrieve file def response = HTTP_CLIENT.get(url, [:]) def code = response.statusCode if(code == 200){ //attaching the file to the alert when retrieving the file successfully. logger.warn("File received") //filename of the attachment file. Change file extension according to your usage. // If your file is a txt, use trial.txt as fileName def fileName = "trial.png" resp = opsgenie.attach([alertId: alert.alertId, stream: new ByteArrayInputStream(response.getContent()), fileName: fileName]) if(resp.success){ logger.warn("Successfully attached details ${fileName}"); }else{ logger.warn("Could not attach details ${fileName}"); } }else{ logger.warn("Could not get file from url ${url}. ResponseCode:${code} Reason:" + response.getContentAsString()) } def createHttpClient() { //if you want to use different timeout value, add "http.timeout" property to Marid's conf file. def timeout = conf["http.timeout"] if(timeout == null){ timeout = 30000; } else{ timeout = timeout.toInteger(); } ClientConfiguration clientConfiguration = new ClientConfiguration().setSocketTimeout(timeout) //To use basic authentication while getting the file that will be attached, // comment in the line below and add "user" and "password" properties to Marid's conf file // .setCredentials(new UsernamePasswordCredentials(conf["user"], conf["password"])) return new OpsGenieHttpClient(clientConfiguration) }


Additional Help