Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use snmp mibs copy while mibs.snmplabs.com is down #7835

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from ...console import CONTEXT_SETTINGS


def fetch_mib(mib):
def fetch_mib(mib, source_url):
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

import pysnmp_mibs
from pysmi.codegen import PySnmpCodeGen
from pysmi.compiler import MibCompiler
Expand All @@ -19,7 +24,8 @@ def fetch_mib(mib):

target_directory = os.path.dirname(pysnmp_mibs.__file__)

reader = HttpReader('mibs.snmplabs.com', 80, '/asn1/@mib@')
parsed_url = urlparse(source_url)
reader = HttpReader(parsed_url.netloc, 80, parsed_url.path)
mibCompiler = MibCompiler(SmiStarParser(), PySnmpCodeGen(), PyFileWriter(target_directory))

mibCompiler.addSources(reader)
Expand All @@ -29,8 +35,13 @@ def fetch_mib(mib):

@click.command(context_settings=CONTEXT_SETTINGS, short_help='Translate MIB name to OIDs in SNMP profiles')
@click.argument('profile_path')
@click.option(
'--mib_source_url',
default='https://raw.githubusercontent.com/projx/snmp-mibs/master/@mib@',
help='Source url to fetch missing MIBS',
)
@click.pass_context
def translate_profile(ctx, profile_path):
def translate_profile(ctx, profile_path, mib_source_url):
"""
Do OID translation in a SNMP profile. This isn't a plain replacement, as it
doesn't preserve comments and indent, but it should automate most of the
Expand All @@ -57,7 +68,7 @@ def translate_profile(ctx, profile_path):
try:
mib_view_controller.mibBuilder.loadModule(mib)
except MibNotFoundError:
fetch_mib(mib)
fetch_mib(mib, source_url=mib_source_url)
if 'table' in metric:
table = metric['table']
node = mib_view_controller.mibBuilder.importSymbols(mib, table)[0]
Expand Down