Esempio n. 1
0
    def test_data_for_leaf_oid_case(self):
        self.snmp_data['walk_flag'] = False
        self.snmp_data['oid'] = u'1.3.6.1.4.1.2021.4.1.0'
        self.snmp_data['varBindTable'] = [
            (ObjectName('1.3.6.1.4.1.2021.4.2.0'), univ.Integer('0'))
        ]

        expected = {
            '_type_str':
            'msg iso_org_dod_internet_private_enterprises_2021_4_2_0 device_name collected_at',
            'device_name': 'localhost',
            'collected_at': 'LiV5',
            'iso_org_dod_internet_private_enterprises_2021_4_2_0': '0'
        }

        processed_by_library = process_snmp_fetcher_data(self.snmp_data)
        data = processed_by_library.next()
        _handle_data(data, '127.0.0.1', 'snmp_fetcher', 'localhost', 'LiV5',
                     self.snmp_fetcher_out)

        mid = data.pop('mid')
        assert re.match(r'^LiV5\|snmp_fetcher\|(127.0.0.1|::1)\|\d+\|\d+$',
                        mid)

        msg = data.pop('msg')
        assert re.match(
            r'iso_org_dod_internet_private_enterprises_2021_4_2_0 = \w+$', msg)

        self.assertEqual(data, expected)
Esempio n. 2
0
    def test_data_for_branch_oid_case(self):
        self.snmp_data['oid'] = u'1.3.6.1.4.1.2021.4'
        self.snmp_data['walk_flag'] = True
        self.snmp_data['varBindTable'] = [[
            (ObjectName('1.3.6.1.4.1.2021.4.1.0'), univ.Integer(0))
        ], [(ObjectName('1.3.6.1.4.1.2021.4.2.0'), univ.OctetString('swap'))
            ], [(ObjectName('1.3.6.1.4.1.2021.4.12.0'), univ.Integer(16000))]]
        expected = [{
            '_type_str':
            'msg iso_org_dod_internet_private_enterprises_2021_4_1_0 device_name collected_at',
            'collected_at': 'LiV5',
            'device_name': 'localhost',
            'iso_org_dod_internet_private_enterprises_2021_4_1_0': '0'
        }, {
            '_type_str':
            'msg iso_org_dod_internet_private_enterprises_2021_4_2_0 device_name collected_at',
            'collected_at':
            'LiV5',
            'device_name':
            'localhost',
            'iso_org_dod_internet_private_enterprises_2021_4_2_0':
            'swap'
        }, {
            '_type_str':
            'msg iso_org_dod_internet_private_enterprises_2021_4_12_0 device_name collected_at',
            'iso_org_dod_internet_private_enterprises_2021_4_12_0': '16000',
            'collected_at': 'LiV5',
            'device_name': 'localhost'
        }]
        processed_by_library = process_snmp_fetcher_data(self.snmp_data)
        oid_suff = [1, 2, 12]
        for index, data in enumerate(processed_by_library):
            _handle_data(data, '127.0.0.1', 'snmp_fetcher', 'localhost',
                         'LiV5', self.snmp_fetcher_out)
            mid = data.pop('mid')
            assert re.match(r'^LiV5\|snmp_fetcher\|(127.0.0.1|::1)\|\d+\|\d+$',
                            mid)

            msg = data.pop('msg')
            assert re.match(
                r'iso_org_dod_internet_private_enterprises_2021_4_%s_0 = \w+$'
                % oid_suff[index], msg)

            self.assertEqual(data, expected[index])
 def test_process_snmp_fetcher_correct(self):
     oid = ObjectName('1.3.6.1.4.1.2021.4.2.0')
     varBindTable = [(ObjectName('1.3.6.1.4.1.2021.4.2.0'), univ.OctetString('swap'))]
     data_dict = get_data(oid, self.cmdGen, self.mibView, walk_flag=False, varBindTable=varBindTable, \
             errorIndication=None, errorStatus=univ.Integer('0'))
     result = process_snmp_fetcher_data(data_dict)
     expected = {'msg': 'iso_org_dod_internet_private_enterprises_2021_4_2_0 = swap',
             'iso_org_dod_internet_private_enterprises_2021_4_2_0': 'swap',
             '_type_str': 'msg iso_org_dod_internet_private_enterprises_2021_4_2_0'}
     self.assertEqual(result.next(), expected)
Esempio n. 4
0
 def setUp(self):
     self.cmdGen = cmdgen.CommandGenerator()
     self.mibView = _get_mib_viewer(self.cmdGen)
     self.snmp_fetcher_out = MockColOut()
     self.snmp_data = {
         'cmdGen': None,
         'errorIndex': univ.Integer('0'),
         'errorStatus': None,
         'mibView': self.mibView,
         'cmdGen': self.cmdGen,
         'errorIndication': None,
     }
def get_data(oid, cmdGen, mibView, walk_flag=False, varBindTable=None, errorStatus=univ.OctetString('noError'), \
                        errorIndex=univ.Integer('0'), errorIndication='Some Error'):
    result_template = {}
    result_template['errorIndication'] = errorIndication
    result_template['errorStatus'] = errorStatus
    result_template['errorIndex'] = errorIndex
    result_template['varBindTable'] = varBindTable
    result_template['oid'] = oid
    result_template['walk_flag'] = walk_flag
    result_template['cmdGen'] = cmdGen
    result_template['mibView'] = mibView

    return result_template
 def test_process_snmp_fetcher_error_status(self):
     oid = ObjectName('1.3.6.1.4.1.2021.4.2.0')
     data_dict = get_data(oid, self.cmdGen, self.mibView, walk_flag=True, errorIndication=None, errorStatus=univ.Integer('1'))
     result = process_snmp_fetcher_data(data_dict)
     self.assertEqual(result.next(), {})