Exemplo n.º 1
0
 private void Recurse(StatusResultsBuilder statusBuilder, int level, int sourceNumber)
 {
     if (level == 0)
     {
         statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
         if (sourceNumber < 3)
         {
             statusBuilder.AddOkay(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Okay", "This is the multiple source okay", 0.5f);
         }
         else if (sourceNumber < 6)
         {
             statusBuilder.AddAlert(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Alert", "This is the multiple source alert", 0.5f);
         }
         else
         {
             statusBuilder.AddFailure(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Fail", "This is the multiple source failure", 0.5f);
         }
     }
     else
     {
         if (level % 2 == 0)
         {
             statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
         }
         StatusResultsBuilder child = new StatusResultsBuilder("Level" + level.ToString());
         child.AddProperty("Level", level);
         child.AddProperty("SourceNumber", sourceNumber);
         Recurse(child, level - 1, sourceNumber);
         statusBuilder.AddChild(child.FinalResults);
     }
 }
Exemplo n.º 2
0
        public void StatusResultsBuilderWorstAlert()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsBuilder test;

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddException(new ExpectedException(), 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.5f, test.WorstAlert?.Rating);
                test.AddException(new ExpectedException(), 0.6f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);
                test.AddException(new ExpectedException(), 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddFailure("Fail", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.5f, test.WorstAlert?.Rating);
                test.AddFailure("Fail", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);
                test.AddFailure("Fail", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Alert - 0.5f, test.WorstAlert?.Rating);
                test.AddAlert("Alert", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Alert - 0.6f, test.WorstAlert?.Rating);
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Alert - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Okay - 0.5f, test.WorstAlert?.Rating);
                test.AddOkay("Okay", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Okay - 0.6f, test.WorstAlert?.Rating);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Okay - 0.6f, test.WorstAlert?.Rating);
            }
        }
Exemplo n.º 3
0
 public void StatusResultsBuilderExceptions()
 {
     using (AmbientClock.Pause())
     {
         StatusResultsBuilder test = new StatusResultsBuilder(nameof(StatusResultsBuilder));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddException(new ApplicationException(), -1.0f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddFailure("Fail", "Terse", "Details", -0.1f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddAlert("Alert", "Terse", "Details", -0.001f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddAlert("Alert", "Terse", "Details", 1.001f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddOkay("Okay", "Terse", "Details", 1.1f));
         Assert.ThrowsException <ArgumentNullException>(() => new StatusResultsBuilder((StatusResults)null !));
         Assert.ThrowsException <ArgumentNullException>(() => new StatusResultsBuilder((StatusChecker)null !));
     }
 }
        public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
            StatusRatingRange currentAuditRating = (StatusRatingRange)(_auditNumber++ % (int)EnumExtensions.MaxEnumValue <StatusRatingRange>());
            float             rating             = (StatusRating.GetRangeUpperBound(currentAuditRating) + StatusRating.GetRangeLowerBound(currentAuditRating)) / 2;

            if (rating <= StatusRating.Fail)
            {
                statusBuilder.AddFailure("FailCode", "Fail", "The system has failed!", StatusRating.Fail - rating);
            }
            else if (rating <= StatusRating.Alert)
            {
                statusBuilder.AddAlert("AlertCode", "Alert", "The system has alerted!", StatusRating.Alert - rating);
            }
            else if (rating <= StatusRating.Okay)
            {
                statusBuilder.AddOkay("OkayCode", "Okay", "The system is okay", StatusRating.Okay - rating);
            }
            else
            {
                statusBuilder.AddOkay("SuperCode", "Superlative", "The system is superlative", StatusRating.Superlative - rating);
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
 private void AddSource(StatusResultsBuilder statusBuilder, int sourceNumber)
 {
     if (sourceNumber < 3)
     {
         statusBuilder.AddOkay(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Okay", "This is the multiple source okay", 0.5f);
     }
     else if (sourceNumber < 6)
     {
         statusBuilder.AddAlert(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Alert", "This is the multiple source alert", 0.5f);
     }
     else
     {
         statusBuilder.AddFailure(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Fail", "This is the multiple source failure", 0.5f);
     }
     statusBuilder.SourceSystem = "Source " + sourceNumber.ToString();
 }
Exemplo n.º 6
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
     if (_rating <= StatusRating.Fail)
     {
         statusBuilder.AddFailure(_auditCode, _terse, _details, _rating);
     }
     else if (_rating <= StatusRating.Alert)
     {
         statusBuilder.AddAlert(_auditCode, _terse, _details, StatusRating.Alert - _rating);
     }
     else
     {
         statusBuilder.AddOkay(_auditCode, _terse, _details, StatusRating.Okay - _rating);
     }
     return(Task.CompletedTask);
 }
Exemplo n.º 7
0
        public void StatusResultsBuilderFinalResults()
        {
            using (AmbientClock.Pause())
            {
                StatusResults        results;
                StatusResultsBuilder test;

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderFinalResults));
                test.AuditDuration = null;
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                results = test.FinalResults;
                Assert.AreEqual(StatusRating.Alert - 0.5f, results.Report?.Alert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderFinalResults));
                test.AuditDuration = TimeSpan.FromMilliseconds(100);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                results = test.FinalResults;
                Assert.AreEqual(StatusRating.Okay - 0.5f, results.Report?.Alert?.Rating);
            }
        }
Exemplo n.º 8
0
    /// <summary>
    /// Performs the disk audit, reporting results into <paramref name="statusBuilder"/>.
    /// </summary>
    /// <param name="statusBuilder">A <see cref="StatusResultsBuilder"/> to write the results into.</param>
    /// <param name="cancel">The optional <see cref="CancellationToken"/>.</param>
    public async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default)
    {
        statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
        statusBuilder.AddProperty("_Path", _driveInfo.Name);
        statusBuilder.AddProperty("_VolumeLabel", _driveInfo.VolumeLabel);
        statusBuilder.AddProperty("DriveFormat", _driveInfo.DriveFormat);
        statusBuilder.AddProperty("DriveType", _driveInfo.DriveType);
        statusBuilder.AddProperty("AvailableFreeBytes", _driveInfo.AvailableFreeSpace);
        statusBuilder.AddProperty("TotalFreeBytes", _driveInfo.TotalFreeSpace);
        statusBuilder.AddProperty("TotalBytes", _driveInfo.TotalSize);
        if (!string.IsNullOrEmpty(_testPath))
        {
            StatusResultsBuilder readBuilder = new StatusResultsBuilder("Read");
            statusBuilder.AddChild(readBuilder);
            try
            {
                // attempt to read a file (if one exists)
                foreach (string file in Directory.EnumerateFiles(Path.Combine(_driveInfo.RootDirectory.FullName, _testPath)))
                {
                    AmbientStopwatch s = AmbientStopwatch.StartNew();
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            byte[] b = new byte[1];
                            await fs.ReadAsync(b, 0, 1, cancel);

                            await fs.FlushAsync();
                        }
                        readBuilder.AddProperty("ResponseMs", s.ElapsedMilliseconds);
                        readBuilder.AddOkay("Ok", "Success", "The read operation succeeded.");
                        break;
                    }
                    catch (IOException) // this will be thrown if the file cannot be accessed because it is open exclusively by another process (this happens a lot with temp files)
                    {
                        // just move on and try the next file
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                readBuilder.AddException(e);
            }
            if (!_readonly)
            {
                StatusResultsBuilder writeBuilder = new StatusResultsBuilder("Write");
                statusBuilder.AddChild(writeBuilder);
                try
                {
                    // attempt to write a temporary file
                    string           targetPath = Path.Combine(_driveInfo.RootDirectory.FullName, Guid.NewGuid().ToString("N"));
                    AmbientStopwatch s          = AmbientStopwatch.StartNew();
                    using (FileStream fs = new FileStream(targetPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose))
                    {
                        byte[] b = new byte[1];
                        await fs.WriteAsync(b, 0, 1);

                        await fs.FlushAsync();

                        readBuilder.AddProperty("ResponseMs", s.ElapsedMilliseconds);
                        writeBuilder.AddOkay("Ok", "Success", "The write operation succeeded.");
                    }
                }
                catch (Exception e)
                {
                    writeBuilder.AddException(e);
                }
            }
        }
    }