...
|
...
|
@@ -2,15 +2,11 @@ package com.monitor.monit.service; |
|
|
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.monit.constant.MConstants;
|
|
|
import com.monitor.monit.model.MMonitInfo;
|
|
|
import com.monitor.monit.model.MServiceInfo;
|
|
|
import com.monitor.monit.model.ServiceResponse;
|
|
|
import com.monitor.monit.model.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
...
|
...
|
@@ -31,42 +27,50 @@ public class SStatuService extends AbstractService { |
|
|
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
|
|
|
response.setData(buildServiceResponse());
|
|
|
List<ServiceResponse> servicesList = new ArrayList<>();
|
|
|
|
|
|
return response;
|
|
|
for (Map.Entry<String, MMonitInfo> entry : MConstants.HOSTSINFO_MAPPER.entrySet()) {
|
|
|
|
|
|
}
|
|
|
ServiceResponse serviceResponse = buildServiceResponse(entry.getValue());
|
|
|
|
|
|
if (null == serviceResponse) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
private List<ServiceResponse> buildServiceResponse() {
|
|
|
List<ServiceResponse> servicesList=new ArrayList<>();
|
|
|
servicesList.add(serviceResponse);
|
|
|
}
|
|
|
|
|
|
for (Map.Entry<String, MMonitInfo> entry : MConstants.HOSTSINFO_MAPPER.entrySet()) {
|
|
|
response.setData(servicesList);
|
|
|
|
|
|
ServiceResponse serviceResponse=new ServiceResponse();
|
|
|
return response;
|
|
|
|
|
|
serviceResponse.setMonitorId(entry.getKey());
|
|
|
}
|
|
|
|
|
|
serviceResponse.setHttpInfo(entry.getValue().getHttpInfo());
|
|
|
|
|
|
List<MServiceInfo> serviceInfos=new ArrayList<>();
|
|
|
private ServiceResponse buildServiceResponse(MMonitInfo mMonitInfo) {
|
|
|
|
|
|
for (Map.Entry<String,MServiceInfo> serviceInfoEntry:entry.getValue().getServiceInfos().entrySet())
|
|
|
{
|
|
|
serviceInfos.add(serviceInfoEntry.getValue());
|
|
|
}
|
|
|
if (null == mMonitInfo) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
serviceResponse.setServicesInfo(serviceInfos);
|
|
|
ServiceResponse serviceResponse = new ServiceResponse();
|
|
|
|
|
|
serviceResponse.setEventsInfo(entry.getValue().getEvents());
|
|
|
serviceResponse.setMonitorId(mMonitInfo.getMonitorId());
|
|
|
|
|
|
servicesList.add(serviceResponse);
|
|
|
serviceResponse.setHttpInfo(mMonitInfo.getHttpInfo());
|
|
|
|
|
|
List<MServiceInfo> serviceInfos = new ArrayList<>();
|
|
|
|
|
|
for (Map.Entry<String, MServiceInfo> serviceInfoEntry : mMonitInfo.getServiceInfos().entrySet()) {
|
|
|
serviceInfos.add(serviceInfoEntry.getValue());
|
|
|
}
|
|
|
|
|
|
return servicesList;
|
|
|
}
|
|
|
serviceResponse.setServicesInfo(serviceInfos);
|
|
|
|
|
|
serviceResponse.setEventsInfo(mMonitInfo.getEvents());
|
|
|
|
|
|
return serviceResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/host/{hostId}", method = RequestMethod.GET)
|
...
|
...
|
@@ -91,4 +95,92 @@ public class SStatuService extends AbstractService { |
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/allMonit")
|
|
|
public BaseResponse fetchAllMonit(@RequestBody MonitRequest request) {
|
|
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
|
|
|
List<MHostInfo> mHostInfos = new ArrayList<>();
|
|
|
|
|
|
if (StringUtils.isBlank(request.getQuery()) || StringUtils.equals(";", request.getQuery().trim())) {
|
|
|
mHostInfos.addAll(MConstants.MHOST_Mapper.values());
|
|
|
} else {
|
|
|
String[] querys = request.getQuery().split(";");
|
|
|
|
|
|
if (StringUtils.isBlank(querys[0])) {
|
|
|
mHostInfos = queryMHostByTags(querys[1]);
|
|
|
} else {
|
|
|
mHostInfos = queryMHostByIp(querys[0]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Collections.sort(mHostInfos, new MHostInfoComparator());
|
|
|
|
|
|
baseResponse.setData(mHostInfos);
|
|
|
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
/* @RequestMapping(value = "/searchMonit")
|
|
|
public BaseResponse fetchAllMonit(MonitRequest query) {
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
|
|
|
List<MHostInfo> mHostInfos = new ArrayList<>();
|
|
|
|
|
|
String ip = StringUtils.trim(query.getQuery());
|
|
|
|
|
|
if (MHostInfoComparator.isIP(ip)) {
|
|
|
//根据Ip查询
|
|
|
mHostInfos = queryMHostByIp(ip);
|
|
|
} else {
|
|
|
//根据tag查询
|
|
|
mHostInfos = queryMHostByTags(ip);
|
|
|
}
|
|
|
|
|
|
Collections.sort(mHostInfos, new MHostInfoComparator());
|
|
|
|
|
|
baseResponse.setData(mHostInfos);
|
|
|
|
|
|
return baseResponse;
|
|
|
}*/
|
|
|
|
|
|
@RequestMapping(value = "/searchService")
|
|
|
public BaseResponse fetchService(@RequestBody MonitRequest request) {
|
|
|
ServiceResponse serviceResponse = buildServiceResponse(MConstants.HOSTSINFO_MAPPER.get(request.getMonitorId()));
|
|
|
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
|
|
|
if (null != serviceResponse) {
|
|
|
response.setData(serviceResponse);
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
private List<MHostInfo> queryMHostByIp(String ip) {
|
|
|
List<MHostInfo> mHostInfos = new ArrayList<>();
|
|
|
|
|
|
if (MConstants.MHOST_Mapper.containsKey(ip)) {
|
|
|
mHostInfos.add(MConstants.MHOST_Mapper.get(ip));
|
|
|
}
|
|
|
|
|
|
return mHostInfos;
|
|
|
}
|
|
|
|
|
|
private List<MHostInfo> queryMHostByTags(String ip) {
|
|
|
List<MHostInfo> mHostInfos = new ArrayList<>();
|
|
|
|
|
|
synchronized (MConstants.LOCK.intern()) {
|
|
|
for (Map.Entry<String, MHostInfo> entry : MConstants.MHOST_Mapper.entrySet()) {
|
|
|
String tags = entry.getValue().getTags();
|
|
|
//tag满足要求
|
|
|
if (StringUtils.isNotBlank(tags) && StringUtils.contains(StringUtils.lowerCase(tags), StringUtils.lowerCase(ip))) {
|
|
|
mHostInfos.add(entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return mHostInfos;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|