Ejemplo n.º 1
0
        public void OnInfo(HeartbeatInfo info)
        {
            var status = Get(info?.InstanceId).status;

            status.OnInfo(info);
            //if (!hasInfo && status.Info != null)
            {
                Log(new HeartbeatTrackerLogItem(LogLevel.Information, "New heartbeat", "New heartbeat: " + status.Key, true));
            }
        }
Ejemplo n.º 2
0
        public async Task SendInfo(HeartbeatOptionsServer server, CancellationToken cancellationToken = default(CancellationToken))
        {
            var o = options.CurrentValue;

            var http = new HttpClient()
            {
                BaseAddress = new Uri(server.Url),
            };

            var heartbeatInfo = new HeartbeatInfo()
            {
                InstanceId        = InstanceId,
                ProgramName       = o.ProgramName ?? HeartbeatOptions.DefaultProgramName,
                HealthCheckUri    = o.HealthCheckUri,
                HeartbeatInterval = Interval,
                HostName          = o.HostName ?? Environment.MachineName,
                InstanceName      = o.InstanceName,
                //SupportsHealthCheck // TODO
            };

            var json = SimpleJson.SimpleJson.SerializeObject(heartbeatInfo);
            var msg  = new HttpRequestMessage(HttpMethod.Post, "api/heartbeat/info")
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            var apiKey = server.ApiKey ?? o.ApiKey;

            if (!string.IsNullOrWhiteSpace(apiKey))
            {
                msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("ApiKey", apiKey);
            }

            HttpResponseMessage response = null;

            try
            {
                response = await http.SendAsync(msg, cancellationToken);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Failed to send heartbeat info to " + server.Url);
            }

            var responseString = await response.Content.ReadAsStringAsync();

            var heartbeatConfig = SimpleJson.SimpleJson.DeserializeObject <HeartbeatConfigFromServer>(responseString);

            if (heartbeatConfig != null)
            {
                server.Config = heartbeatConfig;
            }
        }
Ejemplo n.º 3
0
 public void OnInfo(HeartbeatInfo info)
 {
     Info = info;
     OnSeen();
 }