Ad Widget

Collapse

Send SMS alerts with NowSMS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • melpheos
    Member
    • Dec 2008
    • 64

    #1

    Send SMS alerts with NowSMS

    Hope this will not be interpreted as an ad but this is the only solution i have found in our environement so i think it will be usefull for other (but as there is a how to for clickatell and other paid service i guess it's ok)

    This how to is derived from clickatell on the wiki (script is slightly different to adapt to the way NowSMS work)

    First you have to install NowSMS and configure it properly (RTFM)
    NowSMS Lite is enough for us free trial for 30 days http://www.nowsms.com/productinfo/nowsms-lite

    Then follow the Clickatell how to
    http://www.zabbix.com/wiki/howto/config/alerts/smsapi

    but change the script to
    Code:
    #!/usr/bin/php
    <?php
    // Where should this script log to?
    $logfilelocation        = "/var/log/zabbix/";
    
    // if debug is true, log files will be generated
    $debug    = false;
    
    if ( $debug )
    
    file_put_contents($logfilelocation."sms_alert_".date("YmdHis"),
    serialize($argv));
    if (count($argv)<3) {
        die ("Usage: ".$argv[0]." recipientmobilenumber \"subject\"
    \"message\"\n");
    }
    
    $to         = $argv[1];
    $subject    = $argv[2];
    $message    = $argv[3];
    
    $apiargs=array(
            "PhoneNumber"           => $to,
            "text"          => $subject.": ".$message,
    );
    
    $url    = "http://YOURNOWSMSSERVER:8800/";
    $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 ) {
    
    file_put_contents($logfilelocation."sms_alert_error_".date("YmdHis"),
    curl_error($curl));
        die(curl_error($curl)."\n");
    } else {
        if ( $debug || $result != 100 )
    
    file_put_contents($logfilelocation."sms_alert_answer_".date("YmdHis"),
    $result);
    }
    
    ?>
    I guess you can add username/password if you want authentification on nowsms but we did not used it as we are in a closed circuit.

    Change the YOURNOWSMSSERVER to your server of course.

    The rest of the configuration is the same as on the wiki.
Working...