simple regexing with hardcoded stuff that's not passwords
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Dynamic;
|
||||||
|
using NOCQ.Plugins.Email;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace NOCQ.Application
|
namespace NOCQ.Application
|
||||||
{
|
{
|
||||||
@@ -6,10 +9,33 @@ namespace NOCQ.Application
|
|||||||
{
|
{
|
||||||
public static void Main (string[] args)
|
public static void Main (string[] args)
|
||||||
{
|
{
|
||||||
dynamic settings = new ExpandoObject ();
|
var settings = new EmailSettings ();
|
||||||
//settings.
|
settings.Host = "imap.gmail.com";
|
||||||
|
settings.IsSsl = true;
|
||||||
|
settings.Frequency = 20;
|
||||||
|
settings.Username = "gwyrox@gmail.com";
|
||||||
|
|
||||||
var email = new NOCQ.Plugins.Email.ImapInput(
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,15 +59,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Extensability\Catalog.cs" />
|
<Compile Include="Extensability\Catalog.cs" />
|
||||||
<Compile Include="Plugins\Email\ImapInput.cs">
|
|
||||||
<DependentUpon>IEmailSetting.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Plugins\Email\EmailSettings.cs" />
|
<Compile Include="Plugins\Email\EmailSettings.cs" />
|
||||||
<Compile Include="Imports\IDataImportHook.cs" />
|
<Compile Include="Imports\IDataImportHook.cs" />
|
||||||
<Compile Include="Imports\DataImports.cs" />
|
<Compile Include="Imports\DataImports.cs" />
|
||||||
<Compile Include="DB\RedisDataase.cs" />
|
<Compile Include="DB\RedisDataase.cs" />
|
||||||
<Compile Include="Plugins\Email\ParseRule.cs" />
|
<Compile Include="Plugins\Email\ParseRule.cs" />
|
||||||
<Compile Include="Plugins\Email\IEmailSetting.cs" />
|
<Compile Include="Plugins\Email\ImapInput.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace NOCQ.Plugins.Email
|
namespace NOCQ.Plugins.Email
|
||||||
{
|
{
|
||||||
public class EmailSettings :IEmailSetting
|
public class EmailSettings
|
||||||
{
|
{
|
||||||
public string Username {get;set;}
|
public string Username {get;set;}
|
||||||
public string Password {get;set;}
|
public string Password {get;set;}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Timers;
|
|||||||
using AE.Net.Mail;
|
using AE.Net.Mail;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NOCQ.Plugins.Email
|
namespace NOCQ.Plugins.Email
|
||||||
{
|
{
|
||||||
@@ -28,12 +29,15 @@ namespace NOCQ.Plugins.Email
|
|||||||
|| sets.GetType().GetProperty("Folder") == null)
|
|| sets.GetType().GetProperty("Folder") == null)
|
||||||
throw new ArgumentException ("You are missing a required setting.");
|
throw new ArgumentException ("You are missing a required setting.");
|
||||||
|
|
||||||
|
if (sets.ParseRules != null) {
|
||||||
parseRules = sets.ParseRules.Where (x => x.Enabled).ToList ();
|
parseRules = sets.ParseRules.Where (x => x.Enabled).ToList ();
|
||||||
|
}
|
||||||
|
|
||||||
loginName = sets.Username;
|
loginName = sets.Username;
|
||||||
password = sets.Password;
|
password = sets.Password;
|
||||||
server = sets.Host;
|
server = sets.Host;
|
||||||
folderPath = sets.Folder;
|
folderPath = sets.Folder;
|
||||||
|
port = sets.Port;
|
||||||
|
|
||||||
timer = new Timer (sets.Frequency);
|
timer = new Timer (sets.Frequency);
|
||||||
timer.Elapsed += Execute;
|
timer.Elapsed += Execute;
|
||||||
@@ -41,7 +45,7 @@ namespace NOCQ.Plugins.Email
|
|||||||
|
|
||||||
public void Execute(object sender, ElapsedEventArgs args)
|
public void Execute(object sender, ElapsedEventArgs args)
|
||||||
{
|
{
|
||||||
using(var imap = new ImapClient(server, loginName, password, ImapClient.AuthMethods.Login, port, ssl)) {
|
using(var imap = new ImapClient(server, loginName, password, ImapClient.AuthMethods.Login, 993, true)) {
|
||||||
var msgs = imap.SearchMessages(
|
var msgs = imap.SearchMessages(
|
||||||
SearchCondition.Undeleted().And(
|
SearchCondition.Undeleted().And(
|
||||||
SearchCondition.SentSince(new DateTime(2014, 5, 7))
|
SearchCondition.SentSince(new DateTime(2014, 5, 7))
|
||||||
@@ -51,8 +55,30 @@ namespace NOCQ.Plugins.Email
|
|||||||
{
|
{
|
||||||
var realMsg = msg.Value;
|
var realMsg = msg.Value;
|
||||||
|
|
||||||
Console.WriteLine ("FROM:" + realMsg.From);
|
var rule = parseRules.Where (x => x.From.Equals (realMsg.From.Address, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
//"fuc".Com
|
||||||
|
if (rule.Any ())
|
||||||
|
{
|
||||||
|
var thisRule = rule.First ();
|
||||||
|
|
||||||
|
var source = thisRule.Source;
|
||||||
|
|
||||||
|
var sysRegex = new Regex(thisRule.System);
|
||||||
|
var servRegex = new Regex(thisRule.Service);
|
||||||
|
|
||||||
|
var sysMatch = sysRegex.Match(realMsg.Body);
|
||||||
|
var servMatch = servRegex.Match(realMsg.Body);
|
||||||
|
|
||||||
|
if (sysMatch.Success && servMatch.Success) {
|
||||||
|
Console.WriteLine ("Source: " + source);
|
||||||
|
Console.WriteLine("System: " + sysMatch.Value);
|
||||||
|
Console.WriteLine ("Service: " + servMatch.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Console.WriteLine (system);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user