@Test public void testSnmpAgentSetupWithCommunityContext() { final List<OctetString> contexts = new ArrayList<>(); final List<SnmpmanAgent> snmpmanAgents = snmpman.getAgents(); for (final SnmpmanAgent agent : snmpmanAgents) { agent.registerManagedObjects(); contexts.addAll(Arrays.asList(agent.getServer().getContexts())); } assertTrue(contexts.contains(new OctetString("9"))); assertTrue(contexts.contains(new OctetString("42"))); }
@Override protected void registerManagedObjects() { unregisterDefaultManagedObjects(null); unregisterDefaultManagedObjects(new OctetString()); final List<Long> vlans = configuration.getDevice().getVlans(); for (final Long vlan : vlans) { unregisterDefaultManagedObjects(new OctetString(String.valueOf(vlan))); } log.trace("registering managed objects for agent \"{}\"", configuration.getName()); for (final Long vlan : vlans) { try (final FileInputStream fileInputStream = new FileInputStream(configuration.getWalk()); final BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, DEFAULT_CHARSET))) { Map<OID, Variable> bindings = readVariableBindings(reader); final SortedMap<OID, Variable> variableBindings = this.getVariableBindings(configuration.getDevice(), bindings, new OctetString(String.valueOf(vlan))); final OctetString context = new OctetString(String.valueOf(vlan)); final List<OID> roots = SnmpmanAgent.getRoots(variableBindings); for (final OID root : roots) { MOGroup group = createGroup(root, variableBindings); final Iterable<VariableBinding> subtree = generateSubtreeBindings(variableBindings, root); DefaultMOContextScope scope = new DefaultMOContextScope(context, root, true, root.nextPeer(), false); ManagedObject mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { for (final VariableBinding variableBinding : subtree) { group = new MOGroup(variableBinding.getOid(), variableBinding.getOid(), variableBinding.getVariable()); scope = new DefaultMOContextScope(context, variableBinding.getOid(), true, variableBinding.getOid().nextPeer(), false); mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { log.warn("could not register single OID at {} because ManagedObject {} is already registered.", variableBinding.getOid(), mo); } else { groups.add(group); registerGroupAndContext(group, context); } } } else { groups.add(group); registerGroupAndContext(group, context); } } } catch (final FileNotFoundException e) { log.error("walk file {} not found", configuration.getWalk().getAbsolutePath()); } catch (final IOException e) { log.error("could not read walk file " + configuration.getWalk().getAbsolutePath(), e); } } createAndRegisterDefaultContext(); }
SnmpmanAgent extends BaseAgent { @Override protected void registerManagedObjects() { unregisterDefaultManagedObjects(null); unregisterDefaultManagedObjects(new OctetString()); final List<Long> vlans = configuration.getDevice().getVlans(); for (final Long vlan : vlans) { unregisterDefaultManagedObjects(new OctetString(String.valueOf(vlan))); } log.trace("registering managed objects for agent \"{}\"", configuration.getName()); for (final Long vlan : vlans) { try (final FileInputStream fileInputStream = new FileInputStream(configuration.getWalk()); final BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, DEFAULT_CHARSET))) { Map<OID, Variable> bindings = readVariableBindings(reader); final SortedMap<OID, Variable> variableBindings = this.getVariableBindings(configuration.getDevice(), bindings, new OctetString(String.valueOf(vlan))); final OctetString context = new OctetString(String.valueOf(vlan)); final List<OID> roots = SnmpmanAgent.getRoots(variableBindings); for (final OID root : roots) { MOGroup group = createGroup(root, variableBindings); final Iterable<VariableBinding> subtree = generateSubtreeBindings(variableBindings, root); DefaultMOContextScope scope = new DefaultMOContextScope(context, root, true, root.nextPeer(), false); ManagedObject mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { for (final VariableBinding variableBinding : subtree) { group = new MOGroup(variableBinding.getOid(), variableBinding.getOid(), variableBinding.getVariable()); scope = new DefaultMOContextScope(context, variableBinding.getOid(), true, variableBinding.getOid().nextPeer(), false); mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { log.warn("could not register single OID at {} because ManagedObject {} is already registered.", variableBinding.getOid(), mo); } else { groups.add(group); registerGroupAndContext(group, context); } } } else { groups.add(group); registerGroupAndContext(group, context); } } } catch (final FileNotFoundException e) { log.error("walk file {} not found", configuration.getWalk().getAbsolutePath()); } catch (final IOException e) { log.error("could not read walk file " + configuration.getWalk().getAbsolutePath(), e); } } createAndRegisterDefaultContext(); } }
SnmpmanAgent extends BaseAgent { @Override protected void registerManagedObjects() { unregisterDefaultManagedObjects(null); unregisterDefaultManagedObjects(new OctetString()); final List<Long> vlans = configuration.getDevice().getVlans(); for (final Long vlan : vlans) { unregisterDefaultManagedObjects(new OctetString(String.valueOf(vlan))); } log.trace("registering managed objects for agent \"{}\"", configuration.getName()); for (final Long vlan : vlans) { try (final FileInputStream fileInputStream = new FileInputStream(configuration.getWalk()); final BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, DEFAULT_CHARSET))) { Map<OID, Variable> bindings = readVariableBindings(reader); final SortedMap<OID, Variable> variableBindings = this.getVariableBindings(configuration.getDevice(), bindings, new OctetString(String.valueOf(vlan))); final OctetString context = new OctetString(String.valueOf(vlan)); final List<OID> roots = SnmpmanAgent.getRoots(variableBindings); for (final OID root : roots) { MOGroup group = createGroup(root, variableBindings); final Iterable<VariableBinding> subtree = generateSubtreeBindings(variableBindings, root); DefaultMOContextScope scope = new DefaultMOContextScope(context, root, true, root.nextPeer(), false); ManagedObject mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { for (final VariableBinding variableBinding : subtree) { group = new MOGroup(variableBinding.getOid(), variableBinding.getOid(), variableBinding.getVariable()); scope = new DefaultMOContextScope(context, variableBinding.getOid(), true, variableBinding.getOid().nextPeer(), false); mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { log.warn("could not register single OID at {} because ManagedObject {} is already registered.", variableBinding.getOid(), mo); } else { groups.add(group); registerGroupAndContext(group, context); } } } else { groups.add(group); registerGroupAndContext(group, context); } } } catch (final FileNotFoundException e) { log.error("walk file {} not found", configuration.getWalk().getAbsolutePath()); } catch (final IOException e) { log.error("could not read walk file " + configuration.getWalk().getAbsolutePath(), e); } } createAndRegisterDefaultContext(); } SnmpmanAgent(final AgentConfiguration configuration); }
SnmpmanAgent extends BaseAgent { @Override protected void registerManagedObjects() { unregisterDefaultManagedObjects(null); unregisterDefaultManagedObjects(new OctetString()); final List<Long> vlans = configuration.getDevice().getVlans(); for (final Long vlan : vlans) { unregisterDefaultManagedObjects(new OctetString(String.valueOf(vlan))); } log.trace("registering managed objects for agent \"{}\"", configuration.getName()); for (final Long vlan : vlans) { try (final FileInputStream fileInputStream = new FileInputStream(configuration.getWalk()); final BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, DEFAULT_CHARSET))) { Map<OID, Variable> bindings = readVariableBindings(reader); final SortedMap<OID, Variable> variableBindings = this.getVariableBindings(configuration.getDevice(), bindings, new OctetString(String.valueOf(vlan))); final OctetString context = new OctetString(String.valueOf(vlan)); final List<OID> roots = SnmpmanAgent.getRoots(variableBindings); for (final OID root : roots) { MOGroup group = createGroup(root, variableBindings); final Iterable<VariableBinding> subtree = generateSubtreeBindings(variableBindings, root); DefaultMOContextScope scope = new DefaultMOContextScope(context, root, true, root.nextPeer(), false); ManagedObject mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { for (final VariableBinding variableBinding : subtree) { group = new MOGroup(variableBinding.getOid(), variableBinding.getOid(), variableBinding.getVariable()); scope = new DefaultMOContextScope(context, variableBinding.getOid(), true, variableBinding.getOid().nextPeer(), false); mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { log.warn("could not register single OID at {} because ManagedObject {} is already registered.", variableBinding.getOid(), mo); } else { groups.add(group); registerGroupAndContext(group, context); } } } else { groups.add(group); registerGroupAndContext(group, context); } } } catch (final FileNotFoundException e) { log.error("walk file {} not found", configuration.getWalk().getAbsolutePath()); } catch (final IOException e) { log.error("could not read walk file " + configuration.getWalk().getAbsolutePath(), e); } } createAndRegisterDefaultContext(); } SnmpmanAgent(final AgentConfiguration configuration); String getName(); void execute(); }
SnmpmanAgent extends BaseAgent { @Override protected void registerManagedObjects() { unregisterDefaultManagedObjects(null); unregisterDefaultManagedObjects(new OctetString()); final List<Long> vlans = configuration.getDevice().getVlans(); for (final Long vlan : vlans) { unregisterDefaultManagedObjects(new OctetString(String.valueOf(vlan))); } log.trace("registering managed objects for agent \"{}\"", configuration.getName()); for (final Long vlan : vlans) { try (final FileInputStream fileInputStream = new FileInputStream(configuration.getWalk()); final BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, DEFAULT_CHARSET))) { Map<OID, Variable> bindings = readVariableBindings(reader); final SortedMap<OID, Variable> variableBindings = this.getVariableBindings(configuration.getDevice(), bindings, new OctetString(String.valueOf(vlan))); final OctetString context = new OctetString(String.valueOf(vlan)); final List<OID> roots = SnmpmanAgent.getRoots(variableBindings); for (final OID root : roots) { MOGroup group = createGroup(root, variableBindings); final Iterable<VariableBinding> subtree = generateSubtreeBindings(variableBindings, root); DefaultMOContextScope scope = new DefaultMOContextScope(context, root, true, root.nextPeer(), false); ManagedObject mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { for (final VariableBinding variableBinding : subtree) { group = new MOGroup(variableBinding.getOid(), variableBinding.getOid(), variableBinding.getVariable()); scope = new DefaultMOContextScope(context, variableBinding.getOid(), true, variableBinding.getOid().nextPeer(), false); mo = server.lookup(new DefaultMOQuery(scope, false)); if (mo != null) { log.warn("could not register single OID at {} because ManagedObject {} is already registered.", variableBinding.getOid(), mo); } else { groups.add(group); registerGroupAndContext(group, context); } } } else { groups.add(group); registerGroupAndContext(group, context); } } } catch (final FileNotFoundException e) { log.error("walk file {} not found", configuration.getWalk().getAbsolutePath()); } catch (final IOException e) { log.error("could not read walk file " + configuration.getWalk().getAbsolutePath(), e); } } createAndRegisterDefaultContext(); } SnmpmanAgent(final AgentConfiguration configuration); String getName(); void execute();  }