# EventCenter 整合說明 (20240715更新)
|日期|更新內容|更新者|
|-|-|-|
|2023.12.05|1. 更新欄位說明|cch|
|2023.08.15|1. status修改為appStatus|cch|
|2024.04.08|1.修正一些欄位內容|展豪|
|2024.04.15|1.修正一些欄位內容|展豪|
|2024.04.23|1.修正一些欄位內容|展豪|
|2024.05.16|1.修正一些欄位內容|展豪|
|2024.07.08|1.補充一些說明,新增graphql打法|展豪|
|2024.07.15|1.新增欄位 timeZone|展豪|
## RMQ傳輸方式
使用rabbitMQ傳送,相關設定如下:
|參數|值|說明|
|-|-|-|
|exchange|amq.topic||
|queueName|<不限>||
|topic|ec."appName"|如app name為andon,則發送的的topic為ec.andon|
連線位置獲取方法如下:
https://portal-mp-ensaas.edgehub.wise-paas.io/instance-list
1. 登入MP頁面
2. 搜尋到 instanceID 為 "18f3875d-ce7e-5f93-bae9-c1d8898efbb3" 的服務
3. 進去建立 secret 且其 vhost 名稱為:KAqAAkaExVqG
## API傳輸方式
API地址:
PUT https://event-center-core-wiseiot-ensaas.edgehub.wise-paas.io/v1/logs
傳遞內容與RMQ傳遞內容相同。
## 格式內容
```go!
{
"source":<string>,
"tenantID":<string>,
"creator":<string>,
"eventID": <string>,
"eventCode": <string>,
"subject":<string>,
"target":<string>,
"targetID":<string>,
"targetPath":<string>,
"targetPathID":<string>,
"appStatus":<string>,
"level": <string>,
"owners": <string[]>,
"tags": <string[]>,
"createdAt": <int64>, (ms)
"timeZone": <string>,
"additionalData": map[string]interface{},
"processingEndAt": <int64>, (ms)
"processingStartAt": <int64> (ms)
}
```
## 欄位說明
|名稱|型態|必填|說明|
|-|-|-|-|
|source|string|是|註冊的時候提供的name,非label,[A-Za-z0-9_.-]
|tenantID|string|是|tenant id
|creator|string|否|產生事件的用戶,可以是用戶名也可以是email
|eventID|string|是|該事件發生的唯一ID
|eventCode|string|是|event categories中定義的event code
|subject|string|否|事件名稱
|target|string|是|
|targetID|string|是|
|targetPath|string|是|
|targetPathID|string|是|
|level|string|是|event的等級;如:HH,LL
|appStatus|string|是|event的狀況,如:未分配,已處理
|owners|string[]|否|處理人員
|tags|string[]|否|hash tag
|createdAt|int64|是|epoch timestamp(ms), 未填時以接收時間為準
|timeZone|string|否|時區|
|additionalData|map[string]interface{}|否|想要多塞的資料,只允許string,int,bool,不可以傳入array或是map
|processingEndAt|int64|是|epoch timestamp(ms), 計算異常時間結束
|processingStartAt|int64|是|epoch timestamp(ms), 計算異常時間開始
## Example
```go=
package main
import (
"context"
"encoding/json"
"log"
"time"
amqp "github.com/rabbitmq/amqp091-go"
)
type Log struct {
Source string `json:"source"`
TenantID string `json:"tenantID"`
Creator string `json:"creator"`
EventID string `json:"eventID"`
Subject string `json:"subject"`
Target string `json:"target"`
TargetID string `json:"targetID"`
TargetPath string `bson:"targetPath"`
TargetPathID string `json:"targetPathID"`
AppStatus string `json:"appStatus"`
Level string `json:"level"`
Owners []string `json:"owners"`
Tags []string `json:"tags"`
CreatedAt int64 `json:"createdAt"`
TimeZone string `json:"timeZone"`
ProcessingEndAt int64 `json:"processingEndAt"`
ProcessingEndAt int64 `json:"processingEndAt"`
AdditionalData map[string]interface{} `json:"additionalData"`
}
func failOnError(err error, msg string) {
if err != nil {
log.Panicf("%s: %s", msg, err)
}
}
func main() {
amqpUri := "amqp://admin:admin@172.16.8.9:5672/ec"
exchange := "amq.topic"
appName := "exampleApp"
topic := "ec." + appName
testData := Log{
Source: appName,
TenantID: "test_tenant",
Creator: "test_user",
EventID: "test_uni_id",
EventCode: "FP0001"
Subject: "test event",
Target: "machine01",
TargetID: "machine01-ID",
TargetPath: "/aaa/bbb",
TargetPathID: "/aaa_id/bbb_id",
AppStatus: "Done",
Owners: []string{"owner1", "owner2"},
Tags: []string{"test1", "test2"},
CreatedAt: time.Now().UnixMilli(),
TimeZone: "Asia/Taipei",
ProcessingEndAt: 0,
ProcessingEndAt: 0,
}
conn, err := amqp.Dial(amqpUri)
failOnError(err, "Failed to connect to RabbitMQ")
defer conn.Close()
ch, err := conn.Channel()
failOnError(err, "Failed to open a channel")
defer ch.Close()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
body, _ := json.Marshal(testData)
err = ch.PublishWithContext(ctx,
exchange, // exchange
topic, // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "application/json",
Body: []byte(body),
})
failOnError(err, "Failed to publish a message")
log.Printf(" [x] Sent %s\n", body)
}
```
## GRAPHQL傳輸方式
API地址:
POST https://event-center-core-wiseiot-ensaas.edgehub.wise-paas.io/insight/
## 格式內容
```graphql
mutation{
ecLogsUpdate(input: {
source:"<string>"
tenantID:"<string>"
target:"<string>"
targetID:"<string>"
targetPath:"<string>"
targetPathID:"<string>"
eventID:"<string>"
eventCode:"<string>"
subject:"<string>"
appStatus:"<string>"
creator:"<string>"
level:"<string>"
owners:["<string>","<string>"]
tags:["<string>","<string>"]
additionalData:{
key: "string"
value:"test"
}
createdAt:"<int64String>"
timeZonw:"<string>"
processingStartAt:"<int64String>"
}){
source
tenantID
target
targetID
targetPath
targetPathID
eventID
eventCode
subject
appStatus
creator
level
owners
tags
additionalData{
key
value
}
processingStartAt
processingEndAt
createdAt
timeZone
}
}
```
# 查詢歷史資料
## 查詢API
API地址:
GET https://event-center-core-wiseiot-ensaas.edgehub.wise-paas.io/v1/logs/summary
## 可以攜帶的參數和說明
|名稱|型態|必填|說明|
|-|-|-|-|
|source|string|否|app name|
|target|string|否|設備的名稱|
|appStatus|string|否|APP設定的狀態|
|eventCenterStatus|string|否|EventCenter 對映到的狀態(OPEN、IN PROGRESS、CLOSED)|
|eventID|string|否|該事件發生的唯一ID|
|eventCategories|string|否|EventCode所在的路徑|
|targetPath|string|否|該設備的路徑訊息|
|level|string|否|event的等級;如:HH,LL|
|subject|string|否|該事件設定的主要名稱|
|startTime|int64|否|epoch timestamp(ms), 查詢比startTime還大的數據|
|endTime|int64|否|epoch timestamp(ms), 查詢比endTime還小的數據|
|search|string|否|key:value格式,用來查詢關鍵數據|
|orderBy|string|否|key:value格式,欄位:排序方式,範例:createdAt:desc|
|page|int|否|第幾,預設為1|
|limit|int|否|單一一頁的數量,預設50|
### 返回結果格式
```
{
"pagination": {
"page": 1,
"limit": 50,
"total": 0
},
"data": []
}
```
### 返回結果格式範例
```
{
"pagination": {
"page": 1,
"limit": 50,
"total": 2
},
"data": [
{
"eventID": "achilles08",
"eventCode": "FP11",
"eventCategories": "",
"source": "achillesApp",
"creator": "Achilles",
"subject": "測試案例",
"target": "烟感-10-001",
"targetID": "d578fe3c778a4eb58586c005a6f81a5d",
"targetPath": "SL01/2F/消防/二楼东侧廊道/C区货物走廊/烟感/烟感-10-001",
"targetPathID": "a739eb5235fd476e9085ed97c9924d2b/aed88da29e3d46c6a365ef0125e55c76/985dd2d12cbc4c24b734747d04da9891/67f4dcb40a4d4166830278a9fafa09f3/2b87a50ed57c41af8bf2d94f40ed2452/726e8f8aae844224b7c60b4f0337ff0f/d578fe3c778a4eb58586c005a6f81a5d",
"owners": "Achilles,Achilles2,Achilles3",
"tags": "TEST,TEST2,TEST3",
"updatedHistory": [
{
"source": "achillesApp",
"creator": "Achilles",
"owners": [
"Achilles",
"Achilles2",
"Achilles3"
],
"eventCode": "FP11",
"appStatus": "triggered",
"eventCenterStatus": "In progress",
"additionalData": {},
"level": "HH",
"createdAt": 1720407177000,
"subject": "測試案例"
}
],
"appStatus": "triggered",
"eventCenterStatus": "In progress",
"level": "HH",
"additionalData": {},
"processingStartAt": 1720407177000,
"processingEndAt": 0,
"processingTime": "24m26s",
"abnormalDuration": "24m26s",
"createdAt": 1720407177000,
"updatedAt": 1720407177000
"timeZone": "Asia/Taipei",
},
{
"eventID": "achilles06",
"eventCode": "FP11",
"eventCategories": "",
"source": "achillesApp",
"creator": "Achilles",
"subject": "測試案例",
"target": "烟感-10-001",
"targetID": "d578fe3c778a4eb58586c005a6f81a5d",
"targetPath": "SL01/2F/消防/二楼东侧廊道/C区货物走廊/烟感/烟感-10-001",
"targetPathID": "a739eb5235fd476e9085ed97c9924d2b/aed88da29e3d46c6a365ef0125e55c76/985dd2d12cbc4c24b734747d04da9891/67f4dcb40a4d4166830278a9fafa09f3/2b87a50ed57c41af8bf2d94f40ed2452/726e8f8aae844224b7c60b4f0337ff0f/d578fe3c778a4eb58586c005a6f81a5d",
"owners": "Achilles",
"tags": "TEST",
"updatedHistory": [
{
"source": "achillesApp",
"creator": "Achilles",
"owners": [
"Achilles"
],
"eventCode": "FP11",
"appStatus": "triggered",
"eventCenterStatus": "In progress",
"additionalData": {},
"level": "HH",
"createdAt": 1720175664000,
"subject": "測試案例"
}
],
"appStatus": "triggered",
"eventCenterStatus": "In progress",
"level": "HH",
"additionalData": {},
"processingStartAt": 1720175664000,
"processingEndAt": 0,
"processingTime": "64h42m59s",
"abnormalDuration": "64h42m59s",
"createdAt": 1720175664000,
"updatedAt": 1720175664000
"timeZone": "Asia/Taipei",
}
]
}
```
## 查詢 GRAPHQL API
### 範例
```
query{
ecLogsSummary(input:
{
tenantID:"VGVuYW50.Y8S6RMlyJDcn_Bez"
sources:["testApp"]
}) {
data {
source
subject
appStatus
eventCenterStatus
owners
creator
eventID
level
target
targetPath
processingStartAt
createdAt
processingEndAt
updatedAt
timeZone
processingTime
abnormalDuration
updatedHistory {
appStatus
createdAt
creator
eventCenterStatus
level
}
additionalData{
key
value
}
}
pagination {
total
limit
page
}
}
}
```
# 額外項目
### Assignee API
#### API 內容規劃
|名稱|型態|必填|說明|
|-|-|-|-|
|userName|string|否|用戶名稱|
|confirmed|bool|否|預設false,如果填選了rootCause是要為true?|
|closeEvent|bool|否|預設false,選true需要幫用戶把狀態轉為closed|
|rootCauseTypeID|string|否|rootCauseType的ID|
|rootCauseTypeName|string|否|rootCauseType的內容物|
|rootCauseID|string|否|rootCause的ID|
|rootCauseName|string|否|rootCause的內容物|
|rootCauseDescription|string|否|用戶補充說明 rootCause 情境|
|suggestion|string|否|用戶的額外建議,會與未來AI模組整合?|