public void Handle(MonitoringEnabledForEndpoint message) { // The user could be disabling an endpoint that had the heartbeats plugin, or not. // Check to see if the endpoint had associated heartbeat. using (var session = store.OpenSession()) { var heartbeat = session.Load <Heartbeat>(message.EndpointInstanceId); if (heartbeat != null) { if (!heartbeat.Disabled) { Logger.Info($"Heartbeat monitoring for endpoint {message.EndpointInstanceId} is already enabled"); return; } heartbeat.Disabled = false; session.SaveChanges(); } else { Logger.Info($"Heartbeat for endpoint {message.EndpointInstanceId} not found. Possible cause is that the endpoint may not have the plug in installed."); } } statusProvider.EnableMonitoring(message.Endpoint); bus.Publish(new HeartbeatMonitoringEnabled { EndpointInstanceId = message.EndpointInstanceId }); }
void Initialise() { using (var session = store.OpenSession()) { session.Query <KnownEndpoint, KnownEndpointIndex>() .Lazily(endpoints => { foreach (var knownEndpoint in endpoints.Where(p => p.Monitored)) { statusProvider.RegisterNewEndpoint(knownEndpoint.EndpointDetails); } }); session.Query <Heartbeat, HeartbeatsIndex>() .Lazily(heartbeats => { foreach (var heartbeat in heartbeats) { if (heartbeat.Disabled) { statusProvider.DisableMonitoring(heartbeat.EndpointDetails); continue; } statusProvider.EnableMonitoring(heartbeat.EndpointDetails); if (heartbeat.ReportedStatus == Status.Beating) { statusProvider.RegisterHeartbeatingEndpoint(heartbeat.EndpointDetails, heartbeat.LastReportAt); } else { statusProvider.RegisterEndpointThatFailedToHeartbeat(heartbeat.EndpointDetails); } } }); session.Advanced.Eagerly.ExecuteAllPendingLazyOperations(); } }