variables with spaces used in HMS scripts.
variables with spaces used in HMS scripts.
My apologies if this has been answered elsewhere. I've honestly looked and been unable to locate answers to this one.
I've built an Email test which monitors a mailbox for incoming messages.
If a message comes in the test goes "BAD" and runs the following Action Profile:
HMS Script "c:\Program Files\HostMonitor\Scripts\ack_test.hms"
The ack_test.hms contents are:
AckTestStatus %MailSUBJ% %MailBODY%
The %MailSUBJ% is the <testname> I want to acknowledge and the %MailBODY% should be the free form Acknowledgement comment but if it contains spaces (which it often will) only the text up to the first space appears as the Acknowledgement for the HostMonitor test.
It appears the HM uses spaces to parse the above command but since my Acknowledgement text, and for that matter test names will likely contain spaces I'm sure there needs to be some kind of quoting around the variables. I've tried surrounding the variables with quotes, brackets, single quotes etc and can't seem to get this to work. What is the exact syntax for the AckTestStatus command when using variables to supply the parameters? Can we use some kind of " type code like in HTML?
I've never done much with HMS scripts so perhaps I'm missing the syntax or is there different way to do this?
Thanks in advance for helping.
I've built an Email test which monitors a mailbox for incoming messages.
If a message comes in the test goes "BAD" and runs the following Action Profile:
HMS Script "c:\Program Files\HostMonitor\Scripts\ack_test.hms"
The ack_test.hms contents are:
AckTestStatus %MailSUBJ% %MailBODY%
The %MailSUBJ% is the <testname> I want to acknowledge and the %MailBODY% should be the free form Acknowledgement comment but if it contains spaces (which it often will) only the text up to the first space appears as the Acknowledgement for the HostMonitor test.
It appears the HM uses spaces to parse the above command but since my Acknowledgement text, and for that matter test names will likely contain spaces I'm sure there needs to be some kind of quoting around the variables. I've tried surrounding the variables with quotes, brackets, single quotes etc and can't seem to get this to work. What is the exact syntax for the AckTestStatus command when using variables to supply the parameters? Can we use some kind of " type code like in HTML?
I've never done much with HMS scripts so perhaps I'm missing the syntax or is there different way to do this?
Thanks in advance for helping.
You may use either ' or ", e.g.
AcktestStatus "Free Swap %" "comment for testing"
AcktestStatus "Free Swap %" 'more comments'
Just don't mix marks like "text text'
Does not work? HostMonitor version?
E-Mail in HTML format? Try to use plain text mail. HTML may contain various HTML codes in unexpected places.
Regards
Alex
AcktestStatus "Free Swap %" "comment for testing"
AcktestStatus "Free Swap %" 'more comments'
Just don't mix marks like "text text'
Does not work? HostMonitor version?
E-Mail in HTML format? Try to use plain text mail. HTML may contain various HTML codes in unexpected places.
Regards
Alex
Alex,
I've tried adding the single and double quotes to the HMS file.
E.g.
AckTestStatus %MailSUBJ% %MailBODY%
AckTestStatus "%MailSUBJ%" "%MailBODY%"
AckTestStatus '%MailSUBJ%' '%MailBODY%'
Only the first version works. The second and third don't. I'm imagine HM is interpreting the quotes as meaning do not process the contained text as HM variables.
Yes emails are sourced in TEXT format and I'm using HM v 9.40
I've tried adding the single and double quotes to the HMS file.
E.g.
AckTestStatus %MailSUBJ% %MailBODY%
AckTestStatus "%MailSUBJ%" "%MailBODY%"
AckTestStatus '%MailSUBJ%' '%MailBODY%'
Only the first version works. The second and third don't. I'm imagine HM is interpreting the quotes as meaning do not process the contained text as HM variables.
Yes emails are sourced in TEXT format and I'm using HM v 9.40
Sorry, I get the same results when reversing the BODY and SUBJ variables. I of course then put my desired comment text in the email Subject and the test name in the Body.
AckTestStatus "%MailBODY%" "%MailSUBJ%" doesn't change the test to acknowledged
AckTestStatus %MailBODY% %MailSUBJ% does change the test to acknowledged but the Comment is actually blank. It didn't pick up the text I put in the Subject.
BTW: I also have a Send Email Action in the action profile. This sends a reply with the Subject and Body of the original email that I sent to HM. In all cases this is showing me the results I would expect and seems to indicate HM is grabbing the right info from the email.
I reverted back to my original HMS script becuase it seems to make more sense to me if the subject contains the <testname>:
AckTestStatus %MailSUBJ% %MailBODY%
Then I sent an email with double quotes in the original email body and it worked! However, I can't expect my support staff to remember to quote everything
Any ideas what else I can try to get these variables to interpret properly inthe HMS when quoted?
AckTestStatus "%MailBODY%" "%MailSUBJ%" doesn't change the test to acknowledged
AckTestStatus %MailBODY% %MailSUBJ% does change the test to acknowledged but the Comment is actually blank. It didn't pick up the text I put in the Subject.
BTW: I also have a Send Email Action in the action profile. This sends a reply with the Subject and Body of the original email that I sent to HM. In all cases this is showing me the results I would expect and seems to indicate HM is grabbing the right info from the email.
I reverted back to my original HMS script becuase it seems to make more sense to me if the subject contains the <testname>:
AckTestStatus %MailSUBJ% %MailBODY%
Then I sent an email with double quotes in the original email body and it worked! However, I can't expect my support staff to remember to quote everything

Of course you will have the same problem. If mail body has several lines, you cannot use it as parameter of the command.Sorry, I get the same results when reversing the BODY and SUBJ variables. I of course then put my desired comment text in the email Subject and the test name in the Body.
I meant you should try to use JUST subject line without using mail body in the script.
E.g. you mail contains comment+CRLF symbols, how your scipt will look then?
Code: Select all
AckTestStatus "test name" "comment
"
H'm... then you should provide some GUI interface for your support staff.I can't expect my support staff to remember to quote everything
Like Remote Control Console (RCC)
http://www.ks-soft.net/hostmon.eng/rcc/index.htm
or Web Service
http://www.ks-soft.net/hostmon.eng/webservice/index.htm
If you don't like our interface you may create your own; your application may send commands to HostMonitor using telnet connection
(or send e-mails but I don't think this is most reliable option).
Regards
Alex
Alex,
The short answer is I fixed the issue by adjusting my HMS Script as follows:
--Contents of Ack_test.hms--
SetUserVariable udv_email_subject %MailSUBJ%
SetUserVariable udv_email_body %MailBODY%
AckTestStatus "%udv_email_subject%" "%udv_email_body%"
Notice, the SetUserVariable commands do NOT use quotes around the %MailSubj% and %MailBody%. I tried using quotes but I got strange results in the variable values such as leading quote but no closing quote etc.
However notice I do have quotes around the variables in the AckTestStatus variables.
Why it works to first assign %MailSUBJ% and %MailBODY% into user defined variables without quotes, only to use those same user defined variables in a AckTestStatus with quotes, I can't tell you. I can only say that after many hours of testing, this was the solution. I made sure this was the only change by reverting back to my original HMS and the suggested from you with quotes and it reproduced the problem. So apparently filtering the subject and body through another variable cleaned up something in the data.
I had started writing the following, and while it's not necessary, I thought it might be benefitial for other HM users if I included details of what I'm trying to do.
First, we typically use RCC for management of Host Monitor. RCC is definitely the most robust solution. However we are a highly mobile staff we aren't always at a computer. This is especially true in the evening hours. We do however have mobile phones with email capability.
I also get what you are saying about putting the entire HMS Script AckTestStatus in the email subject. This would avoid the problems an HTML email bring to my solution, but a big negative in my book is that it would be theoretically possible for someone to corrupt the command syntax and/or submit other HMS commands which we don't want to allow. E.g. In my opinion, acknowledging failed tests is fine for an insecure method such as email but pausing etc isn't.
Our HM Deployment is designed so that our failed tests now include the following link in the notification mail profiles: (Yes these are in HTML format and that is okay for the notification side.)
<a href="mailto:blah@Fake.Domain?Subject=%TestName%">Click here to ACK this test</a>
We've tested this and this works. The staff get an alert email in HTML format, they click on the Click here to ACK this test link, then they simply enter the ACKNOWLEDGEMENT COMMENT in the BODY of the TEXT email. Yes, they must make sure their email client is setup to send TEXT. If they aren't using TEXT as their default format, it will not work. Let's just ignore that for now
The TEXT email is then sent to our acknowledgement email address e.g. blah@Fake.Domain and a Mail test checks for emails every couple minutes.
Upon detecting an email, the Mail test runs an Action profile that does two things:
1) Sends a confirmation email back to the sender using a SEND EMAIL Action. This confirmation email has always worked and uses an HTML Mail profile with the following:
<p>At %DATETIME%, <b>%TestName%</b> processed your email automation request.<br/>
Function performed: %CommentLine1%</p>
<b><u>Technical Details</b></u><br/>
Agent that Performed the Test: <b>%Agent%</b></p><br/>
<u><b>Original Email Summary</u></b><br/>
From: %MailFROM%<br/>
Subject: %MailSUBJ%<br/>
%MailBODY%
The returned email always comes with the correct Subject and Body. It sure makes it look like HM can correctly captured the %MailSUBJ% and %MailBODY% from the original email.
2) The Action profile runs an HMS Script "c:\Program Files\HostMonitor\Scripts\ack_test.hms"
The contents of the ack_test.hms script are presently:
SetUserVariable udv_email_subject %MailSUBJ%
SetUserVariable udv_email_body %MailBODY%
AckTestStatus "%udv_email_subject%" "%udv_email_body%"
This then acknowledges the failed test with the comment, including all the spaces, we defined in the Body of the email.
I personally think I should be able to simply use: the HMS Script of AckTestStatus "%MailSUBJ%" "%MailBODY%", however this never worked for me. I don't know if the format of my email was such that HM couldn't interpret it, or if there is a bug in HM? I'll leave that to you to test someday
Until then, I hope this helps others who might be looking
for a similar solution.
The short answer is I fixed the issue by adjusting my HMS Script as follows:
--Contents of Ack_test.hms--
SetUserVariable udv_email_subject %MailSUBJ%
SetUserVariable udv_email_body %MailBODY%
AckTestStatus "%udv_email_subject%" "%udv_email_body%"
Notice, the SetUserVariable commands do NOT use quotes around the %MailSubj% and %MailBody%. I tried using quotes but I got strange results in the variable values such as leading quote but no closing quote etc.
However notice I do have quotes around the variables in the AckTestStatus variables.
Why it works to first assign %MailSUBJ% and %MailBODY% into user defined variables without quotes, only to use those same user defined variables in a AckTestStatus with quotes, I can't tell you. I can only say that after many hours of testing, this was the solution. I made sure this was the only change by reverting back to my original HMS and the suggested from you with quotes and it reproduced the problem. So apparently filtering the subject and body through another variable cleaned up something in the data.
I had started writing the following, and while it's not necessary, I thought it might be benefitial for other HM users if I included details of what I'm trying to do.
First, we typically use RCC for management of Host Monitor. RCC is definitely the most robust solution. However we are a highly mobile staff we aren't always at a computer. This is especially true in the evening hours. We do however have mobile phones with email capability.
I also get what you are saying about putting the entire HMS Script AckTestStatus in the email subject. This would avoid the problems an HTML email bring to my solution, but a big negative in my book is that it would be theoretically possible for someone to corrupt the command syntax and/or submit other HMS commands which we don't want to allow. E.g. In my opinion, acknowledging failed tests is fine for an insecure method such as email but pausing etc isn't.
Our HM Deployment is designed so that our failed tests now include the following link in the notification mail profiles: (Yes these are in HTML format and that is okay for the notification side.)
<a href="mailto:blah@Fake.Domain?Subject=%TestName%">Click here to ACK this test</a>
We've tested this and this works. The staff get an alert email in HTML format, they click on the Click here to ACK this test link, then they simply enter the ACKNOWLEDGEMENT COMMENT in the BODY of the TEXT email. Yes, they must make sure their email client is setup to send TEXT. If they aren't using TEXT as their default format, it will not work. Let's just ignore that for now

The TEXT email is then sent to our acknowledgement email address e.g. blah@Fake.Domain and a Mail test checks for emails every couple minutes.
Upon detecting an email, the Mail test runs an Action profile that does two things:
1) Sends a confirmation email back to the sender using a SEND EMAIL Action. This confirmation email has always worked and uses an HTML Mail profile with the following:
<p>At %DATETIME%, <b>%TestName%</b> processed your email automation request.<br/>
Function performed: %CommentLine1%</p>
<b><u>Technical Details</b></u><br/>
Agent that Performed the Test: <b>%Agent%</b></p><br/>
<u><b>Original Email Summary</u></b><br/>
From: %MailFROM%<br/>
Subject: %MailSUBJ%<br/>
%MailBODY%
The returned email always comes with the correct Subject and Body. It sure makes it look like HM can correctly captured the %MailSUBJ% and %MailBODY% from the original email.
2) The Action profile runs an HMS Script "c:\Program Files\HostMonitor\Scripts\ack_test.hms"
The contents of the ack_test.hms script are presently:
SetUserVariable udv_email_subject %MailSUBJ%
SetUserVariable udv_email_body %MailBODY%
AckTestStatus "%udv_email_subject%" "%udv_email_body%"
This then acknowledges the failed test with the comment, including all the spaces, we defined in the Body of the email.
I personally think I should be able to simply use: the HMS Script of AckTestStatus "%MailSUBJ%" "%MailBODY%", however this never worked for me. I don't know if the format of my email was such that HM couldn't interpret it, or if there is a bug in HM? I'll leave that to you to test someday

Until then, I hope this helps others who might be looking

That's because mail body contains more than one text string.Notice, the SetUserVariable commands do NOT use quotes around the %MailSubj% and %MailBody%. I tried using quotes but I got strange results in the variable values such as leading quote but no closing quote etc.
E.g. you mail contains comment+CRLF symbols, how your scipt will look then?
Code: Select all
AckTestStatus "test name" "comment
"
Probably we just can process data for %MailBody% variable, remove all empty lines... unless somebody will need exact body including these empty lines for some reason

Yes, this makes sense.I also get what you are saying about putting the entire HMS Script AckTestStatus in the email subject. This would avoid the problems an HTML email bring to my solution, but a big negative in my book is that it would be theoretically possible for someone to corrupt the command syntax and/or submit other HMS commands which we don't want to allow. E.g. In my opinion, acknowledging failed tests is fine for an insecure method such as email but pausing etc isn't.
because e-mail body is more than just single line of text.I personally think I should be able to simply use: the HMS Script of AckTestStatus "%MailSUBJ%" "%MailBODY%", however this never worked for me. I don't know if the format of my email was such that HM couldn't interpret it, or if there is a bug in HM?
I forgot about simple solution

Regards
Alex



I LOVE IT! Flexibility. Thanks for the additional options. This provides even greater insight into what's happening on th back end of HM. I've found it facinating the more I understand the logic you've built and maintained as you've developed this software.
I also appreciate your paitience with the illogical ways we sometimes try to utilize HM!
