PowerShell-Influx icon indicating copy to clipboard operation
PowerShell-Influx copied to clipboard

Improve handling of datetime and object properties

Open markwragg opened this issue 5 years ago • 1 comments

some further suggestions from @Tonic8:

  • if a field in an object is a DateType, you can convert it in something InfluxDB will understand:
(dir | select -first1).lastWriteTime | gm
(dir | select -first1).lastWriteTime | get-date -f "yyyy-MM-dd HH:mm:ss.fff"
(dir | select -first1).lastWriteTime | convertTo-UnixTimeNanoseconds

where fff is millisecond, (talked here https://stackoverflow.com/questions/28589520/how-to-store-dates-in-influxdb) and here https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#time-syntax

  • if a field in an object is something not a "string" but a internal field, like this in Citrix sdk (extract of get-brokerSession | GM):
ConnectionViaIP   NoteProperty string ConnectedViaIP=1.2.3.4
ConnectionMode    NoteProperty Citrix.Broker.Admin.SDK.ConnectionMode ConnectionMode=Brokered
  • if you pass it, the conversion is going wrong(missing doublequote), user must prepare the field, to convert it as string, before passing it to convertTo-Metric
  • example with a Boolean field (it should have double-quote), $test = New-Object PSObject -Property @{testBoolean=$True}
  • below the result from the Write-Influx commande in Verbose Xendesktop,computer1 testBoolean=true 12345678898

Originally posted by @Tonic8 in https://github.com/markwragg/PowerShell-Influx/issues/15#issuecomment-457372359

markwragg avatar Jan 25 '19 09:01 markwragg

we can extend the request to any kind of field (except data/time) to set the result tostring()

this could simplify for example, some fields are not strings but can be converted to string...

PS C:\temp> (dir -file | select -First 1).Directory | gm
   TypeName: System.IO.DirectoryInfo

PS C:\temp> (dir -file | select -First 1).Directory.tostring()
C:\temp
PS C:\temp>

PS C:\temp> (dir -file | select -First 1).Directory

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       12/02/2019     20:47                temp

PS C:\temp>

Tonic8 avatar Feb 12 '19 20:02 Tonic8