Warden Spawn first glimpse

Datetime:2016-08-22 22:13:11          Topic: C#  Coder           Share

In case you’re not familiar with the Warden project that I’ve been working for the last few months, I strongly recommend you to take a look, as you may find this tool especially useful for monitoring your infrastructure and resources. So what is the Warden Spawn ?

It’s a brand new repository within the Warden Stack that will let you configure the instance of the Warden monitoring application using the human readable configuration files – and that’s just the beginning!

At first, you might be wondering – why the heck would I need to configure the Warden using e.g. the JSON configuration file? There’s already a set of extensions and a fluent API which allows you to do so using the C# code. Since we (me and my friends) have started working on the new API and there will be new platforms available like the Web and Android (at least at some point in the future) it would be probably wise to make the Warden more user friendly for the folks who are not the programmers, but would still like to easily configure their own monitoring applications.

And that’s where the Warden Spawn comes in handy – the ultimate goal is to integrate this tool with the API and later on create a web interface that will let anyone to configure the Warden using some nice editor containing some forms with checkboxes, drop-down lists etc. which under the hood will generate the configuration object and spin up a new instance of the Warden ready to take care of your infrastructure.

Current state of the Warden Spawn repository is kind of proof of concept, yet it works for some simplistic scenarios and although the code itself is rather chaotic, I’ve already found a way to make it easily extendable (there’s a lot of “magic” going on based on some naming conventions and other stuff). Just take a look at the following sample configuration file:

{
  "wardenName": "Warden Spawn",
  "integrations": [
    {
      "type": "sendGrid",
      "configuration": {
        "apiKey": "xyz",
        "sender": "spawn@getwarden.net",
        "defaultSubject": "Monitoring",
        "defaultMessage": "Monitoring error(s).",
        "defaultReceivers": [ "warden-spawn@mailinator.com" ]
      }
    },
    {
      "type": "console",
      "configuration": {
        "defaultText": "Hello!"
      }
    }
  ],
  "watchers": [
    {
      "type": "Web",
      "name": "My Web Watcher",
      "configuration": {
        "url": "http://www.google.com",
        "timeout": "00:00:05"
      },
      "hooks": [
        {
          "type": "onCompleted",
          "condition": "invalidCheckResult",
          "use": "sendGrid",
          "configuration": {
            "receivers": [ "warden-spawn2@mailinator.com" ]
          }
        },
        {
          "type": "onCompletedAsync",
          "condition": "validCheckResult",
          "use": "sendGrid",
          "configuration": {
            "subject": "Monitoring async",
            "message": "Monitoring error(s) async."
          }
        },
        {
          "type": "onCompleted",
          "condition": "none",
          "use": "console",
          "configuration": {
          }
        },
        {
          "type": "onCompletedAsync",
          "condition": "none",
          "use": "console",
          "configuration": {
            "text": "Hello async!" 
          }
        }
      ]
    }
  ]
}

As you can see, this is a JSON format and it defines a set of integrations and a watcher and it’s hooks (callbacks). Each integration has it’s own configuration, likewise the watcher and it’s hooks that can use the previously defined configurations. It’s quite easy to add new watchers or integrations – there a few simple interfaces that have to be implemented and that’s all.

And here is the actual C# code that creates a Warden instance based on such config file:

var configurationReader = WardenSpawnConfigurationReader
    .Create()
    .WithWatcher<WebWatcherSpawn>()
    .WithIntegration<ConsoleSpawnIntegration>()
    .WithIntegration<SendGridSpawnIntegration>()
    .Build();
 
var configurator = WardenSpawnConfigurator
    .Create()
    .Build();
 
var factory = WardenSpawnFactory
    .Create()
    .WithConfigurationReader(() => configurationReader)
    .WithConfiguration(File.ReadAllText("configuration.json"))
    .WithConfigurator(() => configurator)
    .Build();
 
var spawn = factory.Resolve();
var warden = spawn.Spawn();
System.Console.WriteLine($"Warden: '{warden.Name}' has been created and started monitoring.");
Task.WaitAll(warden.StartAsync());

This is the first working version of the Warden Spawn and probably a lot of things will change.

The point is that we want to make the Warden a truly user-friendly tool, not only for the programmers but also for anyone else who might not know the C# but would still like to use this tool in order to make a custom monitoring application.

And yes, it will remain open source and free as long as you use it on your own hosting environment.





About List