Beispiel #1
0
        private static void PublishKeepAlive()
        {
            try
            {
                List <string> m_redactlist = null;
                var           keepAlive    = m_configsettings["client"];

                keepAlive["timestamp"] = SensuClientHelper.CreateTimeStamp();
                keepAlive["version"]   = m_version_string;
                keepAlive["plugins"]   = "";

                m_redactlist = SensuClientHelper.GetRedactlist((JObject)keepAlive);

                var payload = SensuClientHelper.RedactSensitiveInformaton(keepAlive, m_redactlist);

                Log.Debug("Publishing keepalive");

                var properties = new BasicProperties
                {
                    ContentType  = "application/octet-stream",
                    Priority     = 0,
                    DeliveryMode = 1
                };

                lock (m_lock_pulish)
                {
                    RabbitMQChannel.BasicPublish("", "keepalives", properties, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to publish KeepAlive!");
            }
        }
Beispiel #2
0
        private static void PublishResult(JObject check)
        {
            var payload = new JObject();

            payload["check"]  = check;
            payload["client"] = m_configsettings["client"]["name"];

            try
            {
                Log.Info("Publishing Check Result {0}", JsonConvert.SerializeObject(payload, SerializerSettings));

                Task.Factory.StartNew(() =>
                {
                    var properties = new BasicProperties
                    {
                        ContentType  = "application/octet-stream",
                        Priority     = 0,
                        DeliveryMode = 1
                    };

                    lock (m_lock_pulish)
                    {
                        RabbitMQChannel.BasicPublish("", "results", properties, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
                    }
                });
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Log.Error(ex, "Publishing Check Result failed: {0}", ex.InnerException.Message);
                }
                else
                {
                    Log.Error(ex, "Publishing Check Result failed: {0}", ex.Message);
                }
            }
            finally
            {
                Log.Debug("Check Result successfully published!");

                lock (m_lock_checkinprogress)
                {
                    if (ChecksInProgress.Contains(check["name"].ToString()))
                    {
                        ChecksInProgress.Remove(check["name"].ToString());
                    }
                }
            }
        }