netbox-eosl 0.2.0__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.
- {netbox_eosl-0.2.0/netbox_eosl.egg-info → netbox_eosl-0.3.0}/PKG-INFO +36 -15
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/README.md +35 -14
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/__init__.py +5 -4
- netbox_eosl-0.3.0/netbox_eosl/client.py +165 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/management/commands/eosl_check.py +45 -14
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/templates/netbox_eosl/eosl_panel.html +18 -2
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0/netbox_eosl.egg-info}/PKG-INFO +36 -15
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/SOURCES.txt +1 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/pyproject.toml +1 -1
- netbox_eosl-0.3.0/tests/test_client.py +134 -0
- netbox_eosl-0.2.0/netbox_eosl/client.py +0 -127
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/LICENSE +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/MANIFEST.in +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/management/__init__.py +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/management/commands/__init__.py +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/matching.py +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl/template_content.py +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/dependency_links.txt +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/requires.txt +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/netbox_eosl.egg-info/top_level.txt +0 -0
- {netbox_eosl-0.2.0 → netbox_eosl-0.3.0}/setup.cfg +0 -0
- {netbox_eosl-0.2.0 → 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.
|
|
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,11 +27,12 @@ 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
|
|
30
|
+
the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
|
|
31
31
|
|
|
32
|
-
Matching is
|
|
33
|
-
|
|
34
|
-
offers a search link instead of
|
|
32
|
+
Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
|
|
33
|
+
wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
|
|
34
|
+
matched from. If a part number isn't in the database, it says so and offers a search link instead of
|
|
35
|
+
guessing.
|
|
35
36
|
|
|
36
37
|
## Requirements
|
|
37
38
|
|
|
@@ -63,7 +64,7 @@ PLUGINS = [
|
|
|
63
64
|
PLUGINS_CONFIG = {
|
|
64
65
|
"netbox_eosl": {
|
|
65
66
|
"api_url": "https://eosl.ai", # data source origin
|
|
66
|
-
"cache_timeout":
|
|
67
|
+
"cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
|
|
67
68
|
"request_timeout": 5, # network timeout in seconds
|
|
68
69
|
},
|
|
69
70
|
}
|
|
@@ -90,26 +91,29 @@ python /opt/netbox/netbox/manage.py eosl_check
|
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
```
|
|
93
|
-
EOSL.ai audit
|
|
94
|
+
EOSL.ai audit: 214 device types
|
|
94
95
|
Past / action recommended: 57
|
|
95
96
|
Ending soon (plan/watch): 18
|
|
96
97
|
Tracked, supported: 44
|
|
97
|
-
Active
|
|
98
|
+
Active, no EOL announced: 9
|
|
98
99
|
Not found in EOSL.ai: 79
|
|
99
100
|
No part number set: 7
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
Cisco Catalyst 3850-48P (WS-C3850-48P-S)
|
|
102
|
+
Needs action (past end-of-service-life, or action recommended):
|
|
103
|
+
Cisco Catalyst 3850-48P (WS-C3850-48P-S): Little or no runway, end of service life 2025-10, 12 in service, https://eosl.ai/system/cisco-catalyst-3850/
|
|
104
|
+
Fortinet FortiGate 60E (FortiGate-60E): Action recommended, end of service life 2026-12, 3 in service, https://eosl.ai/system/fortinet-fortigate-60e/
|
|
103
105
|
...
|
|
104
106
|
```
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
"Action recommended" includes hardware whose last date of support is still ahead, so each line
|
|
109
|
+
carries its status and date. Use `--past-only` to print just that list (handy in a cron/report).
|
|
107
110
|
|
|
108
111
|
## How matching works
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
field (a Device inherits it from its Device Type)
|
|
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:
|
|
113
117
|
|
|
114
118
|
1. **Exact** match (case-insensitive).
|
|
115
119
|
2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
|
|
@@ -117,6 +121,12 @@ field (a Device inherits it from its Device Type) in three deterministic, conser
|
|
|
117
121
|
but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
|
|
118
122
|
`FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
|
|
119
123
|
a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
|
|
124
|
+
4. **Variant aliases**: packaging forms of the same hardware,
|
|
125
|
+
such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
|
|
126
|
+
it could mean has the same vendor and the same dates; short keys and keys shared across vendors
|
|
127
|
+
resolve only when the NetBox manufacturer names the vendor.
|
|
128
|
+
5. If the part number finds nothing, the device type's **model name** is tried with the same rules
|
|
129
|
+
(NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
|
|
120
130
|
|
|
121
131
|
There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
|
|
122
132
|
"not tracked" panel with a search link. Nothing is inferred.
|
|
@@ -124,13 +134,24 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
|
|
|
124
134
|
The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
|
|
125
135
|
`tests/` — run `python tests/test_matching.py` (or `pytest`).
|
|
126
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
|
+
|
|
127
148
|
## Data & trust
|
|
128
149
|
|
|
129
150
|
- Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
|
|
130
151
|
for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
|
|
131
152
|
vendor's published support-life policy and labels it "computed".
|
|
132
153
|
- This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
|
|
133
|
-
|
|
154
|
+
requests fetch the public lookup table and the alias file.
|
|
134
155
|
- Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
|
|
135
156
|
migration decision.
|
|
136
157
|
|
|
@@ -6,11 +6,12 @@ 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
|
|
9
|
+
the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
|
|
10
10
|
|
|
11
|
-
Matching is
|
|
12
|
-
|
|
13
|
-
offers a search link instead of
|
|
11
|
+
Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
|
|
12
|
+
wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
|
|
13
|
+
matched from. If a part number isn't in the database, it says so and offers a search link instead of
|
|
14
|
+
guessing.
|
|
14
15
|
|
|
15
16
|
## Requirements
|
|
16
17
|
|
|
@@ -42,7 +43,7 @@ PLUGINS = [
|
|
|
42
43
|
PLUGINS_CONFIG = {
|
|
43
44
|
"netbox_eosl": {
|
|
44
45
|
"api_url": "https://eosl.ai", # data source origin
|
|
45
|
-
"cache_timeout":
|
|
46
|
+
"cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
|
|
46
47
|
"request_timeout": 5, # network timeout in seconds
|
|
47
48
|
},
|
|
48
49
|
}
|
|
@@ -69,26 +70,29 @@ python /opt/netbox/netbox/manage.py eosl_check
|
|
|
69
70
|
```
|
|
70
71
|
|
|
71
72
|
```
|
|
72
|
-
EOSL.ai audit
|
|
73
|
+
EOSL.ai audit: 214 device types
|
|
73
74
|
Past / action recommended: 57
|
|
74
75
|
Ending soon (plan/watch): 18
|
|
75
76
|
Tracked, supported: 44
|
|
76
|
-
Active
|
|
77
|
+
Active, no EOL announced: 9
|
|
77
78
|
Not found in EOSL.ai: 79
|
|
78
79
|
No part number set: 7
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
Cisco Catalyst 3850-48P (WS-C3850-48P-S)
|
|
81
|
+
Needs action (past end-of-service-life, or action recommended):
|
|
82
|
+
Cisco Catalyst 3850-48P (WS-C3850-48P-S): Little or no runway, end of service life 2025-10, 12 in service, https://eosl.ai/system/cisco-catalyst-3850/
|
|
83
|
+
Fortinet FortiGate 60E (FortiGate-60E): Action recommended, end of service life 2026-12, 3 in service, https://eosl.ai/system/fortinet-fortigate-60e/
|
|
82
84
|
...
|
|
83
85
|
```
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
"Action recommended" includes hardware whose last date of support is still ahead, so each line
|
|
88
|
+
carries its status and date. Use `--past-only` to print just that list (handy in a cron/report).
|
|
86
89
|
|
|
87
90
|
## How matching works
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
field (a Device inherits it from its Device Type)
|
|
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:
|
|
92
96
|
|
|
93
97
|
1. **Exact** match (case-insensitive).
|
|
94
98
|
2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
|
|
@@ -96,6 +100,12 @@ field (a Device inherits it from its Device Type) in three deterministic, conser
|
|
|
96
100
|
but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
|
|
97
101
|
`FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
|
|
98
102
|
a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
|
|
103
|
+
4. **Variant aliases**: packaging forms of the same hardware,
|
|
104
|
+
such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
|
|
105
|
+
it could mean has the same vendor and the same dates; short keys and keys shared across vendors
|
|
106
|
+
resolve only when the NetBox manufacturer names the vendor.
|
|
107
|
+
5. If the part number finds nothing, the device type's **model name** is tried with the same rules
|
|
108
|
+
(NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
|
|
99
109
|
|
|
100
110
|
There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
|
|
101
111
|
"not tracked" panel with a search link. Nothing is inferred.
|
|
@@ -103,13 +113,24 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
|
|
|
103
113
|
The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
|
|
104
114
|
`tests/` — run `python tests/test_matching.py` (or `pytest`).
|
|
105
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
|
+
|
|
106
127
|
## Data & trust
|
|
107
128
|
|
|
108
129
|
- Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
|
|
109
130
|
for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
|
|
110
131
|
vendor's published support-life policy and labels it "computed".
|
|
111
132
|
- This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
|
|
112
|
-
|
|
133
|
+
requests fetch the public lookup table and the alias file.
|
|
113
134
|
- Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
|
|
114
135
|
migration decision.
|
|
115
136
|
|
|
@@ -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.
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
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 ""))
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"""`manage.py eosl_check` — audit your NetBox device types against EOSL.ai.
|
|
2
2
|
|
|
3
|
-
Prints a summary of how many tracked device types
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Prints a summary of how many tracked device types need action, are ending soon, are still
|
|
4
|
+
supported or active, or are not found in the EOSL.ai database, then lists the device types that need
|
|
5
|
+
action (past end-of-service-life, or close enough that EOSL.ai rates the runway as action recommended)
|
|
6
|
+
with how many device instances you run. Read-only; changes nothing in NetBox.
|
|
6
7
|
"""
|
|
7
8
|
from collections import Counter
|
|
8
9
|
|
|
9
10
|
from dcim.models import DeviceType
|
|
10
11
|
from django.core.management.base import BaseCommand
|
|
11
12
|
|
|
12
|
-
from netbox_eosl.client import lookup_part
|
|
13
|
+
from netbox_eosl.client import Unavailable, check_many, lookup_part
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class Command(BaseCommand):
|
|
@@ -19,13 +20,28 @@ class Command(BaseCommand):
|
|
|
19
20
|
parser.add_argument(
|
|
20
21
|
"--past-only",
|
|
21
22
|
action="store_true",
|
|
22
|
-
help="Skip the summary; just list device types past end-of-service-life.",
|
|
23
|
+
help="Skip the summary; just list device types that need action (past or near end-of-service-life).",
|
|
23
24
|
)
|
|
24
25
|
|
|
25
26
|
def handle(self, *args, **options):
|
|
26
|
-
device_types = DeviceType.objects.select_related("manufacturer").all()
|
|
27
|
+
device_types = list(DeviceType.objects.select_related("manufacturer").all())
|
|
27
28
|
counts = Counter()
|
|
28
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
|
|
29
45
|
|
|
30
46
|
for dt in device_types:
|
|
31
47
|
part = (dt.part_number or "").strip()
|
|
@@ -38,6 +54,10 @@ class Command(BaseCommand):
|
|
|
38
54
|
# finds nothing (HISTORY §82).
|
|
39
55
|
mfr = getattr(getattr(dt, "manufacturer", None), "name", "") or ""
|
|
40
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
|
|
41
61
|
if not rec:
|
|
42
62
|
counts["not_found"] += 1
|
|
43
63
|
continue
|
|
@@ -48,37 +68,48 @@ class Command(BaseCommand):
|
|
|
48
68
|
total = sum(counts.values())
|
|
49
69
|
|
|
50
70
|
if not options.get("past_only"):
|
|
51
|
-
self.stdout.write(self.style.MIGRATE_HEADING("EOSL.ai audit
|
|
71
|
+
self.stdout.write(self.style.MIGRATE_HEADING("EOSL.ai audit: {} device types".format(total)))
|
|
52
72
|
label = {
|
|
53
73
|
"risk": "Past / action recommended",
|
|
54
74
|
"watch": "Ending soon (plan/watch)",
|
|
55
75
|
"clear": "Tracked, supported",
|
|
56
|
-
"active": "Active
|
|
76
|
+
"active": "Active, no EOL announced",
|
|
57
77
|
"not_found": "Not found in EOSL.ai",
|
|
78
|
+
"not_checked": "NOT CHECKED",
|
|
58
79
|
"no_part_number": "No part number set",
|
|
59
80
|
}
|
|
60
|
-
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"):
|
|
61
82
|
if counts.get(key):
|
|
62
83
|
self.stdout.write(" {:<32} {}".format(label[key] + ":", counts[key]))
|
|
63
84
|
|
|
64
85
|
if past_rows:
|
|
65
86
|
self.stdout.write("")
|
|
66
|
-
|
|
87
|
+
# One heading for both bands: "Action recommended" includes hardware whose last date of
|
|
88
|
+
# support is still ahead, so this list must never be headed "past end-of-service-life".
|
|
89
|
+
self.stdout.write(self.style.WARNING("Needs action (past end-of-service-life, or action recommended):"))
|
|
67
90
|
for dt, rec in sorted(past_rows, key=lambda r: r[1].get("eosl") or ""):
|
|
68
91
|
try:
|
|
69
92
|
instances = dt.instances.count()
|
|
70
93
|
except Exception:
|
|
71
94
|
instances = "?"
|
|
72
95
|
self.stdout.write(
|
|
73
|
-
" {vendor} {model} ({part})
|
|
96
|
+
" {vendor} {model} ({part}): {status}, end of service life {eosl}, {n} in service, {url}".format(
|
|
74
97
|
vendor=rec.get("vendor") or (dt.manufacturer and dt.manufacturer.name) or "",
|
|
75
98
|
model=dt.model,
|
|
76
99
|
part=rec.get("part"),
|
|
77
|
-
|
|
100
|
+
status=rec.get("state_label"),
|
|
101
|
+
eosl=rec.get("eosl") or "not published",
|
|
78
102
|
n=instances,
|
|
79
103
|
url=rec.get("page_url"),
|
|
80
104
|
)
|
|
81
105
|
)
|
|
82
|
-
elif not options.get("past_only"):
|
|
106
|
+
elif not options.get("past_only") and not counts.get("not_checked"):
|
|
107
|
+
self.stdout.write("")
|
|
108
|
+
self.stdout.write(self.style.SUCCESS("No device types need action."))
|
|
109
|
+
|
|
110
|
+
if counts.get("not_checked"):
|
|
83
111
|
self.stdout.write("")
|
|
84
|
-
self.stdout.write(self.style.
|
|
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 "")))
|
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
<div class="card">
|
|
3
3
|
<h2 class="card-header">
|
|
4
4
|
Hardware End-of-Life
|
|
5
|
-
|
|
5
|
+
{# card-actions is NetBox 4.x's header slot; float-end ran the link into the title on 4.7. #}
|
|
6
|
+
<div class="card-actions">
|
|
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
|
+
</div>
|
|
6
9
|
</h2>
|
|
7
|
-
{% 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 %}
|
|
8
18
|
<table class="table table-hover attr-table">
|
|
9
19
|
<tr>
|
|
10
20
|
<th scope="row">Status</th>
|
|
@@ -14,6 +24,12 @@
|
|
|
14
24
|
<th scope="row">Part number</th>
|
|
15
25
|
<td><code>{{ eosl.part }}</code></td>
|
|
16
26
|
</tr>
|
|
27
|
+
{% if eosl.matched_from %}
|
|
28
|
+
<tr>
|
|
29
|
+
<th scope="row">Matched from</th>
|
|
30
|
+
<td><code>{{ eosl.matched_from }}</code> <span class="text-muted">({% if eosl.matched_by_model %}device type model name{% else %}same hardware, different part number form{% endif %})</span></td>
|
|
31
|
+
</tr>
|
|
32
|
+
{% endif %}
|
|
17
33
|
{% if eosl.end_of_sale %}
|
|
18
34
|
<tr>
|
|
19
35
|
<th scope="row">End of sale</th>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: netbox-eosl
|
|
3
|
-
Version: 0.
|
|
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,11 +27,12 @@ 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
|
|
30
|
+
the full EOSL.ai model page. A `manage.py eosl_check` command audits your device types.
|
|
31
31
|
|
|
32
|
-
Matching is
|
|
33
|
-
|
|
34
|
-
offers a search link instead of
|
|
32
|
+
Matching is deterministic and never fuzzy, so the plugin can't put a wrong end-of-life date on the
|
|
33
|
+
wrong device. When it resolves a vendor short code or packaging variant, the panel shows what it
|
|
34
|
+
matched from. If a part number isn't in the database, it says so and offers a search link instead of
|
|
35
|
+
guessing.
|
|
35
36
|
|
|
36
37
|
## Requirements
|
|
37
38
|
|
|
@@ -63,7 +64,7 @@ PLUGINS = [
|
|
|
63
64
|
PLUGINS_CONFIG = {
|
|
64
65
|
"netbox_eosl": {
|
|
65
66
|
"api_url": "https://eosl.ai", # data source origin
|
|
66
|
-
"cache_timeout":
|
|
67
|
+
"cache_timeout": 604800, # seconds to cache each part number's answer (default 7 days)
|
|
67
68
|
"request_timeout": 5, # network timeout in seconds
|
|
68
69
|
},
|
|
69
70
|
}
|
|
@@ -90,26 +91,29 @@ python /opt/netbox/netbox/manage.py eosl_check
|
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
```
|
|
93
|
-
EOSL.ai audit
|
|
94
|
+
EOSL.ai audit: 214 device types
|
|
94
95
|
Past / action recommended: 57
|
|
95
96
|
Ending soon (plan/watch): 18
|
|
96
97
|
Tracked, supported: 44
|
|
97
|
-
Active
|
|
98
|
+
Active, no EOL announced: 9
|
|
98
99
|
Not found in EOSL.ai: 79
|
|
99
100
|
No part number set: 7
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
Cisco Catalyst 3850-48P (WS-C3850-48P-S)
|
|
102
|
+
Needs action (past end-of-service-life, or action recommended):
|
|
103
|
+
Cisco Catalyst 3850-48P (WS-C3850-48P-S): Little or no runway, end of service life 2025-10, 12 in service, https://eosl.ai/system/cisco-catalyst-3850/
|
|
104
|
+
Fortinet FortiGate 60E (FortiGate-60E): Action recommended, end of service life 2026-12, 3 in service, https://eosl.ai/system/fortinet-fortigate-60e/
|
|
103
105
|
...
|
|
104
106
|
```
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
"Action recommended" includes hardware whose last date of support is still ahead, so each line
|
|
109
|
+
carries its status and date. Use `--past-only` to print just that list (handy in a cron/report).
|
|
107
110
|
|
|
108
111
|
## How matching works
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
field (a Device inherits it from its Device Type)
|
|
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:
|
|
113
117
|
|
|
114
118
|
1. **Exact** match (case-insensitive).
|
|
115
119
|
2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
|
|
@@ -117,6 +121,12 @@ field (a Device inherits it from its Device Type) in three deterministic, conser
|
|
|
117
121
|
but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
|
|
118
122
|
`FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
|
|
119
123
|
a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
|
|
124
|
+
4. **Variant aliases**: packaging forms of the same hardware,
|
|
125
|
+
such as Juniper `EX4300-48T-TAA` or Cisco `ASA5506`. EOSL.ai admits an alias only when every record
|
|
126
|
+
it could mean has the same vendor and the same dates; short keys and keys shared across vendors
|
|
127
|
+
resolve only when the NetBox manufacturer names the vendor.
|
|
128
|
+
5. If the part number finds nothing, the device type's **model name** is tried with the same rules
|
|
129
|
+
(NetBox's device-type library leaves some part numbers blank, e.g. Dell "PowerEdge R730").
|
|
120
130
|
|
|
121
131
|
There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
|
|
122
132
|
"not tracked" panel with a search link. Nothing is inferred.
|
|
@@ -124,13 +134,24 @@ There is **no fuzzy or substring matching**. No part number, or no confident mat
|
|
|
124
134
|
The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
|
|
125
135
|
`tests/` — run `python tests/test_matching.py` (or `pytest`).
|
|
126
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
|
+
|
|
127
148
|
## Data & trust
|
|
128
149
|
|
|
129
150
|
- Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
|
|
130
151
|
for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
|
|
131
152
|
vendor's published support-life policy and labels it "computed".
|
|
132
153
|
- This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
|
|
133
|
-
|
|
154
|
+
requests fetch the public lookup table and the alias file.
|
|
134
155
|
- Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
|
|
135
156
|
migration decision.
|
|
136
157
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "netbox-eosl"
|
|
7
|
-
version = "0.
|
|
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,127 +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
|
-
for candidate in (part_number, model):
|
|
99
|
-
if candidate:
|
|
100
|
-
rec = matching.match(candidate, vendor, exact, loose_index, aliases)
|
|
101
|
-
if rec:
|
|
102
|
-
break
|
|
103
|
-
if not rec:
|
|
104
|
-
return None
|
|
105
|
-
state, label, css = matching.classify(rec)
|
|
106
|
-
slug = rec.get("s")
|
|
107
|
-
return {
|
|
108
|
-
"part": rec.get("p"),
|
|
109
|
-
"vendor": rec.get("v"),
|
|
110
|
-
"family": rec.get("f"),
|
|
111
|
-
"end_of_sale": rec.get("eos"),
|
|
112
|
-
"eosl": rec.get("eol"),
|
|
113
|
-
"source_url": rec.get("src"),
|
|
114
|
-
"exposure_score": rec.get("xs"),
|
|
115
|
-
"exposure_band": rec.get("xb"),
|
|
116
|
-
"active": bool(rec.get("a")),
|
|
117
|
-
"state": state,
|
|
118
|
-
"state_label": label,
|
|
119
|
-
"state_css": css,
|
|
120
|
-
"page_url": (_cfg("api_url").rstrip("/") + "/system/" + slug + "/") if slug else _cfg("api_url"),
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def search_url(term):
|
|
125
|
-
"""A safe fallback link into eosl.ai when we have no exact match."""
|
|
126
|
-
base = _cfg("api_url").rstrip("/")
|
|
127
|
-
return "{}/?q={}".format(base, requests.utils.quote(term or ""))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|