Ad Widget

Collapse

sSMTP Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foggymtn
    Junior Member
    • Aug 2007
    • 10

    #1

    sSMTP Script

    Hey Ya'll

    I'm trying to configure an alert script that enables smtp authorization for my exchange server and sends an email to an outside account. Zabbix 1.4.1 is running on FreeBSD.

    I was working off of this thread.



    Now, I can run the script from the command line and it executes and emails fine (of course the variables that should be supplied by zabbix are empty). The owner of the script is zabbix, and the perms are set to 777 for troubleshooting purposes. I have set the webgui to create the script and named it appropriately. The AlertScript location in zabbix_server.conf is default (/home/zabbix/bin/).

    However, when I have an alert, no email is received. Since I can run the script manually, it must be something in zabbix. If I look at the actions tab, it shows it as being sent, but it must fail sometime after that. ONe other tidbit, when sent manually, it shows in the /var/log/maillog file, but not when zabbix supposedly sends it.

    Does anyone have any thoughts?

    I can supply any logs needed.

    Thanks

    on edit, here's my script that works from commandline, but not when called by zabbix.

    #!/bin/sh

    export [email protected]
    export zabbixmailto=$1
    export zabbixsubject=$2
    export zabbixbody=$3
    export smtpdomain=mydomain.org
    export smtpserver=mail.mydomain.org
    export smtplogin=zabbix
    export smtppass=secretpasswd

    echo "From: \"Zabbix Monitor\"<$smtpemailfrom>" > /tmp/mymailinput
    echo "T0: $zabbixmailto" >> /tmp/mymailinput
    echo "Subject: $zabbixsubject" >> /tmp/mymailinput
    echo "" >> /tmp/mymailinput
    echo "This is automated. The message is $zabbixbody" >> /tmp/mymailinput

    ssmtp -v -au zabbix -ap secretpasswd [email protected] < /tmp/mymailinput

    Rob
    Last edited by foggymtn; 29-01-2008, 21:15.
  • foggymtn
    Junior Member
    • Aug 2007
    • 10

    #2
    After reading a few other posts regarding email, I should also add, that I can send emails fine TO our exchange server. I only run into problems when I try to send an email THROUGH our exchange to an outside address. My end goal is to be able to send an alert email of disaster status to [email protected]. I see in the other posts where they cannot send messages. I can, just not through the script.

    Looking for advice

    Rob

    Comment

    • johnzan
      Junior Member
      • Jan 2008
      • 8

      #3
      Hi,

      A couple of ideas that may help...

      I'd run the zabbix_server in debug mode (change the conf file to log level 4) to see if there is any info in the log that may help narrow down the cause of the issue.

      Another thing that I have come across many times (in other systems) when calling a script from an application is the environment variables of the process when spawned are not always the same/what we assume them to be, as when logged in. Have you tried to include the contents of .bashrc/.bash_profile or whatever you use normally in your script?

      Regards,
      J.

      Comment

      • foggymtn
        Junior Member
        • Aug 2007
        • 10

        #4
        Thanks for the tips. Since I can run the script as my zabbix user manually, I don't think it has anything to do with the variables. When I run it manually, it just doesn't plug in any variables.

        I tried changing to debug 4, but I didn't see anything relevant come through. Two other questions tho...

        When I configure media type as script, should the name be "script.sh", or "./script.sh"?

        Also, when I create a new media for a user, what should I put in the "Send to" field? Is that just the user name? Or should it reference the script somehow?

        Thanks!!
        Rob

        Comment

        • trikke
          Senior Member
          • Aug 2007
          • 140

          #5
          Hi There,

          strange, do u see anything in your /tmp/mymailinput ( so your shure that your skript is running??)

          As for your Questions:
          I put the scriptname as is ! No "./"
          When u defined the new Media, See that it's enabled for ALL severity's around the clock for every day!!! In the "Send to" Field it entered the username.

          Other Question are u shure your trigger is firing an action???

          Greets
          Patrick

          Comment

          • foggymtn
            Junior Member
            • Aug 2007
            • 10

            #6
            Originally posted by trikke
            Hi There,

            strange, do u see anything in your /tmp/mymailinput ( so your shure that your skript is running??)
            It seems my /tmp/mymailinput never changes content. This makes me think that the script is not being run.

            I put the scriptname as is ! No "./"
            Ok, that's what I thought, but I was hoping for a stupid mistake on my part.

            When u defined the new Media, See that it's enabled for ALL severity's around the clock for every day!!! In the "Send to" Field it entered the username.
            The "when active" shows the default 1-7,00:00-23:59. I initially set it up for Disaster only, but will change it to everything for testing.

            Other Question are u shure your trigger is firing an action???
            If I go under the monitoring tab > Actions, it will show up as being sent. So I assumed that meant it was executing the script. I may create a new script that is much simpler, like echoing the time into a file, and use that for testing purposes. In the meantime, I set up a rule on my outlook to forward any messages with Disaster in the subject to the required outside account.

            I will post back when I find something new. Thanks for the help, and I welcome any suggestions.

            Rob

            Comment

            • foggymtn
              Junior Member
              • Aug 2007
              • 10

              #7
              Alrighty...

              After playing with this a little more. It seems that it IS calling the script. I changed the script to just create a new file (touch filename). When the trigger triggers an alert, it creates the file specified. So, I know it is getting to the script.

              BUT, when I try to send a simplified message using the script, it doesn't work. Here is the contents

              Code:
              #!/bin/sh
              
              mail me@myexchangeaccount < /tmp/mymailinput
              
              ssmtp -au zabbix -ap [I]password[/I] [email][email protected][/email] < /tmp/mymailinput
              But, the funny thing is I can run the above command from the commandline and it works, and I can call the script from the command line and it works.

              I just added the
              Code:
              mail me@myexchangeaccount
              command in the script and it successfully executes, so it's just the ssmtp command that fails. Why won't it work when zabbix calls the script? (And I can't use the mail command for the external notification because my exchange won't relay it)

              Thanks again for taking the time to help. What am I missing????

              Rob

              Comment

              • johnzan
                Junior Member
                • Jan 2008
                • 8

                #8
                try putting the full path to mail and ssmtp.

                Code:
                #!/bin/sh
                
                [B]/usr/bin/[/B]mail me@myexchangeaccount < /tmp/mymailinput
                
                [B]/usr/bin/[/B]ssmtp -au zabbix -ap password [email protected] < /tmp/mymailinput
                Not sure if it's /usr/sbin..... use which if you're not sure exactly they are installed

                Code:
                which mail
                may help

                Cheers,
                J.
                Last edited by johnzan; 01-02-2008, 09:32. Reason: forgot ssmtp

                Comment

                • foggymtn
                  Junior Member
                  • Aug 2007
                  • 10

                  #9
                  Originally posted by johnzan
                  try putting the full path to mail and ssmtp.

                  Code:
                  #!/bin/sh
                  
                  [B]/usr/bin/[/B]mail me@myexchangeaccount < /tmp/mymailinput
                  
                  [B]/usr/bin/[/B]ssmtp -au zabbix -ap password [email protected] < /tmp/mymailinput
                  Not sure if it's /usr/sbin..... use which if you're not sure exactly they are installed

                  Code:
                  which mail
                  may help

                  Cheers,
                  J.
                  YES!!!!!!!!! Thank you! Apparently the path wasn't complete when zabbix_server ran the script! By adding the full path, it went through slick as a peeled onion!

                  Thank you so all very much!

                  Gratefully,
                  Rob

                  Comment

                  • ThiagoP
                    Junior Member
                    • Sep 2009
                    • 2

                    #10
                    SSMTP Ubuntu Script

                    Hi,

                    I need run ssmtp with zabbix, but I can´t find a script to send e-mails from zabbix actions.

                    Somebody can help me with the script?

                    From the terminal I can send e-mail with ssmtp:

                    ssmtp [email protected] -au([email protected]) -ap(password) < email.txt

                    OK?

                    Thanks.

                    Comment

                    • foggymtn
                      Junior Member
                      • Aug 2007
                      • 10

                      #11
                      Script

                      Not sure if this is what you want...

                      Code:
                      #!/bin/sh
                      export [email protected]
                      export zabbixmailto=$1
                      export zabbixsubject=$2
                      export zabbixbody=$3
                      echo "From: \"Zabbix Monitor\"<$smtpemailfrom>" > /home/zabbix/bin/InputFile
                      echo "T0: $1" >> /home/zabbix/bin/InputFile
                      echo "Subject: $2" >> /home/zabbix/bin/InputFile
                      echo "" >> /home/zabbix/bin/InputFile
                      echo "This is automated. The message is $3" >> /home/zabbix/bin/InputFile
                      /usr/local/sbin/ssmtp -au zabbix -ap secretpassword secretuser < /home/zabbix/bin/InputFile
                      mail [email protected] < ./InputFile

                      Comment

                      • ThiagoP
                        Junior Member
                        • Sep 2009
                        • 2

                        #12
                        Script File

                        Hi foggymtn,

                        you answered me about ssmtp zabbix script and now I need to know about where did you save your script file and what name used?

                        I find in /etc/zabbix/zabbix_server.conf this line:

                        # Location for custom alert scripts
                        AlertScriptsPath=/etc/zabbix/alert.d/

                        I think this is correct folder to save the script but i didn´t the default name for the script.

                        Can you help me?

                        Thanks,
                        Thiago.

                        Comment

                        Working...