public static IActionResult SetValueInRedis( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [RedisOutput(Connection = "%redis_connectionstring%", Key = "%redis_setvalueinredis_key%")] out RedisOutput redisItem, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = new StreamReader(req.Body).ReadToEnd(); redisItem = new RedisOutput() { TextValue = requestBody }; return(new OkResult()); }
public static IActionResult InsertToListInRedis( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [RedisOutput(Connection = "%redis_connectionstring%", Key = "myList", Operation = RedisOutputOperation.ListLeftPush)] out RedisOutput redisItem, ILogger log) { string itemValue = new StreamReader(req.Body).ReadToEnd(); if (string.IsNullOrEmpty(itemValue)) { itemValue = req.Query["value"].ToString(); } redisItem = new RedisOutput() { TextValue = itemValue }; return(new OkResult()); }
public static IActionResult IncrementRedisValue( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [RedisOutput(Connection = "%redis_connectionstring%")] out RedisOutput redisItem, ILogger log) { redisItem = null; string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody); var key = data?.key ?? req.Query["key"]; if (string.IsNullOrEmpty(key)) { return(new BadRequestObjectResult("Please pass a key on the query string or in the request body")); } var valueInput = data?.value ?? req.Query["value"]; if (!long.TryParse(valueInput.ToString(), out long value)) { value = 0; } if (value == 0) { return(new BadRequestObjectResult("Please pass a value on the query string or in the request body")); } redisItem = new RedisOutput() { Key = key, Operation = RedisOutputOperation.IncrementValue, IncrementValue = value }; return(new OkResult()); }
public static async Task Run( [CosmosDBTrigger( databaseName: "AesKeys", containerName: "Items", Connection = "COSMOSDB_CONNECTIONSTRING", LeaseContainerName = "leases", LeaseContainerPrefix = "%LEASE_COLLECTION_PREFIX%", CreateLeaseContainerIfNotExists = true )] IReadOnlyList <AesKey> changeStream, [RedisOutput( Connection = "%REDISCACHE_CONNECTIONSTRING%" )] IAsyncCollector <RedisOutput> cacheKeys, ILogger log) { if (changeStream != null || changeStream.Count > 0) { try { log.LogInformation($"{changeStream.Count} - Documents will be added to Cache"); foreach (var key in changeStream) { var redisItem = new RedisOutput() { Key = key.keyId, TextValue = JsonConvert.SerializeObject(key) }; await cacheKeys.AddAsync(redisItem); } } catch (Exception e) { log.LogInformation($"Failed to index some of the documents: {e.ToString()}"); } } }
public void TestRedisHostCount() { string redisJson = @"{ ""TimberWinR"": { ""Outputs"": { ""Redis"": [{ ""host"": [ ""logaggregator.vistaprint.svc"" ] }] } } }"; Configuration c = Configuration.FromString(redisJson); RedisOutput redis = c.RedisOutputs.First() as RedisOutput; Assert.IsTrue(redis.Host.Length >= 1); }
public void ProcessConfiguration(CancellationToken cancelToken, Configuration config) { // Read the Configuration file if (config != null) { if (OnConfigurationProcessed != null) { OnConfigurationProcessed(config); } if (config.StatsDOutputs != null) { foreach (var ro in config.StatsDOutputs) { var output = new StatsDOutput(this, ro, cancelToken); Outputs.Add(output); } } if (config.RedisOutputs != null) { foreach (var ro in config.RedisOutputs) { var redis = new RedisOutput(this, ro, cancelToken); Outputs.Add(redis); } } if (config.ElasticsearchOutputs != null) { foreach (var ro in config.ElasticsearchOutputs) { var els = new ElasticsearchOutput(this, ro, cancelToken); Outputs.Add(els); } } if (config.StdoutOutputs != null) { foreach (var ro in config.StdoutOutputs) { var stdout = new StdoutOutput(this, ro, cancelToken); Outputs.Add(stdout); } } if (config.FileOutputs != null) { foreach (var ro in config.FileOutputs) { var output = new FileOutput(this, ro, cancelToken); Outputs.Add(output); } } foreach (Parser.IISW3CLogParameters iisw3cConfig in config.IISW3C) { var elistner = new IISW3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (Parser.W3CLogParameters iisw3cConfig in config.W3C) { var elistner = new W3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (Parser.WindowsEvent eventConfig in config.Events) { var elistner = new WindowsEvtInputListener(eventConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var logConfig in config.Logs) { var elistner = new LogsListener(logConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var logConfig in config.TailFiles) { var elistner = new TailFileListener(logConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var tcp in config.Tcps) { var elistner = new TcpInputListener(tcp, cancelToken, tcp.Port); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var udp in config.Udps) { var elistner = new UdpInputListener(udp, cancelToken, udp.Port); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var stdin in config.Stdins) { var elistner = new StdinListener(stdin, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var stdin in config.Generators) { var elistner = new GeneratorInput(stdin, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } var computerName = System.Environment.MachineName + "." + Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\services\Tcpip\Parameters") .GetValue("Domain", "") .ToString(); foreach (var output in Outputs) { var name = Assembly.GetExecutingAssembly().GetName(); JObject json = new JObject( new JProperty("TimberWinR", new JObject( new JProperty("version", Assembly.GetEntryAssembly().GetName().Version.ToString()), //GetAssemblyByName("TimberWinR.ServiceHost").GetName().Version.ToString()), new JProperty("host", computerName), new JProperty("output", output.Name), new JProperty("initialized", DateTime.UtcNow) ))); json.Add(new JProperty("type", "Win32-TimberWinR")); json.Add(new JProperty("host", computerName)); output.Startup(json); } } }
public Manager(string jsonConfigFile, string logLevel, string logfileDir, CancellationToken cancelToken) { StartedOn = DateTime.UtcNow; var vfi = new FileInfo(jsonConfigFile); JsonConfig = vfi.FullName; LogfileDir = logfileDir; numMessages = 0; numConnections = 0; Outputs = new List <OutputSender>(); Listeners = new List <InputListener>(); var loggingConfiguration = new LoggingConfiguration(); // Create our default targets var coloredConsoleTarget = new ColoredConsoleTarget(); Target fileTarget = CreateDefaultFileTarget(logfileDir); loggingConfiguration.AddTarget("Console", coloredConsoleTarget); loggingConfiguration.AddTarget("DailyFile", fileTarget); // The LogLevel.Trace means has to be at least Trace to show up on console loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, coloredConsoleTarget)); // LogLevel.Debug means has to be at least Debug to show up in logfile loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); LogManager.Configuration = loggingConfiguration; LogManager.EnableLogging(); LogManager.GlobalThreshold = LogLevel.FromString(logLevel); LogManager.GetCurrentClassLogger() .Info("TimberWinR Version {0}", GetAssemblyByName("TimberWinR.ServiceHost").GetName().Version.ToString()); // Is it a directory? if (Directory.Exists(jsonConfigFile)) { DirectoryInfo di = new DirectoryInfo(jsonConfigFile); LogManager.GetCurrentClassLogger().Info("Initialized, Reading Configurations From {0}", di.FullName); Config = Configuration.FromDirectory(jsonConfigFile); } else { var fi = new FileInfo(jsonConfigFile); LogManager.GetCurrentClassLogger().Info("Initialized, Reading Configurations From File: {0}", fi.FullName); if (!fi.Exists) { throw new FileNotFoundException("Missing config file", jsonConfigFile); } LogManager.GetCurrentClassLogger().Info("Initialized, Reading Config: {0}", fi.FullName); Config = Configuration.FromFile(jsonConfigFile); } LogManager.GetCurrentClassLogger().Info("Log Directory {0}", logfileDir); LogManager.GetCurrentClassLogger().Info("Logging Level: {0}", LogManager.GlobalThreshold); // Read the Configuration file if (Config != null) { if (Config.RedisOutputs != null) { foreach (var ro in Config.RedisOutputs) { var redis = new RedisOutput(this, ro, cancelToken); Outputs.Add(redis); } } if (Config.ElasticsearchOutputs != null) { foreach (var ro in Config.ElasticsearchOutputs) { var els = new ElasticsearchOutput(this, ro, cancelToken); Outputs.Add(els); } } if (Config.StdoutOutputs != null) { foreach (var ro in Config.StdoutOutputs) { var stdout = new StdoutOutput(this, ro, cancelToken); Outputs.Add(stdout); } } foreach (Parser.IISW3CLog iisw3cConfig in Config.IISW3C) { var elistner = new IISW3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (Parser.W3CLog iisw3cConfig in Config.W3C) { var elistner = new W3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (Parser.WindowsEvent eventConfig in Config.Events) { var elistner = new WindowsEvtInputListener(eventConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var logConfig in Config.Logs) { var elistner = new LogsListener(logConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var tcp in Config.Tcps) { var elistner = new TcpInputListener(cancelToken, tcp.Port); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var udp in Config.Udps) { var elistner = new UdpInputListener(cancelToken, udp.Port); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } foreach (var stdin in Config.Stdins) { var elistner = new StdinListener(cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) { output.Connect(elistner); } } var computerName = System.Environment.MachineName + "." + Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\services\Tcpip\Parameters") .GetValue("Domain", "") .ToString(); foreach (var output in Outputs) { var name = Assembly.GetExecutingAssembly().GetName(); JObject json = new JObject( new JProperty("TimberWinR", new JObject( new JProperty("version", GetAssemblyByName("TimberWinR.ServiceHost").GetName().Version.ToString()), new JProperty("host", computerName), new JProperty("output", output.Name), new JProperty("initialized", DateTime.UtcNow) ))); json.Add(new JProperty("type", "Win32-TimberWinR")); json.Add(new JProperty("host", computerName)); output.Startup(json); } } }