From c6fbbd57cd3f9dc22d9ac56074e60e294ccc2ada Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 23:10:40 +0000 Subject: [PATCH 1/4] Put a full stop between a short MIB description and the object count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The meta description read "Enterprise-subtree for Stulz devices 3,855 objects with OIDs…". Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019ZWdUbfrYRgjQJ2a5qKjtn --- src/mibsite/render.py | 4 +++- tests/test_render.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mibsite/render.py b/src/mibsite/render.py index c130b3a..82d9a47 100644 --- a/src/mibsite/render.py +++ b/src/mibsite/render.py @@ -129,7 +129,9 @@ def _meta_description(m: Module, vendor: str) -> str: facts = f"{len(m.objects):,} objects with OIDs, types and descriptions." if not desc: return clip(f"{m.name} SNMP MIB{of}: {facts}") - return clip(f"{m.name}: {desc}" + (f" {facts}" if len(desc) < 80 else "")) + if len(desc) < 80: + desc = (desc if desc[-1] in ".!?" else desc + ".") + " " + facts + return clip(f"{m.name}: {desc}") MAX_HINT_VALUES = 40 # enumerations listed in a Type tooltip (IANAifType alone has ~280) diff --git a/tests/test_render.py b/tests/test_render.py index 43223b4..bf9e92b 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -235,3 +235,11 @@ def blocks(path): assert vendor[1]["itemListElement"][-1]["item"] == "https://x.test/vendors/example/" assert blocks("mibs/index.html")[0]["@type"] == "CollectionPage" assert blocks("vendors/index.html")[0]["@type"] == "CollectionPage" + + +def test_short_description_gets_a_full_stop_before_the_facts(): + from mibsite.render import _meta_description + m = Module("S-MIB", "s", "s/S-MIB", "pysmi", identity={"description": "Enterprise-subtree for Stulz devices"}) + assert _meta_description(m, "Stulz") == "S-MIB: Enterprise-subtree for Stulz devices. 0 objects with OIDs, types and descriptions." + m.identity["description"] = "Done." + assert _meta_description(m, "Stulz").startswith("S-MIB: Done. 0 objects") From 3c4f3de26c1be3fb14b469127aaedc15356489a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 23:27:43 +0000 Subject: [PATCH 2/4] Use fewer elements per row in the OID tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The kind badge (N, T, C, !, …) is drawn with CSS from a data-k attribute on the row instead of an element in every row. - Trailing empty cells (Type, Access, Status, Example) are left out. Borders move to the row and the hover/target highlight is also drawn as an inset shadow, so rows still look full-width. The target highlight uses an opaque colour, since shadow and background overlap. - The toggle button sits in the indent (absolutely positioned), so the badge still follows it. Stulz-WIB8000-MIB: 1.83 MB -> 1.70 MB of HTML. IF-MIB: 3,512 -> 3,309 elements. Screenshots at 1400, 1100 and 390 px, light and dark, match the previous version. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019ZWdUbfrYRgjQJ2a5qKjtn --- src/mibsite/render.py | 4 +--- src/mibsite/static/style.css | 30 ++++++++++++++++------------- src/mibsite/templates/_tree.html.j2 | 9 +++++++-- tests/test_render.py | 15 +++++++++++++-- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/mibsite/render.py b/src/mibsite/render.py index 82d9a47..14efb51 100644 --- a/src/mibsite/render.py +++ b/src/mibsite/render.py @@ -25,8 +25,6 @@ from .vendors import enterprise_number, module_root_oid, slugify STATIC = Path(__file__).parent / "static" -KIND_ABBR = {"node": "N", "identity": "I", "scalar": "S", "table": "T", "row": "R", "column": "C", - "notification": "!", "group": "G", "compliance": "M"} ACCESS_ABBR = {"read-only": "RO", "read-write": "RW", "read-create": "RC", "not-accessible": "NA", "accessible-for-notify": "AN", "write-only": "WO"} TIER_LABEL = {"pysmi": "Fully parsed", "netsnmp": "Parsed by net-snmp", "regex": "Partially parsed", "raw": "Unparsed"} @@ -87,7 +85,7 @@ def smi_date(value: str) -> tuple[str, str] | None: def make_env(root: str = "") -> Environment: env = Environment(loader=PackageLoader("mibsite", "templates"), autoescape=select_autoescape(["j2", "html"]), trim_blocks=True, lstrip_blocks=True) - env.globals.update(jsonld=jsonld, KIND_ABBR=KIND_ABBR, ACCESS_ABBR=ACCESS_ABBR, TIER_LABEL=TIER_LABEL, root=root, + env.globals.update(jsonld=jsonld, ACCESS_ABBR=ACCESS_ABBR, TIER_LABEL=TIER_LABEL, root=root, asset_v=asset_version()) env.filters["slug"] = slugify env.filters["enum_label"] = enum_label diff --git a/src/mibsite/static/style.css b/src/mibsite/static/style.css index ea70688..445c1e0 100644 --- a/src/mibsite/static/style.css +++ b/src/mibsite/static/style.css @@ -1,6 +1,6 @@ -:root{--red:#db202e;--gray:#575756;--bg:#f6f7f9;--card:#fff;--surface:#f6f8fa;--border:#d0d7de;--line:#eaeef2;--text:#24292f;--muted:#57606a;--link:#1f6fb2;--code:#f0f2f5;--syn:#8a5a00;--hl:#db202e1a;color-scheme:light} -@media (prefers-color-scheme:dark){:root:not([data-theme=light]){--bg:#272b30;--card:#2e3338;--surface:#353a41;--border:#3e444c;--line:#383e45;--text:#f9fafb;--muted:#acb6bf;--link:#6cb6ff;--code:#353a41;--syn:#e3b341;--hl:#db202e33;color-scheme:dark}} -:root[data-theme=dark]{--bg:#272b30;--card:#2e3338;--surface:#353a41;--border:#3e444c;--line:#383e45;--text:#f9fafb;--muted:#acb6bf;--link:#6cb6ff;--code:#353a41;--syn:#e3b341;--hl:#db202e33;color-scheme:dark} +:root{--red:#db202e;--gray:#575756;--bg:#f6f7f9;--card:#fff;--surface:#f6f8fa;--border:#d0d7de;--line:#eaeef2;--text:#24292f;--muted:#57606a;--link:#1f6fb2;--code:#f0f2f5;--syn:#8a5a00;--hl:#db202e1a;--hl-row:color-mix(in srgb,#db202e 10%,#fff);color-scheme:light} +@media (prefers-color-scheme:dark){:root:not([data-theme=light]){--bg:#272b30;--card:#2e3338;--surface:#353a41;--border:#3e444c;--line:#383e45;--text:#f9fafb;--muted:#acb6bf;--link:#6cb6ff;--code:#353a41;--syn:#e3b341;--hl:#db202e33;--hl-row:color-mix(in srgb,#db202e 20%,#2e3338);color-scheme:dark}} +:root[data-theme=dark]{--bg:#272b30;--card:#2e3338;--surface:#353a41;--border:#3e444c;--line:#383e45;--text:#f9fafb;--muted:#acb6bf;--link:#6cb6ff;--code:#353a41;--syn:#e3b341;--hl:#db202e33;--hl-row:color-mix(in srgb,#db202e 20%,#2e3338);color-scheme:dark} *{box-sizing:border-box} body{margin:0;background:var(--bg);color:var(--text);font:15px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",sans-serif} a{color:var(--link);text-decoration:none}a:hover{color:var(--red)} @@ -106,18 +106,22 @@ table.imports td{overflow-wrap:anywhere;color:var(--muted)}table.imports td a{co .tt-wrap{overflow-x:auto;border:1px solid var(--border);border-radius:6px} .tt{border-collapse:collapse;width:100%;font-size:14px} .tt th{text-align:left;font-weight:600;color:var(--muted);background:var(--surface);border-bottom:2px solid var(--border);padding:8px 10px;white-space:nowrap} -.tt td{padding:4px 10px;border-bottom:1px solid var(--line);vertical-align:middle} -.tt tr.r{cursor:pointer}.tt tr.r:hover,.tt tr.r.open{background:var(--surface)} -.tt tr.r:target,.tt tr.r.hl{background:var(--hl)} +.tt td{padding:4px 10px;vertical-align:middle}.tt tr{border-bottom:1px solid var(--line)} +.tt tr.r{cursor:pointer}.tt tr.r:hover,.tt tr.r.open{background:var(--surface);box-shadow:inset 0 0 0 9999px var(--surface)} +.tt tr.r:target,.tt tr.r.hl{background:var(--hl-row);box-shadow:inset 0 0 0 9999px var(--hl-row)} /* opaque: the shadow and the background overlap in the cells */ .tt tr[data-d="1"]{--d:1}.tt tr[data-d="2"]{--d:2}.tt tr[data-d="3"]{--d:3}.tt tr[data-d="4"]{--d:4}.tt tr[data-d="5"]{--d:5}.tt tr[data-d="6"]{--d:6}.tt tr[data-d="7"]{--d:7}.tt tr[data-d="8"]{--d:8}.tt tr[data-d="9"]{--d:9}.tt tr[data-d="10"]{--d:10}.tt tr[data-d="11"]{--d:11}.tt tr[data-d="12"]{--d:12}.tt tr[data-d="13"]{--d:13}.tt tr[data-d="14"]{--d:14}.tt tr[data-d="15"]{--d:15}.tt tr[data-d="16"]{--d:16}.tt tr[data-d="17"]{--d:17}.tt tr[data-d="18"]{--d:18}.tt tr[data-d="19"]{--d:19}.tt tr[data-d="20"]{--d:20}.tt tr[data-d="21"]{--d:21}.tt tr[data-d="22"]{--d:22}.tt tr[data-d="23"]{--d:23}.tt tr[data-d="24"]{--d:24} -.tt td.tn{padding-left:calc(var(--d,0) * 10px);white-space:nowrap}.tt tr.r:not(.br) td.tn{padding-left:calc(var(--d,0) * 10px + 26px)}.tn a{font-weight:600} +.tt td.tn{position:relative;padding-left:calc(var(--d,0) * 10px + 26px);white-space:nowrap}.tt td.tn>.tg{position:absolute;left:calc(var(--d,0) * 10px);top:50%;transform:translateY(-50%)}.tn a{font-weight:600} .tt td.o{white-space:nowrap;color:var(--muted);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px}.tt td.syn{overflow-wrap:anywhere;min-width:8em} .tg{width:22px;height:22px;padding:0;margin-right:4px;font-size:14px;border:0;background:none;color:var(--muted);line-height:1;vertical-align:middle} .tg::before{content:"\25BE"}.tg[aria-expanded="false"]::before{content:"\25B8"}.tg:hover{color:var(--red)} -.k{font-style:normal;display:inline-flex;align-items:center;justify-content:center;width:22px;height:20px;font-size:11px;font-weight:700;border-radius:4px;margin-right:6px;background:var(--code);color:var(--muted);vertical-align:middle} -.k-table,.k-row{color:#8250df}.k-column,.k-scalar{color:#1a7f37}.k-notification{color:var(--red)}.k-identity{color:var(--link)} -:root[data-theme=dark] .k-table,:root[data-theme=dark] .k-row{color:#c297ff}:root[data-theme=dark] .k-column,:root[data-theme=dark] .k-scalar{color:#56d364} -@media (prefers-color-scheme:dark){:root:not([data-theme=light]) .k-table,:root:not([data-theme=light]) .k-row{color:#c297ff}:root:not([data-theme=light]) .k-column,:root:not([data-theme=light]) .k-scalar{color:#56d364}} +/* kind badge, from the row's data-k (an element per row would add thousands of elements to a large page) */ +.tt td.tn::before{content:"N";font-style:normal;display:inline-flex;align-items:center;justify-content:center;width:22px;height:20px;font-size:11px;font-weight:700;border-radius:4px;margin-right:6px;background:var(--code);color:var(--muted);vertical-align:middle} +.tt tr[data-k=identity] td.tn::before{content:"I";color:var(--link)}.tt tr[data-k=scalar] td.tn::before{content:"S";color:#1a7f37} +.tt tr[data-k=table] td.tn::before{content:"T";color:#8250df}.tt tr[data-k=row] td.tn::before{content:"R";color:#8250df} +.tt tr[data-k=column] td.tn::before{content:"C";color:#1a7f37}.tt tr[data-k=notification] td.tn::before{content:"!";color:var(--red)} +.tt tr[data-k=group] td.tn::before{content:"G"}.tt tr[data-k=compliance] td.tn::before{content:"M"} +:root[data-theme=dark] .tt tr:is([data-k=table],[data-k=row]) td.tn::before{color:#c297ff}:root[data-theme=dark] .tt tr:is([data-k=column],[data-k=scalar]) td.tn::before{color:#56d364} +@media (prefers-color-scheme:dark){:root:not([data-theme=light]) .tt tr:is([data-k=table],[data-k=row]) td.tn::before{color:#c297ff}:root:not([data-theme=light]) .tt tr:is([data-k=column],[data-k=scalar]) td.tn::before{color:#56d364}} .syn{color:var(--syn);font-size:13px} .acc{font-size:11px;border:1px solid var(--border);border-radius:4px;padding:1px 6px;color:var(--muted)} .st{font-size:12px;color:var(--red)} @@ -155,8 +159,8 @@ table.imports td{overflow-wrap:anywhere;color:var(--muted)}table.imports td a{co .tt tr.r:not([hidden]){display:grid;grid-template-columns:minmax(0,1fr) auto;column-gap:8px;border-bottom:1px solid var(--line)} .tt tr.r>td{border:0;padding-top:4px;padding-bottom:4px} .tt tr.r>td:nth-child(n+4){display:none} - .tt td.tn{grid-column:1;grid-row:1;white-space:normal;overflow-wrap:anywhere;padding-left:calc(var(--d,0) * 8px + 6px)} - .tt tr.r:not(.br) td.tn{padding-left:calc(var(--d,0) * 8px + 32px)} + .tt td.tn{grid-column:1;grid-row:1;white-space:normal;overflow-wrap:anywhere;padding-left:calc(var(--d,0) * 8px + 32px)} + .tt td.tn>.tg{left:calc(var(--d,0) * 8px + 6px)} .tt td.syn{grid-column:2;grid-row:1;text-align:right;max-width:40vw;min-width:0;font-size:12px} .tt td.o{grid-column:1/-1;grid-row:2;padding-top:0!important;padding-left:calc(var(--d,0) * 8px + 60px);font-size:12px} .tt tr.dr:not([hidden]){display:block}.tt tr.dr>td{display:block;max-width:none} diff --git a/src/mibsite/templates/_tree.html.j2 b/src/mibsite/templates/_tree.html.j2 index 11928fb..87cc3a1 100644 --- a/src/mibsite/templates/_tree.html.j2 +++ b/src/mibsite/templates/_tree.html.j2 @@ -5,8 +5,13 @@ shows. Markup is kept terse on purpose: these pages hold ~1M rows in total and Pages caps the site at 1 GB. #} {% macro node(n, t, d=0) -%} {% set o = n.obj %}{% set ex = t.ex %}{% set has_ex = o.name in ex -%} -{{ KIND_ABBR.get(o.kind, "N") }}{{ o.name }}{% if o.defined_twice %} defined twice{% endif %}{{ o.oid }}{{ (o.syntax or "")|type_link(t.links) }}{% if o.access %}{{ ACCESS_ABBR.get(o.access, o.access) }}{% endif %}{% if o.status and o.status != "current" %}{{ o.status }}{% endif %} -{%- if ex %}{% if has_ex %}{% set e = ex[o.name][0] %}{{ e.v|enum_label(o.enums)|truncate(48, True, "…", 0) }}{% endif %}{% endif %} +{{ o.name }}{% if o.defined_twice %} defined twice{% endif %}{{ o.oid }} +{#- trailing empty cells are left out (fewer elements on pages with thousands of rows); the row's border and highlight span the full width anyway -#} +{%- set has_acc = o.access %}{% set has_st = o.status and o.status != "current" %} +{%- if o.syntax or has_acc or has_st or has_ex %}{{ (o.syntax or "")|type_link(t.links) }}{% endif %} +{%- if has_acc or has_st or has_ex %}{% if has_acc %}{{ ACCESS_ABBR.get(o.access, o.access) }}{% endif %}{% endif %} +{%- if has_st or has_ex %}{% if has_st %}{{ o.status }}{% endif %}{% endif %} +{%- if has_ex %}{% set e = ex[o.name][0] %}{{ e.v|enum_label(o.enums)|truncate(48, True, "…", 0) }}{% endif %} {%- if o.description or o.units or o.indexes or o.augments or o.enums or o.objects or has_ex -%}

{{ o.kind }}{% if o.syntax %} · {{ o.syntax }}{% endif %}{% if o.access %} · {{ o.access }}{% endif %}{% if o.status %} · {{ o.status }}{% endif %}

{%- if o.description %}
{{ o.description }}
{% endif -%} diff --git a/tests/test_render.py b/tests/test_render.py index bf9e92b..7f1791b 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -32,8 +32,8 @@ def test_render_site(tmp_path): assert 'id="goodName"' in page and "1.3.6.1.4.1.99999.1" in page assert '' in page assert "' in page + assert 'data-d="0" data-k="identity" id="goodMIB"' in page and 'data-d="1" data-k="scalar" id="goodName"' in page + assert '
Example" in page and 'w' in page # first example inline - assert 'data-d="0" id="goodMIB"' in page and 'data-d="1" id="goodName"' in page - assert '
goodMIB1.3.6.1.4.1.999991.3.6.1.4.1.7.1Integer32RO1.3.6.1.4.1.7.2Integer32deprecated
' in page From 5e3a2223b0091e53a9752df2dd56c4d9e8d71eac Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 23:31:44 +0000 Subject: [PATCH 3/4] Drop the det class from the detail box in the OID tree The CSS selects it as .dr>td>div instead. Saves about 10 bytes per object with details (Stulz-WIB8000-MIB: 1.70 MB -> 1.67 MB); the page renders pixel-identical. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019ZWdUbfrYRgjQJ2a5qKjtn --- src/mibsite/static/style.css | 10 +++++----- src/mibsite/templates/_tree.html.j2 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mibsite/static/style.css b/src/mibsite/static/style.css index 445c1e0..9a8da48 100644 --- a/src/mibsite/static/style.css +++ b/src/mibsite/static/style.css @@ -102,7 +102,7 @@ table.imports th{white-space:nowrap;font-weight:600}table.imports tr:last-child> table.imports td{overflow-wrap:anywhere;color:var(--muted)}table.imports td a{color:var(--link)} .tcs dt{margin-top:10px;scroll-margin-top:16px;border-radius:4px}.tcs dt:target{background:var(--hl)}.tcs dd{margin:4px 0 0 16px}.tcs p{margin:2px 0} -/* tree-table */ +/* tree-table (the detail box in a .dr row is a class-less div: one class fewer in thousands of rows) */ .tt-wrap{overflow-x:auto;border:1px solid var(--border);border-radius:6px} .tt{border-collapse:collapse;width:100%;font-size:14px} .tt th{text-align:left;font-weight:600;color:var(--muted);background:var(--surface);border-bottom:2px solid var(--border);padding:8px 10px;white-space:nowrap} @@ -129,11 +129,11 @@ table.imports td{overflow-wrap:anywhere;color:var(--muted)}table.imports td a{co .tt td.syn[title]{cursor:help;text-decoration:underline dotted;text-underline-offset:3px} .tt td.exv{max-width:22em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tt td.exv code{font-size:13px} .tt tr.dr>td{max-width:0;background:var(--surface);padding:4px 10px 12px} -.det{background:var(--card);border:1px solid var(--border);border-radius:6px;padding:12px 14px;white-space:normal} -.det p{margin:0} +.dr>td>div{background:var(--card);border:1px solid var(--border);border-radius:6px;padding:12px 14px;white-space:normal} +.dr>td>div p{margin:0} .kl{color:var(--muted);font-size:13px;margin-bottom:8px!important} -.det dl{display:grid;grid-template-columns:max-content 1fr;gap:2px 12px;margin:8px 0 0}.det dt{color:var(--muted)}.det dd{margin:0} -.ex{margin-top:10px;overflow-x:auto}.det{overflow-wrap:anywhere}.exh{color:var(--muted);font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;margin:0 0 6px!important} +.dr>td>div dl{display:grid;grid-template-columns:max-content 1fr;gap:2px 12px;margin:8px 0 0}.dr>td>div dt{color:var(--muted)}.dr>td>div dd{margin:0} +.ex{margin-top:10px;overflow-x:auto}.dr>td>div{overflow-wrap:anywhere}.exh{color:var(--muted);font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;margin:0 0 6px!important} .ex table{border-collapse:separate;border-spacing:0;font-size:13px;width:auto;max-width:100%;border:1px solid var(--border);border-radius:6px;overflow:hidden} .ex th{background:var(--surface);color:var(--muted);font-weight:600;text-align:left;padding:5px 14px;border-bottom:1px solid var(--border);white-space:nowrap} .ex td{padding:5px 14px;border-bottom:1px solid var(--line);vertical-align:top;white-space:nowrap}.ex tr:last-child td{border-bottom:0} diff --git a/src/mibsite/templates/_tree.html.j2 b/src/mibsite/templates/_tree.html.j2 index 87cc3a1..9399cab 100644 --- a/src/mibsite/templates/_tree.html.j2 +++ b/src/mibsite/templates/_tree.html.j2 @@ -13,7 +13,7 @@ {%- if has_st or has_ex %}{% if has_st %}{{ o.status }}{% endif %}{% endif %} {%- if has_ex %}{% set e = ex[o.name][0] %}{{ e.v|enum_label(o.enums)|truncate(48, True, "…", 0) }}{% endif %} {%- if o.description or o.units or o.indexes or o.augments or o.enums or o.objects or has_ex -%} -

{{ o.kind }}{% if o.syntax %} · {{ o.syntax }}{% endif %}{% if o.access %} · {{ o.access }}{% endif %}{% if o.status %} · {{ o.status }}{% endif %}

+

{{ o.kind }}{% if o.syntax %} · {{ o.syntax }}{% endif %}{% if o.access %} · {{ o.access }}{% endif %}{% if o.status %} · {{ o.status }}{% endif %}

{%- if o.description %}
{{ o.description }}
{% endif -%} {%- if o.units or o.indexes or o.augments or o.enums or o.objects %}
{%- if o.units %}
Units
{{ o.units }}
{% endif -%} From e1d45ed508bec76c9fbfe56a7fe4fe74d668ff66 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 23:38:40 +0000 Subject: [PATCH 4/4] Add a generated intro and vendor links to MIB pages - Every MIB page gets a short introduction built from facts the build already has: vendor or standards body, root OID, object counts by kind, the largest tables (linked), how many MIBs import it, how many of its objects LibreNMS uses and how many test devices give example values. A missing or short MIB description is followed or replaced by it in the meta description. - "More MIBs from " lists the 12 MIBs next to this one in the vendor's A-Z list (all of them for a small vendor), so every MIB page is linked from its neighbours. Not shown for vendor "Other". - The redirect pages at the old /mib/_root/ URLs drop noindex: with the canonical link and instant refresh, the old URL's standing moves to the new page. - The sitemap gives vendor pages the newest date of their MIBs, and the home, All MIBs and Vendors pages the newest date overall. - The search page heading is "Find SNMP MIBs, objects and OIDs". Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019ZWdUbfrYRgjQJ2a5qKjtn --- src/mibsite/render.py | 134 ++++++++++++++++++++++----- src/mibsite/static/style.css | 1 + src/mibsite/templates/mib.html.j2 | 2 + src/mibsite/templates/search.html.j2 | 2 +- tests/test_render.py | 54 ++++++++++- 5 files changed, 169 insertions(+), 24 deletions(-) diff --git a/src/mibsite/render.py b/src/mibsite/render.py index 14efb51..03128fe 100644 --- a/src/mibsite/render.py +++ b/src/mibsite/render.py @@ -120,15 +120,69 @@ def summary(m: Module) -> str: return " ".join(_COPYRIGHT.sub("", (m.identity or {}).get("description") or "").split()) -def _meta_description(m: Module, vendor: str) -> str: - """The MIB's own description first (what a searcher wants to read), then what the page holds.""" +def count(n: int, word: str, plural: str | None = None) -> str: + return f"{n:,} {word if n == 1 else plural or word + 's'}" + + +def _series(parts: list[str]) -> str: + return parts[0] if len(parts) == 1 else ", ".join(parts[:-1]) + " and " + parts[-1] + + +MAIN_TABLES = 5 + + +def intro(m: Module, vendor: str, root_oid: str | None, imported_by: int, used_objects: int | None, + example_devices: int) -> dict: + """A short generated introduction for a MIB page, from facts the build already has (many MIBs describe + themselves in a few words or not at all). Sentences are plain text; "tables" names the largest tables, + which the page links to.""" + org = " ".join(((m.identity or {}).get("organization") or "").split()) + if vendor.startswith("Standards (") and vendor.endswith(")"): + who = f"a standard SNMP MIB ({vendor[len('Standards ('):-1]})" + elif vendor != "Other": + who = f"an SNMP MIB from {vendor}" + elif org and len(org) <= 60: + who = f"an SNMP MIB from {org}" + else: + who = "an SNMP MIB" + sentences = [f"{m.name} is {who}" + (f" under OID {root_oid}." if root_oid else ".")] + kinds = Counter(o.kind for o in m.objects) + parts = [count(kinds[k], w) for k, w in (("table", "table"), ("scalar", "scalar"), ("notification", "notification")) + if kinds[k]] + if m.objects: + sentences.append(f"It defines {count(len(m.objects), 'object')}" + + (f", including {_series(parts)}" if parts else "") + ".") + if m.tcs: + sentences.append(f"It {'also ' if m.objects else ''}defines {count(len(m.tcs), 'textual convention')}.") + # largest tables first: a column's OID is its table's OID + ".1.N" + columns = Counter(o.oid.rsplit(".", 2)[0] for o in m.objects if o.kind == "column" and o.oid and o.oid.count(".") > 2) + tables = sorted((o for o in m.objects if o.kind == "table" and o.oid), key=lambda o: (-columns[o.oid], o.oid)) + after = [] + if imported_by: + after.append(f"{count(imported_by, 'other MIB')} import{'s' if imported_by == 1 else ''} it.") + if used_objects: + after.append(f"LibreNMS uses {used_objects:,} of its objects to monitor devices.") + elif used_objects == 0: + after.append("LibreNMS uses this MIB to monitor devices.") + if example_devices: + after.append(f"Example values come from {count(example_devices, 'LibreNMS test device')}.") + return {"sentences": sentences, "tables": [t.name for t in tables[:MAIN_TABLES]], "after": after} + + +def intro_text(i: dict) -> str: + tables = [f"Main tables: {', '.join(i['tables'])}."] if i["tables"] else [] + return " ".join(i["sentences"] + tables + i["after"]) + + +def _meta_description(m: Module, vendor: str, about: str = "") -> str: + """The MIB's own description first (what a searcher wants to read). A short one is followed by the + generated introduction (without its first sentence, which repeats the name); a missing one is replaced by it.""" desc = summary(m) - of = "" if vendor == "Other" else f" ({vendor})" - facts = f"{len(m.objects):,} objects with OIDs, types and descriptions." if not desc: - return clip(f"{m.name} SNMP MIB{of}: {facts}") + return clip(about or f"{m.name} SNMP MIB: {count(len(m.objects), 'object')} with OIDs, types and descriptions.") if len(desc) < 80: - desc = (desc if desc[-1] in ".!?" else desc + ".") + " " + facts + rest = about.split(". ", 1)[1] if ". " in about else f"{count(len(m.objects), 'object')} with OIDs, types and descriptions." + desc = (desc if desc[-1] in ".!?" else desc + ".") + " " + rest return clip(f"{m.name}: {desc}") @@ -173,7 +227,11 @@ def defined_names_of(m: Module) -> frozenset[str]: def mib_context(m: Module, table: SymbolTable, vendor: str, examples: dict[str, list], cfg: SiteConfig, - all_tcs: dict[str, TextualConvention] | None = None, modified: str | None = None) -> dict: + all_tcs: dict[str, TextualConvention] | None = None, modified: str | None = None, + used_objects: int | None = None, related: dict | None = None) -> dict: + """Template context of a MIB page. used_objects: how many of its objects LibreNMS uses (0: it uses the MIB + by name only; None: not at all). related: {"mods": [{name, url}], "count": MIBs of the vendor} for the + "More MIBs from" links.""" root = site_root(cfg) imports, defined_in = [], {} # defined_in: imported symbol -> link to its definition for modname, syms in m.imports.items(): @@ -194,15 +252,18 @@ def mib_context(m: Module, table: SymbolTable, vendor: str, examples: dict[str, type_links[ty] = f"#{ty}" elif ty in defined_in: type_links[ty] = defined_in[ty] + root_oid = module_root_oid(m) + about = intro(m, vendor, root_oid, len(imported_by), used_objects, + len({e["f"] for values in examples.values() for e in values})) return { - "m": m, "vendor": vendor, "vendor_slug": slugify(vendor), "too_large": not m.shows_objects, + "m": m, "vendor": vendor, "intro": about, "related": related, "vendor_slug": slugify(vendor), "too_large": not m.shows_objects, "tree": build_tree(objs), "unresolved": [o for o in objs if not o.oid], "imports": imports, # only what the template shows: whole Modules here would pickle most of the dataset per hub MIB "imported_by": [{"name": x.name, "url": x.url, "dir": x.dir} for x in imported_by], "notifications": [o for o in objs if o.kind == "notification"], "groups": [o for o in objs if o.kind in ("group", "compliance")], - "examples": examples, "hints": hints, "type_links": type_links, "root_oid": module_root_oid(m), "source_url": source_url(m, cfg), - "description": _meta_description(m, vendor), "modified": modified, + "examples": examples, "hints": hints, "type_links": type_links, "root_oid": root_oid, "source_url": source_url(m, cfg), + "description": _meta_description(m, vendor, intro_text(about)), "modified": modified, } @@ -249,8 +310,25 @@ def vendor_oid(mods: list[Module]) -> str | None: return f"1.3.6.1.4.1.{counts.most_common(1)[0][0]}" if counts else None +RELATED = 12 # "More MIBs from " links on a MIB page + + +def related_mibs(m: Module, vendor: str, vendor_mods: list[Module]) -> dict | None: + """MIBs listed under "More MIBs from ": the ones next to m in the vendor's A–Z list (all of them + for a small vendor), so every MIB is linked from its neighbours. None for "Other" (no common vendor).""" + if len(vendor_mods) < 2 or vendor == "Other": + return None + i = vendor_mods.index(m) + others = vendor_mods[i + 1:] + vendor_mods[:i] # wraps around: the last MIBs link to the first + if len(others) > RELATED: + others = others[-RELATED // 2:] + others[:RELATED // 2] + picked = sorted(others, key=lambda x: (x.name.lower(), x.id)) + return {"mods": [{"name": x.name, "url": x.url} for x in picked], "count": len(vendor_mods)} + + def write_moved_pages(out: Path, mods: list[Module], cfg: SiteConfig) -> None: - """Top-level MIBs moved from /mib/_root/NAME/ to /mib/NAME/: leave a redirect (keeping any #anchor).""" + """Top-level MIBs moved from /mib/_root/NAME/ to /mib/NAME/: leave a redirect (keeping any #anchor). No noindex: + with the canonical link and the instant refresh, search engines move the old URL's standing to the new one.""" root = site_root(cfg) for m in mods: new = escape(f"{root}{m.url}") @@ -258,7 +336,7 @@ def write_moved_pages(out: Path, mods: list[Module], cfg: SiteConfig) -> None: dest.parent.mkdir(parents=True, exist_ok=True) dest.write_text( f'{escape(m.name)} has moved' - f'' + f'' f'' f'' f'

Moved to {new}.

\n') @@ -299,8 +377,24 @@ def render_site(out: Path, modules: list[Module], table: SymbolTable, vendors: d mods = sorted(modules, key=lambda m: (m.name.lower(), m.id)) all_tcs = {t.name: t for m in mods for t in m.tcs} + # keyed by slug, the page path: IANA names that differ only in case (6527/7483 "Nokia (formerly/Formerly + # 'Alcatel-Lucent')") share one page, shown under the first of their names + by_vendor: dict[str, list[Module]] = defaultdict(list) + vendor_name: dict[str, str] = {} + for m in mods: + name = vendors.get(m.id, "Other") + slug = slugify(name) + by_vendor[slug].append(m) + vendor_name[slug] = min(vendor_name.get(slug, name), name) + usage = usage or Usage() + + def used_objects(m: Module) -> int | None: + return len(usage.objects[m.id]) if m.id in usage.objects else 0 if m.id in usage.modules else None + contexts = [mib_context(m, table, vendors.get(m.id, "Other"), examples.get(m.id, {}), cfg, all_tcs, - modified.get(m.id)) for m in mods] + modified.get(m.id), used_objects(m), related_mibs(m, vendors.get(m.id, "Other"), + by_vendor[slugify(vendors.get(m.id, "Other"))])) + for m in mods] with Pool(jobs or None, initializer=_init, initargs=(cfg, out)) as pool: progress = Progress("MIB pages", len(contexts)) pages = [] @@ -310,15 +404,6 @@ def render_site(out: Path, modules: list[Module], table: SymbolTable, vendors: d progress.close() env = make_env(site_root(cfg)) - # keyed by slug, the page path: IANA names that differ only in case (6527/7483 "Nokia (formerly/Formerly - # 'Alcatel-Lucent')") share one page, shown under the first of their names - by_vendor: dict[str, list[Module]] = defaultdict(list) - vendor_name: dict[str, str] = {} - for m in mods: - name = vendors.get(m.id, "Other") - slug = slugify(name) - by_vendor[slug].append(m) - vendor_name[slug] = min(vendor_name.get(slug, name), name) mib_groups = group_by_letter(mods, lambda m: m.name) letters = [letter for letter, _ in mib_groups] stats = {"modules": len(mods), "objects": sum(len(m.objects) for m in mods), "vendors": len(by_vendor), @@ -352,6 +437,11 @@ def render_site(out: Path, modules: list[Module], table: SymbolTable, vendors: d (out / "CNAME").write_text(host + "\n") (out / "robots.txt").write_text(f"User-agent: *\nAllow: /\nSitemap: {cfg.base_url}/sitemap.xml\n") lastmod = {m.url: modified[m.id] for m in mods if m.id in modified} + for _, slug, vmods in vendor_list: # a list page changes when one of its MIBs does + if dates := [modified[m.id] for m in vmods if m.id in modified]: + lastmod[f"/vendors/{slug}/"] = max(dates) + if modified: + lastmod.update(dict.fromkeys(("/", "/mibs/", "/vendors/"), max(modified.values()))) urls = "".join(f"{escape(cfg.base_url + p)}" + (f"{lastmod[p]}" if p in lastmod else "") + "" for p in pages) (out / "sitemap.xml").write_text( diff --git a/src/mibsite/static/style.css b/src/mibsite/static/style.css index 9a8da48..296b096 100644 --- a/src/mibsite/static/style.css +++ b/src/mibsite/static/style.css @@ -89,6 +89,7 @@ article.mib{display:flex;flex-direction:column;gap:20px} .pill{padding:4px 10px;border-radius:999px;background:#1f6fb21a;color:var(--link);font-size:13px;font-weight:600} .pill.ext{background:var(--code);color:var(--muted)} pre.lead{font-size:16px;margin:12px 0 0;max-width:860px} +.intro{margin:12px 0 0;max-width:860px;color:var(--muted)} pre.desc{white-space:pre-wrap;font:inherit;margin:0;overflow-wrap:anywhere} /*
: the minifier keeps the MIB's line breaks */
 .meta{display:grid;grid-template-columns:max-content 1fr;gap:6px 20px;margin:16px 0;font-size:14px}.meta dt{color:var(--muted)}.meta dd{margin:0;overflow-wrap:anywhere}
 .srclink{display:inline-flex;align-items:center;gap:6px;font-weight:600}
diff --git a/src/mibsite/templates/mib.html.j2 b/src/mibsite/templates/mib.html.j2
index 1c176cc..e5e5030 100644
--- a/src/mibsite/templates/mib.html.j2
+++ b/src/mibsite/templates/mib.html.j2
@@ -12,6 +12,7 @@
 

{{ m.name }}

{{ vendor }}{% if m.dir == "_external" %}External: LibreNMS does not include this MIB{% endif %}
{% if m.identity and m.identity.description %}
{{ m.identity.description }}
{% endif %} +

{{ intro.sentences|join(" ") }}{% if intro.tables %} Main tables: {% for t in intro.tables %}{% if tree %}{{ t }}{% else %}{{ t }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}.{% endif %}{% if intro.after %} {{ intro.after|join(" ") }}{% endif %}

{% if m.identity and m.identity.organization %}
Organization
{{ m.identity.organization }}
{% endif %} @@ -51,5 +52,6 @@
{% endif %} {% if imported_by %}

Used by

    {% for i in imported_by %}
  • {{ i.name }}{% if i.dir not in ("_root", m.dir) %} ({{ i.dir }}){% endif %}
  • {% endfor %}
{% endif %} +{% if related %}

More MIBs from {{ vendor }}

{% if related.count > related.mods|length + 1 %}

All {{ "{:,}".format(related.count) }} MIBs from {{ vendor }} →

{% endif %}
{% endif %} {% endblock %} diff --git a/src/mibsite/templates/search.html.j2 b/src/mibsite/templates/search.html.j2 index 55f1dc0..61b2e54 100644 --- a/src/mibsite/templates/search.html.j2 +++ b/src/mibsite/templates/search.html.j2 @@ -2,7 +2,7 @@ {% block title %}Find MIBs and OIDs | LibreNMS MIB Browser{% endblock %} {% block description %}Find an SNMP MIB, object or OID in the MIBs of LibreNMS. Type a name, or a numeric OID (an instance OID too) to find the object that defines it.{% endblock %} {% block main %} -

Find

+

Find SNMP MIBs, objects and OIDs

Type the start of a MIB name or an object name. Type a numeric OID to find the object that defines it. An instance OID also gives a result.

diff --git a/tests/test_render.py b/tests/test_render.py index 7f1791b..c9e189e 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -164,7 +164,8 @@ def test_seo_titles_descriptions_and_lastmod(tmp_path): assert article["dateModified"] == "2025-03-04" and article["publisher"] == {"@id": "https://www.librenms.org/#org"} bare_page = canon((tmp_path / "mib/acme/BARE-MIB/index.html").read_text()) assert "BARE-MIB (1.3.6.1.4.1.5) – SNMP MIB |" in bare_page # vendor "Other" is left out - assert 'content="BARE-MIB SNMP MIB: 1 objects with OIDs' in bare_page and "dateModified" not in bare_page + assert 'content="BARE-MIB is an SNMP MIB under OID 1.3.6.1.4.1.5. It defines 1 object." name="description"' in bare_page + assert "dateModified" not in bare_page sitemap = (tmp_path / "sitemap.xml").read_text() assert "<loc>https://x.test/mib/GOOD-MIB/</loc><lastmod>2025-03-04</lastmod></url>" in sitemap assert "<loc>https://x.test/mib/acme/BARE-MIB/</loc></url>" in sitemap @@ -241,6 +242,8 @@ def test_short_description_gets_a_full_stop_before_the_facts(): from mibsite.render import _meta_description m = Module("S-MIB", "s", "s/S-MIB", "pysmi", identity={"description": "Enterprise-subtree for Stulz devices"}) assert _meta_description(m, "Stulz") == "S-MIB: Enterprise-subtree for Stulz devices. 0 objects with OIDs, types and descriptions." + about = "S-MIB is an SNMP MIB from Stulz. It defines 3 objects." + assert _meta_description(m, "Stulz", about) == "S-MIB: Enterprise-subtree for Stulz devices. It defines 3 objects." m.identity["description"] = "Done." assert _meta_description(m, "Stulz").startswith("S-MIB: Done. 0 objects") @@ -254,3 +257,52 @@ def test_rows_leave_out_only_trailing_empty_cells(tmp_path): page = canon((tmp_path / "mib/R-MIB/index.html").read_text()) assert '<td class="o">1.3.6.1.4.1.7.1<td class="syn">Integer32<td><span class="acc">RO</span><tr' in page assert '<td class="o">1.3.6.1.4.1.7.2<td class="syn">Integer32<td><td><span class="st">deprecated</span></table>' in page + + +def test_intro_related_and_list_lastmod(tmp_path): + objs = [Obj("ups", "1.3.6.1.4.1.318", "node"), Obj("upsTable", "1.3.6.1.4.1.318.1", "table"), + Obj("upsEntry", "1.3.6.1.4.1.318.1.1", "row"), Obj("upsA", "1.3.6.1.4.1.318.1.1.1", "column"), + Obj("upsB", "1.3.6.1.4.1.318.1.1.2", "column"), Obj("smallTable", "1.3.6.1.4.1.318.2", "table"), + Obj("smallEntry", "1.3.6.1.4.1.318.2.1", "row"), Obj("smallA", "1.3.6.1.4.1.318.2.1.1", "column"), + Obj("upsName", "1.3.6.1.4.1.318.3", "scalar"), Obj("upsTrap", "1.3.6.1.4.1.318.0.1", "notification")] + main = Module("APC-MIB", "apc", "apc/APC-MIB", "pysmi", objects=objs) + others = [Module(f"APC{i:02d}-MIB", "apc", f"apc/APC{i:02d}-MIB", "pysmi", imports={"APC-MIB": ["ups"]}) + for i in range(20)] + loner = Module("LONE-MIB", "_root", "LONE-MIB", "pysmi", objects=[Obj("l", "1.3.6.1.4.1.9", "node")]) + mods = [main, *others, loner] + vendors = {m.id: "APC" for m in [main, *others]} + examples = {main.id: {"upsName": [{"v": "x", "t": "OCTET STRING", "i": "0", "f": "apc_a"}, + {"v": "y", "t": "OCTET STRING", "i": "0", "f": "apc_b"}]}} + render_site(tmp_path, mods, SymbolTable(mods), vendors, examples, SiteConfig("https://x.test", "abc", "d"), jobs=1, + usage=Usage(objects={main.id: {"upsName", "upsA"}}), + modified={main.id: "2025-01-01", others[3].id: "2025-06-01", loner.id: "2024-01-01"}) + page = canon((tmp_path / "mib/apc/APC-MIB/index.html").read_text()) + intro = page.split('<p class="intro">')[1].split('<div class="summary-grid">')[0].removesuffix("</p>") + assert intro == ("APC-MIB is an SNMP MIB from APC under OID 1.3.6.1.4.1.318. It defines 10 objects, including 2 tables, " + '1 scalar and 1 notification. Main tables: <a href="#upsTable">upsTable</a>, <a href="#smallTable">' + "smallTable</a>. 20 other MIBs import it. LibreNMS uses 2 of its objects to monitor devices. " + "Example values come from 2 LibreNMS test devices.") + related = page.split("More MIBs from APC</h2>")[1].split("</section>")[0] + assert related.count("<li>") == 12 and "APC00-MIB" in related and "APC19-MIB" in related and "APC-MIB<" not in related + assert 'href="/vendors/apc/">All 21 MIBs from APC' in related + assert "More MIBs from" not in canon((tmp_path / "mib/LONE-MIB/index.html").read_text()) # vendor "Other" + small = canon((tmp_path / "mib/apc/APC05-MIB/index.html").read_text()) + assert "1 other MIB imports" not in small and "LibreNMS uses" not in small + sitemap = (tmp_path / "sitemap.xml").read_text() + assert "<loc>https://x.test/vendors/apc/</loc><lastmod>2025-06-01</lastmod>" in sitemap + assert "<loc>https://x.test/</loc><lastmod>2025-06-01</lastmod>" in sitemap + assert "<loc>https://x.test/stats/</loc></url>" in sitemap + old = (tmp_path / "mib/_root/LONE-MIB/index.html").read_text() + assert "noindex" not in old and 'rel="canonical"' in old + assert "<h1>Find SNMP MIBs, objects and OIDs</h1>" in canon((tmp_path / "search/index.html").read_text()) + + +def test_intro_textual_conventions(): + from mibsite.model import TextualConvention + from mibsite.render import intro, intro_text + tcs = [TextualConvention("A"), TextualConvention("B")] + only_tcs = Module("TC-MIB", "_root", "TC-MIB", "pysmi", tcs=tcs) + assert intro_text(intro(only_tcs, "Other", None, 0, None, 0)) == "TC-MIB is an SNMP MIB. It defines 2 textual conventions." + both = Module("B-MIB", "_root", "B-MIB", "pysmi", objects=[Obj("b", "1.3.6.1.4.1.9.1", "scalar")], tcs=tcs) + assert "It defines 1 object, including 1 scalar. It also defines 2 textual conventions." in intro_text( + intro(both, "Standards (IETF)", "1.3.6.1.4.1.9", 1, None, 0))