public Configuration Read() { var config = Settings.GetSettings(); var intervals = new AlertIntervals(config, AlertType); var thresholds = new AlertThreshold(config, AlertType); var notifications = new Notifications(config); var configuration = new Configuration(intervals, thresholds, notifications); return configuration; }
public void Start(Configuration c) { if (Notifier.StartEventSaved && !Notifier.EndEventSaved) { // Ensure we do not dispose of the Observers if they are in the middle of an alert cycle. return; } Subscription?.Dispose(); ConfigurationSync?.Dispose(); RefreshSettings(c); Logger.Trace("New threshold {0}", c.Thresholds.CriticalLoad); Logger.Trace("New interval {0}", c.Intervals.CriticalNotification); ConfigurationSync = Observable .Interval(TimeSpan.FromMinutes(ConfigurationRefreshTime)) // Refresh the settings and counters every X minutes .Select(i => ConfigurationReader.Read()) .DistinctUntilChanged() .Subscribe(Start); Counter = new CpuPerformanceCounter(); if (Enabled) { var alarms = Observable.Interval(c.Intervals.Measurement) // generate endless sequence of events .Select(i => Counter.Value) // convert event index to cpu load value .Select(load => load > c.Thresholds.CriticalLoad); // is critical? convert load to boolean Subscription = alarms // here we throttle critical alarms .Where(critical => critical).Sample(c.Intervals.Notification).Merge( // allow critical notification no more often then ... alarms // here we throttle non critical alarms .Where(critical => !critical).Sample(c.Intervals.Notification)) // allow non critical notification no more often then ... .Subscribe(Notifier.Notify); // our action to send notifications } }
protected override void RefreshSettings(Configuration c) { var settings = SettingsService.GetSettings(); Notifier.Email = new EmailModel { Address = settings.Address, Host = settings.EmailHost, Port = settings.Port, Username = settings.Username, Alert = settings.Alert, Password = settings.Password }; var hdd = settings.AlertRules.FirstOrDefault(x => x.AlertType == AlertTypeDto.Hdd); if (hdd != null) { Enabled = hdd.Enabled; HddId = hdd.DriveId; Notifier.NotificationSettings = new NotificationSettings { PercentageLimit = hdd.Percentage, Enabled = hdd.Enabled, ThresholdTime = hdd.ThresholdTime }; } Logger.Trace("Storage enabled: {0}", Enabled); Notifier.Interval = c.Intervals.CriticalNotification; Logger.Trace(settings.DumpJson().ToString()); Logger.Trace("Settings Refreshed"); }
protected abstract void RefreshSettings(Configuration c);
protected abstract void RefreshSettings(Configuration c);