Beispiel #1
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHomogenous;
     statusBuilder.AddChild(_alwaysAlerting1);
     statusBuilder.AddChild(_alwaysAlerting2);
     return(Task.CompletedTask);
 }
Beispiel #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"));
    }
Beispiel #3
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);
 }
Beispiel #4
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);
     }
 }
Beispiel #5
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);
        }
Beispiel #6
0
 public void StatusResultsBuilderChildren()
 {
     using (AmbientClock.Pause())
     {
         StatusResultsBuilder test  = new StatusResultsBuilder(nameof(StatusResultsBuilderChildren));
         StatusResultsBuilder child = test.AddChild("Child");
         Assert.AreEqual("Child", child.TargetSystem);
     }
 }
Beispiel #7
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);
 }
Beispiel #8
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);
 }
Beispiel #9
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);
     }
 }
Beispiel #10
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);
                }
            }
        }
Beispiel #11
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);
        }
Beispiel #12
0
    /// <summary>
    /// Performs the disk audit, reporting results into <paramref name="statusBuilder"/>.
    /// </summary>
    /// <param name="statusBuilder">A <see cref="StatusResultsBuilder"/> to write the results into.</param>
    /// <param name="cancel">The optional <see cref="CancellationToken"/>.</param>
    public async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default)
    {
        statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
        statusBuilder.AddProperty("_Path", _driveInfo.Name);
        statusBuilder.AddProperty("_VolumeLabel", _driveInfo.VolumeLabel);
        statusBuilder.AddProperty("DriveFormat", _driveInfo.DriveFormat);
        statusBuilder.AddProperty("DriveType", _driveInfo.DriveType);
        statusBuilder.AddProperty("AvailableFreeBytes", _driveInfo.AvailableFreeSpace);
        statusBuilder.AddProperty("TotalFreeBytes", _driveInfo.TotalFreeSpace);
        statusBuilder.AddProperty("TotalBytes", _driveInfo.TotalSize);
        if (!string.IsNullOrEmpty(_testPath))
        {
            StatusResultsBuilder readBuilder = new StatusResultsBuilder("Read");
            statusBuilder.AddChild(readBuilder);
            try
            {
                // attempt to read a file (if one exists)
                foreach (string file in Directory.EnumerateFiles(Path.Combine(_driveInfo.RootDirectory.FullName, _testPath)))
                {
                    AmbientStopwatch s = AmbientStopwatch.StartNew();
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            byte[] b = new byte[1];
                            await fs.ReadAsync(b, 0, 1, cancel);

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

                        await fs.FlushAsync();

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