mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: json-info: cleanup info/json/csv/opensearch, add logging, add some very basic instructions; add Kibana dashboards & docker-compose to bring it OS+Kibana up
This commit is contained in:
@@ -2,20 +2,15 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
from opensearchpy import OpenSearch # pip install opensearch-py
|
||||
from opensearchpy import OpenSearch # pip3 install opensearch-py
|
||||
|
||||
|
||||
def eprint(*args, **kwargs):
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
|
||||
# info = get_info_for_one_board(board, all_params)
|
||||
print(json.dumps({}, indent=4, sort_keys=True))
|
||||
|
||||
eprint("Hello")
|
||||
|
||||
# Read JSON from stdin
|
||||
# - should be array of objects
|
||||
# - should be an array of objects
|
||||
# - loop over array and index each obj into OS in to the passed index
|
||||
# read_from_stdin = sys.stdin.read()
|
||||
|
||||
@@ -23,8 +18,8 @@ json_object = json.load(sys.stdin)
|
||||
|
||||
eprint("Loaded {} objects from stdin...".format(len(json_object)))
|
||||
|
||||
host = '192.168.66.55'
|
||||
port = 31920
|
||||
host = '127.0.0.1'
|
||||
port = 9200
|
||||
|
||||
# Create the OpenSearch client.
|
||||
client = OpenSearch(hosts=[{'host': host, 'port': port}], http_compress=False, use_ssl=False)
|
||||
@@ -35,18 +30,21 @@ index_body = {'settings': {'index': {'number_of_shards': 1, 'number_of_replicas'
|
||||
|
||||
# Delete the index; remove old data.
|
||||
try:
|
||||
response = client.indices.delete(index=index_name)
|
||||
print('\nDeleting index:')
|
||||
print(response)
|
||||
delete_response = client.indices.delete(index=index_name)
|
||||
eprint('\nDeleting index...')
|
||||
# print(delete_response)
|
||||
except:
|
||||
eprint("Failed to delete index {}".format(index_name))
|
||||
|
||||
response = client.indices.create(index_name, body=index_body)
|
||||
print('\nCreating index:')
|
||||
print(response)
|
||||
eprint('\nCreating index...')
|
||||
response_create = client.indices.create(index_name, body=index_body)
|
||||
# print(response_create)
|
||||
|
||||
for obj in json_object:
|
||||
# print(obj)
|
||||
response = client.index(index=index_name, body=obj, refresh=True)
|
||||
print('\nAdding document:')
|
||||
print(response)
|
||||
response = client.index(index=index_name, body=obj)
|
||||
|
||||
eprint("\nRefreshing index...")
|
||||
client.indices.refresh(index=index_name)
|
||||
|
||||
eprint("\nDone.")
|
||||
|
||||
Reference in New Issue
Block a user