Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
FMS_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bashar.hussein
FMS_Project
Commits
c062e29f
Commit
c062e29f
authored
Jul 07, 2023
by
Bashar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configured ElasticSearch
parent
cef61db6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
13 deletions
+92
-13
elasticConfig.java
...a/com/example/Processing/configuration/elasticConfig.java
+64
-11
mappings.json
...ipeline/Processing/src/main/resources/utils/mappings.json
+28
-2
No files found.
SNMP_Pipeline/Processing/src/main/java/com/example/Processing/configuration/elasticConfig.java
View file @
c062e29f
...
...
@@ -2,6 +2,8 @@ package com.example.Processing.configuration;
import
co.elastic.clients.elasticsearch.ElasticsearchClient
;
import
co.elastic.clients.elasticsearch.cluster.PutComponentTemplateRequest
;
import
co.elastic.clients.elasticsearch.core.BulkRequest
;
import
co.elastic.clients.elasticsearch.core.BulkResponse
;
import
co.elastic.clients.elasticsearch.ilm.IlmPolicy
;
import
co.elastic.clients.elasticsearch.ilm.PutLifecycleRequest
;
import
co.elastic.clients.elasticsearch.indices.CreateDataStreamRequest
;
...
...
@@ -10,27 +12,41 @@ import co.elastic.clients.elasticsearch.indices.PutIndexTemplateRequest;
import
co.elastic.clients.json.jackson.JacksonJsonpMapper
;
import
co.elastic.clients.transport.ElasticsearchTransport
;
import
co.elastic.clients.transport.rest_client.RestClientTransport
;
import
com.example.Processing.entities.ProcessedTrap
;
import
com.example.Processing.entities.SeverityLevel
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
jakarta.annotation.PostConstruct
;
import
lombok.Getter
;
import
org.apache.http.HttpHost
;
import
org.elasticsearch.client.RestClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.elasticsearch.core.geo.GeoPoint
;
import
org.springframework.stereotype.Component
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Timer
;
import
java.util.TimerTask
;
@Configuration
@Component
@Getter
public
class
elasticConfig
{
@Value
(
"${workingPath}"
)
private
String
workingPath
;
private
RestClient
restClient
=
RestClient
.
builder
(
new
HttpHost
(
"
localhost
"
,
9200
)).
build
();
new
HttpHost
(
"
192.168.25.254
"
,
9200
)).
build
();
// Create the transport with a Jackson mapper
private
ElasticsearchTransport
transport
=
new
RestClientTransport
(
private
ElasticsearchTransport
transport
=
new
RestClientTransport
(
restClient
,
new
JacksonJsonpMapper
());
// And create the API client
private
final
ElasticsearchClient
elasticClient
=
new
ElasticsearchClient
(
transport
);
private
ElasticsearchClient
elasticClient
=
new
ElasticsearchClient
(
transport
);
public
void
addPolicy
(
String
path
,
String
name
){
FileReader
r
=
null
;
try
{
...
...
@@ -85,20 +101,57 @@ public class elasticConfig {
}
}
public
void
addDataStream
(
String
name
){
CreateDataStreamRequest
createDataStreamRequest
=
new
CreateDataStreamRequest
.
Builder
()
.
name
(
name
).
build
();
try
{
elasticClient
.
indices
().
createDataStream
(
createDataStreamRequest
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
Exception
e
)
{
return
;
// throw new RuntimeException(e);
}
}
@PostConstruct
public
void
ElasticDataStreamConfig
()
throws
JsonProcessingException
,
FileNotFoundException
{
addPolicy
(
"src/main/resources/utils/policy.json"
,
"Bashar"
);
addComponent
(
"src/main/resources/utils/settings.json"
,
"bashar_setting"
);
addComponent
(
"src/main/resources/utils/mappings.json"
,
"bashar_mapping"
);
addIndexTemplate
(
"src/main/resources/utils/index_template.json"
,
"bashar_template"
);
addDataStream
(
"bashar-data-stream-2"
);
String
currentDirectory
=
System
.
getProperty
(
"user.dir"
);
System
.
out
.
println
(
"Current working directory is: "
+
currentDirectory
);
addPolicy
(
workingPath
+
"/policy.json"
,
"Traps_Policy"
);
addComponent
(
workingPath
+
"/settings.json"
,
"traps_setting"
);
addComponent
(
workingPath
+
"/mappings.json"
,
"traps_mapping"
);
addIndexTemplate
(
workingPath
+
"/index_template.json"
,
"traps_template"
);
addDataStream
(
"traps-data-stream"
);
//Bulk Schedule Send
}
public
void
addDoc
(
List
<
ProcessedTrap
>
jsons
){
BulkRequest
.
Builder
br
=
new
BulkRequest
.
Builder
();
for
(
ProcessedTrap
s:
jsons
){
br
.
operations
(
op
->
op
.
create
(
cr
->
cr
.
index
(
"traps-data-stream"
).
document
(
s
))
);
}
BulkResponse
result
=
null
;
System
.
out
.
println
(
"Hey I am here"
);
try
{
System
.
out
.
println
(
"Hey I am here"
);
result
=
elasticClient
.
bulk
(
br
.
build
());
System
.
out
.
println
(
result
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
);
throw
new
RuntimeException
(
e
);
}
/*
Reader input = new StringReader(json);
IndexRequest<JsonData> request = IndexRequest.of(i -> i
.index("bashar-data-stream-2")
.withJson(input)
);
IndexResponse response = null;
try {
response = elasticClient.index(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("Indexed with version " + response.version());*/
}
}
SNMP_Pipeline/Processing/src/main/resources/utils/mappings.json
View file @
c062e29f
...
...
@@ -5,8 +5,34 @@
"type"
:
"date"
,
"format"
:
"date_optional_time||epoch_millis"
},
"message"
:
{
"type"
:
"wildcard"
"enterprise"
:
{
"type"
:
"text"
},
"agentAddress"
:
{
"type"
:
"text"
},
"genericTrap"
:
{
"type"
:
"long"
},
"specificTrap"
:
{
"type"
:
"long"
},
"severity"
:
{
"type"
:
"text"
},
"variableBindings"
:
{
"type"
:
"nested"
,
"properties"
:
{
"oid"
:
{
"type"
:
"keyword"
},
"value"
:
{
"type"
:
"text"
}
}
},
"location"
:
{
"type"
:
"geo_point"
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment