Ejemplo n.º 1
0
 def test_multiget(self):
     response = readbytes('apiv1/multiget_response.hex')
     self.transport.send.return_value = response
     oids = ['1.3.6.1.2.1.1.4.0', '1.3.6.1.2.1.1.6.0']
     result = snmp.multiget('192.168.1.1', 'private', oids,
                            port=161, timeout=1)
     self.assertEqual(result, [b'root', b'On the move'])
     self.assertTrue(self.transport.send.called, 'method was not called')
     for value in result:
         self.assertIsInstance(value, bytes)
Ejemplo n.º 2
0
 def test_multiget(self):
     data = readbytes('multiget_response.hex')
     expected = [
         '1.3.6.1.4.1.8072.3.2.10',
         b"Linux 7fbf2f0c363d 4.4.0-28-generic #47-Ubuntu SMP Fri "
         b"Jun 24 10:09:13 UTC 2016 x86_64"
     ]
     with patch('puresnmp.send') as mck:
         mck.return_value = data
         result = multiget('::1', 'private', [
             '1.3.6.1.2.1.1.2.0',
             '1.3.6.1.2.1.1.1.0',
         ])
     self.assertEqual(result, expected)
Ejemplo n.º 3
0
    def __process_methods(method, common_parameters, datatype_config):
        response = None

        if method == "get":
            oid = datatype_config["oid"]
            response = puresnmp.get(**common_parameters, oid=oid)
        elif method == "multiget":
            oids = datatype_config["oid"]
            oids = oids if isinstance(oids, list) else list(oids)
            response = puresnmp.multiget(**common_parameters, oids=oids)
        elif method == "getnext":
            oid = datatype_config["oid"]
            master_response = puresnmp.getnext(**common_parameters, oid=oid)
            response = {master_response.oid: master_response.value}
        elif method == "multigetnext":
            oids = datatype_config["oid"]
            oids = oids if isinstance(oids, list) else list(oids)
            master_response = puresnmp.multigetnext(**common_parameters,
                                                    oids=oids)
            response = {
                binded_var.oid: binded_var.value
                for binded_var in master_response
            }
        elif method == "walk":
            oid = datatype_config["oid"]
            response = {
                binded_var.oid: binded_var.value
                for binded_var in list(
                    puresnmp.walk(**common_parameters, oid=oid))
            }
        elif method == "multiwalk":
            oids = datatype_config["oid"]
            oids = oids if isinstance(oids, list) else list(oids)
            response = {
                binded_var.oid: binded_var.value
                for binded_var in list(
                    puresnmp.multiwalk(**common_parameters, oids=oids))
            }
        elif method == "set":
            oid = datatype_config["oid"]
            value = datatype_config["value"]
            response = puresnmp.set(**common_parameters, oid=oid, value=value)
        elif method == "multiset":
            mappings = datatype_config["mappings"]
            response = puresnmp.multiset(**common_parameters,
                                         mappings=mappings)
        elif method == "bulkget":
            scalar_oids = datatype_config.get("scalarOid", [])
            scalar_oids = scalar_oids if isinstance(
                scalar_oids, list) else list(scalar_oids)
            repeating_oids = datatype_config.get("repeatingOid", [])
            repeating_oids = repeating_oids if isinstance(
                repeating_oids, list) else list(repeating_oids)
            max_list_size = datatype_config.get("maxListSize", 1)
            response = puresnmp.bulkget(**common_parameters,
                                        scalar_oids=scalar_oids,
                                        repeating_oids=repeating_oids,
                                        max_list_size=max_list_size)._asdict()
        elif method == "bulkwalk":
            oids = datatype_config["oid"]
            oids = oids if isinstance(oids, list) else list(oids)
            bulk_size = datatype_config.get("bulkSize", 10)
            response = {
                binded_var.oid: binded_var.value
                for binded_var in list(
                    puresnmp.bulkwalk(
                        **common_parameters, bulk_size=bulk_size, oids=oids))
            }
        elif method == "table":
            oid = datatype_config["oid"]
            del common_parameters["timeout"]
            num_base_nodes = datatype_config.get("numBaseNodes", 0)
            response = puresnmp.table(**common_parameters,
                                      oid=oid,
                                      num_base_nodes=num_base_nodes)
        elif method == "bulktable":
            oid = datatype_config["oid"]
            num_base_nodes = datatype_config.get("numBaseNodes", 0)
            bulk_size = datatype_config.get("bulkSize", 10)
            response = puresnmp.bulktable(**common_parameters,
                                          oid=oid,
                                          num_base_nodes=num_base_nodes,
                                          bulk_size=bulk_size)
        else:
            log.error("Method \"%s\" - Not found", str(method))
        return response