def _detect(self) -> Collection[SectionName]: return gather_available_raw_section_names( sections=self.snmp_section_detects, on_error=self.on_error, missing_sys_description=self.missing_sys_description, backend=self._backend, )
def _detect(self, *, select_from: Set[SectionName]) -> Set[SectionName]: """Detect the applicable sections for the device in question""" return gather_available_raw_section_names( sections=[(name, self.plugin_store[name].detect_spec) for name in select_from], on_error=self.on_error, missing_sys_description=self.missing_sys_description, backend=self._backend, )
def test_gather_available_raw_section_names_defaults(backend, mocker): assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR] assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ] assert snmp_scan.gather_available_raw_section_names( [(s.name, s.detect_spec) for s in agent_based_register.iter_all_snmp_sections()], on_error=OnError.RAISE, missing_sys_description=False, backend=backend, ) == { SectionName("hr_mem"), SectionName("snmp_info"), SectionName("snmp_os"), SectionName("snmp_uptime"), }
def test_gather_available_raw_section_names_defaults(backend, mocker): assert snmp_cache.get_oid_from_single_oid_cache(snmp_scan.OID_SYS_DESCR) assert snmp_cache.get_oid_from_single_oid_cache(snmp_scan.OID_SYS_OBJ) assert snmp_scan.gather_available_raw_section_names( [SNMPScanSection(_.name, _.detect_spec) for _ in config.registered_snmp_sections.values()], on_error="raise", do_snmp_scan=False, binary_host=False, backend=backend, ) == { "hr_mem", "mgmt_snmp_info", "mgmt_snmp_uptime", "snmp_info", "snmp_os", "snmp_uptime", }
def test_gather_available_raw_section_names_defaults(backend, mocker): assert snmp_cache.get_oid_from_single_oid_cache(snmp_scan.OID_SYS_DESCR) assert snmp_cache.get_oid_from_single_oid_cache(snmp_scan.OID_SYS_OBJ) assert snmp_scan.gather_available_raw_section_names( [ SNMPScanSection(_.name, _.detect_spec) for _ in agent_based_register.iter_all_snmp_sections() ], on_error="raise", binary_host=False, backend=backend, ) == { SectionName("hr_mem"), SectionName("mgmt_snmp_info"), SectionName("snmp_info"), SectionName("snmp_os"), SectionName("snmp_uptime"), }
def _detect( self, *, restrict_to: Optional[Collection[SectionName]] = None, ) -> Set[SectionName]: if restrict_to is None: # TODO: disabled sections must be considered here, once # snmp_section_detects is a global configuration. sections: Collection[ Tuple[SectionName, SNMPDetectSpec]] = self.snmp_section_detects.items() else: sections = [(n, self.snmp_section_detects[n]) for n in restrict_to if n in self.snmp_section_detects] return gather_available_raw_section_names( sections=sections, on_error=self.on_error, missing_sys_description=self.missing_sys_description, backend=self._backend, )
def __call__( self, snmp_config: SNMPHostConfig, ) -> Set[SectionName]: """Returns a list of raw sections that shall be processed by this source. The logic is only processed once. Once processed, the answer is cached. """ if self._cached_result is not None: return self._cached_result self._cached_result = gather_available_raw_section_names( self.sections(), on_error=self.on_error, do_snmp_scan=self.do_snmp_scan, binary_host=config.get_config_cache().in_binary_hostlist( snmp_config.hostname, config.snmp_without_sys_descr, ), backend=factory.backend(snmp_config), ) return self._cached_result