Exemple #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);
     }
 }
Exemple #2
0
    protected override bool Applicable => _ready; // if S3 were optional (for example, if an alternative could be configured), this would check the configuration
    public override async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default)
    {
        statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
        await _tempAuditor.Audit(statusBuilder.AddChild("Temp"));

        await _systemAuditor.Audit(statusBuilder.AddChild("System"));
    }
Exemple #3
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHomogenous;
     statusBuilder.AddChild(_alwaysAlerting1);
     statusBuilder.AddChild(_alwaysAlerting2);
     return(Task.CompletedTask);
 }
Exemple #4
0
        public void StatusResultsBuilder()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsBuilder test = new StatusResultsBuilder(nameof(StatusResultsBuilder));

                Assert.IsNull(test.AuditDuration);
                test.AuditDuration = TimeSpan.FromSeconds(137);
                Assert.AreEqual(TimeSpan.FromSeconds(137), test.AuditDuration);

                Assert.AreEqual(AmbientClock.UtcNow, test.AuditStartTime);
                test.AuditStartTime = DateTime.MinValue;
                Assert.AreEqual(DateTime.MinValue, test.AuditStartTime);

                test.NatureOfSystem = StatusNatureOfSystem.Leaf;
                Assert.AreEqual(StatusNatureOfSystem.Leaf, test.NatureOfSystem);

                Assert.IsNull(test.NextAuditTime);
                test.NextAuditTime = DateTime.MaxValue;
                Assert.AreEqual(DateTime.MaxValue, test.NextAuditTime);

                test.RelativeDetailLevel = 1;
                Assert.AreEqual(1, test.RelativeDetailLevel);

                test.SourceSystem = nameof(StatusResultsBuilder);
                Assert.AreEqual(nameof(StatusResultsBuilder), test.SourceSystem);

                Assert.AreEqual(nameof(StatusResultsBuilder), test.TargetSystem);
            }
        }
Exemple #5
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHomogenous;
     statusBuilder.AddProperty("ChildCount", _diskAuditors.Count());
     statusBuilder.AddFailure("TestFailCode", "TEST-FAIL!", "This is the detailed fail message", 0.0f);
     return(Task.CompletedTask);
 }
Exemple #6
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
     statusBuilder.AddProperty("nc1", "a");
     statusBuilder.AddProperty("nc2", "b");
     statusBuilder.AddProperty("nc2", AmbientClock.UtcNow.AddMinutes(-3));
     return(Task.CompletedTask);
 }
Exemple #7
0
 public void StatusResultsBuilderChildren()
 {
     using (AmbientClock.Pause())
     {
         StatusResultsBuilder test  = new StatusResultsBuilder(nameof(StatusResultsBuilderChildren));
         StatusResultsBuilder child = test.AddChild("Child");
         Assert.AreEqual("Child", child.TargetSystem);
     }
 }
Exemple #8
0
        public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
            StatusResultsBuilder child = new StatusResultsBuilder("IrrelevantChild");

            child.AddException(new ExpectedException(nameof(TestIrrelevantException)));
            statusBuilder.AddChild(child);
            return(Task.CompletedTask);
        }
Exemple #9
0
 public TestHomogeneousWithFailure()
     : base(nameof(TestHomogeneousWithFailure), TimeSpan.FromSeconds(10))
 {
     _alwaysSuperlative  = StatusResultsBuilder.CreateRawStatusResults("Child1AlwaysSuperlative", StatusRating.Superlative, "TestSuperlativeCode", "", "");
     _alwaysOkay         = StatusResultsBuilder.CreateRawStatusResults("Child1AlwaysOkay", StatusRating.Okay, "TestOkayCode", "", "");
     _alwaysAlerting     = StatusResultsBuilder.CreateRawStatusResults("Child2AlwaysAlerting", StatusRating.Alert, "TestAlertCode", "test-alert", "This status node always alerts!");
     _alwaysFailing      = StatusResultsBuilder.CreateRawStatusResults("Child3AlwaysFailing", StatusRating.Fail, "TestFailCode", "test-fail", "This status node always fails!");
     _alwaysCatastrophic = StatusResultsBuilder.CreateRawStatusResults("Child3AlwaysCatastrophic", StatusRating.Catastrophic, "TestCatastrophicCode", "test-catastrophic", "This status node always catastrophic!");
 }
Exemple #10
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
     statusBuilder.AddProperty("wc1", "a");
     statusBuilder.AddProperty("wc2", "b");
     statusBuilder.AddProperty("wc2", AmbientClock.UtcNow.AddMinutes(-10));
     statusBuilder.AddException(new ApplicationException("This is a test"));
     return(Task.CompletedTask);
 }
Exemple #11
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHomogenous;
     statusBuilder.AddChild(_alwaysSuperlative);
     statusBuilder.AddChild(_alwaysOkay);
     statusBuilder.AddChild(_alwaysAlerting);
     statusBuilder.AddChild(_alwaysFailing);
     statusBuilder.AddChild(_alwaysCatastrophic);
     return(Task.CompletedTask);
 }
Exemple #12
0
 public void StatusResultsBuilderProperties()
 {
     using (AmbientClock.Pause())
     {
         StatusCheckerTest    checker  = new StatusCheckerTest();
         StatusResultsBuilder test     = new StatusResultsBuilder(checker, new StatusProperty[] { new StatusProperty("Property1", "Value1"), new StatusProperty("Property2", "Value2") });
         StatusProperty       property = test.FindProperty("Property1");
         Assert.AreEqual("Value1", property?.Value);
     }
 }
        public StatusAuditorAuditExceptionTest(string targetSystem) // note that this parameter prevents this auditor from being used in the default status instance
            : base(targetSystem, TimeSpan.Zero, null)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
        }
Exemple #14
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     for (int source = 0; source < 10; ++source)
     {
         StatusResultsBuilder childBuilder = new StatusResultsBuilder(string.Empty);
         childBuilder.SourceSystem = "Source " + source.ToString();
         Recurse(childBuilder, 4, source);
         statusBuilder.AddChild(childBuilder.FinalResults);
     }
     return(Task.CompletedTask);
 }
Exemple #15
0
        public TestNotApplicableStatus()
            : base(nameof(TestNotApplicableStatus))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            _results = sb.FinalResults;
            SetLatestResults(_results);
        }
        public StatusAuditorAuditNeverRunTest(string targetSystem)
            : base(targetSystem, TimeSpan.MaxValue, null)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
        }
Exemple #17
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     for (int source = 0; source < 10; ++source)
     {
         StatusResultsBuilder childBuilder = new StatusResultsBuilder("Subsystem");
         childBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
         childBuilder.SourceSystem   = "Source " + source.ToString();
         childBuilder.AddProperty("sourceNumber", source);
         AddSource(childBuilder, source);
         statusBuilder.AddChild(childBuilder.FinalResults);
     }
     return(Task.CompletedTask);
 }
Exemple #18
0
        public TestMachineConstantStatus()
            : base(nameof(TestMachineConstantStatus))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("MachineName", Environment.MachineName);
            sb.AddProperty("StartTime", AmbientClock.UtcNow);
            _results = sb.FinalResults;
            SetLatestResults(_results);
        }
Exemple #19
0
 private void Recurse(StatusResultsBuilder statusBuilder, int level)
 {
     if (level == 0)
     {
         statusBuilder.AddFailure(nameof(TestDeepFailure), "test-" + nameof(TestDeepFailure), "This is the deep failure", 0.5f);
     }
     else
     {
         StatusResultsBuilder child = new StatusResultsBuilder("Level" + level.ToString());
         Recurse(child, level - 1);
         statusBuilder.AddChild(child.FinalResults);
     }
 }
Exemple #20
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 StatusCheckerTest()
            : base("StatusCheckerTest")
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
            StatusResults results = sb.FinalResults;

            SetLatestResults(results);
            SetLatestResults(results);  // set the results twice so the first results (which are the same as the second) end up in the history
        }
        public StatusAuditorTest(string targetSystem, Status status = null)
            : base(targetSystem, TimeSpan.FromSeconds(10), status)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
            StatusResults results = sb.FinalResults;

            SetLatestResults(results);
            SetLatestResults(results);  // set the results twice so the first results (which are the same as the second) end up in the history
        }
Exemple #23
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();
 }
Exemple #24
0
        /// <summary>
        /// Computes the current status, building a <see cref="StatusResults"/> to hold information about the status.
        /// </summary>
        /// <param name="statusBuilder">A <see cref="StatusResultsBuilder"/> that may be used to fill in audit information.</param>
        /// <param name="cancel">A <see cref="CancellationToken"/> to cancel the operation before it finishes.</param>
        public override async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            foreach (SampleVolumeAuditor da in _diskAuditors)
            {
                try
                {
                    StatusResultsBuilder childResults = await da.GetStatus(cancel);

                    statusBuilder.AddChild(childResults);
                }
                catch (Exception ex)
                {
                    statusBuilder.AddException(ex);
                }
            }
        }
Exemple #25
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);
 }
Exemple #26
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);
            }
        }
Exemple #27
0
        /// <summary>
        /// Gets the current status of the disk established in the constructor.
        /// </summary>
        /// <param name="cancel">A <see cref="CancellationToken"/> that may be used to cancel the operation before it completes.</param>
        /// <returns>A <see cref="StatusResultsBuilder"/> containing the status of the disk.</returns>
        public Task <StatusResultsBuilder> GetStatus(CancellationToken cancel = default(CancellationToken))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(_targetSystem);

            sb.NatureOfSystem = StatusNatureOfSystem.Leaf;
            if (_fakeFolderPath != null)
            {
                long   totalBytes       = Math.Abs(_fakeFolderPath.GetHashCode());
                long   freeBytes        = totalBytes * 8 / 10;
                long   availableBytes   = totalBytes * 8 / 10;
                double availablePercent = .8;
                sb.AddProperty("TotalBytes", totalBytes);
                sb.AddProperty("FreeBytes", freeBytes);
                sb.AddProperty("AvailableBytes", availableBytes);
                sb.AddProperty("AvailablePercent", availablePercent);
                return(Task.FromResult(sb));
            }
            return(null);
        }
Exemple #28
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);
            }
        }
Exemple #29
0
        public override async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
            foreach (SampleVolumeAuditor da in _diskAuditors)
            {
                try
                {
                    StatusResultsBuilder childResults = await da.GetStatus(cancel);

                    statusBuilder.AddChild(childResults);
                }
                catch (Exception ex)
                {
                    statusBuilder.AddException(ex);
                }
            }
            statusBuilder.AddProperty("wc1", "a");
            statusBuilder.AddProperty("wc2", "b");
            statusBuilder.AddProperty("wc2", AmbientClock.UtcNow.AddMinutes(-10));
            statusBuilder.AddAlert("TestAlertCode", "test-terseAlert", "This is the detailed alert message", 0.1f);
        }
        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);
        }