VMware Cloud Community
kwayley
Contributor
Contributor
Jump to solution

SMS Alerts using local GSM modem and smstools v2

Hi,

I know there have been a couple of threads similar(ish) to this before but I can't find the answer I'm looking for.

I have Hyperic HQ 4.0.3 installed on a machine with a GSM modem attached and smstools installed. I know the SMS functionality is working because I've tested sending a message using smstools and I am also able to receive messages.

My question is this, how can I modify the sms_email.gsp file the send an email to smstools so that smstools can then use its email2sms script.

Has anyone managed to get this working already?

Regards,

Andrew
0 Kudos
1 Solution

Accepted Solutions
jvalkeal_hyperi
Jump to solution

Here's the attached groovy template... it got broken when I tried to include it to my post.

View solution in original post

0 Kudos
19 Replies
jvalkeal_hyperi
Jump to solution

I'm currently doing some planning how to attach real phone to hyperic. Modifying sms template is the way to do it. It's actually the only way to do it.

My plans for sms_email.gsp modifications are:
1. Use phone field (user's information fields) to store the number.
2. Deprecate 'SMS Address' field by giving false email address. This is the address where HQ will try to send content created by sms template. To give false address(in case HQ is using some validity checks) we make sure it's sent somewhere.
3. From sms groovy template, we can access 'user' object and get phone number.

At this point, we need to decide how to interact with gsm phone. There is some alternatives:
A. From groovy we can run external scripts(it think HQ is not preventing this).
B. We can write to-be-send messages to disk and let external batch script on OS level to send actual messages.

I don't yet know which one is better solution.

All of this is actually very easy to implement. I haven't tried to do actual implementation, because I kind of hate these ideas. I've been trying to find more general solution to send sms's directly from HQ server. To do quick and dirty implementation will do the job for one company. If others wants to use it, some modifications is probably needed. It's ok if this modification work is minimized.
jvalkeal_hyperi
Jump to solution

Just talking to myself...

When groovy template to create content is executed, following variables is passed to template:

AlertDefinitionInterface alertdef
AlertInterface alert
ActionExecutionInfo info
Resource resource
AuthzSubject user

params.put("alertDef", alertdef);
params.put("alert", alert);
params.put("action", info);
params.put("resource", resource);
params.put("user", user);

From template we will see user object and it contains interesting fields like:
user.phoneNumber
user.emailAddress
user.sMSAddress

-------------

There is also third way to do this which is not very good solution. If hq server is on unix, give your local OS email address to smsaddress field. This works if hq is sending emails through local sendmail. And if your script can read local mailboxes it can also send messages to your phone. This was my first idea, which is also most worst idea you can get. For obvious reasons....

To execute external scripts from groovy templates is also a bit risky business. If your external script execution blocks, it will mess up alerting framework. I guess those template executions are always queued.
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

Interesting...

What I know is in order for smstools to work I either need to be able to make a txt file in the sms/outgoing folder or send an email which it can then convert. Either way I need to end up with something like:

"To: <phone number>

<message>"

If using the email method I believe the telephone number needs to be in the subject line.

How can I get the groovy template to do any of this? I don't really mind if it's not done a good way just yet, I am more interested in at least proving that it works but I am a little unsure as to how the whole "groovy" thing works.
0 Kudos
jvalkeal_hyperi
Jump to solution

If your script can read message files from 'outgoing' folder, what is the file format? Does file needs to be named is some specific way? I believe this is the best way to do it.

I've done a lot of groovy stuff. Let me see if I find something from my stash 😉
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

It just needs to be a *.txt file, the exact name doesn't matter but if I could create them so that they were fairly unique that would be good to allow for multiple alerts to be in the queue at the same time. Something like username + alert name + time + date would be nice.

eg.

hqadmin_apacheavailability_15:57_11032009.txt

the text file itself just needs to contain:


"To: <phone number>

<message>"

eg.

"To: 447777777777

This is a message."
0 Kudos
jvalkeal_hyperi
Jump to solution

Just tried this. Quite simple example. It's writing files to 'C:\Program Files\Hyperic HQ Enterprise 4.0.1\server-4.0.1-EE\hq-engine\server\default\deploy\hq.ear\smsOutgoing' folder. Files are named as {milliseconds}.txt. Phone number is in 'phone' field. Techically you should receive 'empty message' by email if your smsaddress has valid email address.

What do you think about this?

groovy snippets gets broken in this forum... removing.

Message was edited by: jvalkeal
jvalkeal_hyperi
Jump to solution

Here's the attached groovy template... it got broken when I tried to include it to my post.
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

Wow, thanks, certainly looks promising. Like you it made a directory and the files it is making are the correct format and layout.

Now I just need have it use my "/var/spool/sms/outgoing" folder but hyperic doesn't currently have access to that folder so I think I'll need to sort that out before it'll work.
0 Kudos
jvalkeal_hyperi
Jump to solution

Well, template has variable HQApp.instance.resourceDir which points under HQ's resource directory.

Just change it to:

def dir = new File("/var/spool/sms", "outgoing")
0 Kudos
jvalkeal_hyperi
Jump to solution

Understood your message wrong. Thought you can't read under HQ directories... never mind.
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

It works! 😄
0 Kudos
jvalkeal_hyperi
Jump to solution

Ah, nice 🙂

Btw, did you made any custom modifications to smstools? Or does it support this out of the box. I might want to try this myself...
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

It's pretty much out of the box, the only thing I changed was I set hyperic to be the group owner for the outgoing folder and give hyperic read, write and execute permissions.

I added a couple of extra settings to the smsd.conf file so that it saved sent messages but nothing that actually affects the way it runs.

It was also nice that it automatically found my GSM modem so I didn't need to do anything to configure it, it just worked.
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

Do you know if there's any way I can tweak the message content?
0 Kudos
jvalkeal_hyperi
Jump to solution

Do you mean the sms message body?

Modifying message body is very easy. Those email templates contains examples what you can attach to message itselves(in this case write to the file). I think biggest problem is the 160 char limit if you want to send only one message per alert. You can't write novel with 160 chars. Well you can, but it's really short one 😉

What did you have in mind?
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

Yeh, basically I'd just like it to say something like "message from hyperic" at the start or something to make it a bit more identifiable rather than just giving me the alert name, server name, metric name and value.
0 Kudos
jvalkeal_hyperi
Jump to solution

Well then modify this one liner:

def data = "To: ${user.phoneNumber}\n\n${action.shortReason}"
to
def data = "To: ${user.phoneNumber}\n\nmessage from hyperic ${action.shortReason}"

And if you start modifying this message, you may want to add check if string is max 160 chars. But maybe smstool can also configure to strip characters after 160.
0 Kudos
kwayley
Contributor
Contributor
Jump to solution

Sweet, that's nice and easy.

I've added a couple of bits and my test message is only up to 113 chars so I think I may be safe. 🙂
0 Kudos
shippu4u
Contributor
Contributor
Jump to solution

Hi
can we send SMS alert using open sourse version of Hyperic HQ.if yes plz tell me how?
0 Kudos