Search in sources :

Example 1 with KibanaConfigHolderDto

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();
    }
}
Also used : KibanaConfigHolderDto(org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto) KibanaConfigEntryDto(org.n52.iceland.statistics.api.utils.dto.KibanaConfigEntryDto) ElasticsearchException(org.elasticsearch.ElasticsearchException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with KibanaConfigHolderDto

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();
}
Also used : KibanaConfigHolderDto(org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto) Builder(org.elasticsearch.common.settings.Settings.Builder) FileOutputStream(java.io.FileOutputStream) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 KibanaConfigHolderDto (org.n52.iceland.statistics.api.utils.dto.KibanaConfigHolderDto)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 Builder (org.elasticsearch.common.settings.Settings.Builder)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 KibanaConfigEntryDto (org.n52.iceland.statistics.api.utils.dto.KibanaConfigEntryDto)1