Hello,
I am using FreeNAS 11.3 and I am trying to get alerts using API 2.0. I am doing this with powershell. I do get alerts no problem there. The problem is the date of alerts. This is script I am using:
Code:
$Credentials = IMPORT-CLIXML ".\SecureCredentials.xml"
$RESTAPIUser = $Credentials.UserName
$RESTAPIPassword = $Credentials.GetNetworkCredential().Password
$RESTAPIServer = "ServerFQDN"
$Uri = "https://" + $RESTAPIServer + "/api/v2.0/alert/list"
$Type = "application/json"
$Headers = @{ Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $RESTAPIUser, $RESTAPIPassword))) }
try {
$result = Invoke-RestMethod -Uri $Uri -Headers $Headers -Method Get -SessionVariable Freenas_S -ContentType $Type
$result
}
catch {}This is one of alerts listed:
uuid : ed1857cb-2e2a-4603-95f9-65aab08f4064
source :
klass : ScrubFinished
args : freenas-boot
node : Controller A
key : "freenas-boot"
datetime : @{$date=1592099130997}
dismissed : False
mail :
text : Scrub of pool %r finished.
id : ed1857cb-2e2a-4603-95f9-65aab08f4064
level : INFO
formatted : Scrub of pool 'freenas-boot' finished.
one_shot : True
Powershell sees the value for $date as Int64, running [datetime]::FromFileTime($result[1].datetime.'$date') gives this:
Tuesday, January 2, 1601 21:13:29
I get same date and time for all alerts, although the $date number is different for all the alerts.
I need information how can I convert $date to proper date and time. Any help is appreciated, small "push" to right direction should be enough :)
Cheers