/** * Serialize the profile definition to a JSON string. * * @return The Profiler configuration serialized as a JSON string. * @throws JsonProcessingException */ public String toJSON() throws JsonProcessingException { return JSONUtils.INSTANCE.toJSON(this, true); } }
/** * Serialize a {@link ProfilerConfig} to a JSON string. * * @return The Profiler configuration serialized as a JSON string. * @throws JsonProcessingException */ public String toJSON() throws JsonProcessingException { return JSONUtils.INSTANCE.toJSON(this, true); } }
public String toJSON() throws JsonProcessingException { return JSONUtils.INSTANCE.toJSON(this, true); }
public String toJSON() throws JsonProcessingException { return JSONUtils.INSTANCE.toJSON(this, true); }
@Override public String convertToDatabaseColumn(Object savedSearches) { try { return JSONUtils.INSTANCE.toJSON(savedSearches, false); } catch (JsonProcessingException e) { LOG.error("Error converting value to JSON", e); } return null; }
/** * * Serializes the Enrichment configuration to JSON. * @param enrichmentConfig The Enrichment configuration to serialize to JSON. * @return The Enrichment configuration as JSON. */ private static String toJSON(SensorEnrichmentConfig enrichmentConfig) { try { return JSONUtils.INSTANCE.toJSON(enrichmentConfig, true); } catch (JsonProcessingException e) { throw new IllegalArgumentException("Unable to serialize enrichment config to JSON", e); } }
/** * Transforms a bean (aka POJO) to a JSONObject. */ public JSONObject toJSONObject(Object o) throws JsonProcessingException, ParseException { return (JSONObject) _parser.get().parse(toJSON(o, false)); }
/** * Serializes a configuration object to the raw JSON. * * @param object The configuration object to serialize * @return */ private static String toJSON(Object object) { if(object == null) { return null; } try { return JSONUtils.INSTANCE.toJSON(object, true); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
private void writeMap(File outFile, Map<String, Object> config) throws IOException { FileUtils.write(outFile, JSONUtils.INSTANCE.toJSON(config, true)); }
String createRaw = String .format("{ \"create\" : { \"_id\": \"%s\", \"_type\": \"%s\" } }", id, type); String outData = JSONUtils.INSTANCE.toJSON(inDoc.get("_source"), false); outRecs.add(createRaw); outRecs.add(outData);
@Override public Object apply(List<Object> args, Context context) throws ParseException { String config = (String) args.get(0); if(config == null) { return null; } SensorParserConfig configObj = (SensorParserConfig) PARSER.deserialize(config); FieldTransformer stellarTransformer = getStellarTransformer(configObj); Map<String, String> additionalTransforms = (Map<String, String>) args.get(1); if(additionalTransforms == null || additionalTransforms.isEmpty()) { return config; } for(Map.Entry<String, String> kv : additionalTransforms.entrySet()) { stellarTransformer.getConfig().put(kv.getKey(), kv.getValue()); } List<String> output = new ArrayList<>(); output.addAll(stellarTransformer.getConfig().keySet()); stellarTransformer.setOutput(output); try { return JSONUtils.INSTANCE.toJSON(configObj, true); } catch (JsonProcessingException e) { LOG.error("Unable to convert object to JSON: {}", configObj, e); return config; } }
@Override public void escalateAlerts(List<Map<String, Object>> alerts) throws RestException { String user = SecurityUtils.getCurrentUser(); String topic = environment.getProperty(KAFKA_TOPICS_ESCALATION_PROPERTY); Long now = clock.currentTimeMillis(); LOG.info("Escalating {} alert(s): user={}, topic={}, timestamp={}", alerts.size(), user, topic, now); try { for (Map<String, Object> alert : alerts) { // attribute the escalation to the current user alert.put(METRON_ESCALATION_USER_FIELD, user); alert.put(METRON_ESCALATION_TIMESTAMP_FIELD, now); // serialize the alert and push it to the escalation topic String message = JSONUtils.INSTANCE.toJSON(alert, false); kafkaService.produceMessage(topic, message); } } catch (JsonProcessingException e) { throw new RestException(e); } }
@Override public Object apply(List<Object> args, Context context) throws ParseException { String config = (String) args.get(0); if(config == null) { return null; } SensorParserConfig configObj = (SensorParserConfig) PARSER.deserialize(config); FieldTransformer stellarTransformer = getStellarTransformer(configObj); List<String> removals = (List<String>)args.get(1); if(removals == null || removals.isEmpty()) { return config; } for(String removal : removals) { stellarTransformer.getConfig().remove(removal); } List<String> output = new ArrayList<>(); output.addAll(stellarTransformer.getConfig().keySet()); stellarTransformer.setOutput(output); pruneEmptyStellarTransformers(configObj); try { return JSONUtils.INSTANCE.toJSON(configObj, true); } catch (JsonProcessingException e) { LOG.error("Unable to convert object to JSON: {}", configObj, e); return config; } }
return JSONUtils.INSTANCE.toJSON(configObj, true); } catch (JsonProcessingException e) { LOG.error("Unable to convert object to JSON: {}", configObj, e);
@Override protected void addRecords(List<Map<String, Object>> inputData, String index, String docType) throws IOException, ParseException { es.add(index, docType, inputData.stream().map(m -> { try { return JSONUtils.INSTANCE.toJSON(m, true); } catch (JsonProcessingException e) { throw new IllegalStateException(e.getMessage(), e); } } ).collect(Collectors.toList()) ); }
@Override protected void addTestData(String indexName, String sensorType, List<Map<String, Object>> docs) throws Exception { es.add(index, SENSOR_NAME , Iterables.transform(docs, m -> { try { return JSONUtils.INSTANCE.toJSON(m, true); } catch (JsonProcessingException e) { throw new IllegalStateException(e.getMessage(), e); } } ) ); }
@Override public Document update(Document update, Optional<String> index) throws IOException { for (Map.Entry<String, List<String>> kv : BACKING_STORE.entrySet()) { if (kv.getKey().startsWith(update.getSensorType())) { for (Iterator<String> it = kv.getValue().iterator(); it.hasNext(); ) { String doc = it.next(); Map<String, Object> docParsed = parse(doc); if (docParsed.getOrDefault(Constants.GUID, "").equals(update.getGuid())) { it.remove(); } } kv.getValue().add(JSONUtils.INSTANCE.toJSON(update.getDocument(), true)); } } return update; }
protected SearchResponse buildSearchResponse( SearchRequest searchRequest, QueryResponse solrResponse) { SearchResponse searchResponse = new SearchResponse(); SolrDocumentList solrDocumentList = solrResponse.getResults(); searchResponse.setTotal(solrDocumentList.getNumFound()); // search hits --> search results List<SearchResult> results = solrDocumentList.stream() .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, searchRequest.getFields(), accessConfig.getIndexSupplier())) .collect(Collectors.toList()); searchResponse.setResults(results); // handle facet fields List<String> facetFields = searchRequest.getFacetFields(); if (facetFields != null) { searchResponse.setFacetCounts(getFacetCounts(facetFields, solrResponse)); } if (LOG.isDebugEnabled()) { String response; try { response = JSONUtils.INSTANCE.toJSON(searchResponse, false); } catch (JsonProcessingException e) { response = e.getMessage(); } LOG.debug("Built search response; response={}", response); } return searchResponse; }
String broTemplateJson = JSONUtils.INSTANCE.toJSON(broTemplate, true); HttpEntity broEntity = new NStringEntity(broTemplateJson, ContentType.APPLICATION_JSON); Response response = lowLevelClient.performRequest("PUT", "/_template/bro_template", Collections.emptyMap(), broEntity); String snortTemplateJson = JSONUtils.INSTANCE.toJSON(snortTemplate, true); HttpEntity snortEntity = new NStringEntity(snortTemplateJson, ContentType.APPLICATION_JSON); response = lowLevelClient.performRequest("PUT", "/_template/snort_template", Collections.emptyMap(), snortEntity);
@Before public void setup() throws Exception { client = ElasticsearchClientFactory.create(globals()); retrieveDao = new ElasticsearchRetrieveLatestDao(client); writer = new ElasticsearchBulkDocumentWriter<>(client) .withRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); // add bro template JSONObject broTemplate = JSONUtils.INSTANCE.load(new File(broTemplatePath), JSONObject.class); String broTemplateJson = JSONUtils.INSTANCE.toJSON(broTemplate, true); HttpEntity broEntity = new NStringEntity(broTemplateJson, ContentType.APPLICATION_JSON); Response response = client .getLowLevelClient() .performRequest("PUT", "/_template/bro_template", Collections.emptyMap(), broEntity); assertThat(response.getStatusLine().getStatusCode(), CoreMatchers.equalTo(200)); }