2

I've set up a Xenserver hosting a Debian VM with Zenoss Core 4.2.4. The Xenserver has a Siemens T35 GSM Modem attached to its serial port COM1. I used ser2net + some Xenserver configuration to get it working. (COM1 binding, SELinux, ...) I created a shell script that can easily send SMS messages.

I created a trigger + notification and everything works perfectly EXCEPT that the message is empty!!!

Here is the script:

#!/usr/bin/expect
# - VAR
set ctrlz \032
set xt \135
set timeout 15
set host [lindex $argv 0]
set port [lindex $argv 1]
set number [lindex $argv 2]
set message [lindex $argv 3]
# - LOG
log_file -a sms.log;
send_log "$host $port $number:$message"
# - CONNECT
spawn telnet $host $port
sleep 1
# - SEND
send AT+CMGF=1\r;
expect "OK"
send AT+CMGS="$number"\r;
expect ">"
send "$message$ctrlz";
expect "OK"
# - END

And here is the Zenoss Page Command:

$ZENHOME/bin/sms.sh 10.10.0.52 3333 $RECIPIENT

This works in Linux as follows:

./sms.sh 10.10.0.52 3333 +32486000000 message

I just can't get the message from Zenoss in the SMS message.... I need to complete this last step to get it fully working!

If I try sending a test message from Zenoss, it also arrives but with no text...

Thank you for your time!

grmbl
  • 155
  • 9
  • Extra, updated the script to log what it's getting for parameters but this doesn't work when being called from Zenoss... I'm new to bash scripting btw. – grmbl Jun 04 '14 at 06:45

3 Answers3

2

The problem appears to be that from my understanding Zenoss sends the actual message to the scripts STDIN input, but your script expects it as a command line parameter. You have to modify your expect script in a way that it will read the message from STDIN instead of $argv 3. After that, your test script should work like this:

echo "Message" | ./sms.sh 10.10.0.52 3333 +32486000000 

I don't really know expect, so I can't help with the actual script.

Sven
  • 97,248
  • 13
  • 177
  • 225
2

It's working,

I looked in the /usr/local/zenoss/Products/ZenUtils/Utils.py file to find that Zenoss sends the message text to stdin so I only needed to read stdin in the expect script to get the message.

Here is the new working script: (note that I left out host & port parameters)

#!/usr/bin/expect
# - VAR
set ctrlz \032
set xt \135
set timeout 15
set number [lindex $argv 0]
set message [gets stdin]
# - LOG
log_file -a sms.log;
send_log "$number:$message"
# - CONNECT
spawn telnet 10.10.0.52 3333
sleep 1
# - SEND
send AT+CMGF=1\r;
expect "OK"
send AT+CMGS="$number"\r;
expect ">"
send "$message$ctrlz";
expect "OK"
# - END

Hope this will help anyone!

grmbl
  • 155
  • 9
0

expect ">"? Is that some kind of copy-paste error or should that actually be expect ">"?

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78