List of usage examples for org.apache.commons.logging Log debug
void debug(Object message);
From source file:org.hrva.capture.LogTail.java
/** * Command-line program to tail a log and then push file to the HRT couch * DB.// w w w.j a v a 2 s.c om * <p>All this does is read properties and invoke run_main</p> * * @param args arguments */ public static void main(String[] args) { Log log = LogFactory.getLog(LogTail.class); File prop_file = new File("hrtail.properties"); Properties config = new Properties(); try { config.load(new FileInputStream(prop_file)); } catch (IOException ex) { log.warn("Can't find " + prop_file.getName(), ex); try { log.debug(prop_file.getCanonicalPath()); } catch (IOException ex1) { } } LogTail lt = new LogTail(config); try { lt.run_main(args); } catch (CmdLineException ex1) { log.fatal("Invalid Options", ex1); } catch (MalformedURLException ex2) { log.fatal("Invalid CouchDB URL", ex2); } catch (IOException ex3) { log.fatal(ex3); } }
From source file:org.hrva.capture.Reformat.java
/** * Command-line program to tail a log and then push file to the HRT couch * DB.//from ww w . j a va2s .com * <p>All this does is read properties and invoke run_main</p> * * @param args arguments */ public static void main(String[] args) { Log log = LogFactory.getLog(Reformat.class); File prop_file = new File("hrtail.properties"); Properties config = new Properties(); try { config.load(new FileInputStream(prop_file)); } catch (IOException ex) { log.warn("Can't find " + prop_file.getName(), ex); try { log.debug(prop_file.getCanonicalPath()); } catch (IOException ex1) { } } Reformat fmt = new Reformat(config); try { fmt.run_main(args); } catch (CmdLineException ex1) { log.fatal("Invalid Options", ex1); } catch (MalformedURLException ex2) { log.fatal("Invalid CouchDB URL", ex2); } catch (IOException ex3) { log.fatal(ex3); } }
From source file:org.hyperic.hq.plugin.mssql.MsSQLDetector.java
protected static void debug(Log _log, String msg) { if (_log.isDebugEnabled()) { _log.debug(msg.replaceAll("(-P,? ?)([^ ,]+)", "$1******").replaceAll("(pass[^=]*=)(\\w*)", "$1******")); }//from w w w . ja va2 s. co m }
From source file:org.hyperic.hq.plugin.netdevice.NetworkDeviceDetector.java
public List discoverServices(ConfigResponse serverConfig) throws PluginException { Log log = getLog(); List services = new ArrayList(); openSession(serverConfig);/* w w w. j av a 2s . c om*/ if (log.isDebugEnabled()) { log.debug("Using snmp config=" + serverConfig); } services.addAll(discoverInterfaces(serverConfig)); List extServices = SNMPDetector.discoverServices(this, serverConfig, this.session); services.addAll(extServices); closeSession(); return services; }
From source file:org.hyperic.hq.plugin.netdevice.NetworkDeviceDetector.java
protected List discoverInterfaces(ConfigResponse serverConfig) throws PluginException { Log log = getLog(); List services = new ArrayList(); String type = getServiceTypeName(SVC_NAME); if (!hasInterfaceService()) { log.debug("Skipping discovery of " + type); return services; }/*from ww w. java 2s.co m*/ String[] keys = getCustomPropertiesSchema(type).getOptionNames(); HashMap cpropColumns = new HashMap(); for (int i = 0; i < keys.length; i++) { String key = keys[i]; if (Arrays.binarySearch(FILTER_PROPS, key) != -1) { continue; } try { cpropColumns.put(key, getIfColumn(key)); } catch (PluginException e) { log.warn("Error getting '" + key + "': " + e.getMessage()); } } String columnName = serverConfig.getValue(PROP_IF_IX); if (columnName == null) { columnName = IF_DESCR; } Map interfaces = getIfColumn(columnName); log.debug("Found " + interfaces.size() + " interfaces using " + columnName); String descrColumn = columnName.equals(IF_DESCR) ? IF_NAME : IF_DESCR; Map descriptions; try { descriptions = getIfColumn(descrColumn); } catch (PluginException e) { descriptions = new HashMap(); String msg = "Error getting descriptions from " + descrColumn + ": " + e; log.warn(msg); } List ip_if_ix = getColumn(IP_IF_IX); HashMap ips = new HashMap(); HashMap netmasks = new HashMap(); final String IF_IX_OID = SNMPClient.getOID(IP_IF_IX) + "."; final String NETMASK_OID = SNMPClient.getOID(IP_NETMASK) + "."; String ip, netmask; for (int i = 0; i < ip_if_ix.size(); i++) { SNMPValue value = (SNMPValue) ip_if_ix.get(i); String oid = value.getOID(); String ix = value.toString(); if (oid.startsWith(IF_IX_OID)) { ip = oid.substring(IF_IX_OID.length()); ips.put(ix, ip); try { netmask = this.session.getSingleValue(NETMASK_OID + ip).toString(); netmasks.put(ix, netmask); } catch (SNMPException e) { log.debug("Failed to get netmask for " + ip); } } } for (Iterator it = interfaces.entrySet().iterator(); it.hasNext();) { ConfigResponse config = new ConfigResponse(); ConfigResponse cprops = new ConfigResponse(); Map.Entry entry = (Map.Entry) it.next(); String ix = (String) entry.getKey(); String name = (String) entry.getValue(); String mac = null; ServiceResource service = createServiceResource(SVC_NAME); config.setValue(PROP_IF, name); config.setValue(PROP_IF_IX, columnName); service.setProductConfig(config); // required to auto-enable metric service.setMeasurementConfig(); for (int j = 0; j < keys.length; j++) { String key = keys[j]; Map data = (Map) cpropColumns.get(key); if (data == null) { continue; } String val = (String) data.get(ix); if (val == null) { continue; } cprops.setValue(key, val); if (key.equals(IF_MAC)) { mac = val; } } ip = (String) ips.get(ix); netmask = (String) netmasks.get(ix); if (ip == null) { ip = "0.0.0.0"; } if (netmask == null) { netmask = "0.0.0.0"; } cprops.setValue(PROP_IP, ip); cprops.setValue(PROP_NETMASK, netmask); service.setCustomProperties(cprops); // Might be more than 1 interface w/ the same name, // so append the mac address to make it unique... name = name + " " + SVC_NAME; if ((mac != null) && !mac.equals("0:0:0:0:0:0")) { name += " (" + mac + ")"; } service.setServiceName(name); Object obj = descriptions.get(ix); if (obj != null) { service.setDescription(obj.toString()); } services.add(service); } return services; }
From source file:org.hyperic.hq.plugin.netdevice.NetworkDeviceDetector.java
public List getServerResources(ConfigResponse config) { Log log = getLog(); if (log.isDebugEnabled()) { log.debug("Testing snmp config=" + config); }//from w w w.ja va 2 s .co m if (config.getValue(SNMPClient.PROP_IP) == null) { log.debug("snmp config incomplete, defering server creation"); return null; } try { getSession(config).getSingleValue("sysName"); } catch (Exception e) { // Wait till we have valid snmp config at the platform level... log.debug("snmp config invalid, defering server creation"); return null; } log.debug("snmp config valid, creating server"); return super.getServerResources(config); }
From source file:org.hyperic.hq.plugin.netdevice.NetworkDevicePlatformDetector.java
public PlatformResource getPlatformResource(ConfigResponse config) throws PluginException { String platformIp = config.getValue(ProductPlugin.PROP_PLATFORM_IP); // For command-line -DsnmpIp=x.x.x.x usage... platformIp = getIpProp(SNMPClient.PROP_IP, platformIp, platformIp); String defaultVersion = getIpProp(SNMPClient.PROP_VERSION, platformIp, SNMPClient.VALID_VERSIONS[1]); // v2c String fallbackVersion = SNMPClient.VALID_VERSIONS[0]; // v1 PlatformResource platform = super.getPlatformResource(config); Log log = getLog(); ConfigResponse metricConfig;//from w w w. j a v a 2s . com boolean hasConfig = config.getValue(SNMPClient.PROP_IP) != null; if (hasConfig) { // We've already been here... metricConfig = config; if (log.isDebugEnabled()) { log.debug("Using approved snmp config=" + metricConfig); } } else if (this.autoDefaults) { // Platform was just created, attempt to auto-configure... metricConfig = new ConfigResponse(); metricConfig.setValue(SNMPClient.PROP_IP, platformIp); metricConfig.setValue(SNMPClient.PROP_VERSION, defaultVersion); metricConfig.setValue(SNMPClient.PROP_COMMUNITY, getIpProp(SNMPClient.PROP_COMMUNITY, platformIp, SNMPClient.DEFAULT_COMMUNITY)); metricConfig.setValue(SNMPClient.PROP_PORT, getIpProp(SNMPClient.PROP_PORT, platformIp, SNMPClient.DEFAULT_PORT_STRING)); metricConfig.setValue(NetworkDeviceDetector.PROP_IF_IX, getIpProp(NetworkDeviceDetector.PROP_IF_IX, platformIp, NetworkDeviceDetector.IF_DESCR)); if (log.isDebugEnabled()) { log.debug("Using default snmp config=" + metricConfig); } } else { if (log.isDebugEnabled()) { log.debug("Need user input for snmp config=" + config); } return platform; } ConfigResponse cprops = new ConfigResponse(); SNMPSession session; if ((session = getSession(metricConfig)) == null) { return platform; } try { session.getSingleValue("sysName"); } catch (SNMPException e) { getLog().debug("Unable to connect using " + defaultVersion + ", trying version " + fallbackVersion); metricConfig.setValue(SNMPClient.PROP_VERSION, fallbackVersion); if ((session = getSession(metricConfig)) == null) { return platform; } } String[] keys = getCustomPropertiesSchema().getOptionNames(); for (int i = 0; i < keys.length; i++) { String key = keys[i]; if (Character.isUpperCase(key.charAt(0))) { continue; // Not a MIB name } String val = getString(session, key); if (val == null) { log.debug("'" + key + "'==null"); continue; } cprops.setValue(key, val); } if (!hasConfig) { // Should only happen when the platform is created... config.merge(metricConfig, false); platform.setProductConfig(config); platform.setMeasurementConfig(new ConfigResponse()); log.debug("Setting measurement config=" + metricConfig); } String description = getString(session, "sysDescr"); if (description != null) { platform.setDescription(description); boolean hasVersionCprop = getCustomPropertiesSchema().getOption(PROP_VERSION) != null; if (hasVersionCprop) { // This works for Cisco IOS at least... StringTokenizer tok = new StringTokenizer(description, " ,"); while (tok.hasMoreTokens()) { String s = tok.nextToken(); if (s.equalsIgnoreCase(PROP_VERSION) && tok.hasMoreTokens()) { String version = tok.nextToken(); cprops.setValue(PROP_VERSION, version); break; } } } } platform.setCustomProperties(cprops); return platform; }
From source file:org.hyperic.hq.ui.action.admin.user.RegisterAction.java
/** * Create the user with the attributes specified in the given * <code>NewForm</code> and save it into the session attribute * <code>Constants.USER_ATTR</code>. *//*w w w .j a v a2 s .c o m*/ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final Log log = LogFactory.getLog(RegisterAction.class.getName()); final boolean debug = log.isDebugEnabled(); Integer sessionId = RequestUtils.getSessionId(request); EditForm userForm = (EditForm) form; HttpSession session = request.getSession(false); ActionForward forward = checkSubmit(request, mapping, form); if (forward != null) { return forward; } //get the spiderSubjectValue of the user to be deleated. ServletContext ctx = getServlet().getServletContext(); WebUser webUser = RequestUtils.getWebUser(session); // password was saved off when the user logged in String password = (String) session.getAttribute(Constants.PASSWORD_SES_ATTR); session.removeAttribute(Constants.PASSWORD_SES_ATTR); // use the overlord to register the subject, and don't add // a principal if (debug) log.debug("registering subject [" + webUser.getUsername() + "]"); Integer authzSubjectId = userForm.getId(); AuthzSubject target = authzSubjectManager.findSubjectById(authzSubjectId); authzBoss.updateSubject(sessionId, target, Boolean.TRUE, HQConstants.ApplicationName, userForm.getDepartment(), userForm.getEmailAddress(), userForm.getFirstName(), userForm.getLastName(), userForm.getPhoneNumber(), userForm.getSmsAddress(), null); // nuke the temporary bizapp session and establish a new // one for this subject.. must be done before pulling the // new subject in order to do it with his own credentials // TODO need to make sure this is valid sessionManager.invalidate(sessionId); sessionId = sessionManager.put(authzSubjectManager.findSubjectById(authzSubjectId)); if (debug) log.debug("finding subject [" + webUser.getUsername() + "]"); // the new user has no prefs, but we still want to pick up // the defaults ConfigResponse preferences = (ConfigResponse) ctx.getAttribute(Constants.DEF_USER_PREFS); // look up the user's permissions if (debug) log.debug("getting all operations"); Map<String, Boolean> userOpsMap = new HashMap<String, Boolean>(); List<Operation> userOps = authzBoss.getAllOperations(sessionId); // TODO come back to this and see why this is done... for (Operation op : userOps) { userOpsMap.put(op.getName(), Boolean.TRUE); } // we also need to create up a new web user webUser = new WebUser(target, sessionId, preferences, false); session.setAttribute(Constants.WEBUSER_SES_ATTR, webUser); session.setAttribute(Constants.USER_OPERATIONS_ATTR, userOpsMap); Map<String, Object> parms = new HashMap<String, Object>(1); parms.put(Constants.USER_PARAM, target.getId()); return returnSuccess(request, mapping, parms, false); }
From source file:org.hyperic.hq.ui.action.resource.common.monitor.alerts.config.RemoveDefinitionAction.java
/** * removes alert definitions// www . j a va 2 s .co m */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Log log = LogFactory.getLog(RemoveDefinitionAction.class.getName()); RemoveDefinitionForm rdForm = (RemoveDefinitionForm) form; AppdefEntityID adeId; Map<String, Object> params = new HashMap<String, Object>(); if (rdForm.getRid() != null) { adeId = new AppdefEntityID(rdForm.getType().intValue(), rdForm.getRid()); params.put(Constants.ENTITY_ID_PARAM, adeId.getAppdefKey()); log.debug("###eid = " + adeId.getAppdefKey()); } else { adeId = new AppdefEntityTypeID(rdForm.getAetid()); params.put(Constants.APPDEF_RES_TYPE_ID, adeId.getAppdefKey()); log.debug("###aetid = " + adeId.getAppdefKey()); } Integer[] defs = rdForm.getDefinitions(); if (defs == null || defs.length == 0) { return returnSuccess(request, mapping, params); } Integer sessionId = RequestUtils.getSessionId(request); boolean enable = false; if (rdForm.getSetActiveInactive().equals("y")) { enable = rdForm.getActive().intValue() == 1; if (adeId.isGroup()) { GalertDef[] defPojos = new GalertDef[defs.length]; for (int i = 0; i < defs.length; i++) { defPojos[i] = galertBoss.findDefinition(sessionId.intValue(), defs[i]); } galertBoss.enable(sessionId.intValue(), defPojos, enable); } else { eventsBoss.activateAlertDefinitions(sessionId.intValue(), defs, enable); } RequestUtils.setConfirmation(request, "alerts.config.confirm.activeInactive"); return returnSuccess(request, mapping, params); } if (rdForm.isDeleteClicked()) { if (rdForm.getAetid() != null) { for (Integer def : defs) { eventsBoss.deleteAlertDefinitions(sessionId.intValue(), new Integer[] { def }); } params.put(Constants.APPDEF_RES_TYPE_ID, rdForm.getAetid()); } else { if (adeId.isGroup()) { galertBoss.markDefsDeleted(sessionId.intValue(), defs); } else { eventsBoss.deleteAlertDefinitions(sessionId.intValue(), defs); } } RequestUtils.setConfirmation(request, "alerts.config.confirm.deleteConfig"); } else { // Delete the alerts for the definitions if (adeId.isGroup()) { // XXX - implement alert deletion in gBoss } else { eventsBoss.deleteAlertsForDefinitions(sessionId.intValue(), defs); } RequestUtils.setConfirmation(request, "alerts.config.confirm.deleteAlerts"); } return returnSuccess(request, mapping, params); }
From source file:org.hyperic.hq.ui.action.resource.service.inventory.ViewServiceAction.java
/** * Retrieve this data and store it in the <code>ServerForm</code>: * /*from w w w . j ava 2s. c o m*/ */ public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Log log = LogFactory.getLog(ViewServiceAction.class.getName()); try { ServiceValue service = (ServiceValue) RequestUtils.getResource(request); Integer sessionId = RequestUtils.getSessionId(request); AppdefEntityID entityId = service.getEntityId(); PageControl pcg = RequestUtils.getPageControl(request, "psg", "png", "sog", "scg"); List<AppdefGroupValue> groups = appdefBoss.findAllGroupsMemberInclusive(sessionId.intValue(), pcg, service.getEntityId()); // check to see if this thing is a platform service if (service.getServer().getServerType().getVirtual()) { // find the platform resource and add it to the request scope try { PlatformValue pv = appdefBoss.findPlatformByDependentID(sessionId.intValue(), entityId); request.setAttribute(Constants.PARENT_RESOURCE_ATTR, pv); } catch (PermissionException pe) { // TODO Would like to able to fall back and grab the name // through other means // which isn't easily done right now. Only thing we should // prevent // in the case of an error is plain text instead of a link. log.error("insufficient permissions for parent platform ", pe); RequestUtils.setError(request, "resource.service.inventory.error.ViewParentPlatformPermission"); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, new ArrayList()); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(0)); request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS, new ArrayList()); request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS_COUNT, new Integer(0)); return null; } } request.setAttribute(Constants.ALL_RESGRPS_ATTR, groups); if (service == null) { RequestUtils.setError(request, "resource.service.error.ServiceNotFound"); return null; } // create and initialize the remove resource groups form RemoveResourceGroupsForm rmGroupsForm = new RemoveResourceGroupsForm(); rmGroupsForm.setRid(service.getId()); rmGroupsForm.setType(new Integer(service.getEntityId().getType())); int psg = RequestUtils.getPageSize(request, "psg"); rmGroupsForm.setPsg(new Integer(psg)); request.setAttribute(Constants.RESOURCE_REMOVE_GROUPS_MEMBERS_FORM_ATTR, rmGroupsForm); log.debug("AppdefEntityID = " + entityId.toString()); ConfigSchema config = new ConfigSchema(); ConfigResponse oldResponse = new ConfigResponse(); boolean editConfig = false; try { oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(), ProductPlugin.TYPE_PRODUCT, entityId, false); config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_PRODUCT, oldResponse); editConfig = true; } catch (ConfigFetchException e) { log.warn("Managed Exception ConfigFetchException caught " + e.toString()); } catch (PluginNotFoundException e) { log.warn("Managed Exception PluginNotFoundException caught " + e.toString()); } List<ConfigValues> uiProductOptions = ActionUtils.getConfigValues(config, oldResponse); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, uiProductOptions); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(uiProductOptions.size())); config = new ConfigSchema(); oldResponse = new ConfigResponse(); try { oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(), ProductPlugin.TYPE_MEASUREMENT, entityId, false); config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_MEASUREMENT, oldResponse); } catch (ConfigFetchException e) { // do nothing } catch (PluginNotFoundException e) { // do nothing } setUIOptions(service, request, config, oldResponse); config = new ConfigSchema(); oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(), ProductPlugin.TYPE_CONTROL, entityId, false); try { config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_CONTROL, oldResponse); } catch (PluginNotFoundException e) { // do nothing } List<ConfigValues> uiControlOptions = ActionUtils.getConfigValues(config, oldResponse); request.setAttribute(Constants.CONTROL_CONFIG_OPTIONS, uiControlOptions); request.setAttribute(Constants.CONTROL_CONFIG_OPTIONS_COUNT, new Integer(uiControlOptions.size())); request.setAttribute(Constants.AUTO_INVENTORY, new Boolean(service.getServer().getRuntimeAutodiscovery())); if (!editConfig) RequestUtils.setError(request, "resource.common.inventory.error.serverConfigNotSet", "configServer"); request.setAttribute(Constants.EDIT_CONFIG, new Boolean(editConfig)); setConfigModifier(request, entityId); return null; } catch (ApplicationException e) { log.error("unable to retrieve configuration properties ", e); RequestUtils.setError(request, "resource.common.inventory.error.configRetrieveError"); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, new ArrayList()); request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(0)); request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS, new ArrayList()); request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS_COUNT, new Integer(0)); return null; } }