Ad Widget

Collapse

Possible bug in windows agent when running powershell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pmbraat
    Junior Member
    • May 2017
    • 3

    #1

    Possible bug in windows agent when running powershell script

    Hi, I'm kind of new to Zabbix, but I do believe I might have found some kind of bug. It would be nice to get some input from others.

    The following is tested on a clean Windows 7 and Windows 10 VM with both v3.0.4 and v3.2.0. I got the same results.

    The issue:

    After adding a UserParameter that run a PowerShell script I get the wrong output when getting the key with zabbix_get.

    It's simple to reproduce:

    1.
    Unzip pre-compiled agent to C:\zabbix\

    2.
    Add the following to C:\zabbix\conf\zabbix_agentd.win.conf:
    Code:
    UserParameter=test,C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy "Bypass" -NoProfile -NonInteractive -File "C:\zabbix\get-test.ps1"
    3.
    Add a file C:\zabbix\get-test.ps1 with the following content:
    Code:
    <#
    
    .SYNOPSIS
    ASDF
    
    .DESCRIPTION
    ASDF
    
    #>
    
    [CmdletBinding()] Param()
    
    Begin {
        $x = 1
        Write-Host ("begin {0}" -f ($x++))
    }
    
    Process {
        Write-Host ("process {0}" -f ($x++))
    }
    
    End {
        Write-Host ("end {0}" -f ($x++))
    }
    4.
    Start zabbix_agentd:
    Code:
    C:\zabbix>bin\win64\zabbix_agentd.exe -c conf\zabbix_agentd.win.conf -f
    5.
    Observe wrong output with zabbix_get:
    Code:
    C:\zabbix>bin\win64\zabbix_get.exe -s 127.0.0.1 -k test
    begin 1
    end 2
    Expected output is gotten in different ways.

    cmd and zabbix_agentd:
    Code:
    C:\zabbix>bin\win64\zabbix_agentd.exe -c conf\zabbix_agentd.win.conf -t test
    test                                          [t|begin 1
    process 2
    end 3]
    cmd and powershell:
    Code:
    C:\>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy "Bypass" -NoProfile -NonInteractive -File "C:\zabbix\get-test.ps1"
    begin 1
    process 2
    end 3
    powershell:
    Code:
    PS C:\zabbix> Set-ExecutionPolicy "Bypass"
    PS C:\zabbix> .\get-test.ps1
    begin 1
    process 2
    end 3
    cmd and powershell with wrapping cmd:
    Code:
    C:\>cmd.exe /C C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy "Bypass" -NoProfile -NonInteractive -File "C:\zabbix\get-test.ps1"
    begin 1
    process 2
    end 3
    The only way I've been able to reproduce the output I get with zabbix_get is like this in powershell:
    (This is expected. Short story, if you aren't familiar with powershell: An empty array piped into the script/function means that there is nothing to process and the process block won't be run)
    Code:
    PS C:\zabbix> @() | .\get-test.ps1
    begin 1
    end 2
    So what's going on here? Is Zabbix somehow piping some kind of empty input to the script when getting the key via zabbix_get?

    I haven't been able to test this in a full server/client environment. So I'm not sure whether or not the data sent to the server contains the "process" part.
  • pmbraat
    Junior Member
    • May 2017
    • 3

    #2
    I've also set DebugLevel=5, but can't find anything interesting in the log:
    Code:
      3708:20170523:134325.485 Starting Zabbix Agent [Windows host]. Zabbix 3.2.0 (revision 62444).
      3708:20170523:134325.485 **** Enabled features ****
      3708:20170523:134325.485 IPv6 support:          YES
      3708:20170523:134325.485 TLS support:            NO
      3708:20170523:134325.486 **************************
      3708:20170523:134325.486 using configuration file: conf\zabbix_agentd.win.conf
      3708:20170523:134325.489 In init_collector_data()
      3708:20170523:134325.492 End of init_collector_data()
      3708:20170523:134325.492 In init_perf_collector()
      3708:20170523:134325.493 End of init_perf_collector():SUCCEED
      3708:20170523:134325.493 agent #0 started [main process]
      3712:20170523:134325.493 agent #1 started [collector]
      3728:20170523:134325.494 agent #5 started [active checks #1]
      3712:20170523:134325.495 In init_cpu_collector()
      3716:20170523:134325.495 agent #2 started[listener #1]
      3720:20170523:134325.495 agent #3 started[listener #2]
      3728:20170523:134325.495 In init_active_metrics()
      3724:20170523:134325.495 agent #4 started[listener #3]
      3712:20170523:134325.495 In get_counter_name() pdhIndex:238
      3728:20170523:134325.498 buffer: first allocation for 100 elements
      3728:20170523:134325.498 End of init_active_metrics()
      3728:20170523:134325.498 In send_buffer() host:'127.0.0.1' port:10051 entries:0/100
      3728:20170523:134325.499 End of send_buffer():SUCCEED
      3728:20170523:134325.499 In refresh_active_checks() host:'127.0.0.1' port:10051
      3712:20170523:134325.783 End of get_counter_name():SUCCEED
      3712:20170523:134325.783 In get_counter_name() pdhIndex:6
      3712:20170523:134325.783 End of get_counter_name():SUCCEED
      3712:20170523:134325.787 In add_perf_counter() counter:'\Processor(_Total)\% Processor Time' interval:900
      3712:20170523:134325.789 add_perf_counter(): PerfCounter '\Processor(_Total)\% Processor Time' successfully added
      3712:20170523:134325.789 End of add_perf_counter(): SUCCEED
      3712:20170523:134325.789 In add_perf_counter() counter:'\Processor(0)\% Processor Time' interval:900
      3712:20170523:134325.790 add_perf_counter(): PerfCounter '\Processor(0)\% Processor Time' successfully added
      3712:20170523:134325.790 End of add_perf_counter(): SUCCEED
      3712:20170523:134325.790 In add_perf_counter() counter:'\Processor(1)\% Processor Time' interval:900
      3712:20170523:134325.790 add_perf_counter(): PerfCounter '\Processor(1)\% Processor Time' successfully added
      3712:20170523:134325.790 End of add_perf_counter(): SUCCEED
      3712:20170523:134325.790 In get_counter_name() pdhIndex:2
      3712:20170523:134325.791 End of get_counter_name():SUCCEED
      3712:20170523:134325.791 In get_counter_name() pdhIndex:44
      3712:20170523:134325.791 End of get_counter_name():SUCCEED
      3712:20170523:134325.791 In add_perf_counter() counter:'\System\Processor Queue Length' interval:900
      3712:20170523:134325.793 add_perf_counter(): PerfCounter '\System\Processor Queue Length' successfully added
      3712:20170523:134325.794 End of add_perf_counter(): SUCCEED
      3712:20170523:134325.794 End of init_cpu_collector():SUCCEED
      3712:20170523:134325.794 In collect_perfstat()
      3712:20170523:134325.794 End of collect_perfstat()
      3728:20170523:134326.506 active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: Connection refused.)
      3728:20170523:134326.506 End of refresh_active_checks():FAIL
      3728:20170523:134326.506 In process_active_checks() server:'127.0.0.1' port:10051
      3728:20170523:134326.506 End of process_active_checks()
      3728:20170523:134326.506 In get_min_nextcheck()
      3728:20170523:134326.506 End of get_min_nextcheck():-1
      3728:20170523:134326.507 In send_buffer() host:'127.0.0.1' port:10051 entries:0/100
      3728:20170523:134326.507 End of send_buffer():SUCCEED
      3712:20170523:134326.795 In collect_perfstat()
      3712:20170523:134326.795 End of collect_perfstat()
      3720:20170523:134327.008 Requested [test]
      3728:20170523:134327.507 In send_buffer() host:'127.0.0.1' port:10051 entries:0/100
      3728:20170523:134327.507 End of send_buffer():SUCCEED
      3712:20170523:134327.795 In collect_perfstat()
      3712:20170523:134327.796 End of collect_perfstat()
      3720:20170523:134328.353 EXECUTE_STR() command:'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy "Bypass" -NoProfile -NonInteractive -File "C:\zabbix\get-test.ps1"' len:13 cmd_result:'begin 1
    end 2'
      3720:20170523:134328.353 Sending back [begin 1
    end 2]
      3728:20170523:134328.507 In send_buffer() host:'127.0.0.1' port:10051 entries:0/100
      3728:20170523:134328.507 End of send_buffer():SUCCEED
      3712:20170523:134328.796 In collect_perfstat()
      3712:20170523:134328.797 End of collect_perfstat()
      3832:20170523:134329.456 Got signal. Exiting ...
      3832:20170523:134329.456 zbx_on_exit() called
      3728:20170523:134329.508 In free_active_metrics()
      3728:20170523:134329.510 End of free_active_metrics()
      3712:20170523:134329.797 In free_cpu_collector()
      3712:20170523:134329.797 End of free_cpu_collector()
      3832:20170523:134330.456 Zabbix Agent stopped. Zabbix 3.2.0 (revision 62444).

    Comment

    • pmbraat
      Junior Member
      • May 2017
      • 3

      #3
      I've been able to test this in a server-client environment now.

      The Zabbix-server does get:
      Code:
      begin 1
      process 2
      end 3
      I.e. the expected value.

      Aren't the server and zabbix_get.exe supposed to get the same values? I might be mistaken, but this looks like an issue in zabbix_get.exe

      Comment

      Working...