Ad Widget

Collapse

Execute script on zabbix active agent 7.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ledz0
    Junior Member
    • Jun 2024
    • 2

    #1

    Execute script on zabbix active agent 7.0

    Hi,

    In the announcement of updates for Zabbix 7.0, it was mentioned that the ability to execute remote commands for the active agent was added.
    Also, the official documentation states: 'Note that script execution on an active agent is supported since Zabbix agent 7.0.'

    I have a question: Is it possible to execute scripts through Alerts -> Scripts on the active agent? Or is it implemented only as an Item through the command system.run(<command>)?"

    When I execute script on Zabbix active agent 7.0 i get error:
    Click image for larger version

Name:	image.png
Views:	2106
Size:	16.2 KB
ID:	485557

    Also, I have configured zabbix server config set Timeout=30 and set RefreshActiveChecks​=20 for agent config


    Thanks,
    ​
  • gabriele.daltoe
    Junior Member
    • Jul 2016
    • 2

    #2
    I'm trying too... and it gives me the same message...

    Comment


    • gabriele.daltoe
      gabriele.daltoe commented
      Editing a comment
      I add more info:
      I updated both Zabbix Proxy and Zabbix Agent to version 7.0 (obviously also Zabbix Server to version 7.0)

      Zabbix Agent is running as "Local System" on a Windows Server 2022; in zabbix_agent2.conf I set:

      AllowKey=system.run[*]
      Plugins.SystemRun.LogRemoteCommands=1

      On the Zabbix Server side I created a simple script to restart a service (sc stop "servicename" && sc start "servicename").
      In zabbix_agent2.log I see: .... [SystemRun] Executing command:'sc stop "WMI Mapper" & sc start "WMI Mapper"'

      Immediately after the Zabbix Agent 2 service I find it stopped and in the Windows event log I see: "The Zabbix Agent 2 service terminated unexpectedly..."
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #3
    For everyone getting here for the error message, I have opened issue https://support.zabbix.com/browse/ZBX-24799 about the "timeout while retrieving result for remote command" case. Please watch and vote for that if you have the same issue. (There is no need to have commercial support from Zabbix to do that.)

    I see gabriele.daltoe your case https://support.zabbix.com/browse/ZBX-24823 was closed as duplicate of the issue above. Not sure about agent 2 service terminating unexpectedly though, if that is a separate issue or not. Let's see how the Zabbix support team handles the issue.

    Markku

    Comment

    • jhboricua
      Senior Member
      • Dec 2021
      • 113

      #4
      Tagging MRedbourne per his post on zabbix issue #24799 so he can share how he got this to work as I'm also facing the same issue after migrating from Zabbix 5 passive agents to Zabbix 7 active agents.

      My setup:
      Server: Zabbix 7.0.10
      Agents: Zabbix Agent2 7.0.10
      No proxies

      I'm getting the exact same error described in the opening post of this thread when our action trigger tries the execute a powershell script to restart a failed service.

      Comment

      • MRedbourne
        Senior Member
        • Feb 2023
        • 103

        #5

        Not sure why it took the ZBX Forums 3 days to email me that you tagged me in a post.

        How long running is this command? The reason I ask is some long-running commands (such as restarting an active systemd instance) can exceed the default timeout period, even if the command is 'successful'. We see this periodically in our environment when restarting rsyslog (linux) if it has active data enqueued in memory. THe process to write that data to disk exceeds the specified timeout period for us. Though, if you check the service manually it'll have restarted.

        What happens if you tell your PoSh command to output results to a writable directory (C:\Windows\Temp\MyCommand.txt). If you see an output, it's likely running, just the server or agent isn't waiting long enough for the results. You can try increasing the timeout period in the server config: /path/to/zabbix_server.conf

        Code:
        [...]
        Timeout=30
        [...]
        Note I believe that 30s is the max. time allowed by the timeout process. If you're expecting it to take longer, you have the agent start it in the background, return true() (process successfully started) or false() (process failed to start), and bring the output in via a User Parameter statement (custom item).

        Comment

        • jhboricua
          Senior Member
          • Dec 2021
          • 113

          #6
          Originally posted by MRedbourne
          Not sure why it took the ZBX Forums 3 days to email me that you tagged me in a post.
          It's a feature,

          I increased the timeout value in the Zabbix server configuration file to 30, and I know see that the trigger action to restart the failed service is succeeding. So at least that part is working now. If I kick it off a restart of a service manually via the frontend I still get the same error window as the OP 'timeout while retrieving result for remote command', even though the restart executes successfully on the target server (I see the service being started) and it takes well under 30 seconds.

          Comment

          • MRedbourne
            Senior Member
            • Feb 2023
            • 103

            #7
            It could be a bug in the reporting portion. It may not be. Unfortunately, extending the permissible timeout period is the only option I know of from the top of my head. You can try submitting a bug report on the ZBX Support portal (y'know the way :P) and see if they can help.

            We've been in the process of migrating command execution away from the local agent and onto more reliable options that are consistent with other procedures for us.

            Comment

            Working...