/** * Gets the fixed file name. * * @param oldFile the old file * @return the fixed file name */ protected String getFixedFileName(String oldFile) { return AlphaNumeric.parseAndReplace(oldFile, '_'); }
public static String computePhysAddrForRRD(String physaddr) { String physAddrForRRD = null; if (physaddr != null && !physaddr.equals("")) { String parsedPhysAddr = AlphaNumeric.parseAndTrim(physaddr); if (parsedPhysAddr.length() == 12) { physAddrForRRD = parsedPhysAddr; } } return physAddrForRRD; }
/** * Any character in the passed string which does not match one of the * following values is replaced by the specified replacement character. * * Ascii chars: 0 - 9 (Decimal 48 - 57) A - Z (Decimal 65 - 90) a - z * (Decimal 97 - 122) * * For example: 'Ethernet 10/100' is converted to 'Ethernet_10_100' * * @param str * string to be converted * @param replacement * replacement character * @return Converted value which can be used in a file name. */ public static String parseAndReplace(String str, char replacement) { return parseAndReplaceExcept(str, replacement, new Character(replacement).toString()); }
label = AlphaNumeric.parseAndReplace(name, '_'); } else if (descr != null) { label = AlphaNumeric.parseAndReplace(descr, '_'); } else { throw new IllegalArgumentException("Both name and descr are null, but at least one cannot be."); physAddr = AlphaNumeric.parseAndTrim(physAddr); if (physAddr.length() == 12) { label = label + "-" + physAddr;
label = AlphaNumeric.parseAndReplace(name, '_'); } else if (descr != null) { label = AlphaNumeric.parseAndReplace(descr, '_'); } else { throw new IllegalArgumentException("Both name and descr are null, but at least one cannot be."); physAddr = AlphaNumeric.parseAndTrim(physAddr); if (physAddr.length() == 12) { label = label + "-" + physAddr;
/** * This method removes characters from an object name that are * potentially illegal in a file or directory name, returning a * name that is appropriate for use with the storeByGroup persistence * method. * * @param objectName * @return */ private static String fixGroupName(String objectName) { if (objectName == null) { return "NULL"; } return AlphaNumeric.parseAndReplace(objectName, '_'); }
/** * <p>computePhysAddrForRRD</p> * * @return a {@link java.lang.String} object. */ public String computePhysAddrForRRD() { /* * In order to assure the uniqueness of the RRD file names we now * append the MAC/physical address to the end of label if it is * available. */ String physAddrForRRD = null; if (getPhysAddr() != null) { String parsedPhysAddr = AlphaNumeric.parseAndTrim(getPhysAddr()); if (parsedPhysAddr.length() == 12) { physAddrForRRD = parsedPhysAddr; } else { LOG.debug("physAddrForRRD: physical address len is NOT 12, physAddr={}", parsedPhysAddr); } } LOG.debug("computed physAddr for {} to be {}", this, physAddrForRRD); return physAddrForRRD; }
String getAliasDir(String ifAlias, String ifAliasComment) { if (ifAlias != null) { if (ifAliasComment != null) { int si = ifAlias.indexOf(ifAliasComment); if (si > -1) { ifAlias = ifAlias.substring(0, si).trim(); } } if (ifAlias != null) { ifAlias = AlphaNumeric.parseAndReplaceExcept(ifAlias, AbstractSnmpCollector.nonAnRepl, AbstractSnmpCollector.AnReplEx); } } logAlias(ifAlias); return ifAlias; }
/** * This method removes characters from an object name that are * potentially illegal in a file or directory name, returning a * name that is appropriate for use with the storeByGroup persistence * method. * * @param objectName * @return */ private static String fixGroupName(String objectName) { if (objectName == null) { return "NULL"; } return AlphaNumeric.parseAndReplace(objectName, '_'); }
public static String computeNameForRRD(String ifname, String ifdescr) { String firstChoice = PREFER_IFDESCR ? ifdescr : ifname; String secondChoice = PREFER_IFDESCR ? ifname : ifdescr; String label = null; if (firstChoice != null && !"".equals(firstChoice)) { label = DONT_SANITIZE_IFNAME ? firstChoice : AlphaNumeric.parseAndReplace(firstChoice, '_'); } else if (secondChoice != null && !"".equals(secondChoice)) { label = DONT_SANITIZE_IFNAME ? secondChoice : AlphaNumeric.parseAndReplace(secondChoice, '_'); } return label; }
/** * <p>computeNameForRRD</p> * * @return a {@link java.lang.String} object. */ public String computeNameForRRD() { /* * Determine the label for this interface. The label will be used to * create the RRD file name which holds SNMP data retreived from the * remote agent. If available ifName is used to generate the label * since it is guaranteed to be unique. Otherwise ifDescr is used. In * either case, all non alpha numeric characters are converted to * underscores to ensure that the resuling string will make a decent * file name and that RRD won't have any problems using it */ String firstChoice = RrdLabelUtils.PREFER_IFDESCR ? getIfDescr() : getIfName(); String secondChoice = RrdLabelUtils.PREFER_IFDESCR ? getIfName() : getIfDescr(); String label = null; if (firstChoice != null) { label = RrdLabelUtils.DONT_SANITIZE_IFNAME ? firstChoice : AlphaNumeric.parseAndReplace(firstChoice, '_'); } else if (secondChoice != null) { label = RrdLabelUtils.DONT_SANITIZE_IFNAME ? secondChoice : AlphaNumeric.parseAndReplace(secondChoice, '_'); } else { // TODO: Use IfLabel.NO_IFLABEL instead of "no_ifLabel" LOG.info("Interface ({}) has no ifName and no ifDescr...setting to label to 'no_ifLabel'.", this); label = "no_ifLabel"; } return label; }
protected static String[] getKeysFor(OnmsSnmpInterface snmpInterface) { /* * When Cisco Express Forwarding (CEF) or some ATM encapsulations * (AAL5) are used on Cisco routers, an additional entry might be * in the ifTable for these sub-interfaces, but there is no * performance data available for collection. This check excludes * ifTable entries where ifDescr contains "-cef". See bug #803. */ if (snmpInterface.getIfDescr() != null) { if (Pattern.matches(".*-cef.*", snmpInterface.getIfDescr())) { return new String[0]; } } String replacedIfName = AlphaNumeric.parseAndReplace(snmpInterface.getIfName(), '_'); String replacedIfDescr = AlphaNumeric.parseAndReplace(snmpInterface.getIfDescr(), '_'); return new String[] { replacedIfName + "-", replacedIfDescr + "-", replacedIfName + "-" + snmpInterface.getPhysAddr(), replacedIfDescr + "-" + snmpInterface.getPhysAddr() }; }
if ((AlphaNumeric.parseAndReplace(iface.getIfName(), '_').equals(desc2)) || (AlphaNumeric.parseAndReplace(iface.getIfDescr(), '_').equals(desc2))) {
public ReverseDnsRecord(OnmsIpInterface ipInterface, int level) { OnmsSnmpInterface snmpInterface = ipInterface.getSnmpInterface(); if (snmpInterface == null) { LOG.debug("Constructor: no SnmpInterface found"); m_hostname=ipInterface.getNode().getLabel()+"."; } else if ( snmpInterface.getIfName() != null ) { LOG.debug("Constructor: SnmpInterface found: ifname: {}", snmpInterface.getIfName()); m_hostname=AlphaNumeric.parseAndReplace(snmpInterface.getIfName(),'-')+"-"+ipInterface.getNode().getLabel()+"."; } else if (snmpInterface.getIfDescr() != null ) { LOG.debug("Constructor: SnmpInterface found: ifdescr: {}", snmpInterface.getIfDescr()); m_hostname=AlphaNumeric.parseAndReplace(snmpInterface.getIfDescr(),'-')+"-"+ipInterface.getNode().getLabel()+"."; } else { LOG.debug("Constructor: SnmpInterface found: ifindex: {}", snmpInterface.getIfDescr()); m_hostname="ifindex-"+snmpInterface.getIfIndex()+"-"+ipInterface.getNode().getLabel()+"."; } LOG.debug("Constructor: set hostname: {}", m_hostname); m_ip = ipInterface.getIpAddress(); LOG.debug("Constructor: set ip address: {}", m_ip); if (level == 1) m_zone = ReverseDnsRecord.firstLevelZonefromInet4Address(m_ip.getAddress()); else if (level == 2) m_zone = ReverseDnsRecord.secondLevelZonefromInet4Address(m_ip.getAddress()); else m_zone=ReverseDnsRecord.thirdLevelZonefromInet4Address(m_ip.getAddress()); LOG.debug("Constructor: set zone: {}", m_zone); }