Exemplo n.º 1
0
        private void GetPayloadFromOpenChannel(QueueingBasicConsumer consumer)
        {
            BasicDeliverEventArgs msg;

            try {
                consumer.Queue.Dequeue(100, out msg);
            } catch (Exception e)
            {
                Log.Warn(e);
                _sensuRabbitMqConnectionFactory.CloseRabbitConnection();
                msg = null; // do not process this pass
            }
            if (msg != null)
            {
                var payload = Encoding.UTF8.GetString(((BasicDeliverEventArgs)msg).Body);
                try
                {
                    var check = JObject.Parse(payload);
                    Log.Debug("Received check request: {0}", JsonConvert.SerializeObject(check, SerializerSettings));
                    _processor.ProcessCheck(check);
                }
                catch (JsonReaderException)
                {
                    Log.Error("Malformed Check: {0}", payload);
                }
            }
        }
        private void InitializeSheduledItems()
        {
            var obj = (JObject)_sensuClientConfigurationReader.Configuration.Config["checks"];

            var standAloneChecks = SensuClientHelper.GetStandAloneChecks(obj);

            if (!standAloneChecks.Any())
            {
                return;
            }

            foreach (JObject item in standAloneChecks)
            {
                if (item == null || item["interval"] == null)
                {
                    continue;
                }

                var defaultInterval = item["interval"].Value <int>();
                SheduledItems.TryAdd(item["name"].Value <string>(), new SchedueledItem(() => _processor.ProcessCheck(item), item["name"].Value <string>(), defaultInterval));
                Log.Debug("Adding scheduled item with interval property:  {0} | {1}", defaultInterval, item["name"]);
            }
        }