we have basic read/write to the redisdb
This commit is contained in:
@@ -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<ParseRule> { 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Alert> 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<Alert>(ts);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
44
src/NOCQ/DB/RedisDatabase.cs
Normal file
44
src/NOCQ/DB/RedisDatabase.cs
Normal file
@@ -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<Alert>(ts);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@
|
||||
<Compile Include="Plugins\Email\EmailSettings.cs" />
|
||||
<Compile Include="Imports\IDataImportHook.cs" />
|
||||
<Compile Include="Imports\DataImports.cs" />
|
||||
<Compile Include="DB\RedisDataase.cs" />
|
||||
<Compile Include="Plugins\Email\ParseRule.cs" />
|
||||
<Compile Include="Plugins\Email\ImapInput.cs" />
|
||||
<Compile Include="Model\Alert.cs" />
|
||||
<Compile Include="DB\RedisQueues.cs" />
|
||||
<Compile Include="DB\RedisDatabase.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user