-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Davide Arcuri
committed
Sep 11, 2024
1 parent
25b1a17
commit 8e4188e
Showing
5 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
from elasticsearch import Elasticsearch | ||
from elasticsearch_dsl import Search | ||
|
||
from orochi.website.defaults import RESULT_STATUS_ERROR, RESULT_STATUS_SUCCESS | ||
from orochi.website.models import Result, Value | ||
from orochi.ya.models import Rule | ||
|
||
es_client = Elasticsearch([os.environ["ELASTICSEARCH_URL"]]) | ||
|
||
rules = Rule.objects.filter(rule__isnull=True) | ||
for rule in rules: | ||
try: | ||
with open(rule.path, "rb") as f: | ||
rule.rule = f.read().decode("utf8", "replace")[:65000] | ||
rule.save() | ||
except Exception as e: | ||
print(e) | ||
|
||
|
||
results = Result.objects.filter(result__in=[RESULT_STATUS_SUCCESS, RESULT_STATUS_ERROR]) | ||
for result in results: | ||
if values := Value.objects.filter(result=result): | ||
continue | ||
s = Search( | ||
using=es_client, index=f"{result.dump.index}_{result.plugin.name.lower()}" | ||
) | ||
vals = s.execute() | ||
info = [hit.to_dict() for hit in vals if hit.meta.index.split("_")[0] != ".kibana"] | ||
values = [] | ||
for item in info: | ||
tmp = { | ||
k: v | ||
for k, v in item.items() | ||
if k | ||
not in [ | ||
"orochi_createdAt", | ||
"orochi_os", | ||
"orochi_plugin", | ||
"down_path", | ||
] | ||
} | ||
values.append(Value(result=result, value=tmp)) | ||
Value.objects.bulk_create(values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
1 - start old elastic service | ||
docker compose --profile migration up -d es01 | ||
|
||
2 - add ELASTICSEARCH_URL environment varible | ||
export ELASTICSEARCH_URL=http://es01:9200 | ||
|
||
3 - install elasticsearch python dependencies | ||
pip install elasticsearch elasticsearch_dsl | ||
|
||
4 - open python terminal | ||
python manage.py shell | ||
|
||
5 - copy and execute code from utils > elk_migrate.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters