Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/main/java/org/graylog/inputs/jmx/JMXTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.graylog2.plugin.journal.RawMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.util.parsing.combinator.testing.Str;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
Expand Down Expand Up @@ -211,7 +212,9 @@ private void populateConfiguredAttributes() {
if (attribute.getKey() != null) {
mapKey += attribute.getKey();
}
configuredAttributes.put(mapKey,
String queryStr = queryBuilder.build().getObj();
queryStr = queryStr.replace("*", "");
configuredAttributes.put(queryStr + "+" + mapKey,
attribute);
}
queries.add(queryBuilder.build());
Expand All @@ -233,7 +236,7 @@ private void fetchData() {
for (Query query : queries) {
HashMultimap<ObjectName, Result> results = queryProcessor.processQuery(connection, query);
for (Map.Entry<ObjectName, Result> entry : results.entries()) {
processResult(event, entry);
processResult(event, entry, query);
}
}
publishToGLServer(event);
Expand Down Expand Up @@ -283,10 +286,12 @@ private String sanitize(String string) {


//process JMXTrans result object as per configured json
private void processResult(Map<String, Object> event, Map.Entry<ObjectName, Result> objectResult) {
private void processResult(Map<String, Object> event, Map.Entry<ObjectName, Result> objectResult, Query query) {
Result result = objectResult.getValue();
String attrName = result.getAttributeName();
Set<String> resultKeys = result.getValues().keySet();
String queryStr = query.getObj();
queryStr = queryStr.replace("*", "");

Map<String, String> objectProperties = new HashMap<>();

Expand All @@ -296,21 +301,14 @@ private void processResult(Map<String, Object> event, Map.Entry<ObjectName, Resu

for (String key : resultKeys) {
String label;
String attrKey = attrName;
if (attrName.equals(key)) {
if (configuredAttributes.containsKey(attrKey)) {
if (configuredAttributes.get(attrKey).getLabel() != null) {
label = formatLabel(objectProperties, configuredAttributes.get(attrKey).getLabel());
event.put("_" + label, result.getValues().get(key));
}
}
} else {
String attrKey = queryStr + "+" + attrName;
if (!attrName.equals(key)) {
attrKey += key;
if (configuredAttributes.containsKey(attrKey)) {
if (configuredAttributes.get(attrKey).getLabel() != null) {
label = formatLabel(objectProperties, configuredAttributes.get(attrKey).getLabel());
event.put("_" + label, result.getValues().get(key));
}
}
if (configuredAttributes.containsKey(attrKey)) {
if (configuredAttributes.get(attrKey).getLabel() != null) {
label = formatLabel(objectProperties, configuredAttributes.get(attrKey).getLabel());
event.put("_" + label, result.getValues().get(key));
}
}
}
Expand Down