PHPackages                             preprio/opsgenie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. preprio/opsgenie

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

preprio/opsgenie
================

1.0.9(4mo ago)29.9k↓40.3%[1 PRs](https://github.com/preprio/opsgenie/pulls)MITPHPCI passing

Since Jan 24Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/preprio/opsgenie)[ Packagist](https://packagist.org/packages/preprio/opsgenie)[ RSS](/packages/preprio-opsgenie/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (12)Used By (0)

Prepr Laravel Opsgenie SDK
==========================

[](#prepr-laravel-opsgenie-sdk)

This SDK is used by the Prepr team to monitor Laravel projects in Atlassian Opsgenie.

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require preprio/opsgenie

```

### Config

[](#config)

Publish `opsgenie.php` config

```
php artisan vendor:publish --provider="Prepr\OpsGenie\OpsGenieServiceProvider"

```

Configuration
-------------

[](#configuration)

Update `.env` file with the api access token (API\_ACCESS\_TOKEN) and service id (SERVICE\_ID).

Example:

```
OPSGENIE_KEY=API_ACCESS_TOKEN
OPSGENIE_SERVICE=SERVICE_ID

```

### Optional configuration

[](#optional-configuration)

### Prefix

[](#prefix)

It's optional to add a prefix to the message that's send to Opsgenie, to clearify what service/repo. You can add a prefix by configuring the following line in your `.env` file.

```
OPSGENIE_PREFIX=preprio/mutation.prepr.io

```

Examples:

configresultPREFIX`[PREFIX] Message`preprio/mutation.prepr.io`[preprio/mutation.prepr.io] MESSAGE`mutation-api`[mutation-api] MESSAGE`### Default tags

[](#default-tags)

It's optional to add default tags to the message that's send to Opsgenie. You can add a default tags by configuring the following line in your `.env` file. (comma-separated list)

```
OPSGENIE_TAGS=tagOne,tagTwo,etc.

```

Docs OpsGenie
-------------

[](#docs-opsgenie)

- [Overview](https://docs.opsgenie.com/docs/api-overview)
- [Create Alert](https://docs.opsgenie.com/docs/alert-api#create-alert)
- [Create Incident](https://docs.opsgenie.com/docs/incident-api#create-incident)

Usage
-----

[](#usage)

### Base

[](#base)

#### For an incident

[](#for-an-incident)

```
Ops()->incident()
```

#### For an alert

[](#for-an-alert)

```
Ops()->alert()
```

### Priority functions (required)

[](#priority-functions-required)

Set incident priority.

PriorityFunctionCritical`->P1()` or `->critical()`High`->P2()` or `->high()`Moderate`->P3()` or `->moderate()`Low`->P4()` or `->low()`Informational`->P5()` or `->informational()`### Message (required)

[](#message-required)

Set incident title.

```
->message('Import failed')
```

### Description (optional)

[](#description-optional)

Set incident description.

```
->description('Import failed')
```

### Details (optional)

[](#details-optional)

Set incident details. (Key-Value list)

```
->description([
        'environment' => 'xxx-xxx-xxx',
        'file' => 'xxx_x_xxxx_xxxx_xx.csv'
        'example' => true
    ])
```

### Tags (optional)

[](#tags-optional)

Set incident tags. (Simple list)

```
->tags(['critical', 'import', 'micro-service'])
```

### Send (required)

[](#send-required)

Send incident to Opsgenie.

```
->send();
```

### Full example:

[](#full-example)

Function above combined.

```
Ops()
    ->incident()
    ->critical()
    ->message('Import failed')
    ->description('The import script failed to import data from customer X.')
    ->details([
        'environment' => 'xxx-xxx-xxx',
        'file' => 'xxx_x_xxxx_xxxx_xx.csv'
        'example' => true
    ])
    ->tags(['critical', 'import', 'micro-service'])
    ->send();
```

Alert attachments
-----------------

[](#alert-attachments)

### Attach Resource/Blob (optional)

[](#attach-resourceblob-optional)

You can add attachments to alerts like log files, exception files, renders, json, etc. By adding the following function(s) after `->send()`.

```
Ops()
    ...
    ->send()
    ->attachBlob('RESOURCE/BLOB', 'filename_with.extension');
```

You can also attach multiple files

```
Ops()
    ...
    ->send()
    ->attachBlob('RESOURCE/BLOB', 'filename_with.extension')
    ->attachBlob('Hello World!
