private void thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", MONITOR_PORT.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send step1.Set(); IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(MONITOR_PORT)) { byte[] payload = client.Receive(ref remote_ep); SyslogMessage msg = SyslogMessage.Parse(payload); TestContext.WriteLine("Message1: {0}", msg); payload = client.Receive(ref remote_ep); msg = SyslogMessage.Parse(payload); TestContext.WriteLine("Message2: {0}", msg); } ctrl.UnsubscribeClient(clientid); finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
private void t2_thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", t2_client_port.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send t2_step1.Set(); //Only 6 messages expected IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(t2_client_port)) { byte[] payload = client.Receive(ref remote_ep); TestContext.WriteLine("Time occurred for a message to traverse the bus: {0} milliseconds", (DateTime.Now - t2_start).TotalMilliseconds.ToString(CultureInfo.CurrentUICulture)); SyslogMessage msg = SyslogMessage.Parse(payload); } ctrl.UnsubscribeClient(clientid); t2_finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
private void t1_thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", t1_client_port.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send t1_step1.Set(); //Only 6 messages expected IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(t1_client_port)) for (int i = 0; i < 5; i++) { byte[] payload = client.Receive(ref remote_ep); SyslogMessage msg = SyslogMessage.Parse(payload); Assert.AreEqual(SyslogFacility.Audit, msg.Facility); } ctrl.UnsubscribeClient(clientid); t1_finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
private void WorkerLoop() { try { while (true) { SyslogMessage message = _messageQueue.Dequeue(); //if (message.Facility == SyslogFacility.Internally) continue; //Redundant SyslogAttributes attrs = message.GetAdvancedAttributes(); DateTime? lastHb = null; string host = message.Host ?? "", process = message.ProcessID ?? message.ApplicationName ?? "", logger = attrs.LogName ?? ""; bool ffda = message.MessageId == "FFDA"; if (message.MessageId == "HEARTBEAT" && message.Severity == SyslogSeverity.Debug) { lastHb = message.Timestamp; } try { string entityName = null; //Suppress error about missing initialization try { DataRow newRow = _entityTable.Rows.Add( host, process, logger, message.ApplicationName ?? "", ffda, message.Timestamp, lastHb, DBNull.Value, DBNull.Value ); entityName = GetEntityName(newRow); Log.Debug("Acquired new entity: {0}, {1}FFDA-enabled", entityName, ffda ? "" : "not "); //Now creating channel for new entity IFilter entityFilter = new EntityFilter(host, process, logger); string description = string.Format("Channel monitoring logs from entity {0}", entityName); do { string randomChannelId = "em_" + Randomizer.RandomAlphanumericString(15); try { _logbus.CreateChannel(randomChannelId, "EntityManager auto-generated", entityFilter, description, 0); //Edit row accordingly newRow[_colChannelId] = randomChannelId; break; } catch (LogbusException) //Duplicate channel ID { continue; } } //Not necessarily a poor choice. With 15 chars we have billions of opportunities. //In a real system, we can't have more than thousands of entities. This algorithm //might go into stall only if randomizer is not "random" enough while (true); if (ffda) //Create FFDA channel too { entityFilter = new EntityFilter(host, process, logger, true); description = string.Format("Channel monitoring FFDA logs from entity {0}", entityName); do { string randomChannelId = "em_" + Randomizer.RandomAlphanumericString(15); try { _logbus.CreateChannel(randomChannelId, "EntityManager auto-generated", entityFilter, description, 0); //Edit row accordingly newRow[_colFfdaChannelId] = randomChannelId; break; } catch (LogbusException) //Duplicate channel ID { continue; } } //Like above while (true); } } catch (ConstraintException) { //We suppose we are trying to insert a duplicate primary key, then now we switch to update DataRow existingRow = _entityTable.Select(GetQuery(message))[0]; bool oldFfda = (bool)existingRow[_colFfda]; existingRow.BeginEdit(); existingRow[_colFfda] = ffda | oldFfda; if (lastHb != null) { existingRow[_colLastHeartbeat] = message.Timestamp; } else { existingRow[_colLastAction] = message.Timestamp; } existingRow.EndEdit(); if (ffda && !oldFfda) { Log.Debug("Entity {0} is now FFDA-enabled", entityName); //Create FFDA channel IFilter entityFilter = new EntityFilter(host, process, logger, true); string description = string.Format("Channel monitoring FFDA logs from entity {0}", entityName); do { string randomChannelId = "em_" + Randomizer.RandomAlphanumericString(15); try { _logbus.CreateChannel(randomChannelId, "EntityManager auto-generated", entityFilter, description, 0); //Edit row accordingly existingRow[_colFfdaChannelId] = randomChannelId; break; } catch (LogbusException) //Duplicate channel ID { continue; } } //Like above while (true); } } } catch (ThreadAbortException) { throw; } catch (Exception ex) { Log.Error("Unable to add an entity row into the data table"); Log.Debug(string.Format("Error details: {0}", ex.Message)); } } } catch (ThreadAbortException) { } }
/// <summary> /// Required by ILogBus /// </summary> public void CreateChannel(string channelId, string channelName, IFilter channelFilter, string channelDescription, long coalescenceWindow) { _target.CreateChannel(channelId, channelName, channelFilter, channelDescription, coalescenceWindow); }
void IChannelManagement.CreateChannel(ChannelCreationInformation description) { _target.CreateChannel(description.id, description.title, description.filter, description.description, description.coalescenceWindow); }