Пример #1
0
    def _build_map_by_get(self, oid_name):
        """
        Builds the oids_map for the provided oid_name using snmp get.
        Args:
            oid_name: The oid for which to build the map using snmp get.
        Returns:
            None
        """
        stat = None
        try:
            if self._config[u"oids"][oid_name][u"method"] == u"get":
                stat = self._snmp_connection.get(
                    oid=self._config[u"oids"][oid_name][u"oid"])
        except Exception as e:
            self._polling_status.handle_exception(u"device", e)
            self._handle_exceptions_for_oid(oid_name, e)
            return
        finally:
            # populate snmpget_oid_map keys b/c relied on in _parse_expression
            self._snmpget_oid_map[oid_name] = None

        if stat:
            self._snmpget_oid_map[oid_name] = stat.value
            self._handle_successes_for_oid(oid_name)
        else:
            panoptes_metrics_exception = metrics.PanoptesMetricsNullException()
            self._handle_exceptions_for_oid(oid_name,
                                            panoptes_metrics_exception)
Пример #2
0
    def _build_map_by_bulk_walk(self, oid_name):
        """
        Builds the oids_map for the provided oid_name using snmp bulk walk.
        Args:
            oid_name: The oid for which to build the map using snmp bulk walk.
        Returns:
            None
        """
        self._oid_maps[oid_name] = {}
        device_metrics_map = dict()
        stats = None
        try:
            if self._config[u"oids"][oid_name][u"method"] == u"bulk_walk":
                stats = self._snmp_connection.bulk_walk(
                    oid=self._config[u"oids"][oid_name][u"oid"],
                    non_repeaters=int(
                        self._get_snmp_polling_var(u"non_repeaters", 0)),
                    max_repetitions=int(
                        self._get_snmp_polling_var(u"max_repetitions",
                                                   _MAX_REPETITIONS)))
        except Exception as e:
            self._polling_status.handle_exception(u"device", e)
            self._handle_exceptions_for_oid(oid_name, e)
            return

        if stats:
            for ent in stats:
                index = ent.index
                if u"index_transform" in self._config[u"oids"][oid_name]:
                    if ent.index in self._config[u"oids"][oid_name][
                            u"index_transform"]:
                        index = self._config[u"oids"][oid_name][
                            u"index_transform"][ent.index]
                device_metrics_map[index] = ent.value
            self._oid_maps[oid_name] = device_metrics_map
            self._handle_successes_for_oid(oid_name)
        else:
            panoptes_metrics_exception = metrics.PanoptesMetricsNullException()
            self._handle_exceptions_for_oid(oid_name,
                                            panoptes_metrics_exception)