skywalking告警UI界面有告警信息,webhook接口没有回调,400错误

400错误就是回调接口返回数据的属性对应不上

@PostMapping("/webhook")

public void webhook(@RequestBody List alarmMessageList)

自定义的实体类AlarmMessage有问题

只能去官网找了
告警实体类官网

java 复制代码
@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
@NoArgsConstructor(force = true)
public class AlarmEntity {
    private final String scope;
    private final int scopeId;
    private final String name;
    private final String id0;
    private final String id1;
}

我使用的skywalking的版本是8.8.0

因为告警功能是基于这两个jar实现的

b站上,黑马的和图灵的讲师的实体类都不一样,所以不能直接抄,没有效果只能去分析skywalking的日志,看是不是发请求接口失败400了

完整代码如下:

实体类

java 复制代码
@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
@NoArgsConstructor(force = true)
public class AlarmMessage {
    private final String scope;
    private final int scopeId;
    private final String name;
    private final String id0;
    private final String id1;
}

模拟超时的接口

java 复制代码
@RestController
public class AlarmController {
    @GetMapping("/timeout")
    public String timeout() throws InterruptedException {
        Thread.sleep(1500);
        return "timeout";
    }
}

告警回调接口

java 复制代码
@RestController
public class WebHooks {
    private List<AlarmMessage> lastList=new ArrayList<>();
    @PostMapping("/webhook")
    public void webhook(@RequestBody List<AlarmMessage> alarmMessageList){
        lastList = alarmMessageList;
    }
    @GetMapping("/show")
    public List<AlarmMessage> show(){
        return lastList;
    }
}

skywalking服务配置文件指定告警接口

多次请求http://localhost:8088/timeout

2分钟后一般会有告警信息出现

或者点击右上方的自动,再去请求接口,直到能出现告警

再去请求show接口,查看返回的数据

http://localhost:8088/show

有数据就是成功了,如果是空数组,就是webhook的接口没有回调成功,去看看skywalking的日志吧!!

相关推荐
小雨下雨的雨13 小时前
Flutter 框架跨平台鸿蒙开发 —— Center 控件之完美居中之道
flutter·ui·华为·harmonyos·鸿蒙
小小工匠13 小时前
LLM - A2UI:Google 引领的生成式 UI 革命
ui·a2ui
小雨下雨的雨14 小时前
Flutter 框架跨平台鸿蒙开发 —— Placeholder 控件之布局雏形美学
flutter·ui·华为·harmonyos·鸿蒙系统
Pony_1815 小时前
面试 - web ui 自动化
前端·ui·自动化
Larry_Yanan15 小时前
Qt安卓开发(一)Qt6.10环境配置
android·开发语言·c++·qt·学习·ui
小雨下雨的雨15 小时前
Flutter 框架跨平台鸿蒙开发 —— Padding 控件之空间呼吸艺术
flutter·ui·华为·harmonyos·鸿蒙系统
小雨下雨的雨16 小时前
Flutter 框架跨平台鸿蒙开发 —— Align 控件之精准定位美学
flutter·ui·华为·harmonyos·鸿蒙
Larry_Yanan16 小时前
Qt多进程(九)命名管道FIFO
开发语言·c++·qt·学习·ui
唐虞兮1 天前
UI文件转py文件出问题
ui
梦想的旅途22 天前
基于 UI 自动化(RPA)实现企业微信外部群操作的架构设计
ui·自动化·rpa