preprio/opsgenie

1.0.8 2024-01-05 16:06 UTC

This package is auto-updated.

Last update: 2024-09-05 17:40:35 UTC


README

此SDK由Prepr团队用于监控Atlassian Opsgenie中的Laravel项目。

安装

Composer

composer require preprio/opsgenie

配置

发布 opsgenie.php 配置文件

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

配置

将API访问令牌(API_ACCESS_TOKEN)和服务ID(SERVICE_ID)更新到 .env 文件中。

示例

OPSGENIE_KEY=API_ACCESS_TOKEN
OPSGENIE_SERVICE=SERVICE_ID

可选配置

前缀

添加前缀到发送到Opsgenie的消息是可选的,以明确服务/仓库。您可以通过在 .env 文件中配置以下行来添加前缀。

OPSGENIE_PREFIX=preprio/mutation.prepr.io

示例

默认标签

添加默认标签到发送到Opsgenie的消息是可选的。您可以通过在 .env 文件中配置以下行来添加默认标签。(逗号分隔列表)

OPSGENIE_TAGS=tagOne,tagTwo,etc.

OpsGenie 文档

用法

基础

对于事件

Ops()->incident()

对于警报

Ops()->alert()

优先级函数(必需)

设置事件优先级。

消息(必需)

设置事件标题。

->message('Import failed')

描述(可选)

设置事件描述。

->description('Import failed')

详情(可选)

设置事件详情。(键值列表)

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

标签(可选)

设置事件标签。(简单列表)

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

发送(必需)

将事件发送到Opsgenie。

->send();

完整示例

上述函数的组合。

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();

警报附件

附加资源/二进制文件(可选)

您可以通过在 ->send() 后添加以下函数来向警报添加附件,如日志文件、异常文件、渲染、json等。

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

您也可以附加多个文件

Ops()
    ...
    ->send()
    ->attachBlob('RESOURCE/BLOB', 'filename_with.extension')
    ->attachBlob('<html><body><h1>Hello World!</h1></body></html', 'index.html');
    ->attachBlob('{"Hello":"World"}', 'export.json');

附加文件(可选)⚠️ 未测试

Ops()
    ...
    ->send()
    ->attachFile('/path/to/file');

附加示例/组合

您可以使用 attach-function 多次,并随机混合它们。例如 2x ->attachBlob(),1x ->attachFile()

Ops()
    ...
    ->send()
    ->attachBlob('{"Hello":"World"}', 'export.json')
    ->attachFile('/path/to/file')
    ->attachBlob('<html><body><h1>Hello World!</h1></body></html', 'index.html');