Skip to content

Instantly share code, notes, and snippets.

@higebu
Created March 4, 2013 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save higebu/5083311 to your computer and use it in GitHub Desktop.
Save higebu/5083311 to your computer and use it in GitHub Desktop.
Patch for Zabbix2.0.4 Java Gateway to monitoring java.lang.Double type attributes.
--- zabbix-2.0.4/src/zabbix_java/src/com/zabbix/gateway/JMXItemChecker.java 2012-12-08 20:09:15.000000000 +0900
+++ zabbix-2.0.4_new/src/zabbix_java/src/com/zabbix/gateway/JMXItemChecker.java 2013-01-23 15:24:07.000000000 +0900
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Vector;
+import java.math.BigDecimal;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
@@ -205,10 +206,18 @@
if (fieldNames.equals(""))
{
- if (isPrimitiveAttributeType(dataObject.getClass()))
- return dataObject.toString();
- else
+ if (isPrimitiveAttributeType(dataObject.getClass())) {
+ logger.trace("-------->>>> found dataObject value of a primitive type: {}", dataObject.toString());
+ try {
+ return new BigDecimal(dataObject.toString()).toPlainString();
+ } catch(Exception e) {
+ logger.trace("found dataObject value of a primitive type: {}", dataObject.toString());
+ return dataObject.toString();
+ }
+ }
+ else {
throw new ZabbixException("data object type is not primitive: %s" + dataObject.getClass());
+ }
}
if (dataObject instanceof CompositeData)
@@ -253,7 +262,13 @@
counter.put("{#JMXOBJ}", name);
counter.put("{#JMXATTR}", attrPath);
counter.put("{#JMXTYPE}", attribute.getClass().getName());
- counter.put("{#JMXVALUE}", attribute.toString());
+ logger.trace("-------->>>> found attribute value of a primitive type: {}", attribute.toString());
+ try {
+ counter.put("{#JMXVALUE}", new BigDecimal(attribute.toString()).toPlainString());
+ } catch(Exception e) {
+ counter.put("{#JMXVALUE}", attribute.toString());
+ }
+ logger.trace("-------->>>> put attribute value: {}", counter.get("{#JMXVALUE}"));
counters.put(counter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment