kannel do not directly gives you status for any SMSC it is connected with. i have been asked many times by many that how can we get the status of a given SMSC.
Many times one need to make some decision on current status of SMSC that weather or not one should this SMSC to sent Message. or if you want to get alert or email when one SMSC goes offline.
so i have written a simple php script, which can give you full details about all SMSCs connected to kannel,
This script can run in cronjob every one minute or whatever time you like to update some database. (i am not doing any DB here in this article)
This script uses php curl to get kannel status. and then parse the status and get meaning full data.
smscstatus.php
<?php // check kannel SMSC Online Status include_once("mycurl.php"); $url="http://localhost:13000/status.xml"; $client=new mycurl($url); $client->createCurl($url); $httpResponse=$client->getHttpStatus(); $xString=$client->__tostring(); $xml=simplexml_load_string($xString); $MainStatus=$xml->status; $smscObject=$xml->smscs; $smscCount=$smscObject->count; $smscInnerObject =$smscObject->smsc; $smscInfo = array(); $varadmin_id='admin-id'; for($i=0;$i<$smscCount;$i++) { $smscInfo[$i]['smsc_name']=(string) $smscInnerObject[$i]->name; $smscInfo[$i]['smsc_admin_id']=(string)$smscInnerObject[$i]->$varadmin_id; $smscInfo[$i]['smsc_id']=(string)$smscInnerObject[$i]->id; $smscInfo[$i]['smsc_status']=(string)$smscInnerObject[$i]->status; $smscInfo[$i]['smsc_failed']=(string)$smscInnerObject[$i]->failed; $smscInfo[$i]['smsc_queued']=(string)$smscInnerObject[$i]->queued; $smscInfo[$i]['smsc_received']['sms']=(string)$smscInnerObject[$i]->received->sms; $smscInfo[$i]['smsc_received']['dlr']=(string)$smscInnerObject[$i]->received->dlr; $smscInfo[$i]['smsc_sent']['sms']=(string)$smscInnerObject[$i]->sent->sms; $smscInfo[$i]['smsc_sent']['dlr']=(string)$smscInnerObject[$i]->sent->dlr; } print_r($smscInfo); ?>
mycurl.php
<?php class mycurl { protected $_useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1'; protected $_url; protected $_followlocation; protected $_timeout; protected $_maxRedirects; protected $_cookieFileLocation = './cookie.txt'; protected $_post; protected $_postFields; protected $_referer ="dlr injection-xpowered php"; protected $_session; protected $_webpage; protected $_includeHeader; protected $_noBody; protected $_status; protected $_binaryTransfer; public $authentication = 0; public $auth_name = ''; public $auth_pass = ''; public function useAuth($use){ $this->authentication = 0; if($use == true) $this->authentication = 1; } public function setName($name){ $this->auth_name = $name; } public function setPass($pass){ $this->auth_pass = $pass; } public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false) { $this->_url = $url; $this->_followlocation = $followlocation; $this->_timeout = $timeOut; $this->_maxRedirects = $maxRedirecs; $this->_noBody = $noBody; $this->_includeHeader = $includeHeader; $this->_binaryTransfer = $binaryTransfer; $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt'; } public function setReferer($referer){ $this->_referer = $referer; } public function setCookiFileLocation($path) { $this->_cookieFileLocation = $path; } public function setPost ($postFields) { $this->_post = true; $this->_postFields = $postFields; } public function setUserAgent($userAgent) { $this->_useragent = $userAgent; } public function createCurl($url = 'nul') { if($url != 'nul'){ $this->_url = $url; } $s = curl_init(); curl_setopt($s,CURLOPT_URL,$this->_url); curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:')); curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout); curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects); curl_setopt($s,CURLOPT_RETURNTRANSFER,true); curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation); curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation); curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation); if($this->authentication == 1){ curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass); } if($this->_post) { curl_setopt($s,CURLOPT_POST,true); curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields); } if($this->_includeHeader) { curl_setopt($s,CURLOPT_HEADER,true); } if($this->_noBody) { curl_setopt($s,CURLOPT_NOBODY,true); } /* if($this->_binary) { curl_setopt($s,CURLOPT_BINARYTRANSFER,true); } */ curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent); curl_setopt($s,CURLOPT_REFERER,$this->_referer); $this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE); curl_close($s); } public function getHttpStatus() { return $this->_status; } public function __tostring(){ return $this->_webpage; } } ?>
why kannel monitor not working in centos