public void StatusResultsGetSummaryAlertsNoTime()
        {
            StatusResults results;

            results = new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                    new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                }),
                new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                    new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                }),
            });
            StatusAuditAlert alert;

            alert = results.GetSummaryAlerts(true, float.MaxValue, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Okay, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Alert, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Fail, false);
            alert = results.GetSummaryAlerts(true, float.MaxValue, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Okay, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Alert, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Fail, false, TimeZoneInfo.Local);
        }
Beispiel #2
0
        public void StatusResultsOrganizerPropertiesWorse()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.0"), new StatusProperty("AvailablePercent", "2.1") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                        new StatusResults(null, "/SampleDisk.Temp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.2"), new StatusProperty("AvailableBytes", "1100000000.0") }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(3), AmbientClock.UtcNow.AddSeconds(2), new StatusAuditAlert(StatusRating.Okay - .0001f, "ALERT", "Alert", "AlertDetails"))),
                        new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()),
                    }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
Beispiel #3
0
        public void StatusResultsOrganizerPending()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenIrrelevant, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                Assert.IsTrue(organizer.SomeRatingsPending);
                o = organizer.Children.First().ToString();
            }
        }
Beispiel #4
0
        public void StatusResultsOrganizerTime()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow.AddSeconds(5), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                StatusResults source3Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                organizer.Add(organizer, source1Root);
                organizer.Add(organizer, source2Root);
                organizer.Add(organizer, source3Root);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
        public void StatusResults()
        {
            StatusResults results;

            results = new StatusResults("Source", "StatusTarget", AmbientClock.UtcNow, 1, new StatusProperty[] { new StatusProperty("Property", "Value") }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults("Source", "Target", Array.Empty <StatusResults>()) });
            Assert.AreEqual("Source", results.SourceSystem);
            Assert.AreEqual("Source", results.SourceSystemDisplayName);
            Assert.AreEqual("StatusTarget", results.TargetSystem);
            Assert.AreEqual("StatusTarget", results.TargetSystemDisplayName);
            Assert.IsTrue(results.ToString().Contains("Source"));
            Assert.IsTrue(results.ToString().Contains("StatusTarget"));

            results = new StatusResults("Source", "/", AmbientClock.UtcNow, 1, new StatusProperty[] { new StatusProperty("Property", "Value") }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults("Source", "Target", Array.Empty <StatusResults>()) });
            Assert.AreEqual("Source", results.SourceSystem);
            Assert.AreEqual("Source", results.SourceSystemDisplayName);
            Assert.AreEqual("/", results.TargetSystem);
            Assert.AreEqual("Overall", results.TargetSystemDisplayName);
            Assert.IsTrue(results.ToString().Contains("Source"));
            Assert.IsTrue(results.ToString().Contains("Overall"));

            results = new StatusResults(null, null, AmbientClock.UtcNow, 1, new StatusProperty[] { new StatusProperty("Property", "Value") }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults("Source", "Target", Array.Empty <StatusResults>()) });
            Assert.IsNull(results.SourceSystem);
            Assert.AreEqual("Localhost", results.SourceSystemDisplayName);
            Assert.AreEqual("", results.TargetSystem);
            Assert.AreEqual("Unknown Target", results.TargetSystemDisplayName);
            Assert.IsTrue(results.ToString().Length == 0);

            results = new StatusResults(null, "/SampleDisk.Temp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.2"), new StatusProperty("AvailableBytes", "1100000000.0") }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(3), AmbientClock.UtcNow.AddSeconds(2), new StatusAuditAlert(StatusRating.Okay - .0001f, "ALERT", "Alert", "AlertDetails")));
            Assert.IsTrue(results.ToString().Length != 0);
        }
Beispiel #6
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!");
 }
Beispiel #7
0
        public TestNotApplicableStatus()
            : base(nameof(TestNotApplicableStatus))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            _results = sb.FinalResults;
            SetLatestResults(_results);
        }
        public async Task StatusAuditorHistory()
        {
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(StatusAuditorHistory));

            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionMinutes", "5");
            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionEntries", "10");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> localOverrideTest = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settings))

                using (AmbientClock.Pause())
                {
                    using (StatusAuditorTest test = new StatusAuditorTest(nameof(StatusAuditorTest)))
                    {
                        StatusResults results = await test.GetStatus();

                        Assert.AreEqual("StatusAuditorTest", test.TargetSystem);
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // since we're rotating the status rating, the frequency will vary because of that
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one starts kicking out history items due to count (this was determined by simply trying it out, but that part doesn't matter for this test)
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one should start kicking history items out due to time
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                    }
                }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public void StatusResultsOrganizer()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                organizer.Add(organizer, new StatusResults(null, "/Target1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/Target1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))), "Source2");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.5") }, null), "Source1");
                organizer.Add(organizer, new StatusResults("Source2", "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.Temp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "4.0") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "10.0") }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1))), "Source2");
                organizer.Add(organizer, new StatusResults("Source1", "Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer, new StatusResults("Source2", "Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer, new StatusResults("Source3", "Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.Leaf, new StatusResults[] { StatusResults.GetPendingResults("Leaf", "PendingTarget") }));
                organizer.Add(organizer.Children.First(), new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.Skip(1).First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.Skip(2).First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.ComputeOverallRatingAndSort();
                o = organizer.ToString();
                Assert.IsTrue(o.Contains("Overall:"));
                o = organizer.Children.First().ToString();
                Assert.IsTrue(o.Contains("Source1->"));
                Assert.IsTrue(o.Contains("/Target1:"));

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
        public void StatusResultsGetSummaryAlertsNotificationTime()
        {
            using (AmbientClock.Pause())
            {
                DateTime         now       = AmbientClock.UtcNow;
                string           shortTime = now.ToShortTimeString();
                string           longTime  = now.ToLongTimeString();
                StatusResults    results;
                StatusAuditAlert alert;

                shortTime = now.ToShortTimeString();
                longTime  = now.ToLongTimeString();
                results   = new StatusResults("Source", "StatusTarget", new StatusResults[0]);
                alert     = results.GetSummaryAlerts(true, StatusRating.Okay, false);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Alert, false);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Fail, true);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));

                now       = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Local);
                shortTime = now.ToShortTimeString();
                longTime  = now.ToLongTimeString();
                alert     = results.GetSummaryAlerts(true, StatusRating.Okay, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Alert, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Fail, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
            }
        }
        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
        }
Beispiel #13
0
        public void AggregatedDefaultRating()
        {
            using (AmbientClock.Pause())
            {
                StatusAuditAlert commonAlert = new StatusAuditAlert(.7f, "TestCode", "TerseTest", "Detailed Test Message");
                StatusResults    results     = new StatusResults("TestSource", "TestTarget", ImmutableArray <StatusResults> .Empty);
                AggregatedAlert  alert       = new AggregatedAlert(results);
                Assert.AreEqual(StatusRating.Okay, alert.RatingSum);

                StatusAuditReport report = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10));
                results = new StatusResults("TestSource", "TestTarget", AmbientClock.UtcNow, 0, ImmutableArray <StatusProperty> .Empty, report);
                alert   = new AggregatedAlert(results);
                Assert.AreEqual(StatusRating.Okay, alert.RatingSum);
            }
        }
        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
        }
Beispiel #15
0
        public void NotificationWriterWithProperties()
        {
            StatusNotificationWriter writer = new StatusNotificationWriter();
            string terse;
            string details;

            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(StatusRating.Fail);
            writer.EnterTarget("SampleTarget", StatusRating.Fail - 0.5f);
            writer.LeaveTarget();
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;

            writer = new StatusNotificationWriter();
            writer.EnterHtmlAndBody(StatusRating.Fail);
            writer.EnterStatusRange(StatusRating.Fail);
            writer.EnterTarget("SampleTarget", StatusRating.Fail - 0.5f);
            writer.LeaveTarget();
            writer.LeaveStatusRange();
            writer.LeaveBodyAndHtml();
            terse   = writer.Terse;
            details = writer.Details;

            writer = new StatusNotificationWriter();
            StatusResults   r = new StatusResults("Source", "Target", new StatusResults[0]);
            AggregatedAlert a = new AggregatedAlert(r);

            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(a.AverageRating);
            writer.WriteAggregatedAlert(a);
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;

            writer = new StatusNotificationWriter();
            r      = new StatusResults("Source1", "Target", new StatusResults[0]);
            a      = new AggregatedAlert(r);
            r      = new StatusResults("Source2", "Target", new StatusResults[0]);
            a.Aggregate(r);
            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(a.AverageRating);
            writer.WriteAggregatedAlert(a);
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;
        }
        public async Task StatusChecker()
        {
            using (AmbientClock.Pause())
            {
                using (StatusCheckerTest test = new StatusCheckerTest())
                {
                    StatusResults results = await test.GetStatus();

                    Assert.AreEqual(results, test.LatestResults);
                    Assert.AreEqual(results, test.History.LastOrDefault());   // the most recent history results should be the last one (history is a FIFO queue)
                    Assert.AreEqual("StatusCheckerTest", test.TargetSystem);
                    await test.BeginStop();

                    await test.FinishStop();
                }
            }
        }
Beispiel #17
0
        public void AggregatedAlertExceptions()
        {
            using (AmbientClock.Pause())
            {
                StatusAuditAlert  alert1        = new StatusAuditAlert(.7f, "TestCode1", "TerseTest", "Detailed Test Message");
                StatusAuditAlert  alert2        = new StatusAuditAlert(.7f, "TestCode2", "TerseTest", "Detailed Test Message");
                StatusAuditReport report1       = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), alert1);
                StatusAuditReport report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), alert2);
                AggregatedAlert   first         = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1);
                AggregatedAlert   second        = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2);
                StatusResults     secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2);
                Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate(secondResults));
                Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2));

                report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), alert1);
                secondResults = new StatusResults("TestSource2", "MismatchedTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2);
                Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate(secondResults));
                Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate("TestSource2", "MismatchedTarget", AmbientClock.UtcNow.AddSeconds(-10), report2));
            }
        }
        public async Task StatusAuditor()
        {
            using (AmbientClock.Pause())
            {
                using (StatusAuditorTest test = new StatusAuditorTest(nameof(StatusAuditorTest)))
                {
                    StatusResults results = await test.GetStatus();

                    Assert.AreEqual("StatusAuditorTest", test.TargetSystem);
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));   // each of these skips should trigger another audit, with rotating values
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                    AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                }
            }
        }
Beispiel #19
0
        public void NotificationWriter()
        {
            StatusNotificationWriter writer = new StatusNotificationWriter();
            string terse;
            string details;

            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(StatusRating.Fail);
            writer.EnterTarget("SampleTarget", StatusRating.Fail - 0.5f);
            writer.LeaveTarget();
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("FAIL"));
            Assert.IsTrue(terse.Contains("SampleTarget"));
            Assert.IsTrue(details.Contains("Fail"));
            Assert.IsTrue(details.Contains("SampleTarget"));

            writer = new StatusNotificationWriter();
            writer.EnterHtmlAndBody(StatusRating.Fail);
            writer.EnterStatusRange(StatusRating.Fail);
            writer.EnterTarget("SampleTarget", StatusRating.Fail - 0.5f);
            writer.LeaveTarget();
            writer.LeaveStatusRange();
            writer.LeaveBodyAndHtml();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("FAIL"));
            Assert.IsTrue(terse.Contains("SampleTarget"));
            Assert.IsTrue(details.Contains("Fail"));
            Assert.IsTrue(details.Contains("SampleTarget"));

            writer = new StatusNotificationWriter();
            writer.EnterHtmlAndBody(StatusRating.Fail);
            writer.EnterStatusRange(StatusRating.Okay);
            writer.EnterTarget("SampleTarget", StatusRating.Superlative - 0.5f);
            writer.LeaveTarget();
            writer.LeaveStatusRange();
            writer.LeaveBodyAndHtml();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("OKAY"));
            Assert.IsTrue(terse.Contains("SampleTarget"));
            Assert.IsTrue(details.Contains("Okay"));
            Assert.IsTrue(details.Contains("SampleTarget"));

            writer = new StatusNotificationWriter();
            StatusResults   r = new StatusResults("Source", "Target", new StatusResults[0]);
            AggregatedAlert a = new AggregatedAlert(r);

            a.PropertyRanges.Add(new StatusPropertyRange(new StatusProperty("property", "value1")));
            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(a.AverageRating);
            writer.WriteAggregatedAlert(a);
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("OKAY"));
            Assert.IsTrue(terse.Contains("Target"));
            Assert.IsTrue(details.Contains("Okay"));
            Assert.IsTrue(details.Contains("Target"));

            writer = new StatusNotificationWriter();
            r      = new StatusResults("Source", "Target", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5)));
            a      = new AggregatedAlert(r);
            a.PropertyRanges.Add(new StatusPropertyRange(new StatusProperty("property", "value1")));
            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(a.AverageRating);
            writer.WriteAggregatedAlert(a);
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("OKAY"));
            Assert.IsTrue(terse.Contains("Target"));
            Assert.IsTrue(details.Contains("Okay"));
            Assert.IsTrue(details.Contains("Target"));

            writer = new StatusNotificationWriter();
            r      = new StatusResults("Source1", "Target", new StatusResults[0]);
            a      = new AggregatedAlert(r);
            a.PropertyRanges.Add(new StatusPropertyRange(new StatusProperty("property", "value1")));
            a.PropertyRanges.Add(new StatusPropertyRange(new StatusProperty("property", "value2")));
            a.PropertyRanges.Add(new StatusPropertyRange(new StatusProperty("property", "value5")));
            r = new StatusResults("Source2", "Target", new StatusResults[0]);
            a.Aggregate(r);
            writer = new StatusNotificationWriter();
            writer.EnterStatusRange(a.AverageRating);
            writer.WriteAggregatedAlert(a);
            writer.LeaveStatusRange();
            terse   = writer.Terse;
            details = writer.Details;
            Assert.IsTrue(terse.Contains("OKAY"));
            Assert.IsTrue(terse.Contains("Target"));
            Assert.IsTrue(details.Contains("Okay"));
            Assert.IsTrue(details.Contains("Target"));
        }
Beispiel #20
0
 public TestHomogeneousWithMultipleAlert()
     : base(nameof(TestHomogeneousWithMultipleAlert), TimeSpan.FromSeconds(10))
 {
     _alwaysAlerting1 = StatusResultsBuilder.CreateRawStatusResults("Child1AlwaysAlerting1", StatusRating.Alert, "TestAlertCode", "test-alert1", "This status node always alerts!");
     _alwaysAlerting2 = StatusResultsBuilder.CreateRawStatusResults("Child2AlwaysAlerting2", StatusRating.Alert, "TestAlertCode", "test-alert2", "This status node always alerts!");
 }
Beispiel #21
0
 public TestHomogeneousWithMultipleFailure()
     : base(nameof(TestHomogeneousWithMultipleFailure), TimeSpan.FromSeconds(10))
 {
     _alwaysFailing1 = StatusResultsBuilder.CreateRawStatusResults("Child1AlwaysFailing1", StatusRating.Fail, "TestFailCode", "test-fail", "This status node always fails!");
     _alwaysFailing2 = StatusResultsBuilder.CreateRawStatusResults("Child2AlwaysFailing2", StatusRating.Fail, "TestFailCode", "test-fail", "This status node always fails!");
 }
        public static new StatusResults RefreshStatus(SubmissionInfo submissionData, StatusResults previousStatus)
        {
            string additionalLogDetails = "";

            try
            {
                if (!string.IsNullOrWhiteSpace(previousStatus.State))
                {
                    var stateData = JsonConvert.DeserializeObject <UpdStatusState>(previousStatus.State);

                    additionalLogDetails += "Submitted Fax with etherFAX ID: " + stateData.jobId + "\r\n";
                    additionalLogDetails += "etherFAX Tag: " + stateData.tagValue + "\r\n";

                    string decryptedPassword = Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(stateData.password), _encryptionEntropy, DataProtectionScope.LocalMachine));

                    var       client    = new SampleEtherFaxApi(stateData.account, stateData.username, decryptedPassword);
                    FaxStatus faxStatus = client.GetFaxStatus(stateData.jobId);

                    if (faxStatus.FaxResult == FaxResult.Success) // Success
                    {
                        return(new StatusResults()
                        {
                            Result = true,
                            StatusCode = 100,
                            Message = "Your fax was delivered successfully.",
                            NotifyUser = true,
                            LogDetails = "Your fax was delivered successfully!\r\n" + additionalLogDetails
                        });
                    }
                    else if (faxStatus.FaxResult == FaxResult.InProgress) // Incomplete - check status again
                    {
                        return(new StatusResults()
                        {
                            Result = false,
                            StatusCode = 200 + (int)faxStatus.State,
                            SeverityLevel = StatusResults.SeverityLevels.Low,
                            Message = "Fax in progress. " + faxStatus.State.ToString().Replace("_", " ") + "... " + faxStatus.PagesDelivered + " pages delivered.",
                            NextStatusRefresh = DateTime.Now.AddSeconds(30),
                            State = previousStatus.State,
                            LogDetails = "Fax in progress. " + faxStatus.State.ToString().Replace("_", " ") + "... " + faxStatus.PagesDelivered + " pages delivered.\r\n" + additionalLogDetails
                        });
                    }
                    else if (faxStatus.FaxResult == FaxResult.Cancelled) // Cancelled
                    {
                        return(new StatusResults()
                        {
                            Result = false,
                            StatusCode = 300,
                            SeverityLevel = StatusResults.SeverityLevels.Low,
                            Message = "Your fax was cancelled.",
                            LogDetails = "Fax cancelled: " + faxStatus.ToString().Replace("_", " ") + "\r\n" + additionalLogDetails,
                            NotifyUser = true
                        });
                    }
                    else // All errors
                    {
                        return(new StatusResults()
                        {
                            Result = false,
                            StatusCode = 400 + (int)faxStatus.FaxResult,
                            SeverityLevel = StatusResults.SeverityLevels.High,
                            Message = "Your fax was not delivered. Reason: " + faxStatus.ToString().Replace("_", " "),
                            LogDetails = "Fax failed: " + faxStatus.ToString().Replace("_", " ") + "\r\n" + additionalLogDetails,
                            NotifyUser = true
                        });
                    }
                }
                else
                {
                    return(new StatusResults()
                    {
                        Result = false,
                        StatusCode = 900,
                        SeverityLevel = StatusResults.SeverityLevels.Critical,
                        Message = "Cannot refresh the status. Reason: Missing state data.",
                        LogDetails = "Fax failed: Missing state data." + "\r\n" + additionalLogDetails,
                        NotifyUser = true
                    });
                }
            }
            catch (WebException httpEx)
            {
                string webExDetails = "";

                using (var httpResponse = httpEx.Response as HttpWebResponse)
                {
                    if (httpResponse != null)
                    {
                        HttpStatusCode statusCode        = httpResponse.StatusCode;
                        string         statusDescription = httpResponse.StatusDescription;

                        string responseHeaders = httpResponse.Headers != null?httpResponse.Headers.ToString() : null;

                        using (Stream stream = httpResponse.GetResponseStream())
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                string content = sr.ReadToEnd();
                                webExDetails = "Status: " + statusCode.ToString() + @"/" + statusDescription + "\r\n\r\n" + "Response: " + content;
                            }
                        }
                    }
                }

                return(new StatusResults()
                {
                    Result = false,
                    StatusCode = 901,
                    SeverityLevel = StatusResults.SeverityLevels.Critical,
                    Message = "An error has occurred checking the status.",
                    NextStatusRefresh = DateTime.Now.AddSeconds(30),
                    LogDetails = httpEx.Message + "\r\n\r\n" + webExDetails + "\r\n" + additionalLogDetails,
                    NotifyUser = true,
                    State = previousStatus.State
                });
            }
            catch (Exception ex)
            {
                UpdStatusState stateData = null;
                try
                {
                    stateData = JsonConvert.DeserializeObject <UpdStatusState>(previousStatus.State);
                    stateData.statusRetryCount++;
                }
                catch (Exception stateEx)
                {
                    ex = new AggregateException(new List <Exception>()
                    {
                        ex, stateEx
                    });
                }

                var result = new StatusResults()
                {
                    Result            = false,
                    StatusCode        = 902,
                    SeverityLevel     = StatusResults.SeverityLevels.Critical,
                    Message           = "An error has occurred checking the status.",
                    NextStatusRefresh = DateTime.Now.AddSeconds(30),
                    LogDetails        = ex.Message + "\r\n" + additionalLogDetails,
                    NotifyUser        = true,
                    State             = previousStatus.State
                };
                if (stateData != null && stateData.statusRetryCount < MAX_REFRESH_ERRORS)
                {
                    result.NextStatusRefresh = DateTime.Now.AddSeconds(30);
                }
                return(result);
            }
        }
Beispiel #23
0
        public void AggregatedAlertAggregate()
        {
            using (AmbientClock.Pause())
            {
                StatusAuditAlert  commonAlert   = new StatusAuditAlert(.7f, "TestCode", "TerseTest", "Detailed Test Message");
                StatusAuditReport report1       = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), commonAlert);
                StatusAuditReport report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), commonAlert);
                AggregatedAlert   first         = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1);
                AggregatedAlert   second        = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2);
                StatusResults     secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2);
                first.Aggregate(secondResults);

                report1       = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10));
                report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10));
                first         = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1);
                second        = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2);
                secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2);
                first.Aggregate(secondResults);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);
                first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);

                //report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1));
                //report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2));
                //first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1);
                //second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2);
                //secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray<StatusProperty>.Empty, report2);
                //first.Aggregate(secondResults);
                //Assert.AreEqual(StatusRating.Okay, first.AverageRating);
                //first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2);
                //Assert.AreEqual(StatusRating.Okay, first.AverageRating);

                report1       = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1));
                report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2));
                first         = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1);
                second        = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2);
                secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(50), AmbientClock.UtcNow.AddSeconds(5)));
                first.Aggregate(secondResults);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);
                first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(50), AmbientClock.UtcNow.AddSeconds(5)));
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);

                first         = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, null);
                second        = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, null);
                secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, null);
                first.Aggregate(secondResults);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);
                first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), null);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);

                report1       = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10));
                report2       = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10));
                first         = new AggregatedAlert("TestSource", "TestTarget", DateTime.MinValue, report1);
                second        = new AggregatedAlert("TestSource", "TestTarget", DateTime.MinValue, report2);
                secondResults = new StatusResults("TestSource", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(13)));
                first.Aggregate(secondResults);
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);
                first.Aggregate("TestSource", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(13)));
                Assert.AreEqual(StatusRating.Okay, first.AverageRating);
            }
        }
Beispiel #24
0
        public async Task StatusClass()
        {
            await Status.DefaultInstance.Start();

            Assert.IsFalse(Status.DefaultInstance.ShuttingDown);
            try
            {
                DateTime start = AmbientClock.UtcNow;
                await Status.DefaultInstance.RefreshAsync();

                StatusResults overallStatus = Status.DefaultInstance.Results;

                Assert.AreEqual("/", overallStatus.TargetSystem);
                Assert.AreEqual(0, overallStatus.RelativeDetailLevel);
                Assert.AreEqual(StatusNatureOfSystem.ChildrenHeterogenous, overallStatus.NatureOfSystem);
                Assert.AreEqual(0, overallStatus.Properties.Count());
                Assert.IsTrue(overallStatus.Children.Count() > 0);
                Assert.IsFalse(string.IsNullOrEmpty(overallStatus.ToString()));

                StatusResults sampleDisk = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == "SampleDisk" && c.Children.Any()) as StatusResults;
                Assert.IsNotNull(sampleDisk);
                StatusResults disk = sampleDisk !.Children.FirstOrDefault() as StatusResults;
                Assert.IsNotNull(disk);
                Assert.IsTrue(disk !.Properties.Count() > 0); // the properties in the node itself are the constant properties, ie. the path for a disk test
                Assert.IsFalse(string.IsNullOrEmpty(sampleDisk !.ToString()));

                StatusProperty att = disk.Properties.FirstOrDefault(a => a.Name == "TotalBytes");
                Assert.IsNotNull(att);
                Assert.IsFalse(string.IsNullOrEmpty(att !.ToString()));
                Assert.IsFalse(String.IsNullOrEmpty(att !.Name));
                Assert.IsFalse(String.IsNullOrEmpty(att !.Value));

                HashSet <StatusResults> test = new HashSet <StatusResults>();
                StatusResults           c1   = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestHeterogenousExplicitRating));
                Assert.IsNotNull(c1);
                Assert.IsNotNull(c1 !.Report);
                Assert.IsNotNull(c1 !.Report?.Alert?.Rating);
                Assert.IsFalse(string.IsNullOrEmpty(c1 !.ToString()));
                test.Add(c1);

                StatusResults c2 = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestHomogeneousExplicitFailure));
                Assert.IsNotNull(c2);
                Assert.IsNotNull(c2 !.Report);
                Assert.IsNotNull(c2 !.Report?.Alert?.Rating);
                Assert.AreNotEqual(c1 !.Report?.Alert, c2 !.Report?.Alert);
                Assert.IsFalse(string.IsNullOrEmpty(c2 !.ToString()));
                test.Add(c2);

                StatusResults c3 = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestMachineConstantStatus));
                Assert.IsNotNull(c3);
                Assert.IsNull(c3 !.Report);
                Assert.IsFalse(string.IsNullOrEmpty(c3 !.ToString()));
                test.Add(c3);

                StatusAuditAlert auditResult = overallStatus.GetSummaryAlerts(true, StatusRating.Alert, false);

                Assert.AreEqual(0, overallStatus.Properties.Count());

                HashSet <StatusAuditReport> test3 = new HashSet <StatusAuditReport>();
                Assert.IsTrue(auditResult.Rating >= -1.0f && auditResult.Rating <= 4.0f);
                Assert.IsFalse(string.IsNullOrEmpty(auditResult.Terse));
                Assert.IsFalse(string.IsNullOrEmpty(auditResult.Details));
                Assert.IsTrue(overallStatus.SourceSystem == null);
                Assert.IsTrue(auditResult.Rating <= StatusRating.Fail);
                Assert.IsFalse(string.IsNullOrEmpty(auditResult.ToString()));

                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(100));
                await Status.DefaultInstance.RefreshAsync();

                overallStatus = Status.DefaultInstance.Results;

                StatusAuditAlert notOkayResult = overallStatus.GetSummaryAlerts(true, StatusRating.Okay, false);
                StatusAuditAlert fullResult    = overallStatus.GetSummaryAlerts(true, float.MaxValue, false);

                StatusAuditAlert overallSummaryAlerts = Status.DefaultInstance.Summary;
                Assert.IsTrue(overallSummaryAlerts.Rating <StatusRating.Fail && overallSummaryAlerts.Rating> StatusRating.Catastrophic);
                StatusAuditAlert overallSummaryAlertsAndFailures = Status.DefaultInstance.SummaryAlertsAndFailures;
                Assert.IsTrue(overallSummaryAlertsAndFailures.Rating <StatusRating.Fail && overallSummaryAlertsAndFailures.Rating> StatusRating.Catastrophic);
                StatusAuditAlert overallSummaryFailures = Status.DefaultInstance.SummaryFailures;
                Assert.IsTrue(overallSummaryFailures.Rating <StatusRating.Fail && overallSummaryFailures.Rating> StatusRating.Catastrophic);
            }
            finally
            {
                await Status.DefaultInstance.Stop();
            }
        }
        public void StatusResultsGetSummaryAlerts()
        {
            StatusResults results;

            results = new StatusResults(null, null, AmbientClock.UtcNow, 1, new StatusProperty[] { new StatusProperty("Property", "Value") }, StatusNatureOfSystem.ChildrenHomogenous,
                                        new StatusResults[]
            {
                new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults("Source1", "Target1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.Leaf, new StatusResults[] {
                        new StatusResults("Source1.1", "Target1.1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.Leaf, new StatusResults[0]),
                    }),
                    new StatusResults("Source2", "Target2", AmbientClock.UtcNow, 1, new StatusProperty[] { }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5))),
                    new StatusResults("Source3", "Target3", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))
                                      ),
                    new StatusResults("Source4", "Target4", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Okay, "Okay", "Terse", "Details"))
                                      ),
                    new StatusResults("Source5", "Target5", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Alert, "Alert", "Terse", "Details"))
                                      ),
                    new StatusResults("Source6", "Target6", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                        new StatusResults("Source6.1", "Target6.1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.Leaf, new StatusResults[0]),
                        new StatusResults("Source6.2", "Target6.2", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))
                                          ),
                        new StatusResults("Source6.3", "Target6.3", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Okay, "Okay", "Terse", "Details"))
                                          ),
                        new StatusResults("Source6.4", "Target6.4", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Alert, "Alert", "Terse", "Details"))
                                          ),
                    }),
                    new StatusResults("Source7", "Target7", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                    new StatusResults("Source8", "Target8", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenIrrelevant, new StatusResults[] { }),
                }),
                new StatusResults(nameof(StatusResultsGetSummaryAlertsNoTime), "/", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults("Source1", "Target1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.Leaf, new StatusResults[] {
                        new StatusResults("Source1.1", "Target1.1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.Leaf, new StatusResults[0]),
                    }),
                    new StatusResults("Source2", "Target2", AmbientClock.UtcNow, 1, new StatusProperty[] { }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5))),
                    new StatusResults("Source3", "Target3", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), null, new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))
                                      ),
                    new StatusResults("Source4", "Target4", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), null, new StatusAuditAlert(StatusRating.Okay, "Okay", "Terse", "Details"))
                                      ),
                    new StatusResults("Source5", "Target5", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                      new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), null, new StatusAuditAlert(StatusRating.Alert, "Alert", "Terse", "Details"))
                                      ),
                    new StatusResults("Source6", "Target6", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { }),
                    new StatusResults("Source7", "Target7", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { }),
                    new StatusResults("Source8", "Target8", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenIrrelevant, new StatusResults[] {
                        new StatusResults("Source8.1", "Target8.1", AmbientClock.UtcNow, 1, new StatusProperty[] { }, StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[0]),
                        new StatusResults("Source8.2", "Target8.2", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))
                                          ),
                        new StatusResults("Source8.3", "Target8.3", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Okay, "Okay", "Terse", "Details"))
                                          ),
                        new StatusResults("Source8.4", "Target8.4", AmbientClock.UtcNow, 1, new StatusProperty[] { },
                                          new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5), AmbientClock.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Alert, "Alert", "Terse", "Details"))
                                          ),
                    }),
                }),
            });
            StatusAuditAlert alert;

            alert = results.GetSummaryAlerts(true, float.MaxValue, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Okay, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Alert, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Fail, false);
            alert = results.GetSummaryAlerts(true, StatusRating.Catastrophic, false);
            alert = results.GetSummaryAlerts(true, float.MinValue, true);
            alert = results.GetSummaryAlerts(true, float.MaxValue, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Okay, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Alert, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Fail, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, StatusRating.Catastrophic, false, TimeZoneInfo.Local);
            alert = results.GetSummaryAlerts(true, float.MinValue, true, TimeZoneInfo.Local);
        }