use of io.jpom.model.log.MonitorNotifyLog in project Jpom by dromara.
the class MonitorItem method checkNotify.
/**
* 检查状态
*
* @param monitorModel 监控信息
* @param nodeModel 节点信息
* @param id 项目id
* @param copyId 副本id
* @param runStatus 当前运行状态
*/
private boolean checkNotify(MonitorModel monitorModel, NodeModel nodeModel, String id, String copyId, boolean runStatus) {
// 获取上次状态
String projectCopyId = id;
String copyMsg = StrUtil.EMPTY;
if (StrUtil.isNotEmpty(copyId)) {
projectCopyId = StrUtil.format("{}:{}", id, copyId);
copyMsg = StrUtil.format("副本:{}", copyId);
}
boolean pre = this.getPreStatus(monitorModel.getId(), nodeModel.getId(), projectCopyId);
String title = null;
String context = null;
// 查询项目运行状态
if (runStatus) {
if (!pre) {
// 上次是异常状态
title = StrUtil.format("【{}】节点的【{}】项目{}已经恢复正常运行", nodeModel.getName(), id, copyMsg);
context = "";
}
} else {
//
if (monitorModel.autoRestart()) {
// 执行重启
try {
JsonMessage<String> reJson = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_Restart, "id", id, "copyId", copyId);
if (reJson.getCode() == HttpStatus.HTTP_OK) {
// 重启成功
runStatus = true;
title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,已经执行重启操作,结果成功", nodeModel.getName(), id, copyMsg);
} else {
title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,已经执行重启操作,结果失败", nodeModel.getName(), id, copyMsg);
}
context = "重启结果:" + reJson;
} catch (Exception e) {
DefaultSystemLog.getLog().error("执行重启操作", e);
title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,重启操作异常", nodeModel.getName(), id, copyMsg);
context = ExceptionUtil.stacktraceToString(e);
}
} else {
title = StrUtil.format("【{}】节点的【{}】项目{}已经没有运行", nodeModel.getName(), id, copyMsg);
context = "请及时检查";
}
}
if (!pre && !runStatus) {
// 上一次也是异常,并且当前也是异常
return false;
}
MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
monitorNotifyLog.setStatus(runStatus);
monitorNotifyLog.setTitle(title);
monitorNotifyLog.setContent(context);
monitorNotifyLog.setCreateTime(System.currentTimeMillis());
monitorNotifyLog.setNodeId(nodeModel.getId());
monitorNotifyLog.setProjectId(id);
monitorNotifyLog.setMonitorId(monitorModel.getId());
//
this.notifyMsg(nodeModel, monitorNotifyLog);
return runStatus;
}
use of io.jpom.model.log.MonitorNotifyLog in project Jpom by dromara.
the class MonitorItem method reqNodeStatus.
/**
* 检查节点节点对信息
*
* @param nodeModel 节点
* @param projects 项目
* @return true 所有项目都正常
*/
private boolean reqNodeStatus(NodeModel nodeModel, List<String> projects) {
if (projects == null || projects.isEmpty()) {
return true;
}
List<Boolean> collect = projects.stream().map(id -> {
//
String title;
String context;
try {
// 查询项目运行状态
JsonMessage<JSONObject> jsonMessage = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_GetProjectStatus, "id", id, "getCopy", true);
if (jsonMessage.getCode() == HttpStatus.HTTP_OK) {
JSONObject jsonObject = jsonMessage.getData();
int pid = jsonObject.getIntValue("pId");
boolean runStatus = this.checkNotify(monitorModel, nodeModel, id, null, pid > 0);
// 检查副本
List<Boolean> booleanList = null;
JSONArray copys = jsonObject.getJSONArray("copys");
if (CollUtil.isNotEmpty(copys)) {
booleanList = copys.stream().map(o -> {
JSONObject jsonObject1 = (JSONObject) o;
String copyId = jsonObject1.getString("copyId");
boolean status = jsonObject1.getBooleanValue("status");
return MonitorItem.this.checkNotify(monitorModel, nodeModel, id, copyId, status);
}).filter(aBoolean -> !aBoolean).collect(Collectors.toList());
}
return runStatus && CollUtil.isEmpty(booleanList);
} else {
title = StrUtil.format("【{}】节点的状态码异常:{}", nodeModel.getName(), jsonMessage.getCode());
context = jsonMessage.toString();
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("监控 {} 节点异常 {}", nodeModel.getName(), e.getMessage());
//
title = StrUtil.format("【{}】节点的运行状态异常", nodeModel.getName());
context = ExceptionUtil.stacktraceToString(e);
}
// 获取上次状态
boolean pre = this.getPreStatus(monitorModel.getId(), nodeModel.getId(), id);
if (pre) {
// 上次正常
MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
monitorNotifyLog.setStatus(false);
monitorNotifyLog.setTitle(title);
monitorNotifyLog.setContent(context);
monitorNotifyLog.setCreateTime(System.currentTimeMillis());
monitorNotifyLog.setNodeId(nodeModel.getId());
monitorNotifyLog.setProjectId(id);
monitorNotifyLog.setMonitorId(monitorModel.getId());
//
this.notifyMsg(nodeModel, monitorNotifyLog);
}
return false;
}).filter(aBoolean -> !aBoolean).collect(Collectors.toList());
return CollUtil.isEmpty(collect);
}
use of io.jpom.model.log.MonitorNotifyLog in project Jpom by dromara.
the class MonitorItem method getPreStatus.
/**
* 获取上次是否也为异常状态
*
* @param monitorId 监控id
* @param nodeId 节点id
* @param projectId 项目id
* @return true 为正常状态,false 异常状态
*/
private boolean getPreStatus(String monitorId, String nodeId, String projectId) {
// 检查是否已经触发通知
MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
monitorNotifyLog.setNodeId(nodeId);
monitorNotifyLog.setProjectId(projectId);
monitorNotifyLog.setMonitorId(monitorId);
List<MonitorNotifyLog> queryList = dbMonitorNotifyLogService.queryList(monitorNotifyLog, 1, new Order("createTime", Direction.DESC));
MonitorNotifyLog entity1 = CollUtil.getFirst(queryList);
return entity1 == null || entity1.status();
}
use of io.jpom.model.log.MonitorNotifyLog in project Jpom by dromara.
the class DbMonitorNotifyLogService method updateStatus.
/**
* 修改执行结果
*
* @param logId 通知id
* @param status 状态
* @param errorMsg 错误消息
*/
public void updateStatus(String logId, boolean status, String errorMsg) {
MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
monitorNotifyLog.setId(logId);
monitorNotifyLog.setNotifyStatus(status);
monitorNotifyLog.setNotifyError(errorMsg);
super.update(monitorNotifyLog);
// Entity entity = new Entity();
// entity.set("notifyStatus", status);
// if (errorMsg != null) {
// entity.set("notifyError", errorMsg);
// }
// //
// Entity where = new Entity();
// where.set("logId", logId);
// super.update(entity, where);
}
Aggregations