private void ReadHealthChecks(HealthCheckGroup group)
        {
            var healthChecksRoot = group.ConfigurationNode.Element("HealthChecks");

            foreach (var configXml in healthChecksRoot?.Elements("Check")?.ToList())
            {
                var configNode = new JobConfiguration()
                {
                    Name = ReadAttribute(configXml, "Name"),
                    Type = ReadAttribute(configXml, "Type")
                };

                if (@group.Checks.Any(h => h.JobConfiguration.Name == configNode.Name))
                {
                    _log.Warn("Duplicate Health Check Name: {0}", configNode.Name);
                    throw new DuplicateHealthCheckException("Duplicate Health Check Name: " + configNode.Name);
                }

                configNode.Listeners = configXml.Elements("Listener").ToList();
                configNode.Triggers  = configXml.Elements("Trigger").ToList();
                configNode.Settings  = configXml.Element("Settings");

                var check = new HealthCheckJob()
                {
                    JobConfiguration = configNode,
                    QuietPeriods     = GetQuietPeriods(configXml)
                };

                group.Checks.Add(check);
            }
        }
        private List <HealthCheckGroup> ReadFile(string file)
        {
            var groups = new List <HealthCheckGroup>();

            if (ValidateConfigurationFile(file))
            {
                return(groups);
            }

            var rootNode = XElement.Load(file);

            foreach (var node in rootNode.Elements("Group").ToList())
            {
                var group = new HealthCheckGroup()
                {
                    Name = ReadAttribute(node, "Name")
                };

                var dupeCount = _groups.Count(h => h.Name == @group.Name);

                if (dupeCount > 0)
                {
                    _log.Error("Duplicate Group Name: {0}", group.Name);
                    throw new DuplicateHealthCheckException("Duplicate Group Name: " + group.Name);
                }

                group.ConfigurationNode = node;

                ReadHealthChecks(group);

                if (group.Checks.Count > 0)
                {
                    groups.Add(group);
                }
            }

            return(groups);
        }
Beispiel #3
0
        /// <summary>
        ///   Create the Quartz job based on configuration settings
        /// </summary>
        /// <param name="job">The health check job.</param>
        /// <param name="group">The group this health check job belongs to.</param>
        /// <returns>The Quartz job.</returns>
        public IHealthCheckJob InitializeCheckJob(IHealthCheckJob job, HealthCheckGroup @group)
        {
            _log.Debug("Initializing job: " + job.JobConfiguration.Name);

            var checkConfiguration = job.JobConfiguration;
            var plugin             = _factory.GetPlugin(checkConfiguration.Type);

            plugin.Name      = checkConfiguration.Name;
            plugin.GroupName = @group.Name;

            job.Plugin = plugin;

            if (checkConfiguration.Settings != null)
            {
                plugin.SetTaskConfiguration(checkConfiguration.Settings);
            }

            job.Listeners = CreateListeners(checkConfiguration);
            job.Triggers  = CreateTriggers(checkConfiguration);

            plugin.Startup();

            return(job);
        }