Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
customs-il committed Sep 30, 2024
1 parent 74b804a commit 6b4f0fc
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 46 deletions.
8 changes: 4 additions & 4 deletions generic jobs/FolderCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void VetoFolder(ref Folder folder);
static partial void VetoFolder(Folder folder);

static partial void VetoHost(ref Host host);
static partial void VetoHost(Host host);

static partial void Finilayze(IEnumerable<Folder> folders);

Expand All @@ -30,7 +30,7 @@ public async override Task ExecuteJob(IJobExecutionContext context)
Initialize(ServiceProvider);

var defaults = GetDefaults(Configuration);
var hosts = GetHosts(Configuration, h => VetoHost(ref h));
var hosts = GetHosts(Configuration, h => VetoHost(h));
var folders = GetFolders(Configuration, defaults);

if (folders.Exists(e => e.IsRelativePath))
Expand Down Expand Up @@ -100,7 +100,7 @@ private List<Folder> GetFolders(IConfiguration configuration, Defaults defaults)
{
var folder = new Folder(item, defaults);

VetoFolder(ref folder);
VetoFolder(folder);
if (CheckVeto(folder, "folder")) { continue; }

ValidateFolder(folder);
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/FolderRetention/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void VetoFolder(ref Folder folder);
static partial void VetoFolder(Folder folder);

static partial void VetoHost(ref Host host);
static partial void VetoHost(Host host);

#pragma warning restore S3251 // Implementations should be provided for "partial" methods

Expand All @@ -33,7 +33,7 @@ public async override Task ExecuteJob(IJobExecutionContext context)
Initialize(ServiceProvider);

var defaults = GetDefaults(Configuration);
var hosts = GetHosts(Configuration, h => VetoHost(ref h));
var hosts = GetHosts(Configuration, h => VetoHost(h));
var folders = GetFolders(Configuration, defaults);

if (folders.Exists(e => e.IsRelativePath))
Expand Down Expand Up @@ -116,7 +116,7 @@ private List<Folder> GetFolders(IConfiguration configuration, Defaults defaults)
{
var folder = new Folder(item, defaults);

VetoFolder(ref folder);
VetoFolder(folder);
if (CheckVeto(folder, "folder")) { continue; }

ValidateFolder(folder);
Expand Down
19 changes: 19 additions & 0 deletions generic jobs/HealthCheck/Demo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HealthCheck;

internal partial class Job
{
static partial void VetoHost(Host host)
{
if (host.Name == "http://127.0.0.1")
{
host.Veto = true;
}
}
}
8 changes: 4 additions & 4 deletions generic jobs/HealthCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void VetoEndpoint(ref Endpoint endpoint);
static partial void VetoEndpoint(Endpoint endpoint);

partial void VetoHost(ref Host host);
static partial void VetoHost(Host host);

static partial void Finilayze(IEnumerable<Endpoint> endpoints);

Expand All @@ -32,7 +32,7 @@ public async override Task ExecuteJob(IJobExecutionContext context)
Initialize(ServiceProvider);

var defaults = GetDefaults(Configuration);
var hosts = GetHosts(Configuration, h => VetoHost(ref h));
var hosts = GetHosts(Configuration, h => VetoHost(h));
var endpoints = GetEndpoints(Configuration, defaults);

if (endpoints.Exists(e => e.IsRelativeUrl))
Expand Down Expand Up @@ -86,7 +86,7 @@ private List<Endpoint> GetEndpoints(IConfiguration configuration, Defaults defau
foreach (var item in endpoints.GetChildren())
{
var endpoint = new Endpoint(item, defaults);
VetoEndpoint(ref endpoint);
VetoEndpoint(endpoint);
if (CheckVeto(endpoint, "endpoint")) { continue; }

ValidateEndpoint(endpoint);
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/InfluxDBCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void CustomConfigure(ref InfluxDBServer influxServer, IConfiguration configuration);
static partial void CustomConfigure(InfluxDBServer influxServer, IConfiguration configuration);

static partial void VetoQuery(ref InfluxQuery query);
static partial void VetoQuery(InfluxQuery query);

static partial void Finalayze(IEnumerable<InfluxQuery> endpoints);

Expand All @@ -29,7 +29,7 @@ public override void Configure(IConfigurationBuilder configurationBuilder, IJobE
CustomConfigure(configurationBuilder, context);

var influxServer = new InfluxDBServer();
CustomConfigure(ref influxServer, configurationBuilder.Build());
CustomConfigure(influxServer, configurationBuilder.Build());

if (!influxServer.IsEmpty)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ private IEnumerable<InfluxQuery> GetQueries(IConfiguration configuration, Defaul
foreach (var item in keys.GetChildren())
{
var key = new InfluxQuery(item, defaults);
VetoQuery(ref key);
VetoQuery(key);
if (CheckVeto(key, "query")) { continue; }

ValidateInfluxQuery(key);
Expand Down
24 changes: 20 additions & 4 deletions generic jobs/RabbitMQCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void CustomConfigure(ref RabbitMqServer rabbitMqServer, IConfiguration configuration);
static partial void CustomConfigure(RabbitMqServer rabbitMqServer, IConfiguration configuration);

static partial void VetoQueue(ref Queue queue);
static partial void VetoQueue(Queue queue);

static partial void Finalayze(IEnumerable<Queue> queues);

Expand All @@ -26,7 +26,7 @@ public override void Configure(IConfigurationBuilder configurationBuilder, IJobE
CustomConfigure(configurationBuilder, context);

var rabbitmqServer = new RabbitMqServer();
CustomConfigure(ref rabbitmqServer, configurationBuilder.Build());
CustomConfigure(rabbitmqServer, configurationBuilder.Build());

if (!rabbitmqServer.IsEmpty)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ private IEnumerable<Queue> GetQueue(IConfiguration configuration, Defaults defau
{
var queue = new Queue(section, defaults);

VetoQueue(ref queue);
VetoQueue(queue);
if (CheckVeto(queue, "queue")) { continue; }

ValidateRequired(queue.Name, "name", "queues");
Expand Down Expand Up @@ -234,6 +234,7 @@ private async Task InvokeQueueCheckInner(Queue queue, IEnumerable<QueueDetails>
CheckState(queue, detail);
CheckConsumers(queue, detail);
CheckMessages(queue, detail);
CheckUnacked(queue, detail);
CheckMemory(queue, detail);
IncreaseEffectedRows();
await Task.CompletedTask;
Expand Down Expand Up @@ -271,6 +272,21 @@ private void CheckMessages(Queue queue, QueueDetails detail)
}
}

private void CheckUnacked(Queue queue, QueueDetails detail)
{
if (queue.Unacked.HasValue)
{
if (queue.Unacked.GetValueOrDefault() < detail.MessagesUnacknowledged)
{
Logger.LogInformation("queue '{Name}' unacked is ok. {Unacked:N0} unacked", detail.Name, detail.MessagesUnacknowledged);
}
else
{
throw new CheckException($"queue '{detail.Name}' unacked check failed. {detail.MessagesUnacknowledged:N0} unacked are greater then {queue.Messages.GetValueOrDefault():N0}");
}
}
}

private void CheckConsumers(Queue queue, QueueDetails detail)
{
// Consumers
Expand Down
6 changes: 4 additions & 2 deletions generic jobs/RabbitMQCheck/JobSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ general:
defaults: # default values for all RabbitMq checks. health check and nodes can ovveride these values BUT not queues
retry count: 1 # the number of retry attemp in case of failure
retry interval: 00:00:05 # the interval between retry attemps
allowed fail span: 00:10:00 # the time span which violation of health check will be considered ok

# server: # the servers parameters to be use. usualy this section defined in specific environment job settings
# server: # the servers parameters to be use. usualy this section defined in specific environment job settings
# hosts:
# - http://rabbitmq-server-1:15672 # the rabbitmq hosts
# - http://rabbitmq-server-2:15672
Expand All @@ -32,9 +33,10 @@ nodes:

queues:
- name: demo # the name of the queue
memory: 2mb # the maximum memory used by the queue (in bytes, kb, mb, gb, tb, pb)
messages: 10 # the maximum number of messages in the queue
unacked: 10 # the minimum number of unacked messages in the queue
consumers: null # the minimum number of consumers of the queue
memory: 2mb # the maximum memory used by the queue (in bytes, kb, mb, gb, tb, pb)
check state: true # if true, the job will fail if the queue state is not ok
allowed fail span: 00:00:10 # the time span which violation of the queue will be considered ok
active: true # the default is true
1 change: 1 addition & 0 deletions generic jobs/RabbitMQCheck/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal class Queue(IConfigurationSection section, Defaults defaults) : BaseDef
{
public string Name { get; private set; } = section.GetValue<string>("name") ?? string.Empty;
public int? Messages { get; private set; } = section.GetValue<int?>("messages");
public int? Unacked { get; private set; } = section.GetValue<int?>("unacked");
public string? Memory { get; private set; } = section.GetValue<string>("memory");
public int? Consumers { get; private set; } = section.GetValue<int?>("consumers");
public bool? CheckState { get; private set; } = section.GetValue<bool?>("check state");
Expand Down
10 changes: 6 additions & 4 deletions generic jobs/RabbitMQCheck/QueueDetails.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace RabbitMQCheck;
using Newtonsoft.Json;

namespace RabbitMQCheck;

public class QueueDetails
{
Expand All @@ -8,15 +10,15 @@ public class QueueDetails
public int Consumers { get; set; }
public string State { get; set; } = null!;

[JsonProperty("messages_unacknowledged")]
public int MessagesUnacknowledged { get; set; }

////[JsonProperty("messages_ready")]
////public int MessagesReady { get; set; }

////[JsonProperty("messages_dlx")]
////public int MessagesDlx { get; set; }

////[JsonProperty("messages_unacknowledged")]/
//// /public int MessagesUnacknowledged { get; set; }

//// public Arguments arguments { get; set; }
//// public bool auto_delete { get; set; }
//// public int consumer_capacity { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/RedisCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void CustomConfigure(ref RedisServer redisServer, IConfiguration configuration);
static partial void CustomConfigure(RedisServer redisServer, IConfiguration configuration);

static partial void VetoKey(ref RedisKey key);
static partial void VetoKey(RedisKey key);

static partial void Finalayze(IEnumerable<RedisKey> keys);

Expand All @@ -26,7 +26,7 @@ public override void Configure(IConfigurationBuilder configurationBuilder, IJobE
CustomConfigure(configurationBuilder, context);

var redisServer = new RedisServer();
CustomConfigure(ref redisServer, configurationBuilder.Build());
CustomConfigure(redisServer, configurationBuilder.Build());

if (!redisServer.IsEmpty)
{
Expand Down Expand Up @@ -98,7 +98,7 @@ private IEnumerable<RedisKey> GetKeys(IConfiguration configuration, Defaults def
{
var key = new RedisKey(item, defaults);

VetoKey(ref key);
VetoKey(key);
if (CheckVeto(key, "key")) { continue; }

ValidateRedisKey(key);
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/RedisOperations/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void CustomConfigure(ref RedisServer redisServer, IConfiguration configuration);
static partial void CustomConfigure(RedisServer redisServer, IConfiguration configuration);

static partial void VetoKey(ref RedisKey key);
static partial void VetoKey(RedisKey key);

public override void Configure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context)
{
CustomConfigure(configurationBuilder, context);

var redisServer = new RedisServer();
CustomConfigure(ref redisServer, configurationBuilder.Build());
CustomConfigure(redisServer, configurationBuilder.Build());

if (!redisServer.IsEmpty)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ private IEnumerable<RedisKey> GetKeys(IConfiguration configuration, Defaults def
{
var key = new RedisKey(item, defaults);

VetoKey(ref key);
VetoKey(key);
if (CheckVeto(key, "key")) { continue; }

ValidateRedisKey(key);
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/SqlTableRetention/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void CustomConfigure(ref List<SqlConnectionString> connectionStrings, IConfiguration configuration);
static partial void CustomConfigure(List<SqlConnectionString> connectionStrings, IConfiguration configuration);

static partial void VetoTable(ref Table table);
static partial void VetoTable(Table table);

public override void Configure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context)
{
CustomConfigure(configurationBuilder, context);

var connectionStrings = new List<SqlConnectionString>();
CustomConfigure(ref connectionStrings, configurationBuilder.Build());
CustomConfigure(connectionStrings, configurationBuilder.Build());

if (connectionStrings.Count > 0)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private IEnumerable<Table> GetTables(IConfiguration configuration, Dictionary<st
{
var key = new Table(item, defaults);

VetoTable(ref key);
VetoTable(key);
if (CheckVeto(key, "table")) { continue; }

key.ConnectionString = connectionStrings.GetValueOrDefault(key.ConnectionStringName);
Expand Down
8 changes: 4 additions & 4 deletions generic jobs/WindowsServiceCheck/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal partial class Job : BaseCheckJob

static partial void CustomConfigure(IConfigurationBuilder configurationBuilder, IJobExecutionContext context);

static partial void VetoService(ref Service service);
static partial void VetoService(Service service);

static partial void VetoHost(ref Host host);
static partial void VetoHost(Host host);

static partial void Finalayze(IEnumerable<Service> services);

Expand All @@ -29,7 +29,7 @@ public async override Task ExecuteJob(IJobExecutionContext context)
Initialize(ServiceProvider);

var defaults = GetDefaults(Configuration);
var hosts = GetHosts(Configuration, h => VetoHost(ref h));
var hosts = GetHosts(Configuration, h => VetoHost(h));
var services = GetServices(Configuration, defaults);

ValidateRequired(hosts, "hosts");
Expand Down Expand Up @@ -80,7 +80,7 @@ private List<Service> GetServices(IConfiguration configuration, Defaults default
foreach (var item in services.GetChildren())
{
var service = new Service(item, defaults);
VetoService(ref service);
VetoService(service);
if (CheckVeto(service, "service")) { continue; }
ValidateService(service);
result.Add(service);
Expand Down
Loading

0 comments on commit 6b4f0fc

Please sign in to comment.