Пример #1
0
def test_create_section_plugin_from_legacy(check_info, snmp_info, migrated_agent_sections,
                                           migrated_snmp_sections):
    for name, check_info_dict in check_info.items():
        # only test main checks
        if name != check_utils.section_name_of(name):
            continue

        section_name = PluginName(name)

        with known_exceptions('section', name):
            section = migrated_agent_sections.get(section_name)
            if section is not None:
                assert isinstance(section, AgentSectionPlugin)
            else:
                section = migrated_snmp_sections.get(section_name)
                if section is None:
                    raise NotImplementedError(name)
                assert isinstance(section, SNMPSectionPlugin)

        if section is None:
            continue

        original_parse_function = check_info_dict["parse_function"]
        if original_parse_function is not None:
            assert original_parse_function.__name__ == section.parse_function.__name__
Пример #2
0
    def _make_oid_infos(self):
        # type: () -> Dict[CheckPluginName, Union[OIDInfo, List[SNMPTree]]]
        oid_infos = {}  # Dict[CheckPluginName, Union[OIDInfo, List[SNMPTree]]]
        for check_plugin_name in self._sort_check_plugin_names(
                self.get_check_plugin_names()):
            # Is this an SNMP table check? Then snmp_info specifies the OID to fetch
            # Please note, that if the check_plugin_name is foo.bar then we lookup the
            # snmp info for "foo", not for "foo.bar".
            section_name = check_utils.section_name_of(check_plugin_name)
            oid_info, has_snmp_info = self._oid_info_from_section_name(
                section_name)

            if not has_snmp_info and check_plugin_name in self._fetched_check_plugin_names:
                continue

            if oid_info is None:
                continue

            # This checks data is configured to be persisted (snmp_check_interval) and recent enough.
            # Skip gathering new data here. The persisted data will be added later
            if self._persisted_sections and section_name in self._persisted_sections:
                self._logger.debug(
                    "%s: Skip fetching data (persisted info exists)",
                    check_plugin_name)
                continue

            oid_infos[check_plugin_name] = oid_info
        return oid_infos
Пример #3
0
    def data(self):
        # type: () -> RawSNMPData
        info = {}  # type: RawSNMPData
        for check_plugin_name, oid_info in self._oid_infos.items():
            section_name = check_utils.section_name_of(check_plugin_name)
            # Prevent duplicate data fetching of identical section in case of SNMP sub checks
            if section_name in info:
                self._logger.debug(
                    "%s: Skip fetching data (section already fetched)",
                    check_plugin_name)
                continue

            self._logger.debug("%s: Fetching data", check_plugin_name)

            # oid_info can now be a list: Each element  of that list is interpreted as one real oid_info
            # and fetches a separate snmp table.
            get_snmp = snmp.get_snmp_table_cached if self._use_snmpwalk_cache else snmp.get_snmp_table
            if isinstance(oid_info, list):
                check_info = []  # type: List[SNMPTable]
                for entry in oid_info:
                    check_info_part = get_snmp(self._snmp_config,
                                               check_plugin_name, entry)
                    check_info.append(check_info_part)
                info[section_name] = check_info
            else:
                info[section_name] = get_snmp(self._snmp_config,
                                              check_plugin_name, oid_info)
        return info
def test_create_section_plugin_from_legacy(inv_info):
    for name, inv_info_dict in inv_info.items():
        if 'snmp_info' not in inv_info_dict:
            continue

        section_name = PluginName(check_utils.section_name_of(name))
        with known_exceptions(name):
            if section_name not in config.registered_snmp_sections:
                raise NotImplementedError(name)
            section = config.registered_snmp_sections[section_name]
            assert isinstance(section, SNMPSectionPlugin)
Пример #5
0
    def _execute(self):
        # type: () -> RawSNMPData
        verify_ipaddress(self._ipaddress)
        check_plugin_names = self.get_check_plugin_names()

        snmp_config = self._snmp_config
        info = {}  # type: RawSNMPData
        for check_plugin_name in self._sort_check_plugin_names(check_plugin_names):
            # Is this an SNMP table check? Then snmp_info specifies the OID to fetch
            # Please note, that if the check_plugin_name is foo.bar then we lookup the
            # snmp info for "foo", not for "foo.bar".
            section_name = check_utils.section_name_of(check_plugin_name)
            oid_info, has_snmp_info = SNMPDataSource._oid_info_from_section_name(section_name)

            if not has_snmp_info and check_plugin_name in self._fetched_check_plugin_names:
                continue

            if oid_info is None:
                continue

            # This checks data is configured to be persisted (snmp_check_interval) and recent enough.
            # Skip gathering new data here. The persisted data will be added later
            if self._persisted_sections and section_name in self._persisted_sections:
                self._logger.debug("%s: Skip fetching data (persisted info exists)",
                                   check_plugin_name)
                continue

            # Prevent duplicate data fetching of identical section in case of SNMP sub checks
            if section_name in info:
                self._logger.debug("%s: Skip fetching data (section already fetched)",
                                   check_plugin_name)
                continue

            self._logger.debug("%s: Fetching data", check_plugin_name)

            # oid_info can now be a list: Each element  of that list is interpreted as one real oid_info
            # and fetches a separate snmp table.
            if isinstance(oid_info, list):
                check_info = []  # type: List[SNMPTable]
                for entry in oid_info:
                    check_info_part = snmp.get_snmp_table(snmp_config, check_plugin_name, entry,
                                                          self._use_snmpwalk_cache)
                    check_info.append(check_info_part)
                info[section_name] = check_info
            else:
                info[section_name] = snmp.get_snmp_table(snmp_config, check_plugin_name, oid_info,
                                                         self._use_snmpwalk_cache)

        return info
Пример #6
0
def test_no_subcheck_with_snmp_keywords(snmp_info):
    for name in snmp_info:
        assert name == check_utils.section_name_of(name)