I am trying to write a PowerShell script that will return a value from a command line executable. My script is below:
$text = vssadmin list writers
for ($i=0; $i -lt $text.count; $i++) { if ($text[$i] -like "*Microsoft Exchange Writer*") { $outtext = $text[$i+3] } }
$filteredText = $outtext -replace "^\s*State: \[(\d)].*$",'$1'
$filteredText
I have added the following line to the zabbix configuration:
UserParameter=system.exchangevsswriter,%systemroot %\system32\WindowsPowerShell\v1.0\powershell.exe /nologo C:\Scripts\exchangevsswriter.ps1
If I run the above command on the Zabbix client computer manually in the command line the script returns the correct value (a single digit). Also if I run a check on the zabbix server using telnet I get the following:
[root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
Trying 10.10.1.147...
Connected to 10.10.1.147.
Escape character is '^]'.
system.exchangevsswriter
ZBXD1Connection closed by foreign host.
The value I am expecting to return is '1' which appears to be in the above output. However, the value in zabbix for that item never changes. The item is configured as a zabbix agent type with the key system.exchangevsswriter and I have tried both Text and Numeric(Unsigned). The strange thing is if I cause any error in the PowerShell script such that the script returns an error the error text is correctly shown for the item in zabbix. (Example below)
[root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
Trying 10.10.1.147...
Connected to 10.10.1.147.
Escape character is '^]'.
system.exchangevsswriter
ZBXD[The string starting:
At C:\Scripts\exchangevsswriter.ps1:4 char:1
+ <<<< "$filteredText
is missing the terminator: ".
At C:\Scripts\exchangevsswriter.ps1:4 char:15
+ "$filteredText <<<<
+ CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
eption
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfStringConnection closed by foreign host.
In the above example if I check the latest data for the item in zabbix I find the following text:
The string starting:
At C:\Scripts\exchangevsswriter.ps1:4 char:1
+ <<<< "$filteredText
is missing the terminator: ".
At C:\Scripts\exchangevsswriter.ps1:4 char:15
+ "$filteredText <<<<
+ CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
eption
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
If I remove the error and cause the script to return the correct value of '1' then the item never changes from the above text. It also never changes to unsupported. I just the the text "Zabbix agent item [system.exchangevsswriter] on host [hoexmb02] failed" in the zabbix log every time the item checks.
Any ideas on what is causing this?
$text = vssadmin list writers
for ($i=0; $i -lt $text.count; $i++) { if ($text[$i] -like "*Microsoft Exchange Writer*") { $outtext = $text[$i+3] } }
$filteredText = $outtext -replace "^\s*State: \[(\d)].*$",'$1'
$filteredText
I have added the following line to the zabbix configuration:
UserParameter=system.exchangevsswriter,%systemroot %\system32\WindowsPowerShell\v1.0\powershell.exe /nologo C:\Scripts\exchangevsswriter.ps1
If I run the above command on the Zabbix client computer manually in the command line the script returns the correct value (a single digit). Also if I run a check on the zabbix server using telnet I get the following:
[root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
Trying 10.10.1.147...
Connected to 10.10.1.147.
Escape character is '^]'.
system.exchangevsswriter
ZBXD1Connection closed by foreign host.
The value I am expecting to return is '1' which appears to be in the above output. However, the value in zabbix for that item never changes. The item is configured as a zabbix agent type with the key system.exchangevsswriter and I have tried both Text and Numeric(Unsigned). The strange thing is if I cause any error in the PowerShell script such that the script returns an error the error text is correctly shown for the item in zabbix. (Example below)
[root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
Trying 10.10.1.147...
Connected to 10.10.1.147.
Escape character is '^]'.
system.exchangevsswriter
ZBXD[The string starting:
At C:\Scripts\exchangevsswriter.ps1:4 char:1
+ <<<< "$filteredText
is missing the terminator: ".
At C:\Scripts\exchangevsswriter.ps1:4 char:15
+ "$filteredText <<<<
+ CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
eption
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfStringConnection closed by foreign host.
In the above example if I check the latest data for the item in zabbix I find the following text:
The string starting:
At C:\Scripts\exchangevsswriter.ps1:4 char:1
+ <<<< "$filteredText
is missing the terminator: ".
At C:\Scripts\exchangevsswriter.ps1:4 char:15
+ "$filteredText <<<<
+ CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
eption
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
If I remove the error and cause the script to return the correct value of '1' then the item never changes from the above text. It also never changes to unsupported. I just the the text "Zabbix agent item [system.exchangevsswriter] on host [hoexmb02] failed" in the zabbix log every time the item checks.
Any ideas on what is causing this?
Comment