Ad Widget

Collapse

Running a script on demand.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomekxin1
    Junior Member
    • Apr 2025
    • 11

    #1

    Running a script on demand.

    I have a script that I want to run on demand on zabbix active clients, I placed the script in the folder "C:\script\test.bat"

    I added zabbix_active to the client
    AllowKey=system.run[C:\script\test.bat]
    UserParameter=sb4.send,C:\script\test.bat

    On the zabbix server in the host in item I added a parameter with a refresh time of 1 hour
    The script runs every hour

    However, I need to make a change to run this script on zabbix clients from the zabbix server on demand, not every 1 hour.

    Finally, I would like to place this script on 7 clients so that it runs when I send an email from my email address to, for example, [email protected] with the message "run script test"

  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    The normal way to defice scripts, for release 7.2 (may be different on your release), is to go to Alerts -> Scripts and create your script something like this example called Etherwake. This script runs on the proxy or server, you would want to choose Zabbix agent instead.

    Click image for larger version

Name:	image.png
Views:	239
Size:	31.4 KB
ID:	502032
    Then on screens where hosts in this group appear, click the host name to get a display like this:
    Click image for larger version

Name:	image.png
Views:	190
Size:	23.8 KB
ID:	502033

    Clicking on Etherwake will run the scrip.

    I don't think there is a way in Zabbix to trigger scripts from email, but I think the API can be used to run a script. You would need to get your email to trigger that API call.

    Comment

    • tomekxin1
      Junior Member
      • Apr 2025
      • 11

      #3
      Thanks for the advice, but I've already tried this before writing the post,
      this method doesn't work in my case for 2 reasons:
      - it doesn't work on active agents
      - my script runs for more than 30 seconds (this is less important because after updating the script in a month it will need 15-20 seconds to execute)

      Comment

      • tomekxin1
        Junior Member
        • Apr 2025
        • 11

        #4
        it seems that in zabbix there is no option to run script on request on zabbix agent active

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #5

          Starting with Zabbix agent 7.0, remote commands can also be executed on an agent that is operating in active mode. Zabbix agent - whether active or passive - should run on the remote host, and executes the commands in background.

          Comment

          • tomekxin1
            Junior Member
            • Apr 2025
            • 11

            #6
            I don't know how I checked it before, but I must have messed something up then,
            as I checked now, manual execution of the script behind the zabbix active client works,

            but the problem is that after about 4 seconds the message "timeout while retrieving result for remote command" is displayed,

            I set the timeout on the client to 30 seconds and increased the default timeouts on the server for all items except "connection" to 60 seconds, but it didn't help

            I tried to run the script with the parameters
            C:\script\test.bat]
            C:\script\test.bat,wait
            C:\script\test.bat,nowait

            but in each of these cases I see that the process with the script appears in the Windows task manager and disappears after about 4 seconds, and during this time it will not execute correctly.

            Comment

            • tomekxin1
              Junior Member
              • Apr 2025
              • 11

              #7
              I found one thing,
              in the zabbix server 'zabbix_server.conf' I had set 'timeout = 4',
              I commented out this line and after restarting the server the script stops executing after 3 seconds (default timeout),
              I can change 'timeout ' to 30 seconds, but it is not enough for me, because I need about 47 seconds to execute the script

              so unfortunately it still doesn't meet my needs because the time is too short, but I'm getting closer to solving this problem

              Comment

              • tomekxin1
                Junior Member
                • Apr 2025
                • 11

                #8
                why risky?

                If I change the extension on the computer from bat. to .cmd the script will not execute because zabbix will try to run the .bat file which does not exist on the target computer.

                I managed to bypass the timeout problem,

                I downloaded "Zabbix source", then edited the file
                'src/zabbix_server/server.c',
                with
                Code:
                {"Timeout",            &zbx_config_timeout,            ZBX_CFG_TYPE_INT,
                                ZBX_CONF_PARM_OPT,    1,            30},​
                to
                Code:
                {"Timeout",            &zbx_config_timeout,            ZBX_CFG_TYPE_INT,
                                ZBX_CONF_PARM_OPT,    1,            300},​
                I compiled the server and set it in 'zabbix_server.conf',
                "timeout = 300"​

                Comment


                • mrnobody
                  mrnobody commented
                  Editing a comment
                  Wow, change C font, recompile and reconfigure! What a cool bypass. Thanks for sharing!
              Working...