use of io.jpom.model.data.MonitorModel 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.data.MonitorModel in project Jpom by dromara.
the class ProjectManageControl method deleteProject.
/**
* 删除项目
*
* @param id id
* @return json
*/
@PostMapping(value = "deleteProject", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteProject(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, String copyId) {
NodeModel nodeModel = getNode();
HttpServletRequest servletRequest = getRequest();
if (StrUtil.isEmpty(copyId)) {
// 检查节点分发
List<OutGivingModel> outGivingModels = outGivingServer.listByWorkspace(servletRequest);
if (outGivingModels != null) {
boolean match = outGivingModels.stream().anyMatch(outGivingModel -> outGivingModel.checkContains(nodeModel.getId(), id));
Assert.state(!match, "当前项目存在节点分发,不能直接删除");
// for (OutGivingModel outGivingModel : outGivingModels) {
// if (outGivingModel.checkContains(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, "当前项目存在节点分发,不能直接删除");
// }
// }
}
//
List<MonitorModel> monitorModels = monitorService.listByWorkspace(servletRequest);
if (monitorModels != null) {
boolean match = monitorModels.stream().anyMatch(monitorModel -> monitorModel.checkNodeProject(nodeModel.getId(), id));
// if (monitorService.checkProject(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, );
// }
Assert.state(!match, "当前项目存在监控项,不能直接删除");
}
boolean releaseMethod = buildService.checkReleaseMethod(nodeModel.getId() + StrUtil.COLON + id, servletRequest, BuildReleaseMethod.Project);
Assert.state(!releaseMethod, "当前项目存在构建项,不能直接删除");
}
JsonMessage<Object> request = NodeForward.request(nodeModel, servletRequest, NodeUrl.Manage_DeleteProject);
if (request.getCode() == HttpStatus.OK.value()) {
//
projectInfoCacheService.syncNode(nodeModel);
}
return request.toString();
}
use of io.jpom.model.data.MonitorModel in project Jpom by dromara.
the class MonitorListController method updateMonitor.
/**
* 增加或修改监控
*
* @param id id
* @param name name
* @param notifyUser user
* @return json
*/
@RequestMapping(value = "updateMonitor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String updateMonitor(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "监控名称不能为空") String name, @ValidatorItem(msg = "请配置监控周期") String execCron, String notifyUser, String webhook) {
String status = getParameter("status");
String autoRestart = getParameter("autoRestart");
JSONArray jsonArray = JSONArray.parseArray(notifyUser);
// List<String> notifyUsers = jsonArray.toJavaList(String.class);
List<String> notifyUserList = jsonArray.toJavaList(String.class);
if (CollUtil.isNotEmpty(notifyUserList)) {
for (String userId : notifyUserList) {
Assert.state(userService.exists(new UserModel(userId)), "没有对应的用户:" + userId);
}
}
String projects = getParameter("projects");
JSONArray projectsArray = JSONArray.parseArray(projects);
List<MonitorModel.NodeProject> nodeProjects = projectsArray.toJavaList(MonitorModel.NodeProject.class);
Assert.notEmpty(nodeProjects, "请至少选择一个节点");
for (MonitorModel.NodeProject nodeProject : nodeProjects) {
Assert.notEmpty(nodeProject.getProjects(), "请至少选择一个项目");
for (String project : nodeProject.getProjects()) {
boolean exists = projectInfoCacheService.exists(nodeProject.getNode(), project);
Assert.state(exists, "没有对应的项目:" + project);
}
}
// 设置参数
if (StrUtil.isNotEmpty(webhook)) {
Validator.validateMatchRegex(RegexPool.URL_HTTP, webhook, "WebHooks 地址不合法");
}
Assert.state(CollUtil.isNotEmpty(notifyUserList) || StrUtil.isNotEmpty(webhook), "请选择一位报警联系人或者填写webhook");
boolean start = "on".equalsIgnoreCase(status);
MonitorModel monitorModel = monitorService.getByKey(id);
if (monitorModel == null) {
monitorModel = new MonitorModel();
}
monitorModel.setAutoRestart("on".equalsIgnoreCase(autoRestart));
monitorModel.setExecCron(this.checkCron(execCron));
monitorModel.projects(nodeProjects);
monitorModel.setStatus(start);
monitorModel.setWebhook(webhook);
monitorModel.notifyUser(notifyUserList);
monitorModel.setName(name);
if (StrUtil.isEmpty(id)) {
// 添加监控
monitorService.insert(monitorModel);
return JsonMessage.getString(200, "添加成功");
}
HttpServletRequest request = getRequest();
monitorService.updateById(monitorModel, request);
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.model.data.MonitorModel in project Jpom by dromara.
the class MonitorService method setAlarm.
/**
* 设置报警状态
*
* @param id 监控id
* @param alarm 状态
*/
public void setAlarm(String id, boolean alarm) {
MonitorModel monitorModel = new MonitorModel();
monitorModel.setId(id);
monitorModel.setAlarm(alarm);
super.update(monitorModel);
}
use of io.jpom.model.data.MonitorModel in project Jpom by dromara.
the class MonitorService method queryStartingList.
@Override
public List<MonitorModel> queryStartingList() {
// 关闭监听
MonitorModel monitorModel = new MonitorModel();
monitorModel.setStatus(true);
return super.listByBean(monitorModel);
}
Aggregations