def testDropV2EventForSimpleGlobMatch(self): filterDef = V2FilterDefinition(99, "exclude", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[4] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3.4"} self.assertTrue(filter._dropV2Event(event)) filterDef.action = "include" self.assertFalse(filter._dropV2Event(event))
def testDropV2EventExcludeAll(self): filterDef = V2FilterDefinition(99, "exclude", "*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[1] = filtersByLevel event = {"snmpVersion": "2", "oid": "1"} self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventExcludeAll(self): filterDef = V2FilterDefinition(99, "exclude", "*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[1] = filtersByLevel event = {"snmpVersion": "2", "oid": "1"} self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventForSimpleGlobMatch(self): filterDef = V2FilterDefinition(99, "exclude", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[4] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3.4"} self.assertTrue(filter._dropV2Event(event)) filterDef.action = "include" self.assertFalse(filter._dropV2Event(event))
def testDropV2EventIncludeAllBut(self): filterDef = V2FilterDefinition(99, "include", "*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[1] = filtersByLevel filterDef = V2FilterDefinition(99, "exclude", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[4] = filtersByLevel filterDef = V2FilterDefinition(99, "exclude", "1.4.5") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[3] = filtersByLevel event = {"snmpVersion": "2", "oid": "1"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.4.5.1" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.4.5" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventIncludeAllBut(self): filterDef = V2FilterDefinition(99, "include", "*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[1] = filtersByLevel filterDef = V2FilterDefinition(99, "exclude", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[4] = filtersByLevel filterDef = V2FilterDefinition(99, "exclude", "1.4.5") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[3] = filtersByLevel event = {"snmpVersion": "2", "oid": "1"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.4.5.1" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.4.5" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventForSimpleExactMatches(self): filterDef = V2FilterDefinition(99, "include", "1.2.3") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[3] = filtersByLevel filterDef = V2FilterDefinition(99, "include", "1.2.3.4") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[4] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4" self.assertFalse(filter._dropV2Event(event)) # OIDs with fewer or more levels than the existing filters should NOT match event["oid"] = "1.2" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.9" self.assertTrue(filter._dropV2Event(event)) # OIDs that differ only in the last level should NOT match event["oid"] = "1.2.9" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.9" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventForSimpleExactMatches(self): filterDef = V2FilterDefinition(99, "include", "1.2.3") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[3] = filtersByLevel filterDef = V2FilterDefinition(99, "include", "1.2.3.4") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[4] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4" self.assertFalse(filter._dropV2Event(event)) # OIDs with fewer or more levels than the existing filters should NOT match event["oid"] = "1.2" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.9" self.assertTrue(filter._dropV2Event(event)) # OIDs that differ only in the last level should NOT match event["oid"] = "1.2.9" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3.9" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventForSimpleGlobMatches(self): filterDef = V2FilterDefinition(99, "include", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[4] = filtersByLevel filterDef = V2FilterDefinition(99, "include", "1.2.3.4.5.*") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[6] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3.4"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.99.5" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.99.4" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.99.4.5.6" self.assertTrue(filter._dropV2Event(event))
def testDropV2EventForSimpleGlobMatches(self): filterDef = V2FilterDefinition(99, "include", "1.2.3.*") filtersByLevel = {filterDef.oid: filterDef} filter = TrapFilter() filter._v2Filters[4] = filtersByLevel filterDef = V2FilterDefinition(99, "include", "1.2.3.4.5.*") filtersByLevel = {filterDef.oid: filterDef} filter._v2Filters[6] = filtersByLevel event = {"snmpVersion": "2", "oid": "1.2.3.4"} self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.99.5" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1.2.3.4.5.99" self.assertFalse(filter._dropV2Event(event)) event["oid"] = "1" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.3" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.99.4" self.assertTrue(filter._dropV2Event(event)) event["oid"] = "1.2.99.4.5.6" self.assertTrue(filter._dropV2Event(event))