Add ElasticsearchClient.cs, Update FileEventMonitor.cs

This commit is contained in:
Namhyeon Go 2024-08-12 21:15:03 +09:00
parent e8c69d1489
commit c4740f7d61
2 changed files with 32 additions and 2 deletions

View 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);
}
}
}

View File

@ -171,7 +171,7 @@ namespace WelsonJS.Service
parent.Log($"YARA rule matched: {ruleName}, {filePath}, Offset {x.Offset}");
parent.DispatchServiceEvent("fileRuleMatched", new string[] { ruleName, filePath, x.Offset.ToString() });
IndexMatched(new FileRuleMatched
IndexFileRuleMatched(new FileRuleMatched
{
FilePath = filePath,
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)
}