preprio/opsgenie
GitHub: preprio/opsgenie
为 Laravel 应用提供与 Atlassian Opsgenie 告警平台集成的流式 SDK,简化从应用代码中程序化创建告警和事件的流程。
Stars: 2 | Forks: 0
# Prepr Laravel Opsgenie SDK
本 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 的消息中添加前缀,以明确具体的 service/repo。您可以通过在 `.env` 文件中配置以下行来添加前缀。
```
OPSGENIE_PREFIX=preprio/mutation.prepr.io
```
示例:
| 配置 | 结果 |
|---------------------------|---------------------------------------|
| PREFIX | `[PREFIX] Message` |
| preprio/mutation.prepr.io | `[preprio/mutation.prepr.io] MESSAGE` |
| mutation-api | `[mutation-api] MESSAGE` |
### 默认标签
可选择在发送到 Opsgenie 的消息中添加默认标签。您可以通过在 `.env` 文件中配置以下行来添加默认标签。(以逗号分隔的列表)
```
OPSGENIE_TAGS=tagOne,tagTwo,etc.
```
## OpsGenie 文档
- [概述](https://docs.opsgenie.com/docs/api-overview)
- [创建警报](https://docs.opsgenie.com/docs/alert-api#create-alert)
- [创建事件](https://docs.opsgenie.com/docs/incident-api#create-incident)
## 用法
### 基础
#### 对于事件
```
Ops()->incident()
```
#### 对于警报
```
Ops()->alert()
```
### 优先级函数 (必填)
设置事件优先级。
|优先级|函数|
|---|---|
|Critical| `->P1()` 或 `->critical()`|
|High| `->P2()` 或 `->high()`|
|Moderate| `->P3()` 或 `->moderate()`|
|Low| `->P4()` 或 `->low()`|
|Informational| `->P5()` 或 `->informational()`|
### 消息 (必填)
设置事件标题。
```
->message('Import failed')
```
### 描述 (可选)
设置事件描述。
```
->description('Import failed')
```
### 详情 (可选)
设置事件详情。(Key-Value 列表)
```
->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();
```
## 警报附件
### 附加资源/Blob (可选)
您可以为警报添加附件,如日志文件、异常文件、渲染图、JSON 等。
通过在 `->send()` 之后添加以下函数。
```
Ops()
...
->send()
->attachBlob('RESOURCE/BLOB', 'filename_with.extension');
```
您也可以附加多个文件
```
Ops()
...
->send()
->attachBlob('RESOURCE/BLOB', 'filename_with.extension')
->attachBlob('
Hello World!
attachBlob('{"Hello":"World"}', 'export.json'); ``` ### 附加文件 (可选) ⚠️ 未测试 ``` Ops() ... ->send() ->attachFile('/path/to/file'); ``` ### 附加示例/组合 您可以多次使用附加函数,并以随机顺序混合使用。 例如 2 次 `->attachBlob()`,1 次 `->attachFile()`。 ``` Ops() ... ->send() ->attachBlob('{"Hello":"World"}', 'export.json') ->attachFile('/path/to/file') ->attachBlob('Hello World!
标签:Altering Tool, API集成, Atlassian, Incident Management, Laravel, OpenVAS, Opsgenie, PHP, Prepr, Syscall, Web开发, 代理支持, 可观测性, 告警, 服务可用性, 运维监控, 通知系统, 错误处理