I'm not very familiar with PowerShell, but someone on GitHub seems to have
a working PowerShell script to POST to InfluxDB using some lower level
methods [1].

What do your InfluxDB logs show when you attempt the write?

[1]
https://github.com/vsavornin/Influxdb-Powershell/blob/177f75e/Functions/Internal.ps1#L343

On Wed, Dec 28, 2016 at 12:55 PM, Rod Doe <[email protected]> wrote:

> Does anybody have working examples of how to use PowerShell's
> Invoke-RestMethod -Method POST to add data to an InfluxDB?
>
> This query works correctly to GET data from the database:
>
> # Construct the URI.
> $uri = "http://metrics-data.monitoring.capsbaitshop:8086/
> query?db=dns_resolution_metrics&q=SELECT `"zone`", `"value`", `"host`",
> `"account`" FROM `"count_ns`" WHERE `"zone`" = '172.20.0.0"
>
> # Invoke REST GET.
> Invoke-RestMethod -Method GET -Uri $uri
>
> This should be the reciprocal invocation to POST data:
> # This does not explicitly fail but does not work.
>
> # Construct a time stamp.
> $timeStampNanoSecs = [long] ((New-TimeSpan -Start (Get-Date -Date
> '1970-01-01') -End ((Get-Date).ToUniversalTime())).TotalSeconds * 1E9)
>
> # Define fake data.
> $hostName = '172.20.0.0'
> $account = 'NotARealAccount'
> $zone = 'NotARealZone'
> $value = 4
>
> # Create a URI.
> $uri = 'http://metrics-data.monitoring.capsbaitshop:8086/
> write?db=dns_resolution_metrics'
>
> # Create BODY content.
> $postParams = "count_ns,host=$hostName,account=$account,zone=$zone
> value=$value"
>
> # Invoke REST POST.
> Invoke-RestMethod -Method POST -Uri $uri -Body $postParams
>
> Does anybody see what I'm doing wrong here?  It is not a credential issue
> as this InfluxDB instance is currently purposefully wide open.
>
> This curl invocation works correctly, but for simplicity, I would like to
> get this all working on PowerShell.
>  $dataBinary = "count_ns,host=$hostName,account=$account,zone=$zone
> value=$value"
>  .\curl.exe -i -X POST 'http://metrics-data.monitoring.capsbaitshop:8086/
> write?db=dns_resolution_metrics' --data-binary $dataBinary
>
> The curl documentation <https://curl.haxx.se/docs/manpage.html> suggests
> that the --data-binary behavior is a no-op:
>
> --data-binary <data>
>
> (HTTP) This posts data exactly as specified with no extra processing
> whatsoever.
>
> --
> Remember to include the version number!
> ---
> You received this message because you are subscribed to the Google Groups
> "InfluxData" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/influxdb.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/influxdb/87cafe22-dbda-4346-abc1-fbaf77cf929d%40googlegroups.com
> <https://groups.google.com/d/msgid/influxdb/87cafe22-dbda-4346-abc1-fbaf77cf929d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Remember to include the version number!
--- 
You received this message because you are subscribed to the Google Groups 
"InfluxData" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/influxdb.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/influxdb/CALxJwdPCwUftBxMDCve-7PC9Cfv6B1bEqLQTAtuo-RSOPdrQbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to