I created a PowerShell script that collects some file data from a Win 2008 VM.
Something like this:
It collects the file name, LastWriteTime and file size, then, prints them as a sort of CSV.
All files have a suffix which I can use as input, so I can filter them using an array like this:
I have set up a macro for the file list like this:
It works when I test it from the VM itself, but if I try to start the script from Zabbix using a macro as the input, it always fails, giving me an "Empty" response.
If I remove the -ARQS parameter, it collects data correctly, but with no file filter.
My guess is that the script is receiving the macro value as a single string, not an array. Therefore, the script can not find the requested files.
I have tried to change the macro value in some configurations, but none works out. They all give the same return.
Is there a way to pass an array with Zabbix macros or in such a way that the script sees the string as an array?
Something like this:
Code:
param ($ARQS)
$DATAATUAL = Get-Date -Hour 0 -Minute 0 -Second 0
$PATH = "C:\FTP\import\*"
$FILELIST = Get-ChildItem -Path $PATH -Include $ARQS | Where-Object { $_.LastWriteTime -ge $DATAATUAL } | Select-Object -ExpandProperty Name
if ( $FILELIST -ne $null ) {
$FILELIST | ForEach-Object -Process {
$FILELENGTH = Get-ChildItem -Path $PATH -Include $_ | Select-Object -ExpandProperty Length
$FILEWRITE = Get-ChildItem -Path $PATH -Include $_ | Select-Object -ExpandProperty LastWriteTime | Get-Date -UFormat %s
Write-Host "$_;$FILELENGTH;$FILEWRITE"
}
}
Else {
Write-Host "Empty"
}
All files have a suffix which I can use as input, so I can filter them using an array like this:
Code:
PS > $ARQS="*cacs*_v83*","*cakauto*","*COORD_MULTI*" PS > .\mailing_file_stats.ps1 -ARQS $ARQS 20220709013444_cacs10_v83.txt;698668;1657330159,55 102 20220709013444_cacs10_v83.txt.log;189;1657330721,9 6984 20220709013444_cacs11_v83.txt;18203938;1657330162, 14059 20220709013444_cacs11_v83.txt.log;191;1657333631,6 3953 20220709013445_cakauto4.txt;61484988;1657330161,96 899 20220709013445_cakauto4.txt.log;189;1657337397,767 53 20220709013446_cacs5_v83.txt;5529836;1657330159,58 222 20220709013446_cacs5_v83.txt.log;189;1657332086,79 393 20220709013447_cacs8_v83.txt;52621602;1657330160,7 522 20220709013447_cacs8_v83.txt.log;190;1657337038,16 171 20220709013449_cacs2_imob_v83.txt;17142712;1657330 160,9238 20220709013449_cacs2_imob_v83.txt.log;195;16573338 75,074 20220709013451_cacs1_v83.txt;44894378;1657330162,6 0858 20220709013451_cacs1_v83.txt.log;190;1657335439,80 889 20220709013452_cacs6_v83.txt;11197422;1657330162,4 0578 20220709013452_cacs6_v83.txt.log;190;1657332835,45 848 20220709013455_cacs7_v83.txt;55116530;1657330162,0 4699 20220709013455_cacs7_v83.txt.log;190;1657336966,88 622 20220709_Cacs3_v83_PXW1CEADG018.txt;360097234;1657 330170,42408 20220709_Cacs9_v83_PXW1CEADG021.txt;0;1657330161,4 542
Code:
{$MAILING.FILES} = "*cacs*_v83*","*cakauto*","*COORD_MULTI*"
Code:
system.run["powershell.exe -File C:\zabbix\scripts\mailing_file_stats.ps1 -ARQS {$MAILING.FILES}"]
My guess is that the script is receiving the macro value as a single string, not an array. Therefore, the script can not find the requested files.
I have tried to change the macro value in some configurations, but none works out. They all give the same return.
Code:
"*file1*","*file2*","*file3*" "*file1*,*file2*,*file3*" '*file1*','*file2*','*file3*' '*file1*,*file2*,*file3*' *file1*,*file2*,*file3*
Comment