package com.wgcloud.service;
|
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.wgcloud.entity.OspfInfo;
|
import com.wgcloud.entity.SnmpInfo;
|
import com.wgcloud.mapper.OspfInfoMapper;
|
import com.wgcloud.util.DateUtil;
|
import com.wgcloud.util.UUIDUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @version v3.3
|
* @ClassName:OspfInfoService.java
|
* @author: http://www.wgstart.com
|
* @date: 2021年1月16日
|
* @Description: OspfInfoService.java
|
* @Copyright: 2019-2021 wgcloud. All rights reserved.
|
*/
|
@Service
|
public class OspfInfoService {
|
|
@Autowired
|
private RouterConnectionService routerConnectionService;
|
|
private static final Logger logger = LoggerFactory.getLogger(OspfInfoService.class);
|
|
public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
|
PageHelper.startPage(currPage, pageSize);
|
List<OspfInfo> list = OspfInfoMapper.selectByParams(params);
|
PageInfo<OspfInfo> pageInfo = new PageInfo<OspfInfo>(list);
|
return pageInfo;
|
}
|
|
public void saveRecord(List<OspfInfo> recordList) throws Exception {
|
if (recordList.size() < 1) {
|
return;
|
}
|
Map<String, Object> map = new HashMap<String, Object>();
|
for (OspfInfo as : recordList) {
|
as.setId(UUIDUtil.getUUID());
|
as.setCreateTime(DateUtil.getNowTime());
|
}
|
OspfInfoMapper.insertList(recordList);
|
}
|
|
public void save(OspfInfo ospfInfo) {
|
ospfInfo.setId(UUIDUtil.getUUID());
|
ospfInfo.setCreateTime(DateUtil.getNowTime());
|
try {
|
OspfInfoMapper.save(ospfInfo);
|
} catch (Exception e) {
|
logger.error("保存日志信息异常:", e);
|
}
|
}
|
|
public void updateById(OspfInfo ospfInfo)
|
throws Exception {
|
if (StringUtils.isEmpty(ospfInfo.getHostname())) {
|
ospfInfo.setHostname(ospfInfo.getHostname().trim());
|
}
|
OspfInfoMapper.updateById(ospfInfo);
|
}
|
|
public boolean checkOspfStatus() {
|
String command = "display ospf brief";
|
String output = routerConnectionService.executeCommand(command);
|
|
if (output == null) {
|
return false;
|
}
|
|
// 检查输出中是否包含OSPF相关信息
|
boolean containsRouterId = StringUtils.containsIgnoreCase(output, "Router ID");
|
boolean containsArea = StringUtils.containsIgnoreCase(output, "Area");
|
boolean containsProcessId = StringUtils.containsIgnoreCase(output, "Process ID");
|
|
// 检查是否有错误信息
|
boolean containsError = StringUtils.containsIgnoreCase(output, "Error") ||
|
StringUtils.containsIgnoreCase(output, "Fail") ||
|
StringUtils.containsIgnoreCase(output, "Invalid");
|
|
return (containsRouterId && containsArea && containsProcessId) && !containsError;
|
}
|
|
/**
|
* 获取详细的OSPF邻居信息
|
*/
|
public String getDetailedOspfNeighborInfo() {
|
String command = "display ospf peer";
|
return routerConnectionService.executeCommand(command);
|
}
|
|
/**
|
* 获取OSPF接口状态
|
*/
|
public String getOspfInterfaceStatus() {
|
String command = "display ospf interface";
|
return routerConnectionService.executeCommand(command);
|
}
|
|
|
|
|
public int countByParams(Map<String, Object> params) throws Exception {
|
return OspfInfoMapper.countByParams(params);
|
}
|
|
public int deleteById(String[] id) throws Exception {
|
return OspfInfoMapper.deleteById(id);
|
}
|
|
public OspfInfo selectById(String id) throws Exception {
|
return OspfInfoMapper.selectById(id);
|
}
|
|
public List<OspfInfo> selectAllByParams(Map<String, Object> params) throws Exception {
|
return OspfInfoMapper.selectAllByParams(params);
|
}
|
|
public int deleteByDate(Map<String, Object> map) throws Exception{
|
return OspfInfoMapper.deleteByDate(map);
|
}
|
|
@Autowired
|
private OspfInfoMapper OspfInfoMapper;
|
|
|
}
|