0

I've got a Zabbix discovery rule for Windows servers to run a powershell script and return some SQL instance and database names. This Zabbix agent version (3.4.6) and configuration is working perfectly for the discovery on dozens of other servers, but for some reason this server in particular is adding extra text to the output, which renders the JSON invalid.

Here's a sample of a zabbix_get against that host:

[root@zabbix]# zabbix_get -s host1  -k mssql.db.discovery
Active code page: 1252
{
 "data":[

{ "{#INST}" : "Instance1", "{#DBNAME}" : "Database1" },
{ "{#INST}" : "Instance1", "{#DBNAME}" : "Database2" }

 ]
}

The "Active code page: 1252" message is breaking the JSON. I have a feeling that this is an encoding issue, but I'm not sure where it could be. All of the configs and scripts were copied from the same source that the working servers got theirs from, so I don't know what the difference is.

Interestingly, it isn't just limited to powershell scripts. Running a simple command also generates the message:

[root@zabbix]# zabbix_get -s host1  -k system.run["hostname.exe"]
Active code page: 1252
host1

And another note - running zabbix_agentd.exe -t "mssql.db.discovery" on the host in question also produces the same message. But, executing the script by itself in Powershell ISE, on that host, doesn't produce that message.

My question is this - does anyone know of a way to stop Windows/Zabbix from adding that message, or a workaround to keep it from breaking my JSON?

Nate
  • 36
  • 3
  • Do you invoke "chcp" somwhere in your scripts? Could you insert some write-out to isolate the portion of the script which returns "Active page:" ? – Simone Zabberoni Apr 27 '18 at 22:05
  • @SimoneZabberoni nope, I'm not using chcp anywhere. I experimented with Write-Host in the powershell script - even when I add a Write-Host on the very first line of the script, I get the active code message before any output. – Nate Apr 30 '18 at 12:42

1 Answers1

0

I found a solution that worked. Turns out there was an Autorun registry key for cmd.exe that was running chcp 1252 any time you run a command, causing it to echo that message.

I simply deleted the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\Autorun key altogether, and no more "Active Code Page" messages at the beginning of my commands.

Nate
  • 36
  • 3