Back to index

munin  2.0.1
Config.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.util.HashMap;
00004 import java.util.Map;
00005 
00006 import javax.management.remote.JMXConnector;
00007 
00008 public class Config {
00009 
00010        private static final String IP_PARAM = "ip";
00011        private static final String PORT_PARAM = "port";
00012        private static final String CATEGORY_PARAM = "category";
00013        private static final String USERNAME_PARAM = "username";
00014        private static final String PASSWORD_PARAM = "password";
00015 
00016        private final String ip;
00017        private final String port;
00018        private final String category;
00019        private final String username;
00020        private final String password;
00021        private final String prefix;
00022 
00023        Config(final String prefix) {
00024               ip = System.getenv(IP_PARAM);
00025               port = System.getenv(PORT_PARAM);
00026               String categoryEnv = System.getenv(CATEGORY_PARAM);
00027               username = System.getenv(USERNAME_PARAM);
00028               password = System.getenv(PASSWORD_PARAM);
00029 
00030               if (ip == null || port == null) {
00031                      String message = "The following parameters were not configured:"
00032                                    + (ip == null ? " ip" : "")
00033                                    + (port == null ? " port" : "");
00034                      throw new IllegalStateException(message);
00035               }
00036               if (categoryEnv == null) {
00037                      category = "jvm";
00038               } else {
00039                      category = categoryEnv;
00040               }
00041               if (prefix == null || prefix.length() == 0) {
00042                      this.prefix = "jmx"; 
00043               } else {
00044                      this.prefix = prefix;
00045               }
00046        }
00047 
00048        public String getIp() {
00049               return ip;
00050        }
00051 
00052        public String getPort() {
00053               return port;
00054        }
00055 
00056        public String getCategory() {
00057               return category;
00058        }
00059 
00060        public String getUsername() {
00061               return username;
00062        }
00063 
00064        public String getPassword() {
00065               return password;
00066        }
00067        
00068        public String getPrefix() {
00069               return prefix;
00070        }
00071        
00072        public boolean isDirtyConfg() {
00073               return System.getenv("MUNIN_CAP_DIRTYCONFIG") != null;
00074        }
00075 
00076        public Map<String, Object> getConnectionCredentials() {
00077 
00078               Map<String, Object> credentials = null;
00079 
00080               if (username == null || password == null) {
00081                      return null;
00082               }
00083 
00084               credentials = new HashMap<String, Object>();
00085 
00086               credentials.put(JMXConnector.CREDENTIALS, new String[] { username,
00087                             password });
00088               return credentials;
00089        }
00090 
00091 }