use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyStrategyUpdate.
@SuppressWarnings("unchecked")
@POST
@Path("notify/up/stgy/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyStrategyUpdate(String dataParam, @Suspended AsyncResponse response) throws Exception {
// 添加操作字段
Map<String, Object> stgyMap = JSONHelper.toObject(dataParam, Map.class);
for (Entry<String, Object> objecMap : stgyMap.entrySet()) {
String key = objecMap.getKey();
Object value = stgyMap.get(key);
if (null != value) {
Map<String, Object> idMap = JSONHelper.toObject(String.valueOf(value), Map.class);
idMap.put("uptime", new Date().getTime());
stgyMap.put(key, idMap);
break;
}
}
final String stgyData = JSONHelper.toString(stgyMap);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("body", stgyData);
message.setIntent("strategy.update");
NoitifyStrategyUpdateCB callback = new NoitifyStrategyUpdateCB();
callback.setResponse(response);
callback.setStgyData(stgyData);
doHttpPost("uav.app.godeye.notify.strategy.http.addr", "/rtntf/oper", message, callback);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method doNodeCtrlOperation.
// -----------------------------------------Node Ctrl-------------------------------------
@POST
@Path("node/ctrl")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void doNodeCtrlOperation(String data, @Suspended AsyncResponse response) {
// user info
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("apphub.gui.session.login.user.id");
if (uid == null) {
return;
}
UAVHttpMessage msg = new UAVHttpMessage(data);
String nodeUrl = msg.getRequest("url");
msg.getRequest().remove("url");
long timeStamp = System.currentTimeMillis();
/**
* check node oper security
*/
if (isCheckNodeOperSecurity == true) {
Long ts = (Long) session.getAttribute("apphub.godeye.node.oper." + nodeUrl + ".timeout");
if (ts != null && timeStamp - ts < 3000 && (!"loadnodepro".equalsIgnoreCase(msg.getIntent()) && !"chgsyspro".equalsIgnoreCase(msg.getIntent()))) {
response.resume("{\"rs\":\"ERR\",\"msg\":\"该节点操作3秒内只能操作一次\"}");
return;
}
if (!"loadnodepro".equalsIgnoreCase(msg.getIntent()) && !"chgsyspro".equalsIgnoreCase(msg.getIntent())) {
session.setAttribute("apphub.godeye.node.oper." + nodeUrl + ".timeout", timeStamp);
}
}
String ip = request.getRemoteAddr();
String xip = request.getHeader("X-Forwarded-For");
ip = getClientIP(ip, xip);
msg.getRequest().put("uid", uid);
msg.getRequest().put("uip", ip);
msg.getRequest().put("ts", String.valueOf(timeStamp));
String msgStr = JSONHelper.toString(msg);
if (this.logger.isTraceEnable()) {
this.logger.info(this, "Do RemoteNodeCtrlOpertaion: url=" + nodeUrl + ", msg=" + msgStr + ", timestamp=" + DateTimeHelper.toStandardDateFormat(timeStamp));
}
DoNodeCtrlOperationCB callback = new DoNodeCtrlOperationCB();
callback.setResponse(response);
this.doHttpPost(nodeUrl, null, msg, callback);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyQuery.
@SuppressWarnings({ "unchecked", "rawtypes" })
@POST
@Path("notify/q/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyQuery(String data, @Suspended AsyncResponse response) {
// 数据权限begin
String groups = getUserGroupsByFilter(request);
List groupList = Collections.emptyList();
boolean checkAuthor = true;
if ("NOMAPPING".equals(groups)) {
checkAuthor = false;
} else if ("ALL".equals(groups)) {
/**
* nothing
*/
} else {
String[] gs = groups.split(",");
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
for (String group : gs) {
sBuilder.append("{");
sBuilder.append("\"regex\":{\"appgroup\":\"" + group + "\"}");
sBuilder.append("}");
}
sBuilder.append("]");
HashMap<String, Object> or = new HashMap<String, Object>();
or.put("or", JSONHelper.toObjectArray(sBuilder.toString(), Map.class));
HashMap<String, Object> match = new HashMap<String, Object>();
match.put("match", or);
groupList = new ArrayList<HashMap<String, Object>>();
groupList.add(match);
}
if (checkAuthor) {
// mongodb .为关键字,封装时替换为#交由后台处理
data = data.replaceAll("\\.", "#");
HashMap<String, String> jsonParam = JSONHelper.toObject(data, HashMap.class);
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
// 过滤数据,只查询最近的指定数据 begin
HashMap<String, Object> sortMap = new HashMap<String, Object>();
HashMap<String, Object> sort = new HashMap<String, Object>();
sort.put("values", "time");
sort.put("sortorder", "-1");
sortMap.put("sort", sort);
list.add(sortMap);
HashMap<String, Object> firstRecord = new HashMap<String, Object>();
firstRecord.put("firstrecord", "true");
HashMap<String, Object> firstRecordMatch = new HashMap<String, Object>();
firstRecordMatch.put("match", firstRecord);
list.add(firstRecordMatch);
// 封装组合查询条件
if (jsonParam.containsKey("search")) {
String whereStr = "[{\"regex\":{\"ip\":\"searchValue\"}},{\"regex\":{\"eventid\":\"searchValue\"}},{\"regex\":{\"title\":\"searchValue\"}},{\"regex\":{\"host\":\"searchValue\"}}]";
// mongodb .为关键字,封装时替换为#交由后台处理
String inputSearchStr = jsonParam.get("search").replaceAll("\\.", "#");
whereStr = whereStr.replaceAll("searchValue", inputSearchStr);
HashMap<String, Object> or = new HashMap<String, Object>();
or.put("or", JSONHelper.toObjectArray(whereStr, Map.class));
HashMap<String, Object> match = new HashMap<String, Object>();
match.put("match", or);
list.add(match);
}
// and
if (!groupList.isEmpty()) {
list.addAll(groupList);
}
HashMap<String, Object> skipMap = new HashMap<String, Object>();
skipMap.put("skip", mongodbQueryRangeMap.get("skip"));
list.add(skipMap);
HashMap<String, Object> limitMap = new HashMap<String, Object>();
limitMap.put("limit", mongodbQueryRangeMap.get("limit"));
list.add(limitMap);
// 过滤数据,只查询最近的指定数据 end
HashMap<String, Object> pageIndex = new HashMap<String, Object>();
HashMap<String, Object> pageSize = new HashMap<String, Object>();
pageIndex.put("pageindex", String.valueOf(jsonParam.get("pageindex")));
pageSize.put("pagesize", String.valueOf(jsonParam.get("pagesize")));
list.add(pageIndex);
list.add(pageSize);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("mgo.sql", JSONHelper.toString(list));
message.putRequest("datastore.name", "MT_Notify");
message.putRequest("mgo.coll.name", "uav_notify");
NoitifyQueryCB callback = new NoitifyQueryCB();
callback.setResponse(response);
doHttpPost("uav.app.godeye.healthmanager.http.addr", "/hm/query", message, callback);
} else {
response.resume("{\"rs\":\"[]\"}");
}
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method loadMonitorDataFromCache.
/**
* 从缓存查询最近1min的MonitorData
*
* @param data
* @param response
*/
private void loadMonitorDataFromCache(String data, @Suspended AsyncResponse response, String cacheKey) {
UAVHttpMessage message = new UAVHttpMessage();
message.setIntent("monitor");
message.putRequest("cache.query.json", data);
LoadMonitorDataFromCacheCB callback = new LoadMonitorDataFromCacheCB();
callback.setCacheKey(cacheKey);
callback.setData(data);
callback.setGodeyeCacheRegion(godeyeCacheRegion);
callback.setGodeyeFilterGroupCacheRegion(godeyeFilterGroupCacheRegion);
callback.setResponse(response);
this.doHttpPost("uav.app.godeye.healthmanager.http.addr", "/hm/cache/q", message, callback);
}
use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.
the class GodEyeRestService method noitifyCountQueryBest.
@SuppressWarnings({ "unchecked", "rawtypes" })
@POST
@Path("notify/q/best/count/hm")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void noitifyCountQueryBest(String data, @Suspended AsyncResponse response) {
// 数据权限begin
String groups = getUserGroupsByFilter(request);
List groupList = Collections.emptyList();
boolean checkAuthor = true;
if ("NOMAPPING".equals(groups)) {
checkAuthor = false;
} else if ("ALL".equals(groups)) {
/**
* nothing
*/
} else {
String[] gs = groups.split(",");
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
for (String group : gs) {
sBuilder.append("{");
sBuilder.append("\"regex\":{\"appgroup\":\"" + group + "\"}");
sBuilder.append("}");
}
sBuilder.append("]");
HashMap<String, Object> or = new HashMap<String, Object>();
or.put("or", JSONHelper.toObjectArray(sBuilder.toString(), Map.class));
HashMap<String, Object> match = new HashMap<String, Object>();
match.put("match", or);
groupList = new ArrayList<HashMap<String, Object>>();
groupList.add(match);
}
if (checkAuthor) {
// mongodb .为关键字,封装时替换为#交由后台处理
data = data.replaceAll("\\.", "#");
HashMap<String, String> jsonParam = JSONHelper.toObject(data, HashMap.class);
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
// 过滤数据,只查询最近的指定数据 begin
HashMap<String, Object> sortMap = new HashMap<String, Object>();
HashMap<String, Object> sort = new HashMap<String, Object>();
sort.put("values", "time");
sort.put("sortorder", "-1");
sortMap.put("sort", sort);
list.add(sortMap);
HashMap<String, Object> requestParam = new HashMap<String, Object>();
HashMap<String, Object> firstRecord = new HashMap<String, Object>();
HashMap<String, Object> firstRecordMatch = new HashMap<String, Object>();
firstRecord.put("firstrecord", "true");
firstRecordMatch.put("match", firstRecord);
list.add(firstRecordMatch);
// 封装组合查询条件 list.add = and
if (jsonParam.containsKey("event")) {
HashMap<String, Object> eventMap = new HashMap<String, Object>();
HashMap<String, Object> eventMatch = new HashMap<String, Object>();
eventMap.put("eventid", jsonParam.get("event"));
eventMatch.put("match", eventMap);
list.add(eventMatch);
}
if (jsonParam.containsKey("ip")) {
HashMap<String, Object> ipMap = new HashMap<String, Object>();
HashMap<String, Object> ipRegex = new HashMap<String, Object>();
HashMap<String, Object> ipMatch = new HashMap<String, Object>();
ipMap.put("ip", jsonParam.get("ip"));
ipRegex.put("regex", ipMap);
ipMatch.put("match", ipRegex);
list.add(ipMatch);
}
if (jsonParam.containsKey("host")) {
HashMap<String, Object> hostMap = new HashMap<String, Object>();
HashMap<String, Object> hostRegex = new HashMap<String, Object>();
HashMap<String, Object> hostMatch = new HashMap<String, Object>();
hostMap.put("host", jsonParam.get("host"));
hostRegex.put("regex", hostMap);
hostMatch.put("match", hostRegex);
list.add(hostMatch);
}
if (jsonParam.containsKey("description")) {
HashMap<String, Object> descriptionMap = new HashMap<String, Object>();
HashMap<String, Object> descriptionRegex = new HashMap<String, Object>();
HashMap<String, Object> descriptionMatch = new HashMap<String, Object>();
descriptionMap.put("description", jsonParam.get("description"));
descriptionRegex.put("regex", descriptionMap);
descriptionMatch.put("match", descriptionRegex);
list.add(descriptionMatch);
}
if (jsonParam.containsKey("abstract")) {
HashMap<String, Object> abstractMap = new HashMap<String, Object>();
HashMap<String, Object> abstractRegex = new HashMap<String, Object>();
HashMap<String, Object> abstractMatch = new HashMap<String, Object>();
abstractMap.put("title", jsonParam.get("abstract"));
abstractRegex.put("regex", abstractMap);
abstractMatch.put("match", abstractRegex);
list.add(abstractMatch);
}
if (jsonParam.containsKey("startTime")) {
HashMap<String, Object> startTime = new HashMap<String, Object>();
HashMap<String, Object> startTimeRegex = new HashMap<String, Object>();
HashMap<String, Object> startTimeMatch = new HashMap<String, Object>();
startTime.put("latestrecord_ts", jsonParam.get("startTime"));
startTimeRegex.put(">", startTime);
startTimeMatch.put("match", startTimeRegex);
list.add(startTimeMatch);
}
if (jsonParam.containsKey("endTime")) {
HashMap<String, Object> endTime = new HashMap<String, Object>();
HashMap<String, Object> endTimeRegex = new HashMap<String, Object>();
HashMap<String, Object> endTimeMatch = new HashMap<String, Object>();
endTime.put("latestrecord_ts", jsonParam.get("endTime"));
endTimeRegex.put("<", endTime);
endTimeMatch.put("match", endTimeRegex);
list.add(endTimeMatch);
}
if (!groupList.isEmpty()) {
list.addAll(groupList);
}
HashMap<String, Object> skipMap = new HashMap<String, Object>();
skipMap.put("skip", mongodbQueryRangeMap.get("skip"));
list.add(skipMap);
HashMap<String, Object> limitMap = new HashMap<String, Object>();
limitMap.put("limit", mongodbQueryRangeMap.get("limit"));
list.add(limitMap);
requestParam.put("count", "true");
list.add(requestParam);
// 封装http请求数据
UAVHttpMessage message = new UAVHttpMessage();
message.putRequest("mgo.sql", JSONHelper.toString(list));
message.putRequest("datastore.name", "MT_Notify");
message.putRequest("mgo.coll.name", "uav_notify");
NoitifyCountQueryBestCB callback = new NoitifyCountQueryBestCB();
callback.setResponse(response);
doHttpPost("uav.app.godeye.healthmanager.http.addr", "/hm/query", message, callback);
}
}
Aggregations