use of org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto in project arctic-sea by 52North.
the class KibanaImporter method importJson.
public void importJson(String jsonString) throws JsonParseException, JsonMappingException, IOException {
Objects.requireNonNull(jsonString);
// delete .kibana index
try {
client.admin().indices().prepareDelete(kibanaIndexName).get();
} catch (ElasticsearchException ex) {
LOG.debug("Tried to delete kibana index " + kibanaIndexName + " but it is not exists", ex);
}
ObjectMapper mapper = new ObjectMapper();
KibanaConfigHolderDto holder = mapper.readValue(jsonString, KibanaConfigHolderDto.class);
for (KibanaConfigEntryDto dto : holder.getEntries()) {
processDto(dto);
LOG.debug("Importing {}", dto);
client.prepareIndex(kibanaIndexName, dto.getType(), dto.getId()).setSource(dto.getSource()).get();
}
}
use of org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto in project arctic-sea by 52North.
the class KibanaExporter method main.
// CHECKSTYLE:OFF
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.printf("Usage: java KibanaExporter.jar %s %s%n", "localhost:9300", "my-cluster-name");
System.exit(0);
}
if (!args[0].contains(":")) {
throw new IllegalArgumentException(String.format("%s not a valid format. Expected <hostname>:<port>.", args[0]));
}
// set ES address
String[] split = args[0].split(":");
InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getByName(split[0]), Integer.parseInt(split[1], 10));
// set cluster name
Builder tcSettings = Settings.settingsBuilder();
tcSettings.put("cluster.name", args[1]);
System.out.println("Connection to " + args[1]);
client = TransportClient.builder().settings(tcSettings).build();
client.addTransportAddress(address);
// search index pattern for needle
searchIndexPattern();
KibanaConfigHolderDto holder = new KibanaConfigHolderDto();
System.out.println("Reading .kibana index");
SearchResponse resp = client.prepareSearch(".kibana").setSize(1000).get();
Arrays.asList(resp.getHits().getHits()).stream().map(KibanaExporter::parseSearchHit).forEach(holder::add);
System.out.println("Reading finished");
ObjectMapper mapper = new ObjectMapper();
// we love pretty things
mapper.enable(SerializationFeature.INDENT_OUTPUT);
File f = new File("kibana_config.json");
try (FileOutputStream out = new FileOutputStream(f, false)) {
mapper.writeValue(out, holder);
}
System.out.println("File outputted to: " + f.getAbsolutePath());
client.close();
}
Aggregations