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:
parent
ce340ccf2e
commit
7525387b7a
1 changed files with 3 additions and 3 deletions
|
|
@ -114,7 +114,7 @@ export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A e
|
||||||
constructor(path: string, authToken?: string | null, cookie?: string) {
|
constructor(path: string, authToken?: string | null, cookie?: string) {
|
||||||
super(path, authToken, cookie);
|
super(path, authToken, cookie);
|
||||||
this.skippableZabbixParams.set("selectItems", "items");
|
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 {
|
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;
|
const hosts = <ZabbixHost[]>result;
|
||||||
for (let device of hosts) {
|
for (let device of hosts) {
|
||||||
for (let item of device.items || []) {
|
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(
|
let values = await new ZabbixQueryHistoryRequest(this.authToken, this.cookie).executeRequestReturnError(
|
||||||
zabbixAPI, new ZabbixHistoryGetParams(item.itemid, ["clock", "value", "itemid"], 1, item.value_type))
|
zabbixAPI, new ZabbixHistoryGetParams(item.itemid, ["clock", "value", "itemid"], 1, item.value_type))
|
||||||
if (isZabbixErrorResult(values)) {
|
if (isZabbixErrorResult(values)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue