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 @@ - +