Exemplo n.º 1
0
        public void Test2()
        {
            var testEvent = new TestEvent()
            {
                TestString = "en textx",
                TestGuid   = Guid.NewGuid(),
                TestInt    = 42
            };
            var logger = new SplunkLogger();

            logger.Info(this, testEvent);

            logger.FlushLogs();
        }
        void CallHome(object state)
        {
            try
            {
                var client = new System.Net.Http.HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiToken);


                var sensorList = client.GetStringAsync($"{baseUri}/sensors/list");
                var listResult = JsonConvert.DeserializeObject <SensorList>(sensorList.Result);


                foreach (var sensor in listResult.sensor)
                {
                    try
                    {
                        var streamTask = client.GetStringAsync($"{baseUri}/sensor/info/?id={sensor.id}");
                        var result     = JsonConvert.DeserializeObject <SensorReading>(streamTask.Result);

                        foreach (var r in result.data)
                        {
                            _logger.Info(this, new SensorEvent()
                            {
                                DeviceName = result.name,
                                Name       = r.name,
                                Value      = r.value
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(this, new ExceptionEvent(ex));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(this, new ExceptionEvent(ex));
            }
        }