netbox-eosl 0.1.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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions for
125
+ use, reproduction, or distribution of Your modifications, or for any
126
+ such Derivative Works as a whole, provided Your use, reproduction,
127
+ and distribution of the Work otherwise complies with the conditions
128
+ stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 EOSL.ai
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include netbox_eosl/templates *.html
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: netbox-eosl
3
+ Version: 0.1.0
4
+ Summary: Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai.
5
+ Author-email: "EOSL.ai" <hello@eosl.ai>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://eosl.ai/
8
+ Project-URL: Data source, https://eosl.ai/api/
9
+ Project-URL: Source, https://github.com/Kranny36/netbox-eosl
10
+ Keywords: netbox,netbox-plugin,eosl,end-of-life,eol,lifecycle,dcim
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: System :: Networking :: Monitoring
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.25
20
+ Dynamic: license-file
21
+
22
+ # netbox-eosl
23
+
24
+ Show **source-backed hardware end-of-service-life (EOSL) status** on your NetBox Devices and
25
+ Device Types, straight from [EOSL.ai](https://eosl.ai) — where every date links to the vendor's
26
+ own end-of-life bulletin.
27
+
28
+ A panel appears on the right side of each Device and Device Type page: end-of-sale date,
29
+ end-of-service-life date, the EOSL Exposure 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.
31
+
32
+ Matching is **exact part-number only** — the plugin never fuzzy-matches, so it can't put a wrong
33
+ end-of-life date on the wrong device. If a part number isn't in the database, it says so and
34
+ offers a search link instead of guessing.
35
+
36
+ ## Requirements
37
+
38
+ | | |
39
+ |---|---|
40
+ | NetBox | **4.3** or later (uses the `models` template-extension API) |
41
+ | Python | 3.10+ |
42
+ | Network | outbound HTTPS to `eosl.ai` from the NetBox host |
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ # In your NetBox virtual environment
48
+ source /opt/netbox/venv/bin/activate
49
+ pip install netbox-eosl
50
+ ```
51
+
52
+ Add it to NetBox's `configuration.py`:
53
+
54
+ ```python
55
+ PLUGINS = [
56
+ "netbox_eosl",
57
+ ]
58
+ ```
59
+
60
+ (Optional) tune it:
61
+
62
+ ```python
63
+ PLUGINS_CONFIG = {
64
+ "netbox_eosl": {
65
+ "api_url": "https://eosl.ai", # data source origin
66
+ "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
67
+ "request_timeout": 5, # network timeout in seconds
68
+ },
69
+ }
70
+ ```
71
+
72
+ Then restart NetBox and run migrations (none are added, but this reloads plugins):
73
+
74
+ ```bash
75
+ python /opt/netbox/netbox/manage.py migrate
76
+ sudo systemctl restart netbox netbox-rq
77
+ ```
78
+
79
+ Add `netbox-eosl` to your `local_requirements.txt` so upgrades keep it installed.
80
+
81
+ ## Use
82
+
83
+ **In the UI** — open any Device or Device Type that has a **part number** set. The
84
+ "Hardware End-of-Life" card appears in the right column.
85
+
86
+ **Inventory audit** — from the NetBox host:
87
+
88
+ ```bash
89
+ python /opt/netbox/netbox/manage.py eosl_check
90
+ ```
91
+
92
+ ```
93
+ EOSL.ai audit — 214 device types
94
+ Past / action recommended: 57
95
+ Ending soon (plan/watch): 18
96
+ Tracked, supported: 44
97
+ Active — no EOL announced: 9
98
+ Not found in EOSL.ai: 79
99
+ No part number set: 7
100
+
101
+ Past end-of-service-life:
102
+ Cisco Catalyst 3850-48P (WS-C3850-48P-S) — EOSL 2025-10 — 12 in service — https://eosl.ai/system/cisco-catalyst-3850/
103
+ ...
104
+ ```
105
+
106
+ Use `--past-only` to print just the past-EOSL list (handy in a cron/report).
107
+
108
+ ## How matching works
109
+
110
+ The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
111
+ powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
112
+ field (a Device inherits it from its Device Type) in three deterministic, conservative steps:
113
+
114
+ 1. **Exact** match (case-insensitive).
115
+ 2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
116
+ 3. **Vendor-gated aliases** — expands a manufacturer's short SKU form to the catalogued long form,
117
+ but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
118
+ `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
119
+ a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
120
+
121
+ There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
122
+ "not tracked" panel with a search link. Nothing is inferred.
123
+
124
+ The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
125
+ `tests/` — run `python tests/test_matching.py` (or `pytest`).
126
+
127
+ ## Data & trust
128
+
129
+ - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
130
+ for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
131
+ vendor's published support-life policy and labels it "computed".
132
+ - This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
133
+ request is fetching the public lookup table.
134
+ - Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
135
+ migration decision.
136
+
137
+ ## License
138
+
139
+ Apache-2.0. See `LICENSE`.
140
+
141
+ ## Contributing / publishing
142
+
143
+ Issues and PRs welcome — especially additional vendor SKU aliases (see `FORTINET_PREFIX` in
144
+ `matching.py` for the pattern) and screenshots. Maintainers: see `PUBLISHING.md` for the
145
+ PyPI + NetBox-community release steps.
@@ -0,0 +1,124 @@
1
+ # netbox-eosl
2
+
3
+ Show **source-backed hardware end-of-service-life (EOSL) status** on your NetBox Devices and
4
+ Device Types, straight from [EOSL.ai](https://eosl.ai) — where every date links to the vendor's
5
+ own end-of-life bulletin.
6
+
7
+ A panel appears on the right side of each Device and Device Type page: end-of-sale date,
8
+ end-of-service-life date, the EOSL Exposure 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.
10
+
11
+ Matching is **exact part-number only** — the plugin never fuzzy-matches, so it can't put a wrong
12
+ end-of-life date on the wrong device. If a part number isn't in the database, it says so and
13
+ offers a search link instead of guessing.
14
+
15
+ ## Requirements
16
+
17
+ | | |
18
+ |---|---|
19
+ | NetBox | **4.3** or later (uses the `models` template-extension API) |
20
+ | Python | 3.10+ |
21
+ | Network | outbound HTTPS to `eosl.ai` from the NetBox host |
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ # In your NetBox virtual environment
27
+ source /opt/netbox/venv/bin/activate
28
+ pip install netbox-eosl
29
+ ```
30
+
31
+ Add it to NetBox's `configuration.py`:
32
+
33
+ ```python
34
+ PLUGINS = [
35
+ "netbox_eosl",
36
+ ]
37
+ ```
38
+
39
+ (Optional) tune it:
40
+
41
+ ```python
42
+ PLUGINS_CONFIG = {
43
+ "netbox_eosl": {
44
+ "api_url": "https://eosl.ai", # data source origin
45
+ "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
46
+ "request_timeout": 5, # network timeout in seconds
47
+ },
48
+ }
49
+ ```
50
+
51
+ Then restart NetBox and run migrations (none are added, but this reloads plugins):
52
+
53
+ ```bash
54
+ python /opt/netbox/netbox/manage.py migrate
55
+ sudo systemctl restart netbox netbox-rq
56
+ ```
57
+
58
+ Add `netbox-eosl` to your `local_requirements.txt` so upgrades keep it installed.
59
+
60
+ ## Use
61
+
62
+ **In the UI** — open any Device or Device Type that has a **part number** set. The
63
+ "Hardware End-of-Life" card appears in the right column.
64
+
65
+ **Inventory audit** — from the NetBox host:
66
+
67
+ ```bash
68
+ python /opt/netbox/netbox/manage.py eosl_check
69
+ ```
70
+
71
+ ```
72
+ EOSL.ai audit — 214 device types
73
+ Past / action recommended: 57
74
+ Ending soon (plan/watch): 18
75
+ Tracked, supported: 44
76
+ Active — no EOL announced: 9
77
+ Not found in EOSL.ai: 79
78
+ No part number set: 7
79
+
80
+ Past end-of-service-life:
81
+ Cisco Catalyst 3850-48P (WS-C3850-48P-S) — EOSL 2025-10 — 12 in service — https://eosl.ai/system/cisco-catalyst-3850/
82
+ ...
83
+ ```
84
+
85
+ Use `--past-only` to print just the past-EOSL list (handy in a cron/report).
86
+
87
+ ## How matching works
88
+
89
+ The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
90
+ powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
91
+ field (a Device inherits it from its Device Type) in three deterministic, conservative steps:
92
+
93
+ 1. **Exact** match (case-insensitive).
94
+ 2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
95
+ 3. **Vendor-gated aliases** — expands a manufacturer's short SKU form to the catalogued long form,
96
+ but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
97
+ `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
98
+ a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
99
+
100
+ There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
101
+ "not tracked" panel with a search link. Nothing is inferred.
102
+
103
+ The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
104
+ `tests/` — run `python tests/test_matching.py` (or `pytest`).
105
+
106
+ ## Data & trust
107
+
108
+ - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
109
+ for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
110
+ vendor's published support-life policy and labels it "computed".
111
+ - This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
112
+ request is fetching the public lookup table.
113
+ - Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
114
+ migration decision.
115
+
116
+ ## License
117
+
118
+ Apache-2.0. See `LICENSE`.
119
+
120
+ ## Contributing / publishing
121
+
122
+ Issues and PRs welcome — especially additional vendor SKU aliases (see `FORTINET_PREFIX` in
123
+ `matching.py` for the pattern) and screenshots. Maintainers: see `PUBLISHING.md` for the
124
+ PyPI + NetBox-community release steps.
@@ -0,0 +1,32 @@
1
+ """netbox-eosl — surface source-backed hardware end-of-service-life status inside NetBox.
2
+
3
+ Data comes from EOSL.ai's public API (https://eosl.ai), where every date links to the
4
+ vendor's own end-of-life bulletin. Matching is exact part-number only — the plugin never
5
+ guesses, so it cannot assert an end-of-life date NetBox isn't certain about.
6
+ """
7
+ from netbox.plugins import PluginConfig
8
+
9
+ __version__ = "0.1.0"
10
+
11
+
12
+ class EOSLConfig(PluginConfig):
13
+ name = "netbox_eosl"
14
+ verbose_name = "EOSL.ai — Hardware End-of-Life"
15
+ description = "Show source-backed end-of-sale / end-of-service-life status on Devices and Device Types, from EOSL.ai."
16
+ version = __version__
17
+ author = "EOSL.ai"
18
+ author_email = "hello@eosl.ai"
19
+ base_url = "eosl"
20
+ # PluginTemplateExtension.models (plural) is required from NetBox 4.3 onward.
21
+ min_version = "4.3.0"
22
+ default_settings = {
23
+ # Base origin of the EOSL.ai data source. Override only if you mirror the dataset.
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.
28
+ "request_timeout": 5,
29
+ }
30
+
31
+
32
+ config = EOSLConfig
@@ -0,0 +1,95 @@
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
+ # In-process memo of the built indexes, rebuilt only when the sku set changes.
20
+ _MEMO = {"token": None, "idx": (None, None)}
21
+
22
+
23
+ def _cfg(key):
24
+ return get_plugin_config("netbox_eosl", key)
25
+
26
+
27
+ def _load_skus():
28
+ """Return the list of sku records from EOSL.ai, cached. [] on any failure (never raises)."""
29
+ skus = cache.get(_SKU_CACHE_KEY)
30
+ if skus is not None:
31
+ return skus
32
+
33
+ url = _cfg("api_url").rstrip("/") + "/data/lookup.json"
34
+ try:
35
+ resp = requests.get(
36
+ url,
37
+ timeout=_cfg("request_timeout"),
38
+ headers={"User-Agent": "netbox-eosl/0.1 (+https://eosl.ai)"},
39
+ )
40
+ resp.raise_for_status()
41
+ skus = resp.json().get("skus", [])
42
+ except (requests.RequestException, ValueError) as exc:
43
+ logger.warning("netbox-eosl: could not load lookup data from %s: %s", url, exc)
44
+ cache.set(_SKU_CACHE_KEY, [], 300) # brief negative cache so a broken upstream isn't hammered
45
+ return []
46
+
47
+ cache.set(_SKU_CACHE_KEY, skus, _cfg("cache_timeout"))
48
+ return skus
49
+
50
+
51
+ def _indexes():
52
+ """(exact, loose) indexes, rebuilt in-process only when the sku count changes."""
53
+ skus = _load_skus()
54
+ token = len(skus)
55
+ if _MEMO["token"] != token:
56
+ _MEMO["token"] = token
57
+ _MEMO["idx"] = matching.build_index(skus)
58
+ return _MEMO["idx"]
59
+
60
+
61
+ def lookup_part(part_number, vendor=None):
62
+ """Resolve one part number (optionally with its NetBox manufacturer name) to a display dict, or None.
63
+
64
+ Passing `vendor` enables vendor-gated aliases (e.g. Fortinet FG-60E -> FortiGate-60E) without risking
65
+ a cross-vendor false match. The returned dict is safe to hand straight to the template.
66
+ """
67
+ if not part_number:
68
+ return None
69
+ exact, loose_index = _indexes()
70
+ rec = matching.match(part_number, vendor, exact, loose_index)
71
+ if not rec:
72
+ return None
73
+ state, label, css = matching.classify(rec)
74
+ slug = rec.get("s")
75
+ return {
76
+ "part": rec.get("p"),
77
+ "vendor": rec.get("v"),
78
+ "family": rec.get("f"),
79
+ "end_of_sale": rec.get("eos"),
80
+ "eosl": rec.get("eol"),
81
+ "source_url": rec.get("src"),
82
+ "exposure_score": rec.get("xs"),
83
+ "exposure_band": rec.get("xb"),
84
+ "active": bool(rec.get("a")),
85
+ "state": state,
86
+ "state_label": label,
87
+ "state_css": css,
88
+ "page_url": (_cfg("api_url").rstrip("/") + "/system/" + slug + "/") if slug else _cfg("api_url"),
89
+ }
90
+
91
+
92
+ def search_url(term):
93
+ """A safe fallback link into eosl.ai when we have no exact match."""
94
+ base = _cfg("api_url").rstrip("/")
95
+ return "{}/?q={}".format(base, requests.utils.quote(term or ""))
File without changes
@@ -0,0 +1,79 @@
1
+ """`manage.py eosl_check` — audit your NetBox device types against EOSL.ai.
2
+
3
+ Prints a summary of how many tracked device types are past end-of-service-life, ending soon,
4
+ still active, or not found in the EOSL.ai database — plus the list of past-EOSL types with how
5
+ many device instances you run. Read-only; changes nothing in NetBox.
6
+ """
7
+ from collections import Counter
8
+
9
+ from dcim.models import DeviceType
10
+ from django.core.management.base import BaseCommand
11
+
12
+ from netbox_eosl.client import lookup_part
13
+
14
+
15
+ class Command(BaseCommand):
16
+ help = "Audit NetBox device types against EOSL.ai end-of-life data (read-only)."
17
+
18
+ def add_arguments(self, parser):
19
+ parser.add_argument(
20
+ "--past-only",
21
+ action="store_true",
22
+ help="Skip the summary; just list device types past end-of-service-life.",
23
+ )
24
+
25
+ def handle(self, *args, **options):
26
+ device_types = DeviceType.objects.select_related("manufacturer").all()
27
+ counts = Counter()
28
+ past_rows = []
29
+
30
+ for dt in device_types:
31
+ part = (dt.part_number or "").strip()
32
+ if not part:
33
+ counts["no_part_number"] += 1
34
+ continue
35
+ rec = lookup_part(part)
36
+ if not rec:
37
+ counts["not_found"] += 1
38
+ continue
39
+ counts[rec["state"]] += 1
40
+ if rec["state"] == "risk":
41
+ past_rows.append((dt, rec))
42
+
43
+ total = sum(counts.values())
44
+
45
+ if not options.get("past_only"):
46
+ self.stdout.write(self.style.MIGRATE_HEADING("EOSL.ai audit — {} device types".format(total)))
47
+ label = {
48
+ "risk": "Past / action recommended",
49
+ "watch": "Ending soon (plan/watch)",
50
+ "clear": "Tracked, supported",
51
+ "active": "Active — no EOL announced",
52
+ "not_found": "Not found in EOSL.ai",
53
+ "no_part_number": "No part number set",
54
+ }
55
+ for key in ("risk", "watch", "clear", "active", "not_found", "no_part_number"):
56
+ if counts.get(key):
57
+ self.stdout.write(" {:<32} {}".format(label[key] + ":", counts[key]))
58
+
59
+ if past_rows:
60
+ self.stdout.write("")
61
+ self.stdout.write(self.style.WARNING("Past end-of-service-life:"))
62
+ for dt, rec in sorted(past_rows, key=lambda r: r[1].get("eosl") or ""):
63
+ try:
64
+ instances = dt.instances.count()
65
+ except Exception:
66
+ instances = "?"
67
+ self.stdout.write(
68
+ " {vendor} {model} ({part}) — EOSL {eosl} — {n} in service — {url}".format(
69
+ vendor=rec.get("vendor") or (dt.manufacturer and dt.manufacturer.name) or "",
70
+ model=dt.model,
71
+ part=rec.get("part"),
72
+ eosl=rec.get("eosl") or "n/a",
73
+ n=instances,
74
+ url=rec.get("page_url"),
75
+ )
76
+ )
77
+ elif not options.get("past_only"):
78
+ self.stdout.write("")
79
+ self.stdout.write(self.style.SUCCESS("No device types are past end-of-service-life. 🎉"))
@@ -0,0 +1,93 @@
1
+ """Pure part-number matching logic — no Django/NetBox imports, so it is unit-testable standalone.
2
+
3
+ Matching is deterministic and conservative: exact first, then a punctuation/case-insensitive
4
+ "loose" match, then a **vendor-gated** vendor-abbreviation expansion (e.g. Fortinet FG- -> FortiGate-).
5
+ It never does fuzzy/substring matching, and vendor-specific aliases only apply when the NetBox
6
+ manufacturer matches that vendor — so it can't cross-match one vendor's part onto another's record.
7
+ """
8
+ import re
9
+
10
+ # Official Fortinet SKU-abbreviation -> product-line prefixes. EOSL.ai stores the long form
11
+ # (e.g. "FortiGate-60E"); NetBox device types commonly use the short SKU form (e.g. "FG-60E").
12
+ FORTINET_PREFIX = {
13
+ "FG": "FORTIGATE",
14
+ "FS": "FORTISWITCH",
15
+ "FAP": "FORTIAP",
16
+ "FAZ": "FORTIANALYZER",
17
+ "FMG": "FORTIMANAGER",
18
+ "FWB": "FORTIWEB",
19
+ "FAD": "FORTIADC",
20
+ "FML": "FORTIMAIL",
21
+ "FPX": "FORTIPROXY",
22
+ "FEX": "FORTIEXTENDER",
23
+ "FAC": "FORTIAUTHENTICATOR",
24
+ "FDD": "FORTIDDOS",
25
+ "FSA": "FORTISANDBOX",
26
+ }
27
+
28
+
29
+ def loose(s):
30
+ """Uppercase, strip every non-alphanumeric char. 'FortiGate-60E' and 'fortigate 60e' -> 'FORTIGATE60E'."""
31
+ return re.sub(r"[^A-Z0-9]", "", (s or "").upper())
32
+
33
+
34
+ def build_index(skus):
35
+ """Return (exact, loose_index): UPPER(pid)->rec and loose(pid)->rec. First writer wins on collisions."""
36
+ exact, loose_index = {}, {}
37
+ for rec in skus:
38
+ pid = (rec.get("p") or "").strip().upper()
39
+ if not pid:
40
+ continue
41
+ exact.setdefault(pid, rec)
42
+ loose_index.setdefault(loose(pid), rec)
43
+ return exact, loose_index
44
+
45
+
46
+ def _is_fortinet(vendor):
47
+ return bool(vendor) and "FORTINET" in vendor.upper()
48
+
49
+
50
+ def candidate_loose_keys(part, vendor=None):
51
+ """Loose keys to try, most-specific first. Vendor-gated aliases only; deterministic, never fuzzy."""
52
+ keys, seen = [], set()
53
+
54
+ def add(raw):
55
+ k = loose(raw)
56
+ if k and k not in seen:
57
+ seen.add(k)
58
+ keys.append(k)
59
+
60
+ add(part)
61
+ if _is_fortinet(vendor):
62
+ lp = loose(part)
63
+ for ab, full in FORTINET_PREFIX.items():
64
+ # e.g. 'FG60E'.startswith('FG') -> 'FORTIGATE' + '60E'
65
+ if lp.startswith(ab) and len(lp) > len(ab) and not lp.startswith(full):
66
+ add(full + lp[len(ab):])
67
+ return keys
68
+
69
+
70
+ def match(part, vendor, exact, loose_index):
71
+ """Resolve a part number to a record, or None. Exact -> loose -> vendor-gated alias."""
72
+ if not part:
73
+ return None
74
+ u = part.strip().upper()
75
+ if u in exact:
76
+ return exact[u]
77
+ for k in candidate_loose_keys(part, vendor):
78
+ rec = loose_index.get(k)
79
+ if rec:
80
+ return rec
81
+ return None
82
+
83
+
84
+ def classify(rec):
85
+ """(state, label, bootstrap_css) from a lookup record. Templates stay logic-free."""
86
+ if rec.get("a"):
87
+ return ("active", "Active — no EOL announced", "success")
88
+ band = rec.get("xb") or ""
89
+ if band in ("High exposure", "Action recommended"):
90
+ return ("risk", band, "danger")
91
+ if band in ("Plan", "Watch"):
92
+ return ("watch", band, "warning")
93
+ return ("clear", band or "Tracked", "info")
@@ -0,0 +1,46 @@
1
+ """Inject an EOSL.ai lifecycle panel into Device and Device Type detail pages."""
2
+ from netbox.plugins import PluginTemplateExtension
3
+
4
+ from .client import lookup_part, search_url
5
+
6
+ _TEMPLATE = "netbox_eosl/eosl_panel.html"
7
+
8
+
9
+ def _manufacturer_name(device_type):
10
+ mfr = getattr(device_type, "manufacturer", None)
11
+ return getattr(mfr, "name", "") or ""
12
+
13
+
14
+ def _panel(extension, part_number, vendor):
15
+ """Shared renderer for both models."""
16
+ return extension.render(
17
+ _TEMPLATE,
18
+ extra_context={
19
+ "eosl": lookup_part(part_number, vendor),
20
+ "queried_part": part_number,
21
+ "search_url": search_url(part_number),
22
+ },
23
+ )
24
+
25
+
26
+ class DeviceEOSL(PluginTemplateExtension):
27
+ models = ["dcim.device"]
28
+
29
+ def right_page(self):
30
+ device = self.context["object"]
31
+ # A device's ordering PID + manufacturer live on its device type.
32
+ device_type = getattr(device, "device_type", None)
33
+ part = getattr(device_type, "part_number", "") or ""
34
+ return _panel(self, part, _manufacturer_name(device_type))
35
+
36
+
37
+ class DeviceTypeEOSL(PluginTemplateExtension):
38
+ models = ["dcim.devicetype"]
39
+
40
+ def right_page(self):
41
+ device_type = self.context["object"]
42
+ part = getattr(device_type, "part_number", "") or ""
43
+ return _panel(self, part, _manufacturer_name(device_type))
44
+
45
+
46
+ template_extensions = [DeviceEOSL, DeviceTypeEOSL]
@@ -0,0 +1,57 @@
1
+ {# EOSL.ai lifecycle panel, rendered on the right column of Device and Device Type pages. #}
2
+ <div class="card">
3
+ <h2 class="card-header">
4
+ Hardware End-of-Life
5
+ <a href="https://eosl.ai/" target="_blank" rel="noopener" class="float-end text-muted" title="Data source: EOSL.ai" style="font-size:0.7em;font-weight:400;">EOSL.ai</a>
6
+ </h2>
7
+ {% if eosl %}
8
+ <table class="table table-hover attr-table">
9
+ <tr>
10
+ <th scope="row">Status</th>
11
+ <td><span class="badge text-bg-{{ eosl.state_css }}">{{ eosl.state_label }}</span></td>
12
+ </tr>
13
+ <tr>
14
+ <th scope="row">Part number</th>
15
+ <td><code>{{ eosl.part }}</code></td>
16
+ </tr>
17
+ {% if eosl.end_of_sale %}
18
+ <tr>
19
+ <th scope="row">End of sale</th>
20
+ <td>{{ eosl.end_of_sale }}</td>
21
+ </tr>
22
+ {% endif %}
23
+ <tr>
24
+ <th scope="row">End of service life</th>
25
+ <td>{% if eosl.eosl %}{{ eosl.eosl }}{% else %}<span class="text-muted">Not published</span>{% endif %}</td>
26
+ </tr>
27
+ {% if eosl.exposure_score is not None %}
28
+ <tr>
29
+ <th scope="row">EOSL Exposure Score</th>
30
+ <td>{{ eosl.exposure_score }}/100 <span class="text-muted">({{ eosl.exposure_band }})</span></td>
31
+ </tr>
32
+ {% endif %}
33
+ {% if eosl.source_url %}
34
+ <tr>
35
+ <th scope="row">Vendor bulletin</th>
36
+ <td><a href="{{ eosl.source_url }}" target="_blank" rel="noopener">Source&nbsp;&raquo;</a></td>
37
+ </tr>
38
+ {% endif %}
39
+ </table>
40
+ <div class="card-footer text-end">
41
+ <a href="{{ eosl.page_url }}" target="_blank" rel="noopener" class="btn btn-sm btn-primary">View on EOSL.ai</a>
42
+ </div>
43
+ {% elif queried_part %}
44
+ <div class="card-body">
45
+ <p class="text-muted mb-2">
46
+ No exact end-of-life record for part number <code>{{ queried_part }}</code> in the EOSL.ai database.
47
+ </p>
48
+ <a href="{{ search_url }}" target="_blank" rel="noopener" class="btn btn-sm btn-outline-secondary">Search EOSL.ai</a>
49
+ </div>
50
+ {% else %}
51
+ <div class="card-body">
52
+ <p class="text-muted mb-0">
53
+ Set a <strong>part number</strong> on this device type to check its end-of-life status against EOSL.ai.
54
+ </p>
55
+ </div>
56
+ {% endif %}
57
+ </div>
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: netbox-eosl
3
+ Version: 0.1.0
4
+ Summary: Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai.
5
+ Author-email: "EOSL.ai" <hello@eosl.ai>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://eosl.ai/
8
+ Project-URL: Data source, https://eosl.ai/api/
9
+ Project-URL: Source, https://github.com/Kranny36/netbox-eosl
10
+ Keywords: netbox,netbox-plugin,eosl,end-of-life,eol,lifecycle,dcim
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: System :: Networking :: Monitoring
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.25
20
+ Dynamic: license-file
21
+
22
+ # netbox-eosl
23
+
24
+ Show **source-backed hardware end-of-service-life (EOSL) status** on your NetBox Devices and
25
+ Device Types, straight from [EOSL.ai](https://eosl.ai) — where every date links to the vendor's
26
+ own end-of-life bulletin.
27
+
28
+ A panel appears on the right side of each Device and Device Type page: end-of-sale date,
29
+ end-of-service-life date, the EOSL Exposure 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.
31
+
32
+ Matching is **exact part-number only** — the plugin never fuzzy-matches, so it can't put a wrong
33
+ end-of-life date on the wrong device. If a part number isn't in the database, it says so and
34
+ offers a search link instead of guessing.
35
+
36
+ ## Requirements
37
+
38
+ | | |
39
+ |---|---|
40
+ | NetBox | **4.3** or later (uses the `models` template-extension API) |
41
+ | Python | 3.10+ |
42
+ | Network | outbound HTTPS to `eosl.ai` from the NetBox host |
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ # In your NetBox virtual environment
48
+ source /opt/netbox/venv/bin/activate
49
+ pip install netbox-eosl
50
+ ```
51
+
52
+ Add it to NetBox's `configuration.py`:
53
+
54
+ ```python
55
+ PLUGINS = [
56
+ "netbox_eosl",
57
+ ]
58
+ ```
59
+
60
+ (Optional) tune it:
61
+
62
+ ```python
63
+ PLUGINS_CONFIG = {
64
+ "netbox_eosl": {
65
+ "api_url": "https://eosl.ai", # data source origin
66
+ "cache_timeout": 86400, # seconds to cache the lookup table (default 24h)
67
+ "request_timeout": 5, # network timeout in seconds
68
+ },
69
+ }
70
+ ```
71
+
72
+ Then restart NetBox and run migrations (none are added, but this reloads plugins):
73
+
74
+ ```bash
75
+ python /opt/netbox/netbox/manage.py migrate
76
+ sudo systemctl restart netbox netbox-rq
77
+ ```
78
+
79
+ Add `netbox-eosl` to your `local_requirements.txt` so upgrades keep it installed.
80
+
81
+ ## Use
82
+
83
+ **In the UI** — open any Device or Device Type that has a **part number** set. The
84
+ "Hardware End-of-Life" card appears in the right column.
85
+
86
+ **Inventory audit** — from the NetBox host:
87
+
88
+ ```bash
89
+ python /opt/netbox/netbox/manage.py eosl_check
90
+ ```
91
+
92
+ ```
93
+ EOSL.ai audit — 214 device types
94
+ Past / action recommended: 57
95
+ Ending soon (plan/watch): 18
96
+ Tracked, supported: 44
97
+ Active — no EOL announced: 9
98
+ Not found in EOSL.ai: 79
99
+ No part number set: 7
100
+
101
+ Past end-of-service-life:
102
+ Cisco Catalyst 3850-48P (WS-C3850-48P-S) — EOSL 2025-10 — 12 in service — https://eosl.ai/system/cisco-catalyst-3850/
103
+ ...
104
+ ```
105
+
106
+ Use `--past-only` to print just the past-EOSL list (handy in a cron/report).
107
+
108
+ ## How matching works
109
+
110
+ The plugin downloads `https://eosl.ai/data/lookup.json` (the same part-number → status map that
111
+ powers the eosl.ai bulk checker) and caches it. For each Device Type it resolves the `part_number`
112
+ field (a Device inherits it from its Device Type) in three deterministic, conservative steps:
113
+
114
+ 1. **Exact** match (case-insensitive).
115
+ 2. **Loose** match — ignores spaces/dashes/case, so `FortiGate 60E` resolves `FortiGate-60E`.
116
+ 3. **Vendor-gated aliases** — expands a manufacturer's short SKU form to the catalogued long form,
117
+ but **only when the NetBox manufacturer matches that vendor**. E.g. a Fortinet `FG-60E` resolves
118
+ `FortiGate-60E`, `FS-148E` → `FortiSwitch-148E`, `FAP-221E` → `FortiAP-221E`. The vendor gate means
119
+ a non-Fortinet `FG-…` can never be mis-resolved onto a Fortinet record.
120
+
121
+ There is **no fuzzy or substring matching**. No part number, or no confident match → a neutral
122
+ "not tracked" panel with a search link. Nothing is inferred.
123
+
124
+ The matching logic lives in `netbox_eosl/matching.py` (no Django imports) and is unit-tested in
125
+ `tests/` — run `python tests/test_matching.py` (or `pytest`).
126
+
127
+ ## Data & trust
128
+
129
+ - Dates come from EOSL.ai, sourced from each vendor's official end-of-life bulletin and linked
130
+ for verification. Where a vendor publishes no per-model EOSL date, EOSL.ai computes it from the
131
+ vendor's published support-life policy and labels it "computed".
132
+ - This plugin **reads** public data; it sends none of your inventory anywhere. The only outbound
133
+ request is fetching the public lookup table.
134
+ - Confirm any critical date against the linked vendor bulletin before a purchase, renewal, or
135
+ migration decision.
136
+
137
+ ## License
138
+
139
+ Apache-2.0. See `LICENSE`.
140
+
141
+ ## Contributing / publishing
142
+
143
+ Issues and PRs welcome — especially additional vendor SKU aliases (see `FORTINET_PREFIX` in
144
+ `matching.py` for the pattern) and screenshots. Maintainers: see `PUBLISHING.md` for the
145
+ PyPI + NetBox-community release steps.
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ netbox_eosl/__init__.py
6
+ netbox_eosl/client.py
7
+ netbox_eosl/matching.py
8
+ netbox_eosl/template_content.py
9
+ netbox_eosl.egg-info/PKG-INFO
10
+ netbox_eosl.egg-info/SOURCES.txt
11
+ netbox_eosl.egg-info/dependency_links.txt
12
+ netbox_eosl.egg-info/requires.txt
13
+ netbox_eosl.egg-info/top_level.txt
14
+ netbox_eosl/management/__init__.py
15
+ netbox_eosl/management/commands/__init__.py
16
+ netbox_eosl/management/commands/eosl_check.py
17
+ netbox_eosl/templates/netbox_eosl/eosl_panel.html
18
+ tests/test_matching.py
@@ -0,0 +1 @@
1
+ requests>=2.25
@@ -0,0 +1 @@
1
+ netbox_eosl
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "netbox-eosl"
7
+ version = "0.1.0"
8
+ description = "Show source-backed hardware end-of-service-life status on NetBox Devices and Device Types, from EOSL.ai."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "EOSL.ai", email = "hello@eosl.ai" }]
13
+ keywords = ["netbox", "netbox-plugin", "eosl", "end-of-life", "eol", "lifecycle", "dcim"]
14
+ dependencies = ["requests>=2.25"]
15
+ classifiers = [
16
+ "Framework :: Django",
17
+ "Intended Audience :: System Administrators",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: System :: Networking :: Monitoring",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://eosl.ai/"
25
+ "Data source" = "https://eosl.ai/api/"
26
+ Source = "https://github.com/Kranny36/netbox-eosl"
27
+
28
+ [tool.setuptools.packages.find]
29
+ include = ["netbox_eosl*"]
30
+
31
+ [tool.setuptools.package-data]
32
+ netbox_eosl = ["templates/netbox_eosl/*.html"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,75 @@
1
+ """Unit tests for the pure matching logic. Runnable without NetBox/Django: python -m pytest (or the
2
+ plain-python fallback at the bottom: python tests/test_matching.py)."""
3
+ import importlib.util
4
+ import os
5
+ import sys
6
+
7
+ # Load matching.py directly by path so we don't trigger netbox_eosl/__init__.py (which imports NetBox).
8
+ _MATCHING = os.path.join(os.path.dirname(__file__), "..", "netbox_eosl", "matching.py")
9
+ _spec = importlib.util.spec_from_file_location("netbox_eosl_matching", _MATCHING)
10
+ matching = importlib.util.module_from_spec(_spec)
11
+ _spec.loader.exec_module(matching)
12
+
13
+ # A tiny fixture mirroring the shape of eosl.ai's lookup.json "skus" records.
14
+ SKUS = [
15
+ {"p": "WS-C3850-48P-S", "v": "Cisco", "f": "Catalyst 3850 Series", "s": "cisco-catalyst-3850",
16
+ "eos": "2020-10", "eol": "2025-10", "xb": "High exposure", "xs": 23, "a": 0},
17
+ {"p": "FortiGate-60E", "v": "Fortinet", "f": "FortiGate 60E", "s": "fortinet-fortigate-60e",
18
+ "eos": "2023-06", "eol": "2028-06", "xb": "Plan", "xs": 60, "a": 0},
19
+ {"p": "FortiSwitch-124E", "v": "Fortinet", "f": "FortiSwitch 124E", "s": "fortinet-fortiswitch-124e",
20
+ "eos": "2024-01", "eol": "2029-01", "xb": "Watch", "xs": 75, "a": 0},
21
+ {"p": "J9856A", "v": "HPE", "f": "Aruba 2530", "s": "hpe-aruba-2530", "eol": "2027-01",
22
+ "xb": "Action recommended", "xs": 45, "a": 0},
23
+ {"p": "PA-220", "v": "Palo Alto Networks", "f": "PA-220", "s": "palo-alto-pa-220", "a": 1, "xb": "Current"},
24
+ ]
25
+
26
+
27
+ def _idx():
28
+ return matching.build_index(SKUS)
29
+
30
+
31
+ def check(part, vendor, expected_pid):
32
+ exact, loose = _idx()
33
+ rec = matching.match(part, vendor, exact, loose)
34
+ got = rec["p"] if rec else None
35
+ status = "ok " if got == expected_pid else "FAIL"
36
+ print(f" [{status}] match({part!r}, {vendor!r}) -> {got!r} (expected {expected_pid!r})")
37
+ return got == expected_pid
38
+
39
+
40
+ def run():
41
+ print("matching tests:")
42
+ ok = True
43
+ # Exact matches (any case / punctuation)
44
+ ok &= check("WS-C3850-48P-S", "Cisco", "WS-C3850-48P-S")
45
+ ok &= check("ws-c3850-48p-s", "Cisco", "WS-C3850-48P-S")
46
+ ok &= check("WS C3850 48P S", "Cisco", "WS-C3850-48P-S") # loose (spaces)
47
+ # Fortinet short SKU -> long form, vendor-gated
48
+ ok &= check("FG-60E", "Fortinet", "FortiGate-60E")
49
+ ok &= check("fg-60e", "Fortinet", "FortiGate-60E")
50
+ ok &= check("FortiGate 60E", "Fortinet", "FortiGate-60E")
51
+ ok &= check("FS-124E", "Fortinet", "FortiSwitch-124E")
52
+ # HPE J-number exact
53
+ ok &= check("J9856A", "HPE", "J9856A")
54
+ # Active/noEol product still resolves
55
+ ok &= check("PA-220", "Palo Alto Networks", "PA-220")
56
+ # Safety: the FG- alias must NOT fire for a non-Fortinet vendor (no cross-match)
57
+ ok &= check("FG-60E", "Acme", None)
58
+ ok &= check("FG-60E", None, None)
59
+ # Unknown part -> None
60
+ ok &= check("DOES-NOT-EXIST", "Cisco", None)
61
+ # classify sanity
62
+ assert matching.classify(SKUS[0])[0] == "risk"
63
+ assert matching.classify(SKUS[4])[0] == "active"
64
+ print("classify: ok")
65
+ print("ALL PASS" if ok else "SOME FAILED")
66
+ return ok
67
+
68
+
69
+ # pytest entrypoints
70
+ def test_matching():
71
+ assert run()
72
+
73
+
74
+ if __name__ == "__main__":
75
+ sys.exit(0 if run() else 1)