Skip to content

Commit 0ce0319

Browse files
author
Thomas Rzen
committed
Alert before and after the subscription expires
The subscription due date was only available as text, without any alert. - New item pve.subscription.nextduedate.epoch carrying the due date as a Unix timestamp - Trigger "expires in less than {$PVE.SUBSCRIPTION.EXPIRE.DAYS}", Warning, lead time 30 days by default - Trigger "has expired", Average, once the date has passed Neither needs an enable macro: a host without a subscription reports no due date, so the item stays empty and the triggers cannot fire. {$PVE.SUBSCRIPTION.ALERT} still governs only the status trigger for notfound, invalid and suspended. Both the advance warning and the status trigger depend on the expired trigger, so a lapsed subscription raises one problem instead of three. This is the one place where JavaScript preprocessing is unavoidable. /nodes/{node}/subscription reports nextduedate as a plain date string, unlike the certificate endpoint which already delivers an epoch, and Zabbix has no preprocessing step that parses a date. "Already expired" could be done with date(), "expires in N days" cannot. One line, with a format check: an unexpected format throws so the item turns visibly unsupported instead of yielding a wrong date.
1 parent 3fd7de9 commit 0ce0319

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

Virtualization/template_proxmox-ve-rest-api-zabbix/7.0/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Values must carry a time unit.
123123
| `{$IFACE.ACTIVE.WINDOW}` | `7d` | An interface must have been up once within this window before the interface down trigger fires. |
124124
| `{$PVE.REPL.LAG}` | `2h` | Maximum age of the last successful replication. Must stay above the replication schedule, otherwise the trigger fires between two runs. |
125125
| `{$PVE.CERT.EXPIRE.DAYS}` | `21d` | Lead time before certificate expiry. |
126+
| `{$PVE.SUBSCRIPTION.EXPIRE.DAYS}` | `30d` | Lead time before the subscription expires. |
126127

127128
### Discovery Filter Macros
128129

@@ -187,7 +188,9 @@ Set to `0` to suppress a trigger globally. Supports context macros for per-insta
187188
| APT repository files are broken | Warning | At least one repository file cannot be parsed, updates will fail |
188189
| APT repository configuration has warnings | Info | For example the enterprise repository enabled without a subscription |
189190
| Package updates pending | Info | Disabled by default, like the item it depends on |
190-
| PVE subscription is not active | Warning | Disabled by default, see `{$PVE.SUBSCRIPTION.ALERT}` |
191+
| PVE subscription has expired | Average | The subscription period has ended, the enterprise repository is no longer accessible |
192+
| PVE subscription expires soon | Warning | Advance warning via `{$PVE.SUBSCRIPTION.EXPIRE.DAYS}`, depends on the expired trigger so only one is open at a time |
193+
| PVE subscription is not active | Warning | Status invalid, suspended or notfound. Off by default, see `{$PVE.SUBSCRIPTION.ALERT}` |
191194

192195
### VM / LXC Prototypes
193196

@@ -265,7 +268,7 @@ The template includes a pre-built dashboard **"Proxmox VE - Monitoring Dashboard
265268
- **Physical NIC traffic:** Not available either. `/nodes/{node}/netstat` returns per-guest tap devices and resets its counters on every read, so there are no byte counters for `eno1` or `vmbr0`. `/nodes/{node}/rrddata` only carries the node aggregate.
266269
- **ZFS:** `/nodes/{node}/disks/zfs` requires `Sys.Audit` on `/`, not on `/nodes/{node}`. On nodes without ZFS the discovery simply returns nothing and stays supported.
267270
- **Replication:** The list endpoint already carries the job state, so no extra request per job is needed. Fields such as `last_sync` and `error` are absent before the first run or while the job is healthy; those items discard the value instead of turning unsupported.
268-
- **Subscription:** `/nodes/{node}/subscription` needs no special permission and answers with HTTP 200 even without a subscription, reporting status `notfound`.
271+
- **Subscription:** `/nodes/{node}/subscription` needs no special permission and answers with HTTP 200 even without a subscription, reporting status `notfound`. Unlike the certificate endpoint it reports `nextduedate` as a plain date string rather than an epoch, so a single JavaScript preprocessing line converts it for the expiry triggers. Those triggers need no enable macro: a host without a subscription reports no due date, so the item stays empty and they cannot fire.
269272
- **Permission errors:** The API answers with HTTP 403, so an item lacking permissions turns visibly unsupported rather than silently staying empty.
270273
- **ZFS pool health:** Stored as a number with a value map rather than as text, so it can be graphed and shown on a dashboard. 0 is ONLINE, everything above is a fault. The mapping is done with preprocessing steps, not with a script. A state outside the seven known zpool states leaves text in place and the item turns visibly unsupported instead of reporting a wrong number.
271274
- **Long term data:** Numeric performance and capacity items keep 365 days of trends. Timestamp items such as `last_sync` or `notafter` deliberately keep trends disabled, a trend over a Unix timestamp carries no meaning.

Virtualization/template_proxmox-ve-rest-api-zabbix/7.0/template_proxmox-ve-rest-api.yaml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ zabbix_export:
15361536
delay: '0'
15371537
value_type: CHAR
15381538
trends: '0'
1539-
description: 'Next due date as reported by PVE (string, not a timestamp). Alerting is done on the status item instead.'
1539+
description: 'Next due date as reported by PVE, a plain date string. The numeric form for alerting is in pve.subscription.nextduedate.epoch.'
15401540
preprocessing:
15411541
- type: JSONPATH
15421542
parameters:
@@ -1547,6 +1547,37 @@ zabbix_export:
15471547
tags:
15481548
- tag: PVE
15491549
value: Subscription
1550+
- uuid: d3ed6d06a2194635b5580d04303e143d
1551+
name: 'Subscription expiry'
1552+
type: DEPENDENT
1553+
key: pve.subscription.nextduedate.epoch
1554+
delay: '0'
1555+
value_type: FLOAT
1556+
units: unixtime
1557+
trends: '0'
1558+
description: 'Expiry date as a Unix timestamp so the remaining time can be compared. PVE reports nextduedate as a plain date string, unlike the certificate endpoint which already delivers an epoch. Zabbix has no preprocessing step that parses a date, hence the one line of JavaScript. Without a subscription the field is absent and the value is discarded.'
1559+
preprocessing:
1560+
- type: JSONPATH
1561+
parameters:
1562+
- '$.data.nextduedate'
1563+
error_handler: DISCARD_VALUE
1564+
- type: JAVASCRIPT
1565+
parameters:
1566+
- |
1567+
// PVE reports nextduedate as YYYY-MM-DD. Anchored to UTC so the
1568+
// result does not shift with the server timezone. An unexpected
1569+
// format throws, which turns the item visibly unsupported instead
1570+
// of silently producing a wrong date.
1571+
var t = Date.parse(value + 'T00:00:00Z');
1572+
if (isNaN(t)) {
1573+
throw 'unexpected nextduedate format: ' + value;
1574+
}
1575+
return Math.floor(t / 1000);
1576+
master_item:
1577+
key: pve.subscription.raw
1578+
tags:
1579+
- tag: PVE
1580+
value: Subscription
15501581
discovery_rules:
15511582
- uuid: 91bb690f87b743cb8045704ac4a4c9e0
15521583
name: 'Discover backup'
@@ -4565,6 +4596,9 @@ zabbix_export:
45654596
- macro: '{$PVE.SERVICE.STATE.ALERT}'
45664597
value: '1'
45674598
description: 'Enables the service state trigger. Use the context form {$PVE.SERVICE.STATE.ALERT:"pveproxy"}=0 to silence a single service.'
4599+
- macro: '{$PVE.SUBSCRIPTION.EXPIRE.DAYS}'
4600+
value: 30d
4601+
description: 'Lead time before the subscription expires. Must include a time unit, for example 30d. The expiry triggers need no enable macro: hosts without a subscription report no due date, so the item stays empty.'
45684602
- macro: '{$PVE.SUBSCRIPTION.ALERT}'
45694603
value: '0'
45704604
description: 'Set to 1 on hosts that are meant to carry a subscription. Off by default so community hosts do not alert on status notfound.'
@@ -5474,11 +5508,29 @@ zabbix_export:
54745508
status: DISABLED
54755509
description: 'Disabled by default, like the item it depends on. The master item needs Sys.Modify, which PVEAuditor does not grant.'
54765510
manual_close: 'YES'
5511+
- uuid: 7350199fa4884df6bf61d5797c37cf4a
5512+
expression: 'last(/Template Proxmox VE REST API/pve.subscription.nextduedate.epoch)<now()'
5513+
name: 'PVE subscription has expired on {HOST.NAME}'
5514+
opdata: 'Expired on: {ITEM.LASTVALUE1}'
5515+
priority: AVERAGE
5516+
description: 'The subscription period has ended. Access to the enterprise repository is gone, updates from it will fail. Needs no enable macro: without a subscription PVE does not report a due date, so the item stays empty and this trigger cannot fire on community hosts.'
5517+
- uuid: 3e3366874a4d4191a88632af4344bcce
5518+
expression: 'last(/Template Proxmox VE REST API/pve.subscription.nextduedate.epoch)-now()<{$PVE.SUBSCRIPTION.EXPIRE.DAYS}'
5519+
name: 'PVE subscription expires in less than {$PVE.SUBSCRIPTION.EXPIRE.DAYS} on {HOST.NAME}'
5520+
opdata: 'Expires on: {ITEM.LASTVALUE1}'
5521+
priority: WARNING
5522+
description: 'Advance warning before the subscription runs out, so it can be renewed in time. Depends on the expired trigger, so only one of the two is open at a time.'
5523+
dependencies:
5524+
- name: 'PVE subscription has expired on {HOST.NAME}'
5525+
expression: 'last(/Template Proxmox VE REST API/pve.subscription.nextduedate.epoch)<now()'
54775526
- uuid: 57b2f7fad21f4672874712a66208931a
54785527
expression: 'last(/Template Proxmox VE REST API/pve.subscription.status)<>"active" and {$PVE.SUBSCRIPTION.ALERT}=1'
54795528
name: 'PVE subscription is not active on {HOST.NAME} ({ITEM.LASTVALUE})'
54805529
priority: WARNING
5481-
description: 'Status is notfound, invalid, expired or suspended. Disabled by default, set {$PVE.SUBSCRIPTION.ALERT}=1 on hosts that carry a subscription.'
5530+
description: 'Status is notfound, invalid, expired or suspended. Off by default, set {$PVE.SUBSCRIPTION.ALERT}=1 on hosts that are meant to carry a subscription. Depends on the expired trigger so a lapsed subscription raises one problem, not two.'
5531+
dependencies:
5532+
- name: 'PVE subscription has expired on {HOST.NAME}'
5533+
expression: 'last(/Template Proxmox VE REST API/pve.subscription.nextduedate.epoch)<now()'
54825534
graphs:
54835535
- uuid: bbdef5c2775146b4ad30ac91ad877624
54845536
name: 'Load average'

0 commit comments

Comments
 (0)