public IEnumerable<Endpoint> LoadEndpoints(IHealthMonitorRegistry monitorRegistry)
 {
     using (var conn = _db.OpenConnection())
         return conn.Query<EndpointEntity>("select * from EndpointConfig")
             .Select(
                 e => new Endpoint(e.Id, monitorRegistry.FindByName(e.MonitorType), e.Address, e.Name, e.GroupName))
             .ToArray();
 }
 public IEnumerable <Endpoint> LoadEndpoints(IHealthMonitorRegistry monitorRegistry)
 {
     using (var conn = _db.OpenConnection())
         return(conn.Query <EndpointEntity>("select * from EndpointConfig")
                .Select(
                    e => new Endpoint(e.Id, monitorRegistry.FindByName(e.MonitorType), e.Address, e.Name, e.GroupName))
                .ToArray());
 }
        public MonitorableEndpoint TryRegister(EndpointIdentity identity)
        {
            var monitor = _healthMonitorRegistry.FindByName(identity.MonitorType);

            if (monitor == null)
            {
                return(null);
            }

            var monitorableEndpoint = new MonitorableEndpoint(identity, monitor);

            var current = _endpoints.GetOrAdd(identity.Id, monitorableEndpoint);

            if (ReferenceEquals(current, monitorableEndpoint))
            {
                Logger.Info($"Starting monitoring of: {monitorableEndpoint}");
                NewEndpointAdded?.Invoke(monitorableEndpoint);
            }
            return(current);
        }
Example #4
0
        public Guid RegisterOrUpdate(string monitorType, string address, string group, string name)
        {
            var monitor = _healthMonitorRegistry.FindByName(monitorType);

            if (monitor == null)
            {
                throw new UnsupportedMonitorException(monitorType);
            }

            var key      = GetKey(monitorType, address);
            var newId    = Guid.NewGuid();
            var endpoint = _endpoints.AddOrUpdate(key, new Endpoint(newId, monitor, address, name, group), (k, e) => e.Update(group, name));

            _endpointsByGuid[endpoint.Id] = endpoint;

            if (endpoint.Id == newId && NewEndpointAdded != null)
            {
                NewEndpointAdded(endpoint);
            }

            _endpointConfigurationStore.SaveEndpoint(endpoint);

            return(endpoint.Id);
        }