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/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 new file mode 100644 index 0000000..d0fb4a5 --- /dev/null +++ b/src/NOCQ/Model/Alert.cs @@ -0,0 +1,17 @@ +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 9acdb7f..d0197ea 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 + @@ -65,6 +69,10 @@ + + + + @@ -76,5 +84,6 @@ + diff --git a/src/NOCQ/Plugins/Email/EmailSettings.cs b/src/NOCQ/Plugins/Email/EmailSettings.cs index 0a25ad0..e3c8e3b 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 90cf921..2011af1 100644 --- a/src/NOCQ/Plugins/Email/ImapInput.cs +++ b/src/NOCQ/Plugins/Email/ImapInput.cs @@ -17,13 +17,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; } 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