netbox-eosl 0.2.1__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {netbox_eosl-0.2.1/netbox_eosl.egg-info → netbox_eosl-0.3.0}/PKG-INFO +20 -9
  2. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/README.md +19 -8
  3. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/__init__.py +5 -4
  4. netbox_eosl-0.3.0/netbox_eosl/client.py +165 -0
  5. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/management/commands/eosl_check.py +31 -4
  6. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/templates/netbox_eosl/eosl_panel.html +8 -1
  7. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0/netbox_eosl.egg-info}/PKG-INFO +20 -9
  8. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/SOURCES.txt +1 -0
  9. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/pyproject.toml +1 -1
  10. netbox_eosl-0.3.0/tests/test_client.py +134 -0
  11. netbox_eosl-0.2.1/netbox_eosl/client.py +0 -134
  12. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/LICENSE +0 -0
  13. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/MANIFEST.in +0 -0
  14. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/management/__init__.py +0 -0
  15. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/management/commands/__init__.py +0 -0
  16. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/matching.py +0 -0
  17. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl/template_content.py +0 -0
  18. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/dependency_links.txt +0 -0
  19. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/requires.txt +0 -0
  20. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/top_level.txt +0 -0
  21. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/setup.cfg +0 -0
  22. {netbox_eosl-0.2.1 → netbox_eosl-0.3.0}/tests/test_matching.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netbox-eosl
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai.
5
5
  Author-email: "EOSL.ai" <hello@eosl.ai>
6
6
  License: Apache-2.0
@@ -27,7 +27,7 @@ own end-of-life bulletin.
27
27
 
28
28
  A panel appears on the right side of each Device and Device Type page: end-of-sale date,
29
29
  end-of-service-life date, the Support Runway Score, a link to the vendor bulletin, and a link to
30
- the full EOSL.ai model page. A `manage.py eosl_check` command audits your whole inventory.
30
+ the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
31
31
 
32
32
  Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
33
33
  wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
@@ -64,7 +64,7 @@ PLUGINS = [
64
64
  PLUGINS_CONFIG = {
65
65
  "netbox_eosl": {
66
66
  "api_url": "https://eosl.ai", # data source origin
67
- "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
67
+ "cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
68
68
  "request_timeout": 5, # network timeout in seconds
69
69
  },
70
70
  }
@@ -110,9 +110,10 @@ carries its status and date. Use `--past-only` to print just that list (handy in
110
110
 
111
111
  ## How matching works
112
112
 
113
- The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
114
- powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
115
- field (a Device inherits it from its Device Type) in deterministic, conservative steps:
113
+ Since 0.3.0 the plugin sends the part numbers it needs to `https://eosl.ai/api/v1/check`, at most 25
114
+ in one request, and caches each answer for `cache_timeout`. Matching happens on the EOSL.ai server.
115
+ For each Device Type the `part_number` field (a Device inherits it from its Device Type) is resolved
116
+ in deterministic, conservative steps:
116
117
 
117
118
  1. **Exact** match (case-insensitive).
118
119
  2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
@@ -120,11 +121,10 @@ field (a Device inherits it from its Device Type) in deterministic, conservative
120
121
  but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
121
122
  `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
122
123
  a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
123
- 4. **Variant aliases** from `https://eosl.ai/data/aliases.json`: packaging forms of the same hardware,
124
+ 4. **Variant aliases**: packaging forms of the same hardware,
124
125
  such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
125
126
  it could mean has the same vendor and the same dates; short keys and keys shared across vendors
126
- resolve only when the NetBox manufacturer names the vendor. The file is optional: if it cannot be
127
- fetched, matching runs without it.
127
+ resolve only when the NetBox manufacturer names the vendor.
128
128
  5. If the part number finds nothing, the device type's **model name** is tried with the same rules
129
129
  (NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
130
130
 
@@ -134,6 +134,17 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
134
134
  The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
135
135
  `tests/` — run `python tests/test_matching.py` (or `pytest`).
136
136
 
137
+ ## Limits
138
+
139
+ EOSL.ai checks lists of part numbers 25 at a time, up to a daily allowance per address (the current figure is on https://eosl.ai/api/). Cached
140
+ answers do not count, so with the default 7-day cache an estate with a few hundred device types is
141
+ covered in normal use and a larger one fills in over several days. When a check cannot be made (the
142
+ allowance is used up, or eosl.ai cannot be reached) the panel says so, and `eosl_check` reports those
143
+ device types as **NOT CHECKED** on their own line. They are never counted as "not found".
144
+
145
+ **Upgrading from 0.2.x:** versions up to 0.2.1 downloaded `https://eosl.ai/data/lookup.json`. That
146
+ file stops being served on 31 January 2027; upgrade before then. No settings change is needed.
147
+
137
148
  ## Data & trust
138
149
 
139
150
  - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
@@ -6,7 +6,7 @@ own end-of-life bulletin.
6
6
 
7
7
  A panel appears on the right side of each Device and Device Type page: end-of-sale date,
8
8
  end-of-service-life date, the Support Runway Score, a link to the vendor bulletin, and a link to
9
- the full EOSL.ai model page. A `manage.py eosl_check` command audits your whole inventory.
9
+ the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
10
10
 
11
11
  Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
12
12
  wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
@@ -43,7 +43,7 @@ PLUGINS = [
43
43
  PLUGINS_CONFIG = {
44
44
  "netbox_eosl": {
45
45
  "api_url": "https://eosl.ai", # data source origin
46
- "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
46
+ "cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
47
47
  "request_timeout": 5, # network timeout in seconds
48
48
  },
49
49
  }
@@ -89,9 +89,10 @@ carries its status and date. Use `--past-only` to print just that list (handy in
89
89
 
90
90
  ## How matching works
91
91
 
92
- The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
93
- powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
94
- field (a Device inherits it from its Device Type) in deterministic, conservative steps:
92
+ Since 0.3.0 the plugin sends the part numbers it needs to `https://eosl.ai/api/v1/check`, at most 25
93
+ in one request, and caches each answer for `cache_timeout`. Matching happens on the EOSL.ai server.
94
+ For each Device Type the `part_number` field (a Device inherits it from its Device Type) is resolved
95
+ in deterministic, conservative steps:
95
96
 
96
97
  1. **Exact** match (case-insensitive).
97
98
  2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
@@ -99,11 +100,10 @@ field (a Device inherits it from its Device Type) in deterministic, conservative
99
100
  but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
100
101
  `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
101
102
  a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
102
- 4. **Variant aliases** from `https://eosl.ai/data/aliases.json`: packaging forms of the same hardware,
103
+ 4. **Variant aliases**: packaging forms of the same hardware,
103
104
  such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
104
105
  it could mean has the same vendor and the same dates; short keys and keys shared across vendors
105
- resolve only when the NetBox manufacturer names the vendor. The file is optional: if it cannot be
106
- fetched, matching runs without it.
106
+ resolve only when the NetBox manufacturer names the vendor.
107
107
  5. If the part number finds nothing, the device type's **model name** is tried with the same rules
108
108
  (NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
109
109
 
@@ -113,6 +113,17 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
113
113
  The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
114
114
  `tests/` — run `python tests/test_matching.py` (or `pytest`).
115
115
 
116
+ ## Limits
117
+
118
+ EOSL.ai checks lists of part numbers 25 at a time, up to a daily allowance per address (the current figure is on https://eosl.ai/api/). Cached
119
+ answers do not count, so with the default 7-day cache an estate with a few hundred device types is
120
+ covered in normal use and a larger one fills in over several days. When a check cannot be made (the
121
+ allowance is used up, or eosl.ai cannot be reached) the panel says so, and `eosl_check` reports those
122
+ device types as **NOT CHECKED** on their own line. They are never counted as "not found".
123
+
124
+ **Upgrading from 0.2.x:** versions up to 0.2.1 downloaded `https://eosl.ai/data/lookup.json`. That
125
+ file stops being served on 31 January 2027; upgrade before then. No settings change is needed.
126
+
116
127
  ## Data & trust
117
128
 
118
129
  - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
@@ -6,7 +6,7 @@ guesses, so it cannot assert an end-of-life date NetBox isn't certain about.
6
6
  """
7
7
  from netbox.plugins import PluginConfig
8
8
 
9
- __version__ = "0.2.1"
9
+ __version__ = "0.3.0"
10
10
 
11
11
 
12
12
  class EOSLConfig(PluginConfig):
@@ -22,9 +22,10 @@ class EOSLConfig(PluginConfig):
22
22
  default_settings = {
23
23
  # Base origin of the EOSL.ai data source. Override only if you mirror the dataset.
24
24
  "api_url": "https://eosl.ai",
25
- # How long (seconds) to cache the downloaded lookup table. Default: 24h.
26
- "cache_timeout": 86400,
27
- # Network timeout (seconds) for fetching the lookup table.
25
+ # How long (seconds) to cache each part number's answer. Default: 7 days. Checks count
26
+ # against a free daily allowance on eosl.ai, so a short cache spends it faster.
27
+ "cache_timeout": 604800,
28
+ # Network timeout (seconds) for one request to eosl.ai.
28
29
  "request_timeout": 5,
29
30
  }
30
31
 
@@ -0,0 +1,165 @@
1
+ """Client for the EOSL.ai check route.
2
+
3
+ Since 0.3.0 this plugin asks https://eosl.ai/api/v1/check about the part numbers it needs, at most
4
+ 25 in one request, and caches each answer. Versions up to 0.2.1 downloaded
5
+ https://eosl.ai/data/lookup.json (the whole database) and matched locally; that file stops being
6
+ served on 2027-01-31.
7
+
8
+ Matching now happens on the EOSL.ai server, with the same rules this plugin always used: exact,
9
+ then punctuation-insensitive, then vendor short codes and vetted variant aliases. Never fuzzy: a
10
+ wrong end-of-life date on the wrong device would defeat the point of a source-backed tool.
11
+
12
+ THREE DIFFERENT ANSWERS, NEVER MERGED. A part is found, or it is not tracked, or it COULD NOT BE
13
+ CHECKED (the network failed, or the free allowance of part numbers for the day was used up).
14
+ "Could not be checked" is never reported as "not tracked": `lookup_part` returns a dict with
15
+ state "unavailable" and the reason, and the audit command counts it on its own line.
16
+ """
17
+ import hashlib
18
+ import logging
19
+
20
+ import requests
21
+ from django.core.cache import cache
22
+ from netbox.plugins import get_plugin_config
23
+
24
+ from . import matching
25
+
26
+ logger = logging.getLogger("netbox.plugins.netbox_eosl")
27
+
28
+ USER_AGENT = "netbox-eosl/0.3 (+https://eosl.ai)"
29
+ BATCH = 25 # the route's limit for one request
30
+ _PREFIX = "netbox_eosl:check:v1:"
31
+ _MISS = {"found": False}
32
+ _BLOCK_KEY = "netbox_eosl:blocked:v1"
33
+
34
+
35
+ class Unavailable(Exception):
36
+ """The check could not be made. `reason` is a sentence fit to show to an operator."""
37
+
38
+ def __init__(self, reason):
39
+ super().__init__(reason)
40
+ self.reason = reason
41
+
42
+
43
+ def _cfg(key):
44
+ return get_plugin_config("netbox_eosl", key)
45
+
46
+
47
+ def _key(part, vendor):
48
+ raw = "{}|{}".format((part or "").strip().upper(), (vendor or "").strip().upper())
49
+ return _PREFIX + hashlib.sha1(raw.encode("utf-8")).hexdigest()
50
+
51
+
52
+ def _post(items):
53
+ """One request for at most BATCH items. Returns the list of result rows, in order."""
54
+ url = _cfg("api_url").rstrip("/") + "/api/v1/check"
55
+ try:
56
+ resp = requests.post(
57
+ url,
58
+ json={"items": items, "records": True},
59
+ timeout=_cfg("request_timeout"),
60
+ headers={"User-Agent": USER_AGENT, "Accept": "application/json"},
61
+ )
62
+ except requests.RequestException as exc:
63
+ raise Unavailable("EOSL.ai could not be reached ({}).".format(exc.__class__.__name__))
64
+ try:
65
+ body = resp.json()
66
+ except ValueError:
67
+ body = {}
68
+ if resp.status_code == 429:
69
+ # The server's own sentence states the count and when it resets.
70
+ raise Unavailable(body.get("message") or "The daily allowance of part-number checks is used up.")
71
+ if resp.status_code != 200 or not isinstance(body.get("results"), list) or len(body["results"]) != len(items):
72
+ raise Unavailable(body.get("message") or "EOSL.ai answered HTTP {}.".format(resp.status_code))
73
+ return body["results"]
74
+
75
+
76
+ def check_many(pairs):
77
+ """Resolve [(part, vendor), ...]. Returns {(part, vendor): record_or_None}.
78
+
79
+ Cached answers are used first; the rest go out in requests of BATCH. Raises Unavailable if any
80
+ request fails, after caching what did come back, so a later run resumes where this one stopped.
81
+ """
82
+ out, todo = {}, []
83
+ for part, vendor in pairs:
84
+ if not (part or "").strip():
85
+ continue
86
+ hit = cache.get(_key(part, vendor))
87
+ if hit is None:
88
+ if (part, vendor) not in todo:
89
+ todo.append((part, vendor))
90
+ else:
91
+ out[(part, vendor)] = hit.get("record") if hit.get("found") else None
92
+ if todo:
93
+ blocked = cache.get(_BLOCK_KEY)
94
+ if blocked:
95
+ raise Unavailable(blocked)
96
+ for i in range(0, len(todo), BATCH):
97
+ chunk = todo[i:i + BATCH]
98
+ try:
99
+ rows = _post([{"part": p, **({"vendor": v} if v else {})} for p, v in chunk])
100
+ except Unavailable as exc:
101
+ # Do not re-ask on every page view while the server is refusing: five minutes.
102
+ cache.set(_BLOCK_KEY, exc.reason, 300)
103
+ logger.warning("netbox-eosl: %s", exc.reason)
104
+ raise
105
+ for (part, vendor), row in zip(chunk, rows):
106
+ rec = row.get("record") if row.get("found") else None
107
+ cache.set(_key(part, vendor), {"found": True, "record": rec} if rec else _MISS, _cfg("cache_timeout"))
108
+ out[(part, vendor)] = rec
109
+ return out
110
+
111
+
112
+ def _display(rec, part_number, model, matched_from):
113
+ state, label, css = matching.classify(rec)
114
+ slug = rec.get("s")
115
+ return {
116
+ "part": rec.get("p"),
117
+ "vendor": rec.get("v"),
118
+ "family": rec.get("f"),
119
+ "end_of_sale": rec.get("eos"),
120
+ "eosl": rec.get("eol"),
121
+ "source_url": rec.get("src"),
122
+ "exposure_score": rec.get("xs"),
123
+ "exposure_band": rec.get("xb"),
124
+ "active": bool(rec.get("a")),
125
+ "state": state,
126
+ "state_label": label,
127
+ "state_css": css,
128
+ "page_url": (_cfg("api_url").rstrip("/") + "/system/" + slug + "/") if slug else _cfg("api_url"),
129
+ # What NetBox held that produced the match, shown when it differs from the catalogued part
130
+ # (a vendor short code, a packaging variant, or the device type's model name), so a reader
131
+ # never sees a different part number with no explanation.
132
+ "matched_from": matched_from if matched_from != rec.get("p") else None,
133
+ "matched_by_model": bool(matched_from) and matched_from == model and matched_from != part_number,
134
+ }
135
+
136
+
137
+ def lookup_part(part_number, vendor=None, model=None):
138
+ """Resolve one part number (optionally with its NetBox manufacturer name).
139
+
140
+ Returns a display dict when found, None when EOSL.ai does not track it, and
141
+ {"state": "unavailable", "reason": "..."} when the check could not be made.
142
+
143
+ `vendor` turns on vendor short codes (Fortinet FG-60E -> FortiGate-60E) without risking a
144
+ cross-vendor match. `model` is the device type's model name, tried only when the part number
145
+ finds nothing: NetBox's device-type library leaves some part numbers blank.
146
+ """
147
+ if not part_number and not model:
148
+ return None
149
+ vendor = vendor or ""
150
+ try:
151
+ for candidate in (part_number, model):
152
+ if not candidate:
153
+ continue
154
+ rec = check_many([(candidate, vendor)]).get((candidate, vendor))
155
+ if rec:
156
+ return _display(rec, part_number, model, candidate)
157
+ except Unavailable as exc:
158
+ return {"state": "unavailable", "reason": exc.reason}
159
+ return None
160
+
161
+
162
+ def search_url(term):
163
+ """A safe fallback link into eosl.ai when we have no exact match."""
164
+ base = _cfg("api_url").rstrip("/")
165
+ return "{}/?q={}".format(base, requests.utils.quote(term or ""))
@@ -10,7 +10,7 @@ from collections import Counter
10
10
  from dcim.models import DeviceType
11
11
  from django.core.management.base import BaseCommand
12
12
 
13
- from netbox_eosl.client import lookup_part
13
+ from netbox_eosl.client import Unavailable, check_many, lookup_part
14
14
 
15
15
 
16
16
  class Command(BaseCommand):
@@ -24,9 +24,24 @@ class Command(BaseCommand):
24
24
  )
25
25
 
26
26
  def handle(self, *args, **options):
27
- device_types = DeviceType.objects.select_related("manufacturer").all()
27
+ device_types = list(DeviceType.objects.select_related("manufacturer").all())
28
28
  counts = Counter()
29
29
  past_rows = []
30
+ stopped = None
31
+
32
+ # Ask for every part number up front, 25 to a request, so the loop below reads from the
33
+ # cache. If the server stops answering (the free daily allowance, or the network), what
34
+ # was answered is kept and the rest is counted as NOT CHECKED, never as "not found".
35
+ pairs = []
36
+ for dt in device_types:
37
+ part = (dt.part_number or "").strip()
38
+ mfr = getattr(getattr(dt, "manufacturer", None), "name", "") or ""
39
+ if part and (part, mfr) not in pairs:
40
+ pairs.append((part, mfr))
41
+ try:
42
+ check_many(pairs)
43
+ except Unavailable as exc:
44
+ stopped = exc.reason
30
45
 
31
46
  for dt in device_types:
32
47
  part = (dt.part_number or "").strip()
@@ -39,6 +54,10 @@ class Command(BaseCommand):
39
54
  # finds nothing (HISTORY §82).
40
55
  mfr = getattr(getattr(dt, "manufacturer", None), "name", "") or ""
41
56
  rec = lookup_part(part, mfr, model)
57
+ if rec and rec.get("state") == "unavailable":
58
+ counts["not_checked"] += 1
59
+ stopped = stopped or rec.get("reason")
60
+ continue
42
61
  if not rec:
43
62
  counts["not_found"] += 1
44
63
  continue
@@ -56,9 +75,10 @@ class Command(BaseCommand):
56
75
  "clear": "Tracked, supported",
57
76
  "active": "Active, no EOL announced",
58
77
  "not_found": "Not found in EOSL.ai",
78
+ "not_checked": "NOT CHECKED",
59
79
  "no_part_number": "No part number set",
60
80
  }
61
- for key in ("risk", "watch", "clear", "active", "not_found", "no_part_number"):
81
+ for key in ("risk", "watch", "clear", "active", "not_found", "not_checked", "no_part_number"):
62
82
  if counts.get(key):
63
83
  self.stdout.write(" {:<32} {}".format(label[key] + ":", counts[key]))
64
84
 
@@ -83,6 +103,13 @@ class Command(BaseCommand):
83
103
  url=rec.get("page_url"),
84
104
  )
85
105
  )
86
- elif not options.get("past_only"):
106
+ elif not options.get("past_only") and not counts.get("not_checked"):
87
107
  self.stdout.write("")
88
108
  self.stdout.write(self.style.SUCCESS("No device types need action."))
109
+
110
+ if counts.get("not_checked"):
111
+ self.stdout.write("")
112
+ self.stdout.write(self.style.ERROR(
113
+ "{} device type(s) were NOT CHECKED, so this audit is incomplete. {} "
114
+ "Answers already received are cached; run the command again later to continue.".format(
115
+ counts["not_checked"], stopped or "")))
@@ -7,7 +7,14 @@
7
7
  <a href="https://eosl.ai/" target="_blank" rel="noopener" class="btn btn-ghost-secondary btn-sm" title="Data source: EOSL.ai">EOSL.ai</a>
8
8
  </div>
9
9
  </h2>
10
- {% if eosl %}
10
+ {% if eosl and eosl.state == "unavailable" %}
11
+ <div class="card-body">
12
+ <p class="text-muted mb-0">
13
+ This part number could not be checked just now. {{ eosl.reason }}
14
+ This is not a statement that the hardware is untracked or supported.
15
+ </p>
16
+ </div>
17
+ {% elif eosl %}
11
18
  <table class="table table-hover attr-table">
12
19
  <tr>
13
20
  <th scope="row">Status</th>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netbox-eosl
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai.
5
5
  Author-email: "EOSL.ai" <hello@eosl.ai>
6
6
  License: Apache-2.0
@@ -27,7 +27,7 @@ own end-of-life bulletin.
27
27
 
28
28
  A panel appears on the right side of each Device and Device Type page: end-of-sale date,
29
29
  end-of-service-life date, the Support Runway Score, a link to the vendor bulletin, and a link to
30
- the full EOSL.ai model page. A `manage.py eosl_check` command audits your whole inventory.
30
+ the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
31
31
 
32
32
  Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
33
33
  wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
@@ -64,7 +64,7 @@ PLUGINS = [
64
64
  PLUGINS_CONFIG = {
65
65
  "netbox_eosl": {
66
66
  "api_url": "https://eosl.ai", # data source origin
67
- "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
67
+ "cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
68
68
  "request_timeout": 5, # network timeout in seconds
69
69
  },
70
70
  }
@@ -110,9 +110,10 @@ carries its status and date. Use `--past-only` to print just that list (handy in
110
110
 
111
111
  ## How matching works
112
112
 
113
- The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
114
- powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
115
- field (a Device inherits it from its Device Type) in deterministic, conservative steps:
113
+ Since 0.3.0 the plugin sends the part numbers it needs to `https://eosl.ai/api/v1/check`, at most 25
114
+ in one request, and caches each answer for `cache_timeout`. Matching happens on the EOSL.ai server.
115
+ For each Device Type the `part_number` field (a Device inherits it from its Device Type) is resolved
116
+ in deterministic, conservative steps:
116
117
 
117
118
  1. **Exact** match (case-insensitive).
118
119
  2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
@@ -120,11 +121,10 @@ field (a Device inherits it from its Device Type) in deterministic, conservative
120
121
  but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
121
122
  `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
122
123
  a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
123
- 4. **Variant aliases** from `https://eosl.ai/data/aliases.json`: packaging forms of the same hardware,
124
+ 4. **Variant aliases**: packaging forms of the same hardware,
124
125
  such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
125
126
  it could mean has the same vendor and the same dates; short keys and keys shared across vendors
126
- resolve only when the NetBox manufacturer names the vendor. The file is optional: if it cannot be
127
- fetched, matching runs without it.
127
+ resolve only when the NetBox manufacturer names the vendor.
128
128
  5. If the part number finds nothing, the device type's **model name** is tried with the same rules
129
129
  (NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
130
130
 
@@ -134,6 +134,17 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
134
134
  The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
135
135
  `tests/` — run `python tests/test_matching.py` (or `pytest`).
136
136
 
137
+ ## Limits
138
+
139
+ EOSL.ai checks lists of part numbers 25 at a time, up to a daily allowance per address (the current figure is on https://eosl.ai/api/). Cached
140
+ answers do not count, so with the default 7-day cache an estate with a few hundred device types is
141
+ covered in normal use and a larger one fills in over several days. When a check cannot be made (the
142
+ allowance is used up, or eosl.ai cannot be reached) the panel says so, and `eosl_check` reports those
143
+ device types as **NOT CHECKED** on their own line. They are never counted as "not found".
144
+
145
+ **Upgrading from 0.2.x:** versions up to 0.2.1 downloaded `https://eosl.ai/data/lookup.json`. That
146
+ file stops being served on 31 January 2027; upgrade before then. No settings change is needed.
147
+
137
148
  ## Data & trust
138
149
 
139
150
  - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
@@ -15,4 +15,5 @@ netbox_eosl/management/__init__.py
15
15
  netbox_eosl/management/commands/__init__.py
16
16
  netbox_eosl/management/commands/eosl_check.py
17
17
  netbox_eosl/templates/netbox_eosl/eosl_panel.html
18
+ tests/test_client.py
18
19
  tests/test_matching.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "netbox-eosl"
7
- version = "0.2.1"
7
+ version = "0.3.0"
8
8
  description = "Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1,134 @@
1
+ """Tests for the 0.3 client: it calls /api/v1/check, caches per part, and never reports
2
+ "could not be checked" as "not tracked".
3
+
4
+ Django, NetBox and requests are replaced with small stand-ins, so this runs with plain pytest.
5
+ """
6
+ import importlib
7
+ import os
8
+ import sys
9
+ import types
10
+
11
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
12
+
13
+ REC = {"p": "WS-C3850-24T-L", "f": "Catalyst 3850 Series", "v": "Cisco", "s": "cisco-catalyst-3850",
14
+ "eos": "2020-10", "eol": "2025-10", "src": "https://www.cisco.com/x", "a": 0, "xs": 22,
15
+ "xb": "Little or no runway"}
16
+
17
+
18
+ class FakeCache(dict):
19
+ def set(self, k, v, timeout=None):
20
+ self[k] = v
21
+
22
+
23
+ class FakeResp:
24
+ def __init__(self, status, body):
25
+ self.status_code, self._body = status, body
26
+
27
+ def json(self):
28
+ if self._body is None:
29
+ raise ValueError("no json")
30
+ return self._body
31
+
32
+
33
+ def load(handler):
34
+ """Import netbox_eosl.client against stand-ins. `handler(items)` -> FakeResp or raises."""
35
+ cache = FakeCache()
36
+ calls = []
37
+
38
+ class RequestException(Exception):
39
+ pass
40
+
41
+ def post(url, json=None, timeout=None, headers=None):
42
+ calls.append({"url": url, "json": json, "headers": headers})
43
+ return handler(json["items"], RequestException)
44
+
45
+ requests = types.ModuleType("requests")
46
+ requests.post, requests.RequestException = post, RequestException
47
+ requests.utils = types.SimpleNamespace(quote=lambda s: s)
48
+ dj, core, djcache = types.ModuleType("django"), types.ModuleType("django.core"), types.ModuleType("django.core.cache")
49
+ djcache.cache = cache
50
+ nb, plugins = types.ModuleType("netbox"), types.ModuleType("netbox.plugins")
51
+ plugins.get_plugin_config = lambda name, key: {"api_url": "https://eosl.ai", "cache_timeout": 60, "request_timeout": 5}[key]
52
+ plugins.PluginConfig = object
53
+ sys.modules.update({"requests": requests, "django": dj, "django.core": core, "django.core.cache": djcache,
54
+ "netbox": nb, "netbox.plugins": plugins})
55
+ for m in [k for k in sys.modules if k.startswith("netbox_eosl")]:
56
+ del sys.modules[m]
57
+ return importlib.import_module("netbox_eosl.client"), calls, cache
58
+
59
+
60
+ def answer(items, _exc):
61
+ rows = []
62
+ for it in items:
63
+ if it["part"].upper() == "WS-C3850-24T-L":
64
+ rows.append({"part": it["part"], "found": True, "record": REC})
65
+ else:
66
+ rows.append({"part": it["part"], "found": False})
67
+ return FakeResp(200, {"results": rows})
68
+
69
+
70
+ def test_found_part_is_formatted_and_cached():
71
+ client, calls, _ = load(answer)
72
+ r = client.lookup_part("ws-c3850-24t-l", "Cisco")
73
+ assert r["eosl"] == "2025-10" and r["state"] == "risk" and r["source_url"] == "https://www.cisco.com/x"
74
+ assert r["matched_from"] == "ws-c3850-24t-l"
75
+ assert calls[0]["url"] == "https://eosl.ai/api/v1/check"
76
+ assert calls[0]["json"] == {"items": [{"part": "ws-c3850-24t-l", "vendor": "Cisco"}], "records": True}
77
+ client.lookup_part("ws-c3850-24t-l", "Cisco")
78
+ assert len(calls) == 1, "the second lookup must come from the cache"
79
+
80
+
81
+ def test_untracked_part_is_none_and_the_miss_is_cached():
82
+ client, calls, _ = load(answer)
83
+ assert client.lookup_part("ZZ-NOPE", "Cisco") is None
84
+ assert client.lookup_part("ZZ-NOPE", "Cisco") is None
85
+ assert len(calls) == 1
86
+
87
+
88
+ def test_model_is_tried_only_when_the_part_number_finds_nothing():
89
+ client, calls, _ = load(answer)
90
+ r = client.lookup_part("ZZ-NOPE", "Cisco", "WS-C3850-24T-L")
91
+ assert r["matched_by_model"] is True and len(calls) == 2
92
+ client2, calls2, _ = load(answer)
93
+ client2.lookup_part("WS-C3850-24T-L", "Cisco", "anything")
94
+ assert len(calls2) == 1
95
+
96
+
97
+ def test_daily_limit_is_unavailable_not_untracked():
98
+ msg = "This address has checked 250 of 250 part numbers today."
99
+ client, calls, _ = load(lambda items, exc: FakeResp(429, {"error": "daily_limit", "message": msg}))
100
+ r = client.lookup_part("WS-C3850-24T-L", "Cisco")
101
+ assert r == {"state": "unavailable", "reason": msg}
102
+ # While blocked, further lookups do not hit the server again.
103
+ assert client.lookup_part("OTHER", "Cisco")["state"] == "unavailable"
104
+ assert len(calls) == 1
105
+
106
+
107
+ def test_network_failure_and_bad_answers_are_unavailable():
108
+ def boom(items, exc):
109
+ raise exc("down")
110
+ client, _, _ = load(boom)
111
+ assert client.lookup_part("WS-C3850-24T-L")["state"] == "unavailable"
112
+ client, _, _ = load(lambda items, exc: FakeResp(200, {"results": []})) # short answer
113
+ assert client.lookup_part("WS-C3850-24T-L")["state"] == "unavailable"
114
+ client, _, _ = load(lambda items, exc: FakeResp(503, None))
115
+ assert client.lookup_part("WS-C3850-24T-L")["state"] == "unavailable"
116
+
117
+
118
+ def test_many_parts_go_out_25_to_a_request_and_keep_what_arrived():
119
+ seen = []
120
+
121
+ def handler(items, exc):
122
+ seen.append(len(items))
123
+ if len(seen) == 3:
124
+ return FakeResp(429, {"message": "limit"})
125
+ return answer(items, exc)
126
+ client, calls, cache = load(handler)
127
+ pairs = [("P%d" % i, "") for i in range(60)]
128
+ try:
129
+ client.check_many(pairs)
130
+ raise AssertionError("expected Unavailable")
131
+ except client.Unavailable:
132
+ pass
133
+ assert seen == [25, 25, 10]
134
+ assert sum(1 for k in cache if k.startswith("netbox_eosl:check")) == 50, "the first 50 answers are kept"
@@ -1,134 +0,0 @@
1
- """Client for the EOSL.ai public lookup dataset.
2
-
3
- Downloads https://eosl.ai/data/lookup.json (the same compact part-number -> status map that powers
4
- the eosl.ai bulk checker), caches it, and resolves a part number to its lifecycle record via the
5
- deterministic, vendor-gated matcher in `matching.py`. Never fuzzy-matches — a wrong end-of-life date
6
- on the wrong device would defeat the point of a source-backed tool.
7
- """
8
- import logging
9
-
10
- import requests
11
- from django.core.cache import cache
12
- from netbox.plugins import get_plugin_config
13
-
14
- from . import matching
15
-
16
- logger = logging.getLogger("netbox.plugins.netbox_eosl")
17
-
18
- _SKU_CACHE_KEY = "netbox_eosl:skus:v2"
19
- _ALIAS_CACHE_KEY = "netbox_eosl:aliases:v1"
20
- # In-process memo of the built indexes, rebuilt only when the sku set changes.
21
- _MEMO = {"token": None, "idx": (None, None)}
22
-
23
-
24
- def _cfg(key):
25
- return get_plugin_config("netbox_eosl", key)
26
-
27
-
28
- def _load_skus():
29
- """Return the list of sku records from EOSL.ai, cached. [] on any failure (never raises)."""
30
- skus = cache.get(_SKU_CACHE_KEY)
31
- if skus is not None:
32
- return skus
33
-
34
- url = _cfg("api_url").rstrip("/") + "/data/lookup.json"
35
- try:
36
- resp = requests.get(
37
- url,
38
- timeout=_cfg("request_timeout"),
39
- headers={"User-Agent": "netbox-eosl/0.2 (+https://eosl.ai)"},
40
- )
41
- resp.raise_for_status()
42
- skus = resp.json().get("skus", [])
43
- except (requests.RequestException, ValueError) as exc:
44
- logger.warning("netbox-eosl: could not load lookup data from %s: %s", url, exc)
45
- cache.set(_SKU_CACHE_KEY, [], 300) # brief negative cache so a broken upstream isn't hammered
46
- return []
47
-
48
- cache.set(_SKU_CACHE_KEY, skus, _cfg("cache_timeout"))
49
- return skus
50
-
51
-
52
- def _load_aliases():
53
- """Return https://eosl.ai/data/aliases.json (variant aliases, HISTORY §82), cached, or None.
54
-
55
- Optional by design: when it cannot be fetched, matching is exactly what it was without it.
56
- """
57
- al = cache.get(_ALIAS_CACHE_KEY)
58
- if al is not None:
59
- return al or None
60
- url = _cfg("api_url").rstrip("/") + "/data/aliases.json"
61
- try:
62
- resp = requests.get(url, timeout=_cfg("request_timeout"),
63
- headers={"User-Agent": "netbox-eosl/0.2 (+https://eosl.ai)"})
64
- resp.raise_for_status()
65
- data = resp.json()
66
- al = {"open": data.get("open") or {}, "gated": data.get("gated") or {}}
67
- except (requests.RequestException, ValueError) as exc:
68
- logger.info("netbox-eosl: no alias table from %s (%s); matching without it", url, exc)
69
- cache.set(_ALIAS_CACHE_KEY, {}, 300)
70
- return None
71
- cache.set(_ALIAS_CACHE_KEY, al, _cfg("cache_timeout"))
72
- return al
73
-
74
-
75
- def _indexes():
76
- """(exact, loose) indexes, rebuilt in-process only when the sku count changes."""
77
- skus = _load_skus()
78
- token = len(skus)
79
- if _MEMO["token"] != token:
80
- _MEMO["token"] = token
81
- _MEMO["idx"] = matching.build_index(skus)
82
- return _MEMO["idx"]
83
-
84
-
85
- def lookup_part(part_number, vendor=None, model=None):
86
- """Resolve one part number (optionally with its NetBox manufacturer name) to a display dict, or None.
87
-
88
- Passing `vendor` enables vendor-gated aliases (e.g. Fortinet FG-60E -> FortiGate-60E, Meraki MX67C ->
89
- MX67C-HW-NA) without risking a cross-vendor false match. `model` is the device type's model name,
90
- tried only when the part number finds nothing: NetBox's own device-type library leaves some part
91
- numbers blank and names the product in the model ("PowerEdge R640"). Same matcher, same rules.
92
- """
93
- if not part_number and not model:
94
- return None
95
- exact, loose_index = _indexes()
96
- aliases = _load_aliases()
97
- rec = None
98
- matched_from = None
99
- for candidate in (part_number, model):
100
- if candidate:
101
- rec = matching.match(candidate, vendor, exact, loose_index, aliases)
102
- if rec:
103
- matched_from = candidate
104
- break
105
- if not rec:
106
- return None
107
- state, label, css = matching.classify(rec)
108
- slug = rec.get("s")
109
- return {
110
- "part": rec.get("p"),
111
- "vendor": rec.get("v"),
112
- "family": rec.get("f"),
113
- "end_of_sale": rec.get("eos"),
114
- "eosl": rec.get("eol"),
115
- "source_url": rec.get("src"),
116
- "exposure_score": rec.get("xs"),
117
- "exposure_band": rec.get("xb"),
118
- "active": bool(rec.get("a")),
119
- "state": state,
120
- "state_label": label,
121
- "state_css": css,
122
- "page_url": (_cfg("api_url").rstrip("/") + "/system/" + slug + "/") if slug else _cfg("api_url"),
123
- # What NetBox held that produced the match, shown when it differs from the catalogued part
124
- # (a vendor short code, a packaging variant, or the device type's model name), so a reader
125
- # never sees a different part number with no explanation.
126
- "matched_from": matched_from if matched_from != rec.get("p") else None,
127
- "matched_by_model": bool(matched_from) and matched_from == model and matched_from != part_number,
128
- }
129
-
130
-
131
- def search_url(term):
132
- """A safe fallback link into eosl.ai when we have no exact match."""
133
- base = _cfg("api_url").rstrip("/")
134
- return "{}/?q={}".format(base, requests.utils.quote(term or ""))
File without changes
File without changes
File without changes