I’m using Telegraf to gather some data using a Powershell script, it gives an error which is not seen by Telegraf and therefore is not logged
script file (myScript.ps1):
Get-CimInstance CIM_LogicalDisk -ComputerName _RemoteHost_
Note: in the full script the data gets formatted in influx line format, but to show the problem that’s not needed)
When I run myScript.ps1 from Powershell or cmd
#Powershell
.\myScript.ps1
#cmd
Powershell.exe -Command "C:\Monitoring\telegraf\myScript.ps1"
I get the following error:
Get-CimInstance : Access is denied.
So far everything is ok.
If I create a Telegraf conf file that executes this command (extract of test.conf):
{...}
[agent]
## Log
debug = true
quiet = false
## empty string means to log to stderr.
#logfile = ""
{...}
[[inputs.exec]]
## Commands array
commands = [
'powershell.exe "C:\Monitoring\telegraf\myScript.ps1"'
]
{...}
and then I test it
.\telegraf.exe --config .\test.conf --test
#Output
2019-12-06T14:05:17Z I! Starting Telegraf 1.12.5
2019-12-06T14:05:17Z D! [agent] Initializing plugins
As you can see no error is reported, but I expect to see one since an exception is raised by the script.
Have you ever faced this problem?