告警平台对接
parent
604817a173
commit
7d816e91b9
|
@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.bocloud.sms.entity.User;
|
import com.bocloud.sms.entity.User;
|
||||||
|
import com.bocloud.sms.enums.WarnInfo;
|
||||||
import com.bocloud.sms.enums.YkInfo;
|
import com.bocloud.sms.enums.YkInfo;
|
||||||
import com.bocloud.sms.interfaces.IndexService;
|
import com.bocloud.sms.interfaces.IndexService;
|
||||||
import com.bocloud.sms.repository.UserRepository;
|
import com.bocloud.sms.repository.UserRepository;
|
||||||
|
import com.bocloud.sms.utils.WarnUtil;
|
||||||
import com.bocloud.sms.utils.YkUtil;
|
import com.bocloud.sms.utils.YkUtil;
|
||||||
import com.megatron.common.model.GeneralResult;
|
import com.megatron.common.model.GeneralResult;
|
||||||
import com.megatron.common.model.Pager;
|
import com.megatron.common.model.Pager;
|
||||||
|
@ -28,6 +30,8 @@ public class IndexServiceImpl implements IndexService {
|
||||||
private YkUtil ykUtil;
|
private YkUtil ykUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
@Autowired
|
||||||
|
private WarnUtil warnUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext) {
|
public GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext) {
|
||||||
|
@ -91,29 +95,19 @@ public class IndexServiceImpl implements IndexService {
|
||||||
@Override
|
@Override
|
||||||
public GeneralResult userDataStatic(RequestContext requestContext) {
|
public GeneralResult userDataStatic(RequestContext requestContext) {
|
||||||
try {
|
try {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
|
||||||
//查询当前用户授权应用
|
|
||||||
List<JSONObject> userAppList = getUserAppList(requestContext);
|
|
||||||
resultMap.put("userAppCount", userAppList.size());
|
|
||||||
|
|
||||||
|
|
||||||
//获取运维任务申请表
|
|
||||||
JSONObject taskJson = getTaskList(requestContext);
|
|
||||||
Integer total = taskJson.getInteger("total");
|
|
||||||
resultMap.put("taskCount", total);
|
|
||||||
|
|
||||||
|
|
||||||
//获取用户数据权限申请数量
|
//获取用户数据权限申请数量
|
||||||
JSONObject userParam = new JSONObject();
|
JSONObject userParam = new JSONObject();
|
||||||
userParam.put("userId", "1111");
|
userParam.put("userId", "1111");
|
||||||
String userDataAuthStr = ykUtil.call(YkInfo.getUserDataAuth, userParam, JSONArray.class);
|
String userDataAuthStr = ykUtil.call(YkInfo.getCountTaskByUser, userParam, JSONArray.class);
|
||||||
List<JSONObject> userDataJAuthJson = JSONObject.parseObject(userDataAuthStr, List.class);
|
List<JSONObject> userDataJAuthJson = JSONObject.parseObject(userDataAuthStr, List.class);
|
||||||
List<JSONObject> authResList = JSONObject.parseObject(userDataJAuthJson.get(0).getString("authRes"),List.class);
|
List<JSONObject> authResList = JSONObject.parseObject(userDataJAuthJson.get(0).getString("authRes"),List.class);
|
||||||
|
|
||||||
resultMap.put("userAuthList", authResList.size());
|
String result = warnUtil.call(WarnInfo.get1DayWarnCount.getUrl(), "GET");
|
||||||
log.info("resultMap:{}", JSON.toJSONString(resultMap));
|
log.info("result:"+result);
|
||||||
|
|
||||||
return new GeneralResult(true, resultMap, "查询成功");
|
// log.info("resultMap:{}", JSON.toJSONString(resultMap));
|
||||||
|
|
||||||
|
return new GeneralResult(true, "查询成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("查询失败", e);
|
log.info("查询失败", e);
|
||||||
return new GeneralResult(false, "查询失败");
|
return new GeneralResult(false, "查询失败");
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bocloud.sms.enums;
|
||||||
|
|
||||||
|
public enum WarnInfo {
|
||||||
|
|
||||||
|
//单日告警统计
|
||||||
|
get1DayWarnCount("/alistar/api/v1/alarm/current/statistics/7d"),
|
||||||
|
//近7日告警趋势统计
|
||||||
|
get7DayWarnTrend("/alistar/api/v1/alarm/current/today/all");
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
WarnInfo(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,8 @@ public enum YkInfo {
|
||||||
getAllAppList("/system/sysapp/getAppList"),
|
getAllAppList("/system/sysapp/getAppList"),
|
||||||
//获取用户角色信息
|
//获取用户角色信息
|
||||||
getUserRoles("/system/user/queryUserRoles"),
|
getUserRoles("/system/user/queryUserRoles"),
|
||||||
|
//数据展示
|
||||||
|
getCountTaskByUser("/system/task/countTaskByUser"),
|
||||||
//用户数据权限信息查询接口
|
//用户数据权限信息查询接口
|
||||||
getUserDataAuth("/system/user/queryUserAuthres"),
|
getUserDataAuth("/system/user/queryUserAuthres"),
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.bocloud.sms.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class WarnUtil {
|
||||||
|
|
||||||
|
@Value("${warn.url:127.0.0.1:1234}")
|
||||||
|
private String url;
|
||||||
|
@Value("${warn.user:alistar}")
|
||||||
|
private String user;
|
||||||
|
@Value("${warn.password:alistarapi123}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
public String call(String urlSuffix, String method) throws Exception {
|
||||||
|
URL obj = new URL(url + urlSuffix);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
|
||||||
|
|
||||||
|
// 设置请求方法
|
||||||
|
connection.setRequestMethod(method);
|
||||||
|
|
||||||
|
// 添加Basic Auth鉴权头
|
||||||
|
String auth = user + ":" + password;
|
||||||
|
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
|
||||||
|
String authHeaderValue = "Basic " + encodedAuth;
|
||||||
|
connection.setRequestProperty("Authorization", authHeaderValue);
|
||||||
|
|
||||||
|
// 发起请求并获取响应码
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
log.info("Response Code: " + responseCode);
|
||||||
|
|
||||||
|
|
||||||
|
// 读取响应数据
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
// 输出响应
|
||||||
|
log.info("Response: " + response.toString());
|
||||||
|
return response.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue