Search in sources :

Example 1 with OpRouterMonitorServiceVO

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);
    }
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) OpRouterMonitorServiceVO(com.cloud.network.dao.OpRouterMonitorServiceVO) GetRouterAlertsCommand(com.cloud.agent.api.routing.GetRouterAlertsCommand) ParseException(java.text.ParseException) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) SimpleDateFormat(java.text.SimpleDateFormat) DomainRouterVO(com.cloud.vm.DomainRouterVO) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) JsonSyntaxException(com.google.gson.JsonSyntaxException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ParseException(java.text.ParseException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1 GetRouterAlertsCommand (com.cloud.agent.api.routing.GetRouterAlertsCommand)1 GetRouterMonitorResultsAnswer (com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer)1 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ConnectionException (com.cloud.exception.ConnectionException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 OpRouterMonitorServiceVO (com.cloud.network.dao.OpRouterMonitorServiceVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1