-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hey there,
After switching to invoke checks through the internal RestAPI, we noticed a problem with our german localized machines.
Our check looks something like this:
'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' -C {Use-Icinga -Minimal; $counterset = Get-Counter -ListSet 'Netzwerkschnittstelle' | Select-Object -ExpandProperty pathswithinstances | where {$_ -inotmatch 'isatap'}; Exit-IcingaExecutePlugin -Command Invoke-IcingaCheckPerfcounter -PerfCounter $counterset -Verbose 0}
Naturally, this outputs all perfcounters related to the NICs, excluding ISATAP.
But after executing the check, we are greeted with this exception:
[UNKNOWN] Check package "Performance Counter" - [UNKNOWN] \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\Aktive TCP-Verbindungen f???r RSC: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname Aktive TCP-Verbindungen f???r RSC.", \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\Ausgabewarteschlangenl???nge: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname Ausgabewarteschlangenl???nge.", \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\TCP RSC: durchschnittliche Paketgr??????e: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname TCP RSC: durchschnittliche Paketgr??????e.", \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\TCP-RSC: zusammengef???gte Pakete/Sek.: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname TCP-RSC: zusammengef???gte Pakete/Sek.."
\_ [UNKNOWN] \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\Aktive TCP-Verbindungen f???r RSC: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname Aktive TCP-Verbindungen f???r RSC."
\_ [UNKNOWN] \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\Ausgabewarteschlangenl???nge: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname Ausgabewarteschlangenl???nge."
\_ [UNKNOWN] \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\TCP RSC: durchschnittliche Paketgr??????e: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname TCP RSC: durchschnittliche Paketgr??????e."
\_ [UNKNOWN] \Netzwerkschnittstelle(Realtek PCIe GbE Family Controller)\TCP-RSC: zusammengef???gte Pakete/Sek.: Ausnahme beim Aufrufen von "NextValue" mit 0 Argument(en): "Der Leistungsindikator mit dem angegebenen Kategorienamen Netzwerkschnittstelle konnte nicht gefunden werden; Indikatorname TCP-RSC: zusammengef???gte Pakete/Sek.."
As you might notice, there is an encoding problem, where e.g. "Paketgr??????e" should be "Paketgröße". Therefore, if the check is executed with the wrong perfcounter name it won't find any values. Strangely, every 10th try or so, the check succeeds, followed by an exception the check after.
When executing the check with a normal "exit" instead of "Exit-IcingaExecutePlugin", it works as expected so I looked a little deeper into the function.
Exit-IcingaExecutePlugin calls the function Invoke-IcingaInternalServiceCall, which itself invokes a webrequest at line 88.
I pulled the json conversion of the command arguments out of the webrequest and during the request, i converted it into utf8.
It now looks like this:
$CommandArgumentsJSON = ($CommandArguments | ConvertTo-Json -Depth 100);
$ApiResult = Invoke-WebRequest -Method POST -UseBasicParsing -Uri ([string]::Format('https://localhost:{0}/v1/checker?command={1}', $RestApiPort, $Command)) -Body ([System.Text.Encoding]::UTF8.GetBytes($CommandArgumentsJSON)) -ContentType 'application/json' -TimeoutSec $Timeout;
This might not be the best solution, but it certainly worked for me.
Curiously enough, blacklisting the command Invoke-IcingaCheckPerfcounter after whitelisting Invoke-IcingaCheck* doesn't seem to stop the execution over the RestAPI, but that might be a different issue.
Expected Behavior
Executing a check over localized perfcounters through Exit-IcingaExecutePlugin should succeed.
Current Behavior
Executing a check over localized perfcounters through Exit-IcingaExecutePlugin throws an exception because of encoding problems in the webrequest.
Possible Solution
Converting the passed Arguments for the Checkcommand into UTF8 like:
$CommandArgumentsJSON = ($CommandArguments | ConvertTo-Json -Depth 100);
$ApiResult = Invoke-WebRequest -Method POST -UseBasicParsing -Uri ([string]::Format('https://localhost:{0}/v1/checker?command={1}', $RestApiPort, $Command)) -Body ([System.Text.Encoding]::UTF8.GetBytes($CommandArgumentsJSON)) -ContentType 'application/json' -TimeoutSec $Timeout;
Steps to Reproduce (for bugs)
- On a german localized machine, execute:
'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' -C {Use-Icinga -Minimal; $counterset = Get-Counter -ListSet 'Netzwerkschnittstelle' | Select-Object -ExpandProperty pathswithinstances | where {$_ -inotmatch 'isatap'}; Exit-IcingaExecutePlugin -Command Invoke-IcingaCheckPerfcounter -PerfCounter $counterset -Verbose 0}
- Exiting normally will execute the check locally with no errors:
'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' -C {Use-Icinga -Minimal; $counterset = Get-Counter -ListSet 'Netzwerkschnittstelle' | Select-Object -ExpandProperty pathswithinstances | where {$_ -inotmatch 'isatap'}; exit Invoke-IcingaCheckPerfcounter -PerfCounter $counterset -Verbose 0}
Context
Your Environment
- PowerShell Version used (
$PSVersionTable.PSVersion
):
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
- Operating System and version (
Get-IcingaWindowsInformation Win32_OperatingSystem | Select-Object Version, BuildNumber, Caption
):
Version BuildNumber Caption
------- ----------- -------
10.0.19042 19042 Microsoft Windows 10 Enterprise