mooli tayer has uploaded a new change for review. Change subject: notifier: add support for snmpv6 in SNMP_MANAGERS. ......................................................................
notifier: add support for snmpv6 in SNMP_MANAGERS. Change-Id: I9a21038928b7e553feefb9ab7669eac588c1c93c Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1073498 Signed-off-by: Mooli Tayer <mta...@redhat.com> (cherry picked from commit 89ecae235bd8f73b8e44044b1fe6ae32562035da) --- M backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java A backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/transport/snmp/ProfileTest.java M packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in 3 files changed, 60 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/33640/1 diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java index ec62f97..1001173 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java @@ -176,7 +176,7 @@ } } - private static class Host { + static class Host { public String name; public int port = 162; @@ -201,8 +201,8 @@ } } - private static class Profile { - private static final Pattern HOST_PATTERN = Pattern.compile("(?<host>[^:\\s]+)(:(?<port>[^\\s]*))?"); + static class Profile { + Pattern HOST_PATTERN = Pattern.compile("(?<host>(([^\\[:\\s]+)|(\\[[^\\]]+\\])))(:(?<port>[^\\s]*))?"); public List<Host> hosts = new LinkedList<>(); public OctetString community; diff --git a/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/transport/snmp/ProfileTest.java b/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/transport/snmp/ProfileTest.java new file mode 100644 index 0000000..ffcd45b --- /dev/null +++ b/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/transport/snmp/ProfileTest.java @@ -0,0 +1,56 @@ +package org.ovirt.engine.core.notifier.transport.snmp; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.ovirt.engine.core.common.utils.Pair; + +public class ProfileTest { + + // this has to be defined as paris since Snmp.Hosts doesn't distinguish between Host(x, null) to Host(x, 162) + private static final List<Pair<String, String>> hosts = new ArrayList<>( + Arrays.asList( + new Pair<String, String>("[::1]", null), + new Pair<>("[::1]", "1"), + new Pair<String, String>("localhost", null), + new Pair<>("localhost", "162"), + new Pair<String, String>("192.168.0.1", null), + new Pair<>("192.168.0.1", "163"), + new Pair<String, String>("manager1.example.com", null), + new Pair<>("manager1.example.com", "164"), + new Pair<String, String>("[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]", null), + new Pair<>("[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]", "165") + ) + ); + + + @Test + public void testSnmpManagersParsing() { + List<Snmp.Host> expectedManagers = new ArrayList<>(); + StringBuilder snmpManagers = new StringBuilder(); + for (Pair<String, String> host : hosts) { + expectedManagers.add(new Snmp.Host(host.getFirst(), host.getSecond())); + snmpManagers.append(host.getFirst()); + if (host.getSecond() != null) { + snmpManagers.append(":").append(host.getSecond()); + } + snmpManagers.append(" "); + } + Snmp.Profile profile = new Snmp.Profile( + snmpManagers.toString(), + "public", + "1.3.6.1.4.1.2312.13.1.1"); + for (int i = 0; i < expectedManagers.size(); i++) { + Snmp.Host parsed = profile.hosts.get(i); + Snmp.Host expected = expectedManagers.get(i); + Assert.assertEquals(parsed.name, expected.name); + Assert.assertEquals(parsed.port, expected.port); + } + } + + +} diff --git a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in index 1cdbe24..e071b47 100644 --- a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in +++ b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in @@ -145,7 +145,7 @@ # SNMP_MANAGERS="host" # FILTER="include:*(snmp:) ${FILTER}" -# Default whitespace separated IP/DNS list with optional port, default is 162. +# Default whitespace separated IPv4/[IPv6]/DNS list with optional port, default is 162. # SNMP_MANAGERS="manager1.example.com manager2.example.com:164" SNMP_MANAGERS= -- To view, visit http://gerrit.ovirt.org/33640 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9a21038928b7e553feefb9ab7669eac588c1c93c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: mooli tayer <mta...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches