Introduction
The SMS Gateway for green-corridor is two things:
- A standalone XML-RPC server running on 192.168.1.7 (Nagios machine) on port 8000, offering a method
send that allows anyone to send SMS messages.
- A listener running on 192.168.1.7 (Nagios machine) that notifies the Green-Corridor.com Traceability module whenever an SMS message that matches the regular expression
gc[, ]?[0-9]+[, ]?(.*)$ is received, it does so by calling traceability.message.add method using Drupal’s XMLRPC server (which internally routes the call to traceability module). Drupal’s XMLRPC server can be accessed at http://green-corridor.com/xmlrpc.php.
With these two parts, from the traceability module, we are able to send and receive SMS messages that match our format (see the regular expression above).
Details about the standalone XML-RPC (that allows us to send)
In 192.168.1.7, The file to start the server is /home/sms/pySMSTools/xmlrpc.py
It starts the server on port 8000 by default, to make sure that the server is running, from a browser try accessing http://192.168.1.7:8000/, you should get a message like this:
Error response
Error code 501.
Message: Unsupported method ('GET').
Error code explanation: 501 = Server does not support this operation.
This is normal, it just means that it doesn’t expect you to call it from a browser! :-). If you got a connection refused or a timeout, then something is wrong.
Details about the listener (that allows us to receive)
Whenever a message arrives, the SMS Gateway executes the file /home/sms/pySMSTools/listeners/gcorridor.py
When executed, gcorridor.py connects to http://green-corridor.com/xmlrpc.py and executed the remote method traceability.message.add passing it the received SMS message. The listener now exits, and Drupal’s traceability module takes it from there.
traceability.message.add is an alias for the function traceability_message_xmlrpc_add in file /home/gcorridor/www/drupal/traceability/traceability.module in the webserver.
traceability_message_xmlrpc_add extracts different parts of the message, and stores it for the specified product, then it tries to forward the message to any numbers subscribed to this product (it does so by using the sending service described above). When the extraction of the message fails (that is, if the SMS message wasn’t in the correct format), a log entry is added to indicate the failure.