fix: extend impliedFields map and improve lastclock validation for Zabbix items

- Added `items.lastclock` and `items.lastvalue` to the implied fields for `state`.
- Enhanced conversion to ensure `lastclock` is neither 0 nor "0" while checking if history value needs to be retrieved.
This commit is contained in:
Andreas Hilbig 2026-02-22 13:52:26 +01:00
parent ce340ccf2e
commit 7525387b7a

View file

@ -114,7 +114,7 @@ export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A e
constructor(path: string, authToken?: string | null, cookie?: string) {
super(path, authToken, cookie);
this.skippableZabbixParams.set("selectItems", "items");
this.impliedFields.set("state", ["items"]);
this.impliedFields.set("state", ["items", "items.lastclock", "items.lastvalue"]);
}
createZabbixParams(args?: A, output?: string[]): ZabbixParams {
@ -176,11 +176,11 @@ export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A e
}
}
if (result && !isZabbixErrorResult(result) && (!output || output.includes("items.lastclock") || output.includes("items.lastvalue"))) {
if (result && !isZabbixErrorResult(result) && (!output || output.includes("state.current") || output.includes("items.lastclock") || output.includes("items.lastvalue"))) {
const hosts = <ZabbixHost[]>result;
for (let device of hosts) {
for (let item of device.items || []) {
if (!item.lastclock) {
if (!item.lastclock || !Number(item.lastclock)) {
let values = await new ZabbixQueryHistoryRequest(this.authToken, this.cookie).executeRequestReturnError(
zabbixAPI, new ZabbixHistoryGetParams(item.itemid, ["clock", "value", "itemid"], 1, item.value_type))
if (isZabbixErrorResult(values)) {