示例#1
0
        private async Task <bool> InspectExistingAlarm(string alarmName,
                                                       double thresholdInUnits, int periodSeconds, string targetTopic)
        {
            var existingAlarm = await _alarmFinder.FindAlarmByName(alarmName);

            if (existingAlarm == null)
            {
                _logger.Info($"Table alarm {alarmName} does not already exist. Creating it at threshold {thresholdInUnits}");
                return(true);
            }

            if (!MetricAlarmHelper.AlarmActionsEqualsTarget(existingAlarm.AlarmActions, targetTopic))
            {
                _logger.Info($"Index alarm {alarmName} alarm target has changed to {targetTopic}");
                return(true);
            }


            if (!MetricAlarmHelper.AlarmAndOkActionsAreEqual(existingAlarm))
            {
                _logger.Info($"Index alarm {alarmName} alarm actions does not match ok actions");
                return(true);
            }

            if (AlarmThresholds.AreEqual(existingAlarm.Threshold, thresholdInUnits) && (existingAlarm.Period == periodSeconds))
            {
                _logger.Detail($"Table alarm {alarmName} already exists at same threshold {existingAlarm.Threshold}");
                return(false);
            }

            LogDifferences(existingAlarm, alarmName, thresholdInUnits, periodSeconds);
            return(true);
        }
示例#2
0
        private void LogDifferences(MetricAlarm existingAlarm, string alarmName, double thresholdInUnits, int periodSeconds)
        {
            if (existingAlarm.Period != periodSeconds)
            {
                _logger.Info($"Table alarm {alarmName} period has changed from {existingAlarm.Period} to {periodSeconds}");
            }

            if (AlarmThresholds.AreEqual(existingAlarm.Threshold, thresholdInUnits))
            {
                return;
            }

            if (existingAlarm.Threshold < thresholdInUnits)
            {
                _logger.Info($"Table alarm {alarmName} already exists at lower threshold {existingAlarm.Threshold}. Will increase to {thresholdInUnits}");
            }
            else
            {
                _logger.Info($"Table alarm {alarmName} already exists at higher threshold {existingAlarm.Threshold}. Will decrease to {thresholdInUnits}");
            }
        }