mirror of
				https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
				synced 2025-11-03 20:17:53 +00:00 
			
		
		
		
	Merge pull request #45 from Telecominfraproject/disable_eq_alarms_sp
Move the raising and clearing of the threshold alarms into the gatewa…
This commit is contained in:
		@@ -6,6 +6,7 @@ import java.net.Inet6Address;
 | 
				
			|||||||
import java.net.InetAddress;
 | 
					import java.net.InetAddress;
 | 
				
			||||||
import java.net.UnknownHostException;
 | 
					import java.net.UnknownHostException;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.Date;
 | 
					import java.util.Date;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
@@ -16,6 +17,7 @@ import java.util.Set;
 | 
				
			|||||||
import org.slf4j.Logger;
 | 
					import org.slf4j.Logger;
 | 
				
			||||||
import org.slf4j.LoggerFactory;
 | 
					import org.slf4j.LoggerFactory;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Value;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					import com.google.protobuf.ByteString;
 | 
				
			||||||
@@ -23,6 +25,12 @@ import com.google.protobuf.Descriptors;
 | 
				
			|||||||
import com.google.protobuf.InvalidProtocolBufferException;
 | 
					import com.google.protobuf.InvalidProtocolBufferException;
 | 
				
			||||||
import com.google.protobuf.util.JsonFormat;
 | 
					import com.google.protobuf.util.JsonFormat;
 | 
				
			||||||
import com.google.protobuf.util.JsonFormat.TypeRegistry;
 | 
					import com.google.protobuf.util.JsonFormat.TypeRegistry;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.AlarmServiceInterface;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.models.Alarm;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.models.AlarmCode;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.models.AlarmDetails;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.models.AlarmScopeType;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.alarm.models.OriginatorType;
 | 
				
			||||||
import com.telecominfraproject.wlan.client.ClientServiceInterface;
 | 
					import com.telecominfraproject.wlan.client.ClientServiceInterface;
 | 
				
			||||||
import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails;
 | 
					import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails;
 | 
				
			||||||
import com.telecominfraproject.wlan.client.session.models.AssociationState;
 | 
					import com.telecominfraproject.wlan.client.session.models.AssociationState;
 | 
				
			||||||
@@ -68,6 +76,7 @@ import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric;
 | 
				
			|||||||
import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourReport;
 | 
					import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourReport;
 | 
				
			||||||
import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourScanReports;
 | 
					import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourScanReports;
 | 
				
			||||||
import com.telecominfraproject.wlan.status.StatusServiceInterface;
 | 
					import com.telecominfraproject.wlan.status.StatusServiceInterface;
 | 
				
			||||||
 | 
					import com.telecominfraproject.wlan.status.equipment.models.EquipmentAdminStatusData;
 | 
				
			||||||
import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID;
 | 
					import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID;
 | 
				
			||||||
import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs;
 | 
					import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs;
 | 
				
			||||||
import com.telecominfraproject.wlan.status.equipment.report.models.EquipmentCapacityDetails;
 | 
					import com.telecominfraproject.wlan.status.equipment.report.models.EquipmentCapacityDetails;
 | 
				
			||||||
@@ -133,6 +142,17 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
    private CloudEventDispatcherInterface cloudEventDispatcherInterface;
 | 
					    private CloudEventDispatcherInterface cloudEventDispatcherInterface;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private RealtimeEventPublisher realtimeEventPublisher;
 | 
					    private RealtimeEventPublisher realtimeEventPublisher;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private AlarmServiceInterface alarmServiceInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Value("${tip.wlan.mqttStatsPublisher.temperatureThresholdInC:80}")
 | 
				
			||||||
 | 
					    private int temperatureThresholdInC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Value("${tip.wlan.mqttStatsPublisher.cpuUtilThresholdPct:80}")
 | 
				
			||||||
 | 
					    private int cpuUtilThresholdPct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Value("${tip.wlan.mqttStatsPublisher.memoryUtilThresholdPct:70}")
 | 
				
			||||||
 | 
					    private int memoryUtilThresholdPct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void processMqttMessage(String topic, WCStatsReport wcStatsReport) {
 | 
					    public void processMqttMessage(String topic, WCStatsReport wcStatsReport) {
 | 
				
			||||||
        LOG.info("Received WCStatsReport {}", wcStatsReport.toString());
 | 
					        LOG.info("Received WCStatsReport {}", wcStatsReport.toString());
 | 
				
			||||||
@@ -222,9 +242,12 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
                LOG.debug("Current timestamp for service metrics is {}", serviceMetricTimestamp);
 | 
					                LOG.debug("Current timestamp for service metrics is {}", serviceMetricTimestamp);
 | 
				
			||||||
                metricRecordList.stream().forEach(smr -> {
 | 
					                metricRecordList.stream().forEach(smr -> {
 | 
				
			||||||
                    smr.setCreatedTimestamp(serviceMetricTimestamp);
 | 
					                    smr.setCreatedTimestamp(serviceMetricTimestamp);
 | 
				
			||||||
                    if (smr.getLocationId() == 0) smr.setLocationId(locationId);
 | 
					                    if (smr.getLocationId() == 0)
 | 
				
			||||||
                    if(smr.getCustomerId() == 0) smr.setCustomerId(customerId);
 | 
					                        smr.setLocationId(locationId);
 | 
				
			||||||
                    if (smr.getEquipmentId() == 0L) smr.setEquipmentId(equipmentId);
 | 
					                    if (smr.getCustomerId() == 0)
 | 
				
			||||||
 | 
					                        smr.setCustomerId(customerId);
 | 
				
			||||||
 | 
					                    if (smr.getEquipmentId() == 0L)
 | 
				
			||||||
 | 
					                        smr.setEquipmentId(equipmentId);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                metricRecordList.stream().forEach(smr -> {
 | 
					                metricRecordList.stream().forEach(smr -> {
 | 
				
			||||||
                    LOG.debug("ServiceMetric {}", smr);
 | 
					                    LOG.debug("ServiceMetric {}", smr);
 | 
				
			||||||
@@ -938,22 +961,43 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
                        numSamples++;
 | 
					                        numSamples++;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (numSamples > 0) {
 | 
					                if (numSamples > 0) {
 | 
				
			||||||
                    avgRadioTemp = Math.round((cpuTemperature / numSamples));
 | 
					                    avgRadioTemp = Math.round((cpuTemperature / numSamples));
 | 
				
			||||||
                    apPerformance.setCpuTemperature(avgRadioTemp);
 | 
					                    apPerformance.setCpuTemperature(avgRadioTemp);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                if (avgRadioTemp > temperatureThresholdInC) {
 | 
				
			||||||
 | 
					                    raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature, deviceReport.getTimestampMs());
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // Clear any existing temperature alarms for this ap
 | 
				
			||||||
 | 
					                    clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (deviceReport.hasCpuUtil() && deviceReport.getCpuUtil().hasCpuUtil()) {
 | 
					            if (deviceReport.hasCpuUtil() && deviceReport.getCpuUtil().hasCpuUtil()) {
 | 
				
			||||||
                Integer cpuUtilization = deviceReport.getCpuUtil().getCpuUtil();
 | 
					                Integer cpuUtilization = deviceReport.getCpuUtil().getCpuUtil();
 | 
				
			||||||
                apPerformance.setCpuUtilized(new int[] {cpuUtilization});
 | 
					                apPerformance.setCpuUtilized(new int[] {cpuUtilization});
 | 
				
			||||||
 | 
					                if (cpuUtilization > cpuUtilThresholdPct) {
 | 
				
			||||||
 | 
					                    raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization, deviceReport.getTimestampMs());
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // Clear any existing cpuUtilization alarms
 | 
				
			||||||
 | 
					                    clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            apPerformance.setEthLinkState(EthernetLinkState.UP1000_FULL_DUPLEX);
 | 
					            apPerformance.setEthLinkState(EthernetLinkState.UP1000_FULL_DUPLEX);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (deviceReport.hasMemUtil() && deviceReport.getMemUtil().hasMemTotal() && deviceReport.getMemUtil().hasMemUsed()) {
 | 
					            if (deviceReport.hasMemUtil() && deviceReport.getMemUtil().hasMemTotal() && deviceReport.getMemUtil().hasMemUsed()) {
 | 
				
			||||||
                apPerformance.setFreeMemory(deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed());
 | 
					                apPerformance.setFreeMemory(deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                double usedMemory = deviceReport.getMemUtil().getMemUsed();
 | 
				
			||||||
 | 
					                double totalMemory = deviceReport.getMemUtil().getMemTotal();
 | 
				
			||||||
 | 
					                if (usedMemory/totalMemory * 100 > memoryUtilThresholdPct) {
 | 
				
			||||||
 | 
					                    raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization, deviceReport.getTimestampMs());
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // Clear any existing cpuUtilization alarms
 | 
				
			||||||
 | 
					                    clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            apPerformance.setUpTime((long) deviceReport.getUptime());
 | 
					            apPerformance.setUpTime((long) deviceReport.getUptime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -969,7 +1013,6 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
            if (apNodeMetrics.getSourceTimestampMs() < deviceReport.getTimestampMs())
 | 
					            if (apNodeMetrics.getSourceTimestampMs() < deviceReport.getTimestampMs())
 | 
				
			||||||
                apNodeMetrics.setSourceTimestampMs(deviceReport.getTimestampMs());
 | 
					                apNodeMetrics.setSourceTimestampMs(deviceReport.getTimestampMs());
 | 
				
			||||||
            updateDeviceStatusForReport(customerId, equipmentId, deviceReport, avgRadioTemp);
 | 
					            updateDeviceStatusForReport(customerId, equipmentId, deviceReport, avgRadioTemp);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // statusList.add(status);
 | 
					        // statusList.add(status);
 | 
				
			||||||
@@ -1133,7 +1176,8 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
                    radioUtil.setTimestampSeconds((int) ((survey.getTimestampMs()) / 1000));
 | 
					                    radioUtil.setTimestampSeconds((int) ((survey.getTimestampMs()) / 1000));
 | 
				
			||||||
                    radioUtil.setSourceTimestampMs(survey.getTimestampMs());
 | 
					                    radioUtil.setSourceTimestampMs(survey.getTimestampMs());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // The service metric report's sourceTimestamp will be the most recent timestamp from its contributing stats
 | 
					                    // The service metric report's sourceTimestamp will be the most recent timestamp from its
 | 
				
			||||||
 | 
					                    // contributing stats
 | 
				
			||||||
                    if (apNodeMetrics.getSourceTimestampMs() < survey.getTimestampMs())
 | 
					                    if (apNodeMetrics.getSourceTimestampMs() < survey.getTimestampMs())
 | 
				
			||||||
                        apNodeMetrics.setSourceTimestampMs(survey.getTimestampMs());
 | 
					                        apNodeMetrics.setSourceTimestampMs(survey.getTimestampMs());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1197,6 +1241,35 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
        updateDeviceStatusRadioUtilizationReport(customerId, equipmentId, radioUtilizationReport);
 | 
					        updateDeviceStatusRadioUtilizationReport(customerId, equipmentId, radioUtilizationReport);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void clearDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode) {
 | 
				
			||||||
 | 
					        alarmServiceInterface.get(customerId, Set.of(equipmentId), Set.of(alarmCode)).stream().forEach(a -> {
 | 
				
			||||||
 | 
					            Alarm alarm = alarmServiceInterface.delete(customerId, equipmentId, a.getAlarmCode(), a.getLastModifiedTimestamp());
 | 
				
			||||||
 | 
					            LOG.info("Cleared device threshold alarm {}", alarm);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void raiseDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode, long timestampMs) {
 | 
				
			||||||
 | 
					        // Raise an alarm for temperature
 | 
				
			||||||
 | 
					        Alarm alarm = new Alarm();
 | 
				
			||||||
 | 
					        alarm.setCustomerId(customerId);
 | 
				
			||||||
 | 
					        alarm.setEquipmentId(equipmentId);
 | 
				
			||||||
 | 
					        alarm.setAlarmCode(alarmCode);
 | 
				
			||||||
 | 
					        alarm.setOriginatorType(OriginatorType.AP);
 | 
				
			||||||
 | 
					        alarm.setSeverity(alarmCode.getSeverity());
 | 
				
			||||||
 | 
					        alarm.setScopeType(AlarmScopeType.EQUIPMENT);
 | 
				
			||||||
 | 
					        alarm.setScopeId("" + equipmentId);
 | 
				
			||||||
 | 
					        alarm.setCreatedTimestamp(timestampMs);
 | 
				
			||||||
 | 
					        AlarmDetails alarmDetails = new AlarmDetails();
 | 
				
			||||||
 | 
					        alarmDetails.setMessage(alarmCode.getDescription());
 | 
				
			||||||
 | 
					        alarmDetails.setAffectedEquipmentIds(Collections.singletonList(equipmentId));
 | 
				
			||||||
 | 
					        alarm.setDetails(alarmDetails);
 | 
				
			||||||
 | 
					        List<Alarm> alarms = alarmServiceInterface.get(customerId, Set.of(equipmentId), Set.of(alarmCode));
 | 
				
			||||||
 | 
					        if (alarms.isEmpty()) {
 | 
				
			||||||
 | 
					            alarm.setCreatedTimestamp(timestampMs);
 | 
				
			||||||
 | 
					            alarm = alarmServiceInterface.create(alarm);
 | 
				
			||||||
 | 
					        } 
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    private void checkIfOutOfBound(String checkedType, int checkedValue, Survey survey, int totalDurationMs, int busyTx, int busyRx, int busy, int busySelf) {
 | 
					    private void checkIfOutOfBound(String checkedType, int checkedValue, Survey survey, int totalDurationMs, int busyTx, int busyRx, int busy, int busySelf) {
 | 
				
			||||||
        if (checkedValue > 100 || checkedValue < 0) {
 | 
					        if (checkedValue > 100 || checkedValue < 0) {
 | 
				
			||||||
            LOG.warn(
 | 
					            LOG.warn(
 | 
				
			||||||
@@ -1391,6 +1464,8 @@ public class MqttStatsPublisher {
 | 
				
			|||||||
        LOG.debug("updated status {}", status);
 | 
					        LOG.debug("updated status {}", status);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void populateApClientMetrics(List<ServiceMetric> metricRecordList, Report report, int customerId, long equipmentId, long locationId) {
 | 
					    void populateApClientMetrics(List<ServiceMetric> metricRecordList, Report report, int customerId, long equipmentId, long locationId) {
 | 
				
			||||||
        LOG.info("populateApClientMetrics for Customer {} Equipment {}", customerId, equipmentId);
 | 
					        LOG.info("populateApClientMetrics for Customer {} Equipment {}", customerId, equipmentId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user