Example #1
0
 def testGetMacAddress(self):
     """Get a MAC address"""
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SNIMPY-MIB.mib"))
     oid, a = self.session.get((1, 3, 6, 1, 2, 1, 45121, 1, 15, 0))[0]
     self.assertEqual(a, b"\x11\x12\x13\x14\x15\x16")
     b = basictypes.build("SNIMPY-MIB", "snimpyMacAddress", a)
     self.assertEqual(b, "11:12:13:14:15:16")
Example #2
0
    def setUp(self):
        mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              "SNIMPY-MIB.mib"))
        self.nodes = ["snimpy",
                      "snimpyScalars",
                      "snimpyTables"]
        self.nodes.sort()
        self.tables = ["snimpyComplexTable",
                       "snimpyInetAddressTable",
                       "snimpySimpleTable",
                       "snimpyIndexTable",
                       "snimpyInvalidTable",
                       "snimpyEmptyTable"]
        self.tables.sort()
        self.columns = ["snimpyComplexFirstIP",
                        "snimpyComplexSecondIP",
                        "snimpySimpleIndex",
                        "snimpyComplexState",
                        "snimpyInetAddressType",
                        "snimpyInetAddress",
                        "snimpyInetAddressState",
                        "snimpySimpleDescr",
                        "snimpySimplePhys",
                        "snimpySimpleType",
                        "snimpyIndexVarLen",
                        "snimpyIndexIntIndex",
                        "snimpyIndexOidVarLen",
                        "snimpyIndexFixedLen",
                        "snimpyIndexImplied",
                        "snimpyIndexInt",
                        "snimpyInvalidIndex",
                        "snimpyInvalidDescr",
                        "snimpyEmptyIndex",
                        "snimpyEmptyDescr"
                        ]
        self.columns.sort()
        self.scalars = ["snimpyIpAddress",
                        "snimpyString",
                        "snimpyInteger",
                        "snimpyEnum",
                        "snimpyObjectId",
                        "snimpyBoolean",
                        "snimpyCounter",
                        "snimpyGauge",
                        "snimpyTimeticks",
                        "snimpyCounter64",
                        "snimpyBits",
                        "snimpyNotImplemented",
                        "snimpyOctetString",
                        "snimpyUnicodeString",
                        "snimpyMacAddress",
                        "snimpyMacAddressInvalid"]
        self.scalars.sort()

        self.expected_modules = [u"SNMPv2-SMI",
                                 u"SNMPv2-TC",
                                 u"SNIMPY-MIB",
                                 u"INET-ADDRESS-MIB",
                                 u"IANAifType-MIB"]
Example #3
0
 def setAndCheck(self, oid, value):
     """Set and check a value"""
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SNIMPY-MIB.mib"))
     ooid = mib.get("SNIMPY-MIB", oid).oid + (0,)
     self.session.set(ooid, basictypes.build("SNIMPY-MIB", oid, value))
     self.assertEqual(
         basictypes.build("SNIMPY-MIB", oid, self.session.get(ooid)[0][1]),
         basictypes.build("SNIMPY-MIB", oid, value),
     )
Example #4
0
 def setUpClass(cls):
     mib.load('IF-MIB')
     mib.load('SNMPv2-MIB')
     cls.agent = None
     cls.agent2 = None
     cls.agent = agent.TestAgent(community='public',
                                 authpass='public-authpass',
                                 privpass='public-privpass')
     cls.agent2 = agent.TestAgent(community='private',
                                  authpass='private-authpass',
                                  privpass='private-privpass')
Example #5
0
 def testVariousSet(self):
     """Set value of many types. This test should be monitored with a traffic capture"""
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           "SNIMPY-MIB.mib"))
     for oid, value in [('snimpyIpAddress', '10.14.12.12'),
                        ('snimpyInteger', 1574512),
                        ('snimpyEnum', 'testing'),
                        ('snimpyObjectId', (1,2,3,4,5,6)),
                        ('snimpyCounter', 545424),
                        ('snimpyGauge', 4857544),
                        ('snimpyTimeticks', timedelta(3, 18)),
                        ('snimpyBits', ["third", "last"])]:
         self.assertRaises(self.version == 1 and snmp.SNMPNoSuchName or snmp.SNMPNoAccess,
                           self.session.set,
                           mib.get('SNIMPY-MIB', oid).oid + (0,),
                           basictypes.build('SNIMPY-MIB', oid, value))
Example #6
0
def load(mibname):
    """Load a MIB in memory.

    :param mibname: MIB name or filename
    :type mibname: str
    """
    m = mib.load(mibname)
    if m not in loaded:
        loaded.append(m)
        if Manager._complete:
            for o in mib.getScalars(m) + mib.getColumns(m):
                setattr(Manager, str(o), 1)
Example #7
0
 def setUp(self):
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SNIMPY-MIB.mib"))
     self.nodes = ["snimpy", "snimpyScalars", "snimpyTables"]
     self.nodes.sort()
     self.tables = ["snimpyComplexTable", "snimpySimpleTable", "snimpyIndexTable"]
     self.tables.sort()
     self.columns = [
         "snimpyComplexFirstIP",
         "snimpyComplexSecondIP",
         "snimpySimpleIndex",
         "snimpyComplexState",
         "snimpySimpleDescr",
         "snimpySimplePhys",
         "snimpySimpleType",
         "snimpyIndexVarLen",
         "snimpyIndexIntIndex",
         "snimpyIndexOidVarLen",
         "snimpyIndexFixedLen",
         "snimpyIndexImplied",
         "snimpyIndexInt",
     ]
     self.columns.sort()
     self.scalars = [
         "snimpyIpAddress",
         "snimpyString",
         "snimpyInteger",
         "snimpyEnum",
         "snimpyObjectId",
         "snimpyBoolean",
         "snimpyCounter",
         "snimpyGauge",
         "snimpyTimeticks",
         "snimpyCounter64",
         "snimpyBits",
         "snimpyNotImplemented",
         "snimpyOctetString",
         "snimpyUnicodeString",
         "snimpyMacAddress",
     ]
     self.scalars.sort()
Example #8
0
 def setUpClass(cls):
     mib.load('IF-MIB')
     mib.load('SNMPv2-MIB')
Example #9
0
 def setUpClass(cls):
     mib.load('IF-MIB')
     mib.load('SNMPv2-MIB')
     cls.agent = agent.TestAgent()
Example #10
0
 def setUpClass(cls):
     mib.load('IF-MIB')
     mib.load('SNMPv2-MIB')
     cls.agents = []
     cls.agent = cls.addAgent('public',
                              'public-authpass', 'public-privpass')
Example #11
0
 def setUp(self):
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           "SNIMPY-MIB.mib"))
Example #12
0
 def setUpClass(cls):
     mib.load("IF-MIB")
     mib.load("SNMPv2-MIB")
Example #13
0
 def setUpClass(cls):
     mib.load("IF-MIB")
     mib.load("SNMPv2-MIB")
     cls.agents = []
     cls.agent = cls.addAgent("public", "public-authpass", "public-privpass")
Example #14
0
 def setUp(self):
     mib.load('IF-MIB')
     mib.load('SNMPv2-MIB')
     self.session = snmp.Session(host="localhost",
                                 community="public",
                                 version=self.version)