Ad Widget

Collapse

Media script not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emx
    Junior Member
    • Aug 2006
    • 19

    #1

    Media script not working

    I have defined a new media to call a script (used to send SMS texts).

    1. Zabbix server config
    First I modified my zabbix_server.conf and changed the default location for the scripts:
    Code:
    AlertScriptsPath=/opt/zabbix/scripts
    I then restarted the server. In this directory I have a Perl script called "sendsms" that takes the parameters passed to it and uses that to send a text message by SMS through a web-based provider.
    The script works fine and only uses absolute paths.

    2. Front-end config
    I went to 'Administration' - 'Media Types' and then "Create Media Type".
    I then created it by defining it as a Type 'Script' and ScriptName 'sendsms'
    After that I went to 'Users' and selected my own user. There is already a Media there (Email) that works just fine. I added a new one and put my username in the field "Send to". The new Media shows as created and enabled properly.

    At this stage I was assuming that everything was in order. The server config points to the right directory, the script is correctly written with proper permissions, the front-end has been configured correctly.

    Time for a test. I kill the zabbix-agentd on one monitored server. The alarm shows on the Dashboard, and I receive an email alert. The SMS script is however never called.

    I put the server in debug mode (4) and tried again - no useful information in the logs.

    At this stage I don't know what else to try.

    Using Zabbix 1.8.3 on Linux Ubuntu 10.04 with MySQL 5.1
  • JBo
    Senior Member
    • Jan 2011
    • 310

    #2
    Hi,

    You can go Monitoring / events, find the event that should have triggered a call to your script.
    Click on on it. You should get "Event details" page.
    Look at "Message actions" section (it is a drop-down section, you may have to click on top right icon to see the details).
    If only your email appears there, you have a problem with your Media setup.
    If both email and sendsms appear. Check Status of sendsms:
    If Status is "not sent", Error field should give you some details.
    If Status is "sent", Zabbix called your script and got a proper exit code. It may be time to add some debug messages to your script.

    Hope this helps,
    JBo

    Comment

    • emx
      Junior Member
      • Aug 2006
      • 19

      #3
      Media script not working

      Thanks, this is useful info.

      In "Message Actions" I only see the email. No mention whatsoever of the sendsms script.

      According to your guidelines, I have a problem with my "Media Setup". Would you know what kind of problem that is?

      My script is defined in Administration - Media Types as follows:
      Code:
      Description: send text
      Type: Script
      Script name: sendsms
      Here is the relevant line from the server config:
      Code:
      $ grep AlertScriptsPath zabbix_server.conf
      ### Option: AlertScriptsPath
      AlertScriptsPath=/opt/zabbix/scripts
      Here is the script in that location:
      Code:
      $ ls -l /opt/zabbix/scripts
      -rwxr-xr-x 1 zabbix zabbix 923 2011-02-07 17:55 sendsms
      Any suggestion welcome!
      Thanks.

      Comment

      • JBo
        Senior Member
        • Jan 2011
        • 310

        #4
        Hi,

        The setup you showed seems correct.

        One more point to check:
        In Configuration / Actions, if you:
        - Edit your action
        - Look at " Action operations" section
        - You probably have a "Send message to User ..." action
        - Edit this action
        - Make sure that "Send only to" is set to "-- All --"
        - You should see email and sendsms in "User medias" section.

        Hope this helps
        JBo

        Comment

        • emx
          Junior Member
          • Aug 2006
          • 19

          #5
          I have checked as you suggested and everything looks good. However, it just doesn't work. The email alert is received ok, the sms script is never called.

          See attached screenshot showing the Actions config.

          Thanks for any suggestion!
          Attached Files

          Comment

          • JBo
            Senior Member
            • Jan 2011
            • 310

            #6
            Sorry no more ideas.

            I have used several external scripts for alerts. The checks I suggested where enough in my case to get them work.

            The only thing different is that I have never changed Zabbix default locations (AlertScriptsPath).
            It seems quite strange but... who knows ?

            JBo

            Comment

            • emx
              Junior Member
              • Aug 2006
              • 19

              #7
              Never work as root. It's dangerous and it can create issues.

              Ok, I found the problem. What an idiot I am.

              I tested the script as 'root' and of course it worked. When testing it as user 'zabbix', the script couldn't write to a root-owned log file and died because of this.

              Changed ownership and now everything works!

              Sorry for the trouble...

              Encore merci

              Comment

              • Slesers
                Junior Member
                • Feb 2011
                • 11

                #8
                Same problem for me. In this case Zabbix 1.8.5. Web frontend is showing that messages using script is sent but in real life it's not happening.

                Script is based on the php.

                When trying to run script using CLI it works, with persmissions everything ok, checked twice. Can be run using zabbix user.

                Script looks like this:

                Code:
                #!/usr/bin/php
                <?php
                
                
                //UN = username
                $UN                             = "username";
                //P = password
                $P                              = "password";
                //System=H
                $S                              = "H";
                
                
                if (count($argv)<3) {
                    die ("Usage: ".$argv[0]." recipientmobilenumber \"message\"\n");
                }
                
                if ( $debug )
                    to = urllib.quote_plus(recipient(sys.argv[1]))
                $DA         = $argv[1];
                $M          = $argv[2];
                
                
                $apiargs=array(
                        "UN"            => $UN,
                        "P"             => $P,
                        "DA"            => $DA,
                        "SA"            => $SA
                        "M"             => $M);
                
                $url    = "http://sms1.cardboardfish.com:9001/HTTPSMS?";
                $params = "";
                
                foreach ($apiargs as $k=>$v) {
                    if ( $params != "" ) {
                        $params .= "&";
                    }
                    $params .= $k."=".urlencode($v);
                }
                
                $url .= $params;
                
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url );
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $result = curl_exec($curl);
                
                if ( $result === false ) {
                
                
                ?>

                Comment

                • Joby
                  Junior Member
                  • Nov 2012
                  • 29

                  #9
                  Full script please

                  Originally posted by Slesers
                  Same problem for me. In this case Zabbix 1.8.5. Web frontend is showing that messages using script is sent but in real life it's not happening.

                  Script is based on the php.

                  When trying to run script using CLI it works, with persmissions everything ok, checked twice. Can be run using zabbix user.

                  Script looks like this:

                  Code:
                  #!/usr/bin/php
                  <?php
                  
                  
                  //UN = username
                  $UN                             = "username";
                  //P = password
                  $P                              = "password";
                  //System=H
                  $S                              = "H";
                  
                  
                  if (count($argv)<3) {
                      die ("Usage: ".$argv[0]." recipientmobilenumber \"message\"\n");
                  }
                  
                  if ( $debug )
                      to = urllib.quote_plus(recipient(sys.argv[1]))
                  $DA         = $argv[1];
                  $M          = $argv[2];
                  
                  
                  $apiargs=array(
                          "UN"            => $UN,
                          "P"             => $P,
                          "DA"            => $DA,
                          "SA"            => $SA
                          "M"             => $M);
                  
                  $url    = "http://sms1.cardboardfish.com:9001/HTTPSMS?";
                  $params = "";
                  
                  foreach ($apiargs as $k=>$v) {
                      if ( $params != "" ) {
                          $params .= "&";
                      }
                      $params .= $k."=".urlencode($v);
                  }
                  
                  $url .= $params;
                  
                  $curl = curl_init();
                  curl_setopt($curl, CURLOPT_URL, $url );
                  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
                  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                  $result = curl_exec($curl);
                  
                  if ( $result === false ) {
                  
                  
                  ?>
                  Hi,

                  Could you please paste the full script here. Also can you explain where all in the script I will have to modify the parameters in order to use my own service provider details. I would like to use free sms service provider for my environment. Any help very much appreciated.

                  Thanks,
                  JVA

                  Comment

                  Working...