protected String snmpGet(SnmpManager snmpManager, String oidString) { try { return snmpManager.snmpGet(oidString); } catch (IOException e) { logger.info(e.getMessage()); return null; } }
/** * <p>setParameters.</p> * * @param conParams a {@link java.util.Map} object. */ public void setParameters(Map<String, String> conParams) { if (conParams!=null) { this.retries = convertStringToIntParam("retries", conParams.get("retries"), 3); this.timeout = convertStringToIntParam("timeout", conParams.get("timeout"), 1000); this.maxSizeRequestPDU = convertStringToIntParam("maxSizeRequestPDU", conParams.get("maxSizeRequestPDU"), 1000); this.maxRepetitions = convertStringToIntParam("maxRepetitions", conParams.get("maxRepetitions"), 10); doSetParameters(conParams); } }
/** * <p>snmpWalk.</p> * * @param includes an array of {@link java.lang.String} objects. * @return a {@link net.itransformers.snmp2xml4j.snmptoolkit.Node} object. * @throws java.io.IOException if any. */ public Node snmpWalk(String[] includes) throws IOException { ObjectIdentifierValue oid = loader.getRootOid(); Set<String> includesSet = new HashSet<String>(Arrays.asList(includes)); Node rootNode = new Node(oid, null); fillTreeFromMib(rootNode); fillDoWalk(rootNode, includesSet); fillTreeFromSNMP(rootNode); return rootNode; }
snmpUdpv2Manager.init(); OID oid = new OID(oid1); OID oids[] = new OID[]{oid}; ResponseEvent responseEvent = snmpUdpv2Manager.snmpGet(oids); snmpUdpv3Manager.init(); responseEvent = snmpUdpv3Manager.snmpGet(oids); logger.debug("PDU response event is null"); SnmpXmlPrinter xmlPrinter = new SnmpXmlPrinter(mibLoaderHolder.getLoader(),snmpUdpv3Manager.snmpWalk(new String[]{"system", "interfaces"}));
snmpManager.init(); sysDescr = snmpManager.snmpGet("1.3.6.1.2.1.1.1.0"); snmpManager.closeSnmp(); logger.info("Can't connect to: " + initialSnmpConnParams.get("ipAddress") + " with " + initialSnmpConnParams); return null; snmpManager = snmpManagerCreator.create(initialSnmpConnParams); snmpManager.init(); sysDescr = snmpManager.snmpGet("1.3.6.1.2.1.1.1.0"); if (sysDescr == null) { logger.info("Can't connect to: " + ipAddressStr + " with " + initialSnmpConnParams); snmpManager.closeSnmp(); } else { return snmpManager;
snmpManager.init(); sysDescr = snmpGet(snmpManager,"1.3.6.1.2.1.1.1.0"); snmpManager.closeSnmp(); logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams); snmpManager.init(); sysDescr = snmpGet(snmpManager, "1.3.6.1.2.1.1.1.0"); if (sysDescr == null) { logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams); snmpManager.closeSnmp(); } else { deviceType = DeviceTypeResolver.getDeviceType(sysDescr); net.itransformers.idiscover.api.models.node_data.RawDeviceData rawData = null; try { rawDatNode = snmpManager.snmpWalk(requestParamsList); snmpManager.closeSnmp();
private static byte[] snmpWalk(Map<String,String> settings) throws Exception {//}, MibLoaderException { String queryParameters = settings.get("query.parameters"); String[] params = queryParameters.split(","); String mibDir = settings.get("mibDir"); MibLoaderHolder holder = new MibLoaderHolder(new File(System.getProperty("base.dir"), mibDir), false); SnmpManager snmpManager = new SnmpUdpV2Manager(holder.getLoader(),ipAddress.toString(),settings.get("community-ro"),3,1000,10,65535,161); snmpManager.init(); //(holder,new UdpTransportMappingFactory(), new DefaultMessageDispatcherFactory()); String address = ipAddress; if (address == null) throw new RuntimeException("Resource Address is null"); Properties parameters = new Properties(); parameters.put(SnmpConfigurator.O_ADDRESS, Arrays.asList(address)); parameters.put(SnmpConfigurator.O_COMMUNITY, Arrays.asList(settings.get("community-ro"))); String version = settings.get("version") == null ? "2c" : settings.get("version"); int retriesInt = settings.get("retries") == null ? 3 : Integer.parseInt(settings.get("retries")); int timeoutInt = settings.get("timeout") == null ? 1200 : Integer.parseInt(settings.get("timeout")); int maxrepetitions = settings.get("max-repetitions") == null ? 100 : Integer.parseInt(settings.get("max-repetitions")); int nonrepeaters = settings.get("non-repeaters") == null ? 10 : Integer.parseInt(settings.get("max-repetitions")); parameters.put(SnmpConfigurator.O_VERSION, Arrays.asList(version)); parameters.put(SnmpConfigurator.O_TIMEOUT, Arrays.asList(timeoutInt)); parameters.put(SnmpConfigurator.O_RETRIES, Arrays.asList(retriesInt)); parameters.put(SnmpConfigurator.O_MAX_REPETITIONS, Arrays.asList(maxrepetitions)); parameters.put(SnmpConfigurator.O_NON_REPEATERS,Arrays.asList(nonrepeaters)); Node root = snmpManager.snmpWalk(params); SnmpXmlPrinter snmpXmlPrinter = new SnmpXmlPrinter(holder.getLoader(),root); String xml = snmpXmlPrinter.printTreeAsXML(); return xml.getBytes(); } private synchronized void doPause() {
protected RawDeviceData getRawData (SnmpManager snmpManager,DiscoveryHelper discoveryHelper){ String[] requestParamsList = discoveryHelper.getRequestParams(discoveryTypes); Node rawDatNode = null; RawDeviceData rawData = null; try { rawDatNode = snmpManager.snmpWalk(requestParamsList); snmpManager.closeSnmp(); } catch (IOException e) { logger.error(e.getMessage(),e); } if (rawDatNode != null) { SnmpXmlPrinter snmpXmlPrinter = new SnmpXmlPrinter(mibLoaderHolder.getLoader(), rawDatNode); rawData = new RawDeviceData(snmpXmlPrinter.printTreeAsXML().getBytes()); logger.trace(new String(rawData.getData())); } else { return null; } return rawData; }
/** {@inheritDoc} */ @Override public void doSetParameters(Map<String, String> conParams) { int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161); this.tcpAddress = new TcpAddress(conParams.get("ipAddress")+"/"+destinationPort); this.snmpCommunity=conParams.get("snmpCommunity"); }
private void fillDoWalk(Node node, Set includes) { if (includes.contains(node.getObjectIdentifierValue().getName())) { // set parents and itself Node currentNode = node; while (currentNode != null) { currentNode.setDoWalk(true); currentNode = currentNode.getParent(); } fillDoWalkChildren(node); } for (Node child : node.getChildren()) { fillDoWalk(child, includes); } }
/** * <p>set.</p> * * @param oids an array of {@link org.snmp4j.smi.OID} objects. * @param value a int. * @return a {@link org.snmp4j.event.ResponseEvent} object. */ public ResponseEvent set(OID oids[], int value) { PDU pdu = createPDU(); for (OID oid : oids) { pdu.add(new VariableBinding(oid, new Integer32(value))); } pdu.setType(PDU.SET); ResponseEvent event = null; try { event = snmp.send(pdu, getTarget(), null); } catch (IOException ioe) { System.out.println("Error SNMP SET"); } if (event != null) { return event; } throw new RuntimeException("SET timed out"); }
/** * <p>init.</p> * * @throws java.io.IOException if any. */ public void init() throws IOException { TransportMapping transportMapping = transportMappingAbstractFactory.createTransportMapping(transportLocalIpAddress); MessageDispatcher messageDispatcher = messageDispatcherFactory.createMessageDispatcherMapping(); snmp = new Snmp(messageDispatcher, transportMapping); doInit(); transportMapping.listen(); }
snmpManager.init(); deviceNameFromSNMP = snmpManager.snmpGet("1.3.6.1.2.1.1.5.0"); snmpManager.closeSnmp(); for (ResourceType snmpResource : snmpResources) { connParams = resourceManager.getParamMap(snmpResource, "snmp"); logger.info("Trying ipAddress " + ipAddress + " with " + connParams); snmpManager = createSnmpManager(connParams); snmpManager.init(); deviceNameFromSNMP = snmpManager.snmpGet("1.3.6.1.2.1.1.5.0"); if (deviceNameFromSNMP == null) { snmpManager.closeSnmp(); final String sysDescr = snmpManager.snmpGet("1.3.6.1.2.1.1.1.0"); deviceTypeFromSNMP = getDeviceType(sysDescr); snmpManager.closeSnmp();
/** {@inheritDoc} */ @Override public void doSetParameters(Map<String, String> conParams) { int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161); this.udpAddress = new UdpAddress(conParams.get("ipAddress")+"/"+destinationPort); this.snmpCommunity=conParams.get("snmpCommunity"); }
public String snmpWalkToString(String[] includes) throws IOException { ObjectIdentifierValue oid = loader.getRootOid(); Set<String> includesSet = new HashSet<String>(Arrays.asList(includes)); Node rootNode = new Node(oid, null); fillTreeFromMib(rootNode); fillDoWalk(rootNode, includesSet); fillTreeFromSNMP(rootNode); SnmpXmlPrinter snmpXmlPrinter = new SnmpXmlPrinter(loader,rootNode); return snmpXmlPrinter.printTreeAsXML(); }
public static String getByOid(String ipAddress, String oid, String community,String timeout, String retries) throws Exception { if (mockSnmpForXslt != null) { return mockSnmpForXslt.getByOid(ipAddress, oid, community, timeout, retries); } HashMap<String, String> deviceNameMap = discoveredIPs.get(ipAddress); String deviceName = null; if(!ipAddressValidator.isValid(ipAddress)) return null; if (deviceNameMap != null) { deviceName = deviceNameMap.get(community); } if ("".equals(deviceName)) { return null; } else if (deviceName == null) { if ("".equals(retries) || retries==null) retries = "1"; if ("".equals(timeout) || timeout==null) timeout = "300"; Map<String, String> resourceParams = new HashMap<String, String>(); resourceParams.put("snmpCommunity", community); resourceParams.put("version", "1"); resourceParams.put("retries", retries); resourceParams.put("timeout", timeout); resourceParams.put("ipAddress",ipAddress); SnmpManager snmpManager = createSnmpManager(resourceParams); final String oidValue = snmpManager.snmpGet(oid); logger.debug("hostname:" + ipAddress + ", community: " + community + ", oidValue:" + oidValue); return oidValue; } else { return null; } }
/** {@inheritDoc} */ @Override protected void doSetParameters(Map<String, String> conParams) { int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161); this.udpAddress = new UdpAddress(conParams.get("ipAddress")+"/"+destinationPort); this.snmpCommunity=conParams.get("snmpCommunity"); }
/** {@inheritDoc} */ @Override public void doSetParameters(Map<String, String> conParams) { int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161); this.tcpAddress = new TcpAddress(conParams.get("ipAddress")+"/"+destinationPort); this.ver3Username = conParams.get("ver3Username"); this.ver3AuthPasscode = conParams.get("ver3Username"); this.authenticationProtocol = conParams.get("authenticationProtocol"); this.privacyProtocol = conParams.get("privacyProtocol"); this.privacyProtocolPassShare = conParams.get("privacyProtocolPassShare"); }