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;
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);
+ }
}
}
}
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);
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;
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 ++) {
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)
{
*/
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
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
*/
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
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);