I am using this small powershell script to extract some info of the current network-adapters on a windows host. If I run the script manually I get one POST for each network-adapter inserted in the influxdb.
But when I run the same script from telegraf the script only posts the first result.
Function StatusReplace($status) {
switch ($status)
{
"Disconnected" { 1 }
"Up" { 0 }
default { 2 }
}
}
Get-NetAdapter | Select-Object "InterfaceDescription", "Status", "LinkSpeed" | %{
$data="win_networkadapters,host=$env:computername,interface=$($_.InterfaceDescription -replace ' ', '\ '),linkspeed=$($_.LinkSpeed -replace ' ', '\ '),connection=$($_.Status -replace ' ', '\ ') status=$(StatusReplace($_.Status))"
Invoke-WebRequest -Uri "http://<Server>:8086/write?db=telegraf" -Method POST -Body $data
}
telegraf.conf
[[inputs.exec]]
interval = "1m"
commands = [ "powershell C:/Temp/getNetworkadapterInfo.ps1" ]
timeout = "20s"
data_format = "influx"