Skip to content
Snippets Groups Projects
Commit d5bf0491 authored by Sam Roberts's avatar Sam Roberts
Browse files

only build snmp indices once per endpoint request

parent 737df390
Branches
Tags 1.1.30
1 merge request!14only build snmp indices once per endpoint request
......@@ -67,6 +67,7 @@ import itertools
import json
import logging
import re
from functools import partial
from flask import Blueprint, Response, current_app, request, jsonify
......@@ -1214,9 +1215,7 @@ def _get_services_internal(service_type=None):
num_threads=20):
yield doc['value']
def _add_snmp(s):
all_snmp_info = common.load_snmp_indexes(
current_app.config['INVENTORY_PROVIDER_CONFIG'], )
def _add_snmp(s, all_snmp_info):
snmp_interfaces = all_snmp_info.get(s['hostname'], {})
interface_info = snmp_interfaces.get(s['interface'], None)
if interface_info:
......@@ -1272,7 +1271,8 @@ def _get_services_internal(service_type=None):
result = filter(_wanted_in_output, result)
result = map(_format_services, result)
if include_snmp:
result = map(_add_snmp, result)
all_snmp_info = common.load_snmp_indexes(current_app.config['INVENTORY_PROVIDER_CONFIG'])
result = map(partial(_add_snmp, all_snmp_info=all_snmp_info), result)
result = list(result)
if not result:
......
......@@ -3,6 +3,7 @@ envlist = py36
[flake8]
exclude = venv,.tox,build
max-line-length = 120
[testenv]
passenv = TEST_OPSDB_HOSTNAME,TEST_OPSDB_DBNAME,TEST_OPSDB_USERNAME,TEST_OPSDB_PASSWORD
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment