Ad Widget

Collapse

Zabbix Server 'Action' call to Agent doesn't seem to properly trigger User Parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • J_Adatasol
    Member
    • Dec 2018
    • 74

    #1

    Zabbix Server 'Action' call to Agent doesn't seem to properly trigger User Parameter

    Hey all... next phase of troubleshooting my Powershell script problem...

    I have some custom User Parameters defined in my Agent config file. These parameters are calling Windows Powershell scripts that I created.

    Example UserParameter in the config file:
    HTML Code:
     UserParameter=test.testParams_ps,powershell -noninteractive "C:\Program Files\Zabbix Agent\scripts\Testing\testParams3.ps1"

    When I activate the Userparameter manually:
    HTML Code:
    > zabbix_get -s 127.0.0.1 -k fmsadmin.testParams_ps
    ... that results in log entries like this:
    HTML Code:
    8436:20200429:191306.168 Requested [test.testParams_ps]
      8436:20200429:191306.486 EXECUTE_STR() command:'powershell -noninteractive -file "C:\Program Files\Zabbix Agent\scripts\Testing\testParams.ps1"' len:54 cmd_result:'Executing PS script '
      8436:20200429:191306.486 Sending back [Executing PS script from source = Zabbix server action]


    When I trigger an "Action" on the Zabbix server, which in turn calls the remote Agent on this Host:
    HTML Code:
      7524:20200429:191400.494 Requested [system.run[\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k test.testParams_ps,nowait]]
      7524:20200429:191400.495 Executing command '\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k test.testParams_ps'
      7524:20200429:191400.495 zbx_execute_nowait(): executing [cmd /C "\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k test.testParams_ps"]
      7524:20200429:191400.496 Sending back [1]
  • J_Adatasol
    Member
    • Dec 2018
    • 74

    #2
    I have done more testing, but haven't gotten anywhere with this. I thought it might be a permissions issue on the "scripts" sub-folder, but the "System" user has full control over the sub-folders and the script files themselves.

    1) I can run the PS script directly on the Host (in a Powershell prompt) - no problems. (Logged into the Host via RDP - using a different account than "System", though.)

    2) I can use the Zabbix Agent, via "zabbix_get", to trigger this Key, and the PS script, via a PS command shell running on the local machine - no problems. (Logged in via RDP to the Host, using the same account as in test 1.)

    3) Server-side triggered "Action" that calls the Host's Agent, using the same Key: fails to run script, but the attempt to trigger the script DOES show up in the local Agent log on the Host.

    There is apparently so disconnect between the Agent and the PS script engine, when that Key is called from a server Action.

    Comment

    • J_Adatasol
      Member
      • Dec 2018
      • 74

      #3
      I'm still having this disconnect problem - the server functions appear to be correctly calling the Agent on the Host, the Agent appears to be getting the request and logs the process, but the PS script itself isn't being run.

      Does anyone have any insight into why that might be?

      Comment

      • J_Adatasol
        Member
        • Dec 2018
        • 74

        #4
        Is it possible that it's a Powershell configuration problem? Some flag or setting on the scripts? (I thought I had checked those, and that they were OK - but maybe there is a different one that I'm missing.)

        Have checked:
        • Get-ExecutionPolicy
        • Unblock-file

        Comment

        • J_Adatasol
          Member
          • Dec 2018
          • 74

          #5
          Thanks for the feedback, I will give that a try.

          Comment

          • J_Adatasol
            Member
            • Dec 2018
            • 74

            #6
            I have tried something similar to what you described, splitek, but haven't had any luck with it.

            This system, including these scripts, WAS working previously, on a Zabbix v3.4 installation (server and agent). Is there perhaps a compatibility issue with Zabbix Server v4.4.0 and Zabbix Agent v4.4.5?

            Here is the actual Powershell code that I am trying to run - fairly straightforward, I think:

            Code:
            Set-Variable -Name CurDate -Value (get-date)
            write-host "Hello world! " (get-Date)
            
            Start-Sleep -s 1
            
            $CurrDate = get-date
            $Message = "Signing off - this is a TEST of the Event Logging system"
            write-host "Signing off, World! ($CurrDate)"
            Write-EventLog -EventId 4 -LogName Application -Message $Message -Source "Zabbix_Agent" -EntryType Warning

            Then I run it from the command line, using this command, and get these results:
            Code:
            PS C:\Program Files\Zabbix Agent> zabbix_get -s 127.0.0.1 -k admin.testHello_ps
            Hello world! 6/3/2020 12:10:10 PM
            Signing off, World! (06/03/2020 12:10:11)
            PS C:\Program Files\Zabbix Agent>
            This test does create an Application log entry visible in the Event Viewer - as it should.


            I have tried a couple of additional things... but haven't gotten the PS script to actually run yet, when called from the server. Here are the actions and the Log entries (debug = 5):

            Manual trigger:
            Code:
            zabbix_get -s 127.0.0.1 -k admin.testHello_ps
            
            [Log results for manual trigger:]
            7812:20200603:123312.440 EXECUTE_STR() command:'powershell -file "C:\Program Files\Zabbix Agent\scripts\Testing\HelloWorld.ps1"' len:78 cmd_result:'Hello world! 6/3/2'
            7812:20200603:123312.440 Sending back [Hello world! 6/3/2020 12:33:11 PM
            Signing off, World! (06/03/2020 12:33:12)]

            Manual trigger:
            Code:
            zabbix_get -s 127.0.0.1 -p 10050 -k admin.testHello_ps
            
            [Log Results:]
            7812:20200603:124432.795 EXECUTE_STR() command:'powershell -file "C:\Program Files\Zabbix Agent\scripts\Testing\HelloWorld.ps1"' len:78 cmd_result:'Hello world! 6/3/2'
            7812:20200603:124432.796 Sending back [Hello world! 6/3/2020 12:44:31 PM
            Signing off, World! (06/03/2020 12:44:32)]


            Automatic trigger:
            Code:
            \Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p {HOST.PORT} -k admin.testHello_ps
            
            [Log entry for automated trigger:]
            6640:20200603:123400.020 Requested [system.run[\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k admin.testHello_ps,nowait]]
            6640:20200603:123400.020 Executing command '\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k admin.testHello_ps'
            6640:20200603:123400.020 zbx_execute_nowait(): executing [cmd /C "\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -p 10050 -k admin.testHello_ps"]
            6640:20200603:123400.021 Sending back [1]

            Automatic trigger:
            Code:
            \Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -k admin.testHello_ps
            
            [Log entry for automated trigger:]
            6640:20200603:125057.647 Requested [system.run[\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -k admin.testHello_ps,nowait]]
            6640:20200603:125057.647 Executing command '\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -k admin.testHello_ps'
            6640:20200603:125057.648 zbx_execute_nowait(): executing [cmd /C "\Program Files\Zabbix Agent\zabbix_get -s 127.0.0.1 -k admin.testHello_ps"]
            6640:20200603:125057.649 Sending back [1]
            I changed the Execution Policy setting on the Powershell environment to allow Remote-Signed (it had been 'Unrestricted'). I was still getting the same non-activation results as above.

            Last edited by J_Adatasol; 03-06-2020, 19:10.

            Comment

            • RaulChiarella
              Member
              • Apr 2021
              • 59

              #7
              How did you do it for your Zabbix Log to start generating logs on the manual command?
              I am reading my Zabbix Agent Log on my host and it does not generate those log entries. I am having the exact same problem as you...

              Did you manage to solve this? Thanks.

              Comment

              • J_Adatasol
                Member
                • Dec 2018
                • 74

                #8
                Oh, this is an old one... sorry, but I don't know if I ever solved this one. I don't think this is being used anymore, anyway.

                Comment

                • RaulChiarella
                  Member
                  • Apr 2021
                  • 59

                  #9
                  Originally posted by J_Adatasol
                  Oh, this is an old one... sorry, but I don't know if I ever solved this one. I don't think this is being used anymore, anyway.
                  Hi, I just had to increase the debug level in Zabbix Config file, and it worked... Thank you.

                  Comment

                  Working...