diff --git a/src/mibsite/render.py b/src/mibsite/render.py index c130b3a..03128fe 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 @@ -122,14 +120,70 @@ 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(f"{m.name}: {desc}" + (f" {facts}" if len(desc) < 80 else "")) + return clip(about or f"{m.name} SNMP MIB: {count(len(m.objects), 'object')} with OIDs, types and descriptions.") + if len(desc) < 80: + 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}") MAX_HINT_VALUES = 40 # enumerations listed in a Type tooltip (IANAifType alone has ~280) @@ -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 ea70688..296b096 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)} @@ -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}
@@ -102,22 +103,26 @@ 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}
-.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)}
@@ -125,11 +130,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}
@@ -155,8 +160,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..9399cab 100644
--- a/src/mibsite/templates/_tree.html.j2
+++ b/src/mibsite/templates/_tree.html.j2
@@ -5,10 +5,15 @@
    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 %}

+

{{ 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 -%} 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 43223b4..c9e189e 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.99999