From af9dbe5b74e581b43e2c91a9dc639649b1f7dccc Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 13:59:06 -0700 Subject: [PATCH 1/4] deleting file --- NOCQ.userprefs | 29 +++++++++++++++---------- src/NOCQ/NOCQ.csproj | 2 -- src/NOCQ/Plugins/Email/IEmailSetting.cs | 17 --------------- 3 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 src/NOCQ/Plugins/Email/IEmailSetting.cs diff --git a/NOCQ.userprefs b/NOCQ.userprefs index 02029e3..bfd823d 100644 --- a/NOCQ.userprefs +++ b/NOCQ.userprefs @@ -1,21 +1,28 @@  - + - - - - - - - + + + + + + + + - - - + + + + + + + + + diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 9663b03..001d196 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -58,7 +58,6 @@ ..\..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll - monodevelop @@ -70,7 +69,6 @@ - diff --git a/src/NOCQ/Plugins/Email/IEmailSetting.cs b/src/NOCQ/Plugins/Email/IEmailSetting.cs deleted file mode 100644 index 1e4dfc2..0000000 --- a/src/NOCQ/Plugins/Email/IEmailSetting.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -namespace NOCQ.Plugins.Email -{ - public interface IEmailSetting - { - string Username {get;set;} - string Password {get;set;} - string Host {get;set;} - int Port {get;set;} - string Folder {get;set;} - bool IsSsl {get;set;} - int Frequency { get; set; } - IEnumerable ParseRules {get;set;} - } -} - From 91fb8d9e7dc726130e964c41b038e03fefe23638 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 14:36:29 -0700 Subject: [PATCH 2/4] we have basic read/write to the redisdb --- src/NOCQ.Application/Program.cs | 39 ++++++++++------------------- src/NOCQ/DB/RedisDataase.cs | 42 ------------------------------- src/NOCQ/DB/RedisDatabase.cs | 44 +++++++++++++++++++++++++++++++++ src/NOCQ/DB/RedisQueues.cs | 4 +-- src/NOCQ/NOCQ.csproj | 2 +- 5 files changed, 60 insertions(+), 71 deletions(-) delete mode 100644 src/NOCQ/DB/RedisDataase.cs create mode 100644 src/NOCQ/DB/RedisDatabase.cs diff --git a/src/NOCQ.Application/Program.cs b/src/NOCQ.Application/Program.cs index 2b53dba..e5fcbd7 100644 --- a/src/NOCQ.Application/Program.cs +++ b/src/NOCQ.Application/Program.cs @@ -2,6 +2,7 @@ using System; using System.Dynamic; using NOCQ.Plugins.Email; using System.Collections.Generic; +using System.Threading.Tasks; namespace NOCQ.Application { @@ -9,33 +10,19 @@ namespace NOCQ.Application { public static void Main (string[] args) { - var settings = new EmailSettings (); - settings.Host = "imap.gmail.com"; - settings.IsSsl = true; - settings.Frequency = 20; - settings.Username = "gwyrox@gmail.com"; + var al = new Alert() + {Data = "data", Runbook = "runbook", Service = "service", + Severity = "sev", + Source = "Source", + System = "System", + TimeStamp = new DateTime(2011,1,1) + }; - - Console.WriteLine ("Password: "); - settings.Password = Console.ReadLine (); - settings.Port = 993; - settings.Folder = "INBOX"; - - var rule = new ParseRule (); - rule.Name = "Nagios"; - rule.Enabled = true; - rule.From = "gwyrox@gmail.com"; - rule.Source = "Nagios"; - rule.System = "(?<=Host: ).*"; - rule.Service = "(?<=Service: ).*"; - rule.Data = "(?<=Additional Info:[\\n]*).*"; - rule.Severity = "P3"; - rule.Runbook = "http://google.com"; - - settings.ParseRules = new List { rule }; - - var email = new ImapInput (settings); - email.Execute (null,null); + RedisDatabase.SaveAlert(al, "127.0.0.1", RedisQueues.Input, 6379, 3000); + var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000); + Console.WriteLine(s.Data); + Console.ReadLine(); + } } } diff --git a/src/NOCQ/DB/RedisDataase.cs b/src/NOCQ/DB/RedisDataase.cs deleted file mode 100644 index 609e3cc..0000000 --- a/src/NOCQ/DB/RedisDataase.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using ctstone.Redis; -using System.Threading.Tasks; -using System.Configuration; -using Newtonsoft.Json; -namespace NOCQ -{ - public class RedisDataase - { - public RedisDataase(){} - - public static async Task SaveAlert(Alert alert, string q) - { - using (var redis = new RedisClientAsync(q, - Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), - Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) - )) - { - await redis.LPush(q, alert); - - } - - } - - public static async Task GetNextAlert(string q) - { - - using (var redis = new RedisClientAsync(q, - Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), - Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) - )) - { - var ts = await redis.RPop(q); - - return await JsonConvert.DeserializeObjectAsync(ts); - - } - } - - } -} - diff --git a/src/NOCQ/DB/RedisDatabase.cs b/src/NOCQ/DB/RedisDatabase.cs new file mode 100644 index 0000000..063a7c0 --- /dev/null +++ b/src/NOCQ/DB/RedisDatabase.cs @@ -0,0 +1,44 @@ +using System; +using ctstone.Redis; +using System.Threading.Tasks; +using System.Configuration; +using Newtonsoft.Json; +namespace NOCQ +{ + public class RedisDatabase + { + public RedisDatabase(){} + + public static void SaveAlert(Alert alert, string host, string q) + { + using (var redis = new RedisClient(host, + Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), + Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + )) + { + + + redis.LPush(q, JsonConvert.SerializeObject(alert)); + + } + + } + + public static Alert GetNextAlert(string host, string q ) + { + + using (var redis = new RedisClient(host, + Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), + Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + )) + { + var ts = redis.RPop(q); + + return JsonConvert.DeserializeObject(ts); + + } + } + + } +} + diff --git a/src/NOCQ/DB/RedisQueues.cs b/src/NOCQ/DB/RedisQueues.cs index e6c8556..8afe855 100644 --- a/src/NOCQ/DB/RedisQueues.cs +++ b/src/NOCQ/DB/RedisQueues.cs @@ -5,8 +5,8 @@ namespace NOCQ { public struct RedisQueues { - public static string Input = ConfigurationManager.AppSettings["DBQueueInput"]; - public static string Output = ConfigurationManager.AppSettings["DBQueueOutput"]; + public static string Input = "DBQueueInput"; + public static string Output = "DBQueueOutput"; } } diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 001d196..0870bec 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -66,11 +66,11 @@ - + From 0ea807b1d186e312ffed6752d4b29338b27d9b71 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 14:42:03 -0700 Subject: [PATCH 3/4] adding fileio permissions, and changes to db access --- src/NOCQ/DB/RedisDatabase.cs | 12 ++++++------ src/NOCQ/Properties/AssemblyInfo.cs | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/NOCQ/DB/RedisDatabase.cs b/src/NOCQ/DB/RedisDatabase.cs index 063a7c0..e0d749f 100644 --- a/src/NOCQ/DB/RedisDatabase.cs +++ b/src/NOCQ/DB/RedisDatabase.cs @@ -9,11 +9,11 @@ namespace NOCQ { public RedisDatabase(){} - public static void SaveAlert(Alert alert, string host, string q) + public static void SaveAlert(Alert alert, string host, string q, int port, int timeout) { using (var redis = new RedisClient(host, - Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), - Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + port, + timeout )) { @@ -24,12 +24,12 @@ namespace NOCQ } - public static Alert GetNextAlert(string host, string q ) + public static Alert GetNextAlert(string host, string q, int port, int timeout ) { using (var redis = new RedisClient(host, - Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), - Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + port, + timeout )) { var ts = redis.RPop(q); diff --git a/src/NOCQ/Properties/AssemblyInfo.cs b/src/NOCQ/Properties/AssemblyInfo.cs index 29cfbc3..9318ac2 100644 --- a/src/NOCQ/Properties/AssemblyInfo.cs +++ b/src/NOCQ/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ using System.Reflection; using System.Runtime.CompilerServices; - +using System.Security.Permissions; // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. [assembly: AssemblyTitle("NOCQ")] @@ -15,6 +15,7 @@ using System.Runtime.CompilerServices; // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. [assembly: AssemblyVersion("1.0.*")] +[assembly: FileIOPermission] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. //[assembly: AssemblyDelaySign(false)] From e5ed166572b47afde75d47f888768ae5b8d528f2 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 14:57:15 -0700 Subject: [PATCH 4/4] minor changes --- src/NOCQ.Application/Program.cs | 30 +++++++++++++++++++---------- src/NOCQ/NOCQ.csproj | 4 +++- src/NOCQ/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/NOCQ.Application/Program.cs b/src/NOCQ.Application/Program.cs index e5fcbd7..2c2c572 100644 --- a/src/NOCQ.Application/Program.cs +++ b/src/NOCQ.Application/Program.cs @@ -1,6 +1,8 @@ using System; using System.Dynamic; +using System.Linq; using NOCQ.Plugins.Email; +using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; @@ -10,17 +12,25 @@ namespace NOCQ.Application { public static void Main (string[] args) { - var al = new Alert() - {Data = "data", Runbook = "runbook", Service = "service", - Severity = "sev", - Source = "Source", - System = "System", - TimeStamp = new DateTime(2011,1,1) - }; + var list = new List(); + for (var i = 0; i < 3000; i++) + { + var al = new Alert() + {Data = "data" + Guid.NewGuid(), Runbook = "runbook", Service = "service", + Severity = "sev", + Source = "Source", + System = "System", + TimeStamp = new DateTime(2011,1,1) + }; + list.Add(al); + } + list.ForEach(al => RedisDatabase.SaveAlert(al, "127.0.0.1", RedisQueues.Input, 6379, 3000)); + for (var i = 0; i < 3000; i++) + { + var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000); + Console.WriteLine(s.Data); + } - RedisDatabase.SaveAlert(al, "127.0.0.1", RedisQueues.Input, 6379, 3000); - var s = RedisDatabase.GetNextAlert("127.0.0.1", RedisQueues.Input, 6379, 3000); - Console.WriteLine(s.Data); Console.ReadLine(); } diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 0870bec..f5541ed 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -67,7 +67,9 @@ - + + EmailSettings.cs + diff --git a/src/NOCQ/Properties/AssemblyInfo.cs b/src/NOCQ/Properties/AssemblyInfo.cs index 9318ac2..c61243c 100644 --- a/src/NOCQ/Properties/AssemblyInfo.cs +++ b/src/NOCQ/Properties/AssemblyInfo.cs @@ -15,7 +15,7 @@ using System.Security.Permissions; // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. [assembly: AssemblyVersion("1.0.*")] -[assembly: FileIOPermission] + // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. //[assembly: AssemblyDelaySign(false)]