aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-07-06 08:32:21 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-07-06 08:32:21 +0100
commit07b8d8cb2d14a357f196afcb42aa8469b43a6167 (patch)
tree73a56583201f9fb293a141406a1fdf615facd1c1
parent5edc6c8a10ad9f325d6e6bc1b0d4aed12e58a9e1 (diff)
downloadrspamd-07b8d8cb2d14a357f196afcb42aa8469b43a6167.tar.gz
rspamd-07b8d8cb2d14a357f196afcb42aa8469b43a6167.zip
[Rework] Allow to use custom callback for monitored checks
-rw-r--r--src/libserver/monitored.c28
-rw-r--r--src/libserver/monitored.h14
-rw-r--r--src/worker.c2
3 files changed, 41 insertions, 3 deletions
diff --git a/src/libserver/monitored.c b/src/libserver/monitored.c
index 09d642d09..472c3d4e6 100644
--- a/src/libserver/monitored.c
+++ b/src/libserver/monitored.c
@@ -39,6 +39,8 @@ struct rspamd_monitored_ctx {
struct rdns_resolver *resolver;
struct event_base *ev_base;
GPtrArray *elts;
+ mon_change_cb change_cb;
+ gpointer ud;
gdouble monitoring_interval;
guint max_errors;
gboolean initialized;
@@ -94,6 +96,10 @@ rspamd_monitored_propagate_error (struct rspamd_monitored *m,
error, m->url);
m->alive = FALSE;
m->offline_time = rspamd_get_calendar_ticks ();
+
+ if (m->ctx->change_cb) {
+ m->ctx->change_cb (m->ctx, m, FALSE, m->ctx->ud);
+ }
}
}
}
@@ -115,6 +121,10 @@ rspamd_monitored_propagate_success (struct rspamd_monitored *m, gdouble lat)
m->offline_time = 0;
m->nchecks = 1;
m->latency = lat;
+
+ if (m->ctx->change_cb) {
+ m->ctx->change_cb (m->ctx, m, TRUE, m->ctx->ud);
+ }
}
else {
m->latency = (lat + m->latency * m->nchecks) / (m->nchecks + 1);
@@ -351,7 +361,9 @@ void
rspamd_monitored_ctx_config (struct rspamd_monitored_ctx *ctx,
struct rspamd_config *cfg,
struct event_base *ev_base,
- struct rdns_resolver *resolver)
+ struct rdns_resolver *resolver,
+ mon_change_cb change_cb,
+ gpointer ud)
{
struct rspamd_monitored *m;
guint i;
@@ -361,6 +373,8 @@ rspamd_monitored_ctx_config (struct rspamd_monitored_ctx *ctx,
ctx->resolver = resolver;
ctx->cfg = cfg;
ctx->initialized = TRUE;
+ ctx->change_cb = change_cb;
+ ctx->ud = ud;
/* Start all events */
for (i = 0; i < ctx->elts->len; i ++) {
@@ -437,6 +451,18 @@ rspamd_monitored_alive (struct rspamd_monitored *m)
return m->alive;
}
+gboolean
+rspamd_monitored_set_alive (struct rspamd_monitored *m, gboolean alive)
+{
+ gboolean st;
+
+ g_assert (m != NULL);
+ st = m->alive;
+ m->alive = alive;
+
+ return st;
+}
+
gdouble
rspamd_monitored_offline_time (struct rspamd_monitored *m)
{
diff --git a/src/libserver/monitored.h b/src/libserver/monitored.h
index 4c55a5646..e342a5886 100644
--- a/src/libserver/monitored.h
+++ b/src/libserver/monitored.h
@@ -38,6 +38,9 @@ enum rspamd_monitored_flags {
*/
struct rspamd_monitored_ctx *rspamd_monitored_ctx_init (void);
+typedef void (*mon_change_cb) (struct rspamd_monitored_ctx *ctx,
+ struct rspamd_monitored *m, gboolean alive,
+ void *ud);
/**
* Configure context for monitored objects
* @param ctx context
@@ -48,7 +51,9 @@ struct rspamd_monitored_ctx *rspamd_monitored_ctx_init (void);
void rspamd_monitored_ctx_config (struct rspamd_monitored_ctx *ctx,
struct rspamd_config *cfg,
struct event_base *ev_base,
- struct rdns_resolver *resolver);
+ struct rdns_resolver *resolver,
+ mon_change_cb change_cb,
+ gpointer ud);
/**
* Create monitored object
@@ -73,6 +78,13 @@ struct rspamd_monitored *rspamd_monitored_create (
gboolean rspamd_monitored_alive (struct rspamd_monitored *m);
/**
+ * Force alive flag for a monitored object
+ * @param m monitored object
+ * @return TRUE or FALSE
+ */
+gboolean rspamd_monitored_set_alive (struct rspamd_monitored *m, gboolean alive);
+
+/**
* Returns the current offline time for a monitored object
* @param m
* @return
diff --git a/src/worker.c b/src/worker.c
index 49336e22d..8cf2f5fe8 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -604,7 +604,7 @@ rspamd_worker_init_scanner (struct rspamd_worker *worker,
struct rspamd_dns_resolver *resolver)
{
rspamd_monitored_ctx_config (worker->srv->cfg->monitored_ctx,
- worker->srv->cfg, ev_base, resolver->r);
+ worker->srv->cfg, ev_base, resolver->r, NULL, NULL);
rspamd_stat_init (worker->srv->cfg, ev_base);
g_ptr_array_add (worker->finish_actions,
(gpointer) rspamd_worker_on_terminate);