Ad Widget

Collapse

V 1.4.4: cannot make alert script run

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreas
    Member
    • Aug 2007
    • 89

    #16
    Okay this is very weird. I have two alert scripts (both .sh). One of them was working fine. I added a second slightly more complex one that never seemed to be called.

    However when I commented the following line, it suddenly worked:
    DIFF=$(( $CURRENTDATE - $MODIFICATIONDATE ))

    I am completely at loss why that would be. Running things manually works fine. Enabling the line (even without any code using it further in the script) breaks the notification. Disabling it solves the notification.

    Running "echo test1 > test.txt" before the DIFF does work. Running "echo test2 >> test.txt" after the DIFF never gets executed.
    Last edited by dreas; 29-02-2008, 16:45.

    Comment

    • dreas
      Member
      • Aug 2007
      • 89

      #17
      Okay. In my case the problem was that I was using a command without the full path:
      stat output/output_limited.txt -c %Y

      This worked fine when manually testing myself but resulted in an empty value when run from Zabbix causing the DIFF to fail and the script to stop. Changing it to:
      stat /etc/zabbix/alert.d/output/output_limited.txt -c %Y

      solved the issue. Not sure if this helps you.

      Comment

      • chrism01
        Junior Member
        • Feb 2008
        • 11

        #18
        Well, I was doing a simple echo test like yours, so this morning I changed it to use the full pathname of the destination file thus:

        echo "test string" >>/home/zabbix/bin/test_zabbix_out.dat

        As per usual, it says it's firing the trigger in the monitor overviews, but no file created/appended.
        I do login as zabbix to do any manual tests.
        Anyone (hint Alexei ..) have the answer, it must be something simple surely???
        Thx Dreas for continuing to look at this.

        Comment

        • dreas
          Member
          • Aug 2007
          • 89

          #19
          Just to make sure .. create a file/home/zabbix/bin/test_zabbix_out.dat with permission 777 owned by user/group Zabbix. Then use the following .sh script (permission 755):

          #!/bin/sh
          echo "test string" >> /home/zabbix/bin/test_zabbix_out.dat

          Comment

          • chrism01
            Junior Member
            • Feb 2008
            • 11

            #20
            No, tried that, same old, same old

            Comment

            • dreas
              Member
              • Aug 2007
              • 89

              #21
              Ok then I give up

              Comment

              • Crazy Marty
                Member
                • Sep 2007
                • 75

                #22
                Here's a possibility: /bin/sh is *not* /bin/bash, and the expression you're using (with the doubled parentheses) is no supported by /bin/sh. Change the top line to read "#!/bin/bash", and I'll bet it works.... Good luck!

                Comment

                • chrism01
                  Junior Member
                  • Feb 2008
                  • 11

                  #23
                  Actually, if by 'doubled parentheses' you mean '>>', that's a doulbe greater-than, which afaik is std on just about all shells for concatenate as opposed to '>', ie overwrite.
                  (correct me if I'm wrong).
                  In any case, I'm not specifying the shell in the script, so it's using the default setting, which for zabbix (according to my /etc/passwd) is /bin/bash anyway.

                  Comment

                  • Crazy Marty
                    Member
                    • Sep 2007
                    • 75

                    #24
                    Originally posted by dreas
                    Okay this is very weird. I have two alert scripts (both .sh). One of them was working fine. I added a second slightly more complex one that never seemed to be called.

                    However when I commented the following line, it suddenly worked:
                    DIFF=$(( $CURRENTDATE - $MODIFICATIONDATE ))

                    I am completely at loss why that would be. Running things manually works fine. Enabling the line (even without any code using it further in the script) breaks the notification. Disabling it solves the notification.

                    Running "echo test1 > test.txt" before the DIFF does work. Running "echo test2 >> test.txt" after the DIFF never gets executed.
                    That line above that if you comment it out makes the script work is probably not supported by your /bin/sh ( the "((" and "))" are "double-parentheses"). If you change the 1st line in your script from "#!/bin/sh" to "#!/bin/bash", it will probably just work. Do try it. Let us know. (And if you don't have the "#!/bin/sh" as the 1st line, put my suggestion as the 1st line anyway.)
                    Last edited by Crazy Marty; 05-03-2008, 00:43. Reason: extended

                    Comment

                    • chrism01
                      Junior Member
                      • Feb 2008
                      • 11

                      #25
                      Ah, you meant Dreas, not me. Ignore my comment above (for anyone else reading)

                      Comment

                      • dreas
                        Member
                        • Aug 2007
                        • 89

                        #26
                        Originally posted by Crazy Marty
                        That line above that if you comment it out makes the script work is probably not supported by your /bin/sh ( the "((" and "))" are "double-parentheses"). If you change the 1st line in your script from "#!/bin/sh" to "#!/bin/bash", it will probably just work. Do try it. Let us know. (And if you don't have the "#!/bin/sh" as the 1st line, put my suggestion as the 1st line anyway.)
                        Actually it is supported The problem was my $MODIFICATIONDATE variable being empty because I was using a relative path for the "stat" command which was supposed to be an absolute path. I am using "double-parentheses" fine with sh now.

                        Comment

                        • dah
                          Junior Member
                          • May 2013
                          • 1

                          #27
                          (This thread is currently the only step-by-step debugging howto to external&alert scripts, which I could google after spending lots and lots of time and reading into this. I therefore necro this thread, sorry.)

                          A good checklist for external/alert scripts (Zabbix 2.0):

                          Is there a trigger? (Monitoring/Triggers)
                          Is there an event? (Monitoring/Events)
                          Did they cause an action? (Actions column on Monitoring/Events)
                          What did the Action do? (Admin/Audit/Actions)


                          (In my case two package managers had created two zabbix_server.conf. The one in /usr/... was in use. But I did the debugging with the one in /etc/)

                          Comment

                          Working...