public Task <Message> GetAsync(DiskDriveMetrics diskDriveMetrics) { if (diskDriveMetrics == null) { throw new NullReferenceException(nameof(diskDriveMetrics)); } var test = this.config.Value.Test; var config = this.config.Value.DiskDrive; this.logger.LogDebug($"{diskDriveMetrics.Debug}"); var isReady = diskDriveMetrics.IsReady; var usage = Math.Round(System.Convert.ToDouble(100 * diskDriveMetrics.Used) / diskDriveMetrics.Total); var warning = !isReady || (usage > config.Partitions.FirstOrDefault(x => x.Path == diskDriveMetrics.Path).MaxPercentageUsage); var send = config.ReportMode || warning || test; Message message = null; if (send) { var path = diskDriveMetrics.Path; var title = (warning ? "Warning - " : "") + $"DiskDrive - {path}"; string content; if (isReady) { var nl = "".NL(); var lines = new List <string>(); if (warning) { lines.Add($"Critical drive {path} {usage}% usage!{nl}{nl}"); } lines.Add($"Capacity: {diskDriveMetrics.Total.BytesToString()}"); lines.Add($"Free space: {diskDriveMetrics.Free.BytesToString()}"); content = string.Join(nl, lines); } else { content = $"Drive {path} is not ready!"; } message = new Message { Title = title, Content = content }; } return(Task.FromResult(message)); }
public Task <DiskDriveMetrics> GetDiskDriveMetricsAsync(DiskDriveConfig.Partition partition) { if (partition == null) { throw new NullReferenceException(nameof(partition)); } DriveInfo di = new DriveInfo(partition.Path); var metrics = new DiskDriveMetrics() { IsReady = di.IsReady, Path = partition.Path }; if (metrics.IsReady) { metrics.Total = di.TotalSize; metrics.Free = di.AvailableFreeSpace; } return(Task.FromResult(metrics)); }
public void Mock_GetDiskDriveMetrics(DiskDriveMetrics response) { this.Mock .Setup(x => x.GetDiskDriveMetricsAsync(It.IsAny <DiskDriveConfig.Partition>())) .ReturnsAsync(response); }
public void Mock_GetDiskDriveMetrics(Expression <Func <DiskDriveConfig.Partition, bool> > match, DiskDriveMetrics response) { this.Mock .Setup(x => x.GetDiskDriveMetricsAsync(It.Is(match))) .ReturnsAsync(response); }