Ad Widget

Collapse

How to debug Remote Command?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DenisBY
    Member
    • Jul 2006
    • 44

    #1

    How to debug Remote Command?

    I have an action which has an operation "Remote command" with target 'Current host', type 'Custom script' and Execute on 'Zabbix agent'
    Commands:
    Code:
    echo "zabbix" >/tmp/test-zabbix.log
    sudo /usr/bin/pkill -9 -f test.conf >>/tmp/test-zabbix.log 2>&1
    sleep 5
    sudo supervisorctl start test >>/tmp/test-zabbix.log 2>&1​
    When an event has happened on the Zabbix dashboard in Actions I see 'Remote command Executed', however on affected host in /tmp/test-zabbix.log I see only 'zabbix' and nothing else. The supervised process 'test' also didn't start. If I try to execute the same commands directly on the server under the user 'zabbix' they are executed without any issue.
    Where I can find any debug logs or is there any way to debug it?
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    Depending on your version, have you configured AllowKeys in the agent? Also set log remote commands on the agent.

    Comment

    • DenisBY
      Member
      • Jul 2006
      • 44

      #3
      Yes, AllowKeys (EnableRemoteCommands) is enabled. As I mentioned first command `echo "zabbix" >/tmp/test-zabbix.log` executed, I can see 'zabbix' in /tmp/test-zabbix.log and timestamp is updated.
      How I can 'set log remote commands on the agent'? I couldn't find any option for this.

      Comment

      • Bartosz Mickiewicz
        Junior Member
        • Oct 2022
        • 27

        #4
        Since the first line of the command is being executed, I'd assume that rest is being discarded, or there is a problem when using sudo. Did you allow user Zabbix to use sudo without a password? A possible workaround would be to create a bash script on the system and run it using a simple one-line command in Zabbix. Also, please take your time and watch this video (https://www.youtube.com/watch?v=CMlpFuGBruE), there is a lot of information on how to use remote commands and how to enable remote command logging.

        Comment

        • Semiadmin
          Senior Member
          • Oct 2014
          • 1625

          #5
          To log remote commands, you need to set LogRemoteCommands=1 in the agent config. But only successful executions will be logged in this case. To log unsuccessful ones, you will have to raise the debug level to 4

          Comment

          • adavis373315
            Junior Member
            • Aug 2024
            • 8

            #6
            Originally posted by Semiadmin
            To log remote commands, you need to set LogRemoteCommands=1 in the agent config. But only successful executions will be logged in this case. To log unsuccessful ones, you will have to raise the debug level to 4
            Looks like there isn't a debug level 4 anymore, at least not with the version of Zabbix we are on (6.0.28). Adding "LogRemoteCommands=1" to your zabbix config file will suffice according to the Zabbix documentation https://www.zabbix.com/documentation.../zabbix_agentd

            Comment

            Working...