mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 09:24:58 +00:00
Add ElasticsearchClient.cs, Update FileEventMonitor.cs
This commit is contained in:
parent
e8c69d1489
commit
c4740f7d61
30
WelsonJS.Toolkit/WelsonJS.Service/ElasticsearchClient.cs
Normal file
30
WelsonJS.Toolkit/WelsonJS.Service/ElasticsearchClient.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// ElasticsearchClient.cs
|
||||||
|
// https://github.com/gnh1201/welsonjs
|
||||||
|
using RestSharp.Authenticators;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
namespace WelsonJS.Service
|
||||||
|
{
|
||||||
|
public class ElasticsearchClient
|
||||||
|
{
|
||||||
|
private readonly RestClient client;
|
||||||
|
|
||||||
|
public ElasticsearchClient(string baseUrl, string username, string password)
|
||||||
|
{
|
||||||
|
var options = new RestClientOptions(baseUrl)
|
||||||
|
{
|
||||||
|
Authenticator = new HttpBasicAuthenticator(username, password)
|
||||||
|
};
|
||||||
|
client = new RestClient(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestResponse IndexDocument(string indexName, object document)
|
||||||
|
{
|
||||||
|
var request = new RestRequest($"/{indexName}/_doc", Method.Post);
|
||||||
|
request.AddHeader("Content-Type", "application/json");
|
||||||
|
request.AddJsonBody(document);
|
||||||
|
|
||||||
|
return client.Execute(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -171,7 +171,7 @@ namespace WelsonJS.Service
|
||||||
parent.Log($"YARA rule matched: {ruleName}, {filePath}, Offset {x.Offset}");
|
parent.Log($"YARA rule matched: {ruleName}, {filePath}, Offset {x.Offset}");
|
||||||
parent.DispatchServiceEvent("fileRuleMatched", new string[] { ruleName, filePath, x.Offset.ToString() });
|
parent.DispatchServiceEvent("fileRuleMatched", new string[] { ruleName, filePath, x.Offset.ToString() });
|
||||||
|
|
||||||
IndexMatched(new FileRuleMatched
|
IndexFileRuleMatched(new FileRuleMatched
|
||||||
{
|
{
|
||||||
FilePath = filePath,
|
FilePath = filePath,
|
||||||
Offset = x.Offset,
|
Offset = x.Offset,
|
||||||
|
@ -189,7 +189,7 @@ namespace WelsonJS.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IndexMatched(FileRuleMatched match)
|
private void IndexFileRuleMatched(FileRuleMatched match)
|
||||||
{
|
{
|
||||||
// todo (save result to the search engine)
|
// todo (save result to the search engine)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user