use of com.cloud.network.dao.OpRouterMonitorServiceVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method getRouterAlerts.
protected void getRouterAlerts() {
try {
final List<DomainRouterVO> routers = _routerDao.listByStateAndManagementServer(VirtualMachine.State.Running, mgmtSrvrId);
s_logger.debug("Found " + routers.size() + " running routers. ");
for (final DomainRouterVO router : routers) {
final String serviceMonitoringFlag = SetServiceMonitor.valueIn(router.getDataCenterId());
// Monitor service is not enabled in the corresponding Zone
if (!Boolean.parseBoolean(serviceMonitoringFlag)) {
continue;
}
String controlIP = _routerControlHelper.getRouterControlIp(router.getId());
if (controlIP != null && !controlIP.equals("0.0.0.0")) {
OpRouterMonitorServiceVO opRouterMonitorServiceVO = _opRouterMonitorServiceDao.findById(router.getId());
GetRouterAlertsCommand command = null;
if (opRouterMonitorServiceVO == null) {
// To
command = new GetRouterAlertsCommand(new String("1970-01-01 00:00:00"));
// avoid
// sending
// null
// value
} else {
command = new GetRouterAlertsCommand(opRouterMonitorServiceVO.getLastAlertTimestamp());
}
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlIP);
try {
final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
GetRouterAlertsAnswer answer = null;
if (origAnswer == null) {
s_logger.warn("Unable to get alerts from router " + router.getHostName());
continue;
}
if (origAnswer instanceof GetRouterAlertsAnswer) {
answer = (GetRouterAlertsAnswer) origAnswer;
} else {
s_logger.warn("Unable to get alerts from router " + router.getHostName());
continue;
}
if (!answer.getResult()) {
s_logger.warn("Unable to get alerts from router " + router.getHostName() + " " + answer.getDetails());
continue;
}
final String[] alerts = answer.getAlerts();
if (alerts != null) {
final String lastAlertTimeStamp = answer.getTimeStamp();
final SimpleDateFormat sdfrmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdfrmt.setLenient(false);
try {
sdfrmt.parse(lastAlertTimeStamp);
} catch (final ParseException e) {
s_logger.warn("Invalid last alert timestamp received while collecting alerts from router: " + router.getInstanceName());
continue;
}
for (final String alert : alerts) {
_alertMgr.sendAlert(AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), "Monitoring Service on VR " + router.getInstanceName(), alert);
}
if (opRouterMonitorServiceVO == null) {
opRouterMonitorServiceVO = new OpRouterMonitorServiceVO(router.getId(), router.getHostName(), lastAlertTimeStamp);
_opRouterMonitorServiceDao.persist(opRouterMonitorServiceVO);
} else {
opRouterMonitorServiceVO.setLastAlertTimestamp(lastAlertTimeStamp);
_opRouterMonitorServiceDao.update(opRouterMonitorServiceVO.getId(), opRouterMonitorServiceVO);
}
}
} catch (final Exception e) {
s_logger.warn("Error while collecting alerts from router: " + router.getInstanceName(), e);
continue;
}
}
}
} catch (final Exception e) {
s_logger.warn("Error while collecting alerts from router", e);
}
}
Aggregations