Skip to content

Commit

Permalink
fix: fix tencentCloudAlarmMetricSchema incorrect problem
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Aug 10, 2024
1 parent f1aaa70 commit 914046a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
59 changes: 59 additions & 0 deletions src/server/model/_schema/__tests__/feed.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, expect, test } from 'vitest';
import {
tencentCloudAlarmMetricSchema,
tencentCloudAlarmSchema,
} from '../feed.js';

describe('tencentCloudAlarmSchema', () => {
test('should be pass in ', () => {
const data = {
sessionId: '395d4bb4-08bf-45fd-a820-ef27047a00009',
alarmStatus: '1',
alarmType: 'metric',
alarmObjInfo: {
region: 'sh',
namespace: 'qce/lb',
appId: '1257200005',
uin: '10000670009',
dimensions: {
deviceName: 'Tailchat',
objId: '953a6ec8-f9ff-4c6f-96f6-37c2005dddfb',
objName: '172.17.32.0#41119',
unInstanceId: 'ins-n0y0008z',
},
},
alarmPolicyInfo: {
policyId: 'policy-b900061',
policyType: 'cvm_device',
policyName: 'xxxxx',
policyTypeCName: 'xxxxx-xxxxxx',
policyTypeEname: '',
conditions: {
metricName: 'outratio',
metricShowName: 'xxxxxxxxxxxxx',
calcType: '>',
calcValue: '95',
currentValue: '95.255',
historyValue: '',
unit: '%',
calcUnit: '%',
period: '300',
periodNum: '5',
alarmNotifyType: 'continuousAlarm',
alarmNotifyPeriod: 86400,
},
tag: [],
policyTags: [],
},
firstOccurTime: '2024-08-07 07:55:00',
durationTime: 0,
recoverTime: '0',
policyDetailURL: 'https://tcop.qq.com/r/xxxxxx',
};

const res = tencentCloudAlarmSchema.safeParse(data);

expect(res.success).toBe(true);
expect((res as any).data).toEqual(data);
});
});
4 changes: 2 additions & 2 deletions src/server/model/_schema/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const tencentCloudAlarmEventSchema = z.object({
});

// 定义 metric 类型
const tencentCloudAlarmMetricSchema = z.object({
export const tencentCloudAlarmMetricSchema = z.object({
sessionId: z.string(),
alarmStatus: z.union([z.literal('0'), z.literal('1')]),
alarmType: z.literal('metric'),
alarmLevel: z.string(),
alarmLevel: z.string().optional(),
alarmObjInfo: z.object({
region: z.string().optional(),
namespace: z.string(),
Expand Down

0 comments on commit 914046a

Please sign in to comment.