How do you call/execute a UserParameter key from Server, in an 'Action->Operation'?

  • Filter
  • Time
  • Show
Clear All
new posts

    How do you call/execute a UserParameter key from Server, in an 'Action->Operation'?

    Hi all,

    Zabbix v 3.4; the 'Host' is a Windows machine (Server 2012 R2).

    I'm new to the Zabbix monitoring and responding world, and I think I have made some good progress so far. I have a Zabbix_server and an Agent on a Host that I'm monitoring. I have configured UserParameters on the Agent and defined some custom keys. These keys simply trigger scripts on the Host/Agent machine. (These are used as hooks to allow the Server to restart processes on the Host when it detects that the processes have stopped working.)

    I've run into a small problem - How do you get a Server 'Action' to perform a custom UserParameter on the Host, instead of running a Remote Command? (I suppose that I could just rewrite it as an actual Remote command...RemoteCommands are enabled on the Agent. But I have already got it set up and running via a UserParameter, so I'd like to just reuse that if I can.)

    The configuration for the Action->Operation just gives you 'Send Message' or "Remote Command". I have configured a UserParameter on the Host/Agent to run the command that I want it to run:
    When I call that key using Zabbix_get from a different remote machine (i.e. not from the Zabbix_server, and not the Host), it successfully performs the command:
    ./zabbix_get -s -p ####  -k custom.restartPE
    So I want my Server Action to do the same thing - just query/call the Host Agent UserParameter/Key, to trigger that same command.

    And when this UserParameter is called and the command is run, it is running as a PowerShell script and not as a simple OS batch file. Is there a way to alter that? (I wrote the script as a simple batch file and not a PS script. It's only 3 lines, so would probably be simple to rewrite as PowerShell, but I'm curious about how these things are called and executed.)

    Any pointers would be appreciated.

    -- J

    I'm dabbling with this, in the configuration of the Action -> Operation (under 'Custom script'). This essentially just recreates what I'm doing from my own machine's command line, during my testing.

    /usr/local/bin/zabbix_get -s {HOST.HOST} -p {HOST.PORT} -k fmsadmin.restartWPE
    I don't know yet if the macros are usable here. In the Macro definition list, it doesn't specify 'Action', but does specify Trigger...not sure about the functional difference. And I can't test it yet because there are users on the system.


      The two macros I was trying to use DO correctly get parsed when used in the Action -> Operation -> Remote Command area. The command I ended up with in my configuration was:
      \Zabbix\zabbix_get -s -p {HOST.PORT} -k fmsadmin.restartWPE
      When looking at the results of that command, the Zabbix server also prepended the target server name. So it ended up looking like this after the macro expansion:
      Code:\Zabbix\zabbix_get -s -p 10051 -k fmsadmin.restartWPE
      And I modified the command for the path used on the target Host to Zabbix, not the path used to get to the 'zabbix_get' from the Zabbix_Server instance itself. (I saw stuff in the documentation that made it sound like the path to the program on the server-side was what should be used. It makes sense that it is not that one, but the Host.)


        So I reworked things a bit, because it turns out I was running into TimeOuts on the zabbix_agent when calling the UserParameter/Key. (It has a 30 second max timeout.) So, to get around that I thought I would try just calling the script directly, instead of using the Userparameter. But...even that seems like it might run into the Timeout limit, as it is being called through the Zabbix_agent it seems.

        But to make that call, I reworked the Custom Script -> Command configuration a couple of different ways. But I never got something that worked.

        First I tried this:

        ...and would end up with this in the log file (not sure where the double came from...):
        23308:20181216:175838.477 Requested [["[c:\Zabbix_adatasol\scripts\restart_WPE.ps1]",nowait]]
         23308:20181216:175838.477 Executing command '[c:\Zabbix_adatasol\scripts\restart_WPE.ps1]'
         23308:20181216:175838.477 zbx_execute_nowait(): executing [cmd /C "[c:\Zabbix_adatasol\scripts\restart_WPE.ps1]"]
         23308:20181216:175838.477 Sending back [1]
        So then, to eliminate the double '' I shortened it to this:
        I would get no resulting action, and this in my log file:
        22840:20181216:180947.970 Requested [[c:\Zabbix_adatasol\scripts\FMSAdmin_restart_WPE.ps1,nowait]]
         22840:20181216:180947.970 Executing command 'c:\Zabbix_adatasol\scripts\FMSAdmin_restart_WPE.ps1'
         22840:20181216:180947.970 zbx_execute_nowait(): executing [cmd /C "c:\Zabbix_adatasol\scripts\FMSAdmin_restart_WPE.ps1"]
         22840:20181216:180947.970 Sending back [1]

        So what do I need to put in the configuration box to call a script on the Host machine (Windows Powershell script)? It's trying to do something, but apparently failing.


          So it appears that my timeout issue was caused by a bad syntax when calling the Powershell script. This is the UserParameter definition that I ended up with, to correctly call the Powershell from the UserParameter:

          UserParameter=test.testHello_ps,powershell -noninteractive c:\Zabbix\scripts\HelloWorld.ps1
          And the 'Action' on the server side looks like what I had before:

          \Zabbix\zabbix_get -s -p {HOST.PORT} -k test.testHello_ps
          It seems strange that I need to send a command to the remote Host that calls the Userparameter Key; I would think that I would be able to directly query, and thus trigger, a Userparameter Key from the server.

          Now that I seem to have that can I view this command's result in the Zabbix Server? I don't want to have to log into the target Host every time to see what the result of running my command was. (I did a test run and in the Zabbix_agent.log file I see that the results of my command ARE shown as being sent back to the server:
          2248:20181218:163728.350 EXECUTE_STR() command:'powershell -noninteractive c:\Zabbix\scripts\HelloWorld.ps1' len:79 cmd_result:'Hello world!   12/18'
          2248:20181218:163728.350 Sending back [Hello world!   12/18/2018 4:37:27 PM
          Signing off, World!  (12/18/2018 16:37:28)]



          No announcement yet.