Ad Widget

Collapse

Action remote execute batch file fails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orangejuice
    Junior Member
    • Mar 2015
    • 7

    #1

    Action remote execute batch file fails

    Hello Zabbix forum!

    I have the following running:

    Server1: executes a webscenario that shows a trigger when fails. When it fails it also runs an action that executes the following:
    system.run[C:\commands\this.bat]

    this command should execute on Server2 but it doesnt, when the trigger pops up the action shows:
    SERVER2:system.run[C:\commands\this.bat] Sent but nothing happend on Server2.

    Batch contents:
    @echo off
    mkdir c:\commands\newdirectory


    SERVER2 has windows server 2012 running and the agent has EnableRemoteCommands=1 enabled

    Any ideas why this fails?
  • jamesNJ
    Senior Member
    • Jun 2015
    • 103

    #2
    Hard to guess. Can you post the server1 trigger logic you have, and then maybe a screen capture of the Action, Condition, Operation screens you have?

    It sounds like you are trying to test a condition on server1 and when the condition fails, trigger a script to run on server2. I think that should be possible. The Condition screen should probably filter on the server1 host name and trigger name, and then the operation tab should have the server2 in the target list, and probably zabbix agent with the commands you intend to run.

    Comment

    • orangejuice
      Junior Member
      • Mar 2015
      • 7

      #3
      Hello jamesNJ,

      This is my setup:


      Template testimus

      Application:
      testapp

      Trigger:
      Testapp
      {Template testimus:web.test.fail[testapp].last(0)}#0

      Web scenario:
      testapp - checks website if it contains a certain text, if it doesnt; trigger!

      Action testgo

      Conditions:
      (A) Trigger value = PROBLEM
      (B) Trigger severity = Disaster
      (C) Trigger = SERVER1: Testapp
      Based on AND

      Operations:
      Step From 1 to 1
      Operation Type: Remote Command
      Targetlist: Host: Server2
      Type: Custom script
      Exec on: Zabbix agent
      Commands: system.run[C:\commands\this.bat]
      Conditions: empty

      Comment

      • jamesNJ
        Senior Member
        • Jun 2015
        • 103

        #4
        I think that looks correct.

        I think you should be able to test your system.run[C:\commands\this.bat] command using zabbix_get from the zabbix server.

        I know permissions on windows can be funny sometimes; I'm not an expert on that. Try to move your script into a wide-open directory like c:\temp that is open to "everyone" and full access, and see if maybe it is an access or permission issue.

        On linux, zabbix agent runs as user 'zabbix' and so all scripts/files need to be accessible by that ID. I think I remember zabbix on windows running a local system account, which may have its limitations. If you think it is a permissions is, you could also try running zabbix agent on windows as some user or admin account.

        Comment

        • orangejuice
          Junior Member
          • Mar 2015
          • 7

          #5
          Thank you for your feedback and suggestions. I will change the directory and see if that works.

          Comment

          • orangejuice
            Junior Member
            • Mar 2015
            • 7

            #6
            I ended up using the Zabbix server as the host and giving it the zabbix_get command as a custom script. Now it works like a charm.

            For those having the same issue:

            Operations tab:
            Target: Your zabbix server (host)
            Type: Custom Script
            Exec on: Zabbix Server
            Commands: zabbix_get -s 111.222.333.444 -p 10050 -k "system.run[C:\temp\this.bat]"
            Conditions: empty

            #mods: its solved, please lock

            Comment

            • drseussofporn
              Junior Member
              • Feb 2015
              • 2

              #7
              Just for archiving purposes, when executing a remote command that is a custom script, you leave off the system.run[] command (at least under Windows). Therefore, your custom script should be "C:\temp\this.bat",nowait

              I hope this helps someone as I was banging my head against this problem for weeks.

              Comment

              • gobenb
                Junior Member
                • Mar 2016
                • 1

                #8
                I've found that if you try and run the command from Zabbix (In other words, you put something like 'net stop "ServiceName"' in the Command field under Operations for the Action), the command will fail due to Windows permissions.

                However, if you make a .bat file and stick that in a folder on the machines C: drive, then put something like "C:\Scripts\RestartService.bat" in the Command field for the Operation (as Dr Suess mentioned) it will work like a charm.

                Comment

                Working...