From 2ab96369b549374cd1b21ec675391180c82dfed6 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 12:55:29 -0700 Subject: [PATCH 1/2] adding some interfaces and added alert class --- NOCQ.userprefs | 20 ++------------------ src/NOCQ/Model/Alert.cs | 18 ++++++++++++++++++ src/NOCQ/Model/IAlert.cs | 16 ++++++++++++++++ src/NOCQ/NOCQ.csproj | 4 ++++ src/NOCQ/Plugins/Email/EmailSettings.cs | 2 +- src/NOCQ/Plugins/Email/IEmailSetting.cs | 2 +- src/NOCQ/Plugins/Email/IParseRule.cs | 18 ++++++++++++++++++ src/NOCQ/Plugins/Email/ImapInput.cs | 4 ++-- src/NOCQ/Plugins/Email/ParseRule.cs | 2 +- 9 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 src/NOCQ/Model/Alert.cs create mode 100644 src/NOCQ/Model/IAlert.cs create mode 100644 src/NOCQ/Plugins/Email/IParseRule.cs diff --git a/NOCQ.userprefs b/NOCQ.userprefs index 0cde9f1..2a64010 100644 --- a/NOCQ.userprefs +++ b/NOCQ.userprefs @@ -2,25 +2,9 @@ - - + + - - - - - - - - - - - - - - - - diff --git a/src/NOCQ/Model/Alert.cs b/src/NOCQ/Model/Alert.cs new file mode 100644 index 0000000..fa5908e --- /dev/null +++ b/src/NOCQ/Model/Alert.cs @@ -0,0 +1,18 @@ +using System; + +namespace NOCQ +{ + public class Alert : IAlert + { + + public DateTime TimeStamp {get; set;} + public string Source {get;set;} + public string System {get;set;} + public string Service {get;set;} + public string Data {get;set;} + public string Runbook {get; set;} + public string Severity {get;set;} + } +} + + diff --git a/src/NOCQ/Model/IAlert.cs b/src/NOCQ/Model/IAlert.cs new file mode 100644 index 0000000..2de249d --- /dev/null +++ b/src/NOCQ/Model/IAlert.cs @@ -0,0 +1,16 @@ +using System; + +namespace NOCQ +{ + public interface IAlert + { + DateTime TimeStamp {get; set;} + string Source {get;set;} + string System {get;set;} + string Service {get;set;} + string Data {get;set;} + string Runbook {get; set;} + string Severity {get;set;} + } +} + diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 6206afc..0a1d4a5 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -68,6 +68,9 @@ + + + @@ -79,5 +82,6 @@ + diff --git a/src/NOCQ/Plugins/Email/EmailSettings.cs b/src/NOCQ/Plugins/Email/EmailSettings.cs index d5af464..acd6613 100644 --- a/src/NOCQ/Plugins/Email/EmailSettings.cs +++ b/src/NOCQ/Plugins/Email/EmailSettings.cs @@ -12,7 +12,7 @@ namespace NOCQ.Plugins.Email public string Folder {get;set;} public bool IsSsl {get;set;} public int Frequency { get; set; } - public IEnumerable ParseRules {get;set;} + public IEnumerable ParseRules {get;set;} } } diff --git a/src/NOCQ/Plugins/Email/IEmailSetting.cs b/src/NOCQ/Plugins/Email/IEmailSetting.cs index e4244ca..0ca692b 100644 --- a/src/NOCQ/Plugins/Email/IEmailSetting.cs +++ b/src/NOCQ/Plugins/Email/IEmailSetting.cs @@ -11,7 +11,7 @@ namespace NOCQ.Plugins.Email string Folder {get;set;} bool IsSsl {get;set;} int Frequency { get; set; } - IEnumerable ParseRules {get;set;} + IEnumerable ParseRules {get;set;} } } diff --git a/src/NOCQ/Plugins/Email/IParseRule.cs b/src/NOCQ/Plugins/Email/IParseRule.cs new file mode 100644 index 0000000..4d0eedb --- /dev/null +++ b/src/NOCQ/Plugins/Email/IParseRule.cs @@ -0,0 +1,18 @@ +using System; + +namespace NOCQ.Plugins.Email +{ + public interface IParseRule + { + string Name { get; set; } + bool Enabled { get; set; } + string From {get;set;} + string Source {get;set;} + string System {get;set;} + string Service {get;set;} + string Data {get;set;} + string Runbook { get; set;} + string Severity {get;set;} + } +} + diff --git a/src/NOCQ/Plugins/Email/ImapInput.cs b/src/NOCQ/Plugins/Email/ImapInput.cs index 33ae6e3..95e798a 100644 --- a/src/NOCQ/Plugins/Email/ImapInput.cs +++ b/src/NOCQ/Plugins/Email/ImapInput.cs @@ -16,13 +16,13 @@ namespace NOCQ.Plugins.Email int port { get; set; } bool ssl { get; set; } DateTime lastRun { get; set; } - List parseRules{ get; set; } + List parseRules{ get; set; } public ImapInput (dynamic settings) { var sets = settings as EmailSettings; - if (sets.GetType().GetProperty("Username") == null + if (sets.GetType().GetProperty("Username") == null || sets.GetType().GetProperty("Password") == null || sets.GetType().GetProperty("Host") == null || sets.GetType().GetProperty("Folder") == null) diff --git a/src/NOCQ/Plugins/Email/ParseRule.cs b/src/NOCQ/Plugins/Email/ParseRule.cs index a67b10f..7c89b42 100644 --- a/src/NOCQ/Plugins/Email/ParseRule.cs +++ b/src/NOCQ/Plugins/Email/ParseRule.cs @@ -2,7 +2,7 @@ using System; namespace NOCQ.Plugins.Email { - public class ParseRule + public class ParseRule : IParseRule { public string Name { get; set; } public bool Enabled { get; set; } From ee65dbc1f378c298b1a4a24d75d918706e8a434d Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 7 May 2014 13:34:13 -0700 Subject: [PATCH 2/2] adding redis read/writes --- src/NOCQ/DB/RedisDataase.cs | 31 ++++++++++++++++++++++++++++++- src/NOCQ/Model/Alert.cs | 1 - src/NOCQ/NOCQ.csproj | 4 ++++ src/NOCQ/packages.config | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/NOCQ/DB/RedisDataase.cs b/src/NOCQ/DB/RedisDataase.cs index 6400059..3166e72 100644 --- a/src/NOCQ/DB/RedisDataase.cs +++ b/src/NOCQ/DB/RedisDataase.cs @@ -1,11 +1,40 @@ 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(IAlert alert) + { + using (var redis = new RedisClientAsync(ConfigurationManager.AppSettings["DBQueueKey"], + Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), + Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + )) + { + await redis.LPush(ConfigurationManager.AppSettings["DBQueueKey"], alert); + + } + + } + + public static async Task GetNextAlert() + { + using (var redis = new RedisClientAsync(ConfigurationManager.AppSettings["DBQueueKey"], + Convert.ToInt32(ConfigurationManager.AppSettings["Port"]), + Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]) + )) + { + var ts = await redis.RPop(ConfigurationManager.AppSettings["DBQueueKey"]); + + return JsonConvert.DeserializeObject(ts); + + } + } } } diff --git a/src/NOCQ/Model/Alert.cs b/src/NOCQ/Model/Alert.cs index fa5908e..d0fb4a5 100644 --- a/src/NOCQ/Model/Alert.cs +++ b/src/NOCQ/Model/Alert.cs @@ -4,7 +4,6 @@ namespace NOCQ { public class Alert : IAlert { - public DateTime TimeStamp {get; set;} public string Source {get;set;} public string System {get;set;} diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 0a1d4a5..6531573 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -55,6 +55,10 @@ ..\..\packages\AE.Net.Mail.1.7.9.1\lib\net45\AE.Net.Mail.dll + + + ..\..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll + diff --git a/src/NOCQ/packages.config b/src/NOCQ/packages.config index f7664ea..136988d 100644 --- a/src/NOCQ/packages.config +++ b/src/NOCQ/packages.config @@ -3,4 +3,5 @@ + \ No newline at end of file