This commit is contained in:
Norm MacLennan
2014-05-07 13:40:55 -07:00
11 changed files with 98 additions and 24 deletions

View File

@@ -2,25 +2,9 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="src/NOCQ/Plugins/Email/ImapInput.cs">
<Files>
<File FileName="src/NOCQ/Plugins/Email/EmailSettings.cs" Line="15" Column="16" />
<File FileName="src/NOCQ/Plugins/Email/ImapInput.cs" Line="68" Column="31" />
<File FileName="src/NOCQ/DB/RedisDataase.cs" Line="10" Column="6" />
<File FileName="src/NOCQ/Plugins/Email/ImapInput.cs" Line="9" Column="24" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State expanded="True">
<Node name="NOCQ" expanded="True">
<Node name="Extensability" expanded="True" />
<Node name="Imports" expanded="True" />
<Node name="Plugins" expanded="True">
<Node name="Email" expanded="True" />
</Node>
</Node>
<Node name="NOCQ.Application" expanded="True" selected="True">
<Node name="References" expanded="True" />
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />

View File

@@ -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<Alert> 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<Alert>(ts);
}
}
}
}

17
src/NOCQ/Model/Alert.cs Normal file
View File

@@ -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;}
}
}

16
src/NOCQ/Model/IAlert.cs Normal file
View File

@@ -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;}
}
}

View File

@@ -55,6 +55,10 @@
<HintPath>..\..\packages\AE.Net.Mail.1.7.9.1\lib\net45\AE.Net.Mail.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Configuration" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -65,6 +69,10 @@
<Compile Include="DB\RedisDataase.cs" />
<Compile Include="Plugins\Email\ParseRule.cs" />
<Compile Include="Plugins\Email\ImapInput.cs" />
<Compile Include="Plugins\Email\IEmailSetting.cs" />
<Compile Include="Model\Alert.cs" />
<Compile Include="Plugins\Email\IParseRule.cs" />
<Compile Include="Model\IAlert.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -76,5 +84,6 @@
<Folder Include="DB\" />
<Folder Include="Plugins\" />
<Folder Include="Plugins\Email\" />
<Folder Include="Model\" />
</ItemGroup>
</Project>

View File

@@ -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<ParseRule> ParseRules {get;set;}
public IEnumerable<IParseRule> ParseRules {get;set;}
}
}

View File

@@ -11,7 +11,7 @@ namespace NOCQ.Plugins.Email
string Folder {get;set;}
bool IsSsl {get;set;}
int Frequency { get; set; }
IEnumerable<ParseRule> ParseRules {get;set;}
IEnumerable<IParseRule> ParseRules {get;set;}
}
}

View File

@@ -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;}
}
}

View File

@@ -17,13 +17,13 @@ namespace NOCQ.Plugins.Email
int port { get; set; }
bool ssl { get; set; }
DateTime lastRun { get; set; }
List<ParseRule> parseRules{ get; set; }
List<IParseRule> 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)

View File

@@ -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; }

View File

@@ -3,4 +3,5 @@
<package id="AE.Net.Mail" version="1.7.9.1" targetFramework="net45" />
<package id="csredis" version="1.4.7.1" targetFramework="net45" />
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
</packages>