Getting a data element from the ZPI Zabbix. One of the output parameters is “lastclock”.
If I understand correctly, this parameter is responsible for the time of the last check. If not, please explain what this parameter is for?
And the second question is: How do I convert the value of this parameter to a time format?
And where i can get describe about all parameters below?
Code and Output below:
$GetValue = @{
"jsonrpc"= "2.0";
"method"= "item.get";
"params"= @{
"output"= "extend";
"selectMappings" = "extend";
"hostids" = "11130"
"search" = @{
"name" = "Interface Vlan25(): Operational status"
}
}
"id"= 2;
"auth" = $token
}
$HostValue = Invoke-RestMethod -Method 'Post' -Uri "http://$ZabbixIP/zabbix/api_jsonrpc.php" -Body ($GetValue | ConvertTo-Json) -ContentType "application/json"
Output:
itemid : 161511
type : 20
snmp_oid : 1.3.6.1.2.1.2.2.1.8.11025
hostid : 11130
name : Interface Vlan25(): Operational status
key_ : net.if.status[ifOperStatus.11025]
delay : 30
history : 7d
trends : 365d
status : 0
value_type : 3
trapper_hosts :
units :
formula :
logtimefmt :
templateid : 0
valuemapid : 1035
params :
ipmi_sensor :
authtype : 0
username :
password :
publickey :
privatekey :
flags : 4
interfaceid : 583
description :
inventory_link : 0
lifetime : 30d
evaltype : 0
jmx_endpoint :
master_itemid : 0
timeout : 3s
url :
query_fields : {}
posts :
status_codes : 200
follow_redirects : 1
post_type : 0
http_proxy :
headers : {}
retrieve_mode : 0
request_method : 0
output_format : 0
ssl_cert_file :
ssl_key_file :
ssl_key_password :
verify_peer : 0
verify_host : 0
allow_traps : 0
uuid :
state : 0
error :
parameters : {}
lastclock : 1724923393
lastns : 412969585
lastvalue : 1
prevvalue : 1
If I understand correctly, this parameter is responsible for the time of the last check.
Yes; the docs state re lastclock
, which is of type timestamp
(see below):
Time when the item value was last updated.
By default, only values that fall within the last 24 hours are displayed. You can extend this time period by changing the value of Max history display period parameter in the Administration → General menu section.
Complementarily, lastns
(whose type is integer
) provides additional accuracy:
Nanoseconds when the item value was last updated.
Data type timestamp
in the context of the ZABBIX API means that a point in time is expressed in Unix time, i.e. “by the number of non-leap seconds that have elapsed since 00:00:00 UTC on 1st January 1970, the Unix epoch” – that is, the granularity of this time stamp is whole seconds.
You can translate such a value into a .NET [datetimeoffset]
/ [datetime]
instance as follows:
$dto =
[datetimeoffset]::FromUnixTimeSecond($HostValue.lastclock)
# Use $dto.LocalDateTime / $dto.UtcDateTime to get a local / UTC
# timestamp of type [datetime].
If you need the added accuracy provided by the lastns
value:
$dto =
[datetimeoffset]::FromUnixTimeSecond($HostValue.lastclock) +
$HostValue.lastns / 100
Note: [datetimeoffset]
and [datetime]
instances have a granularity of so-called ticks, which are 100-nanosecond units; thus, the nanonsecond value stored in .lastns
is divided by 100
above, which means there’s a slight loss of accuracy.
To get a local / UTC [datetime]
instance from the above, use $dto.LocalTime
/ $dto.UtcDateTime
.