Start or Stop a Service via Email

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

but, it´s just for testing. I have changed it and the behaviour is still the same.
bad status will stop service named in %Mailbody%, Good status will be set when a "Good mail" is detected, and then starts the service again.
Please provide details.
What exactly action and actions settings do you use now?
Test status?
Recurrences value?
Quick Log results?
and then let HMS disable this test. Our Service tests are all named like %Servername%\%Servicename% so this should be possible, right?!
1)
It does not matter what name do you use for your Service tests. You assign action to E-Mail test. This means the action can use variables provided by E-Mail test (e.g. it can use %MailSubj% variable but cannot use %ServiceName% variable)
It cannot use any variables related to your Service test UNLESS you specify variable with link to other test.
Please check the following section of the manual
http://www.ks-soft.net/hostmon.eng/mfra ... #specmacro

In other words, if you want to use single action to restart different services in respond to some e-mail (not service test failure), then you need to send servicehost, servicename as part of the mail or send name of related Service test as part of e-mail.

2)
There is no "restart service" HMScript command so I am not sure why do you want to use HM Script action.
I think you may use "Execute external program" action and %MailSubj% variable...
%MailBody% may have many lines, its not really good for such action. We can implement additional variables in next version, e.g. %MailLine1%..%MailLine9% :roll:

Also, if you want to use %MailBody% within HM Script, please check this note
------------------
Note: for security reasons commands StartProgram and ExecuteProgram restricted for HM Scripts when such commands specified within mail body, mail subject, HTTP page or HTTP header.
You may define parameters of StartProgram and ExecuteProgram commands using variables (e.g. StartProgram %MailSubj%), in such case HostMonitor will start external application specified in your e-mail but we do NOT RECOMMEND using such scripts for security reasons.
Also, please make sure you are using mail servers with secure connection!
------------------

BTW:
simple way (use "restart service" action plus "send e-mail" action after 2nd failure) does not work for you?
This way HostMonitor may restarts service automatically; if this does not fix the problem it sends e-mail to admin. Then admin logins to the system, fix the problem and starts service.

Regards
Alex
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

Hey Alex,

let me explain it again. It doesn´t matter to me, if we use external scripts, HMS or anything else...
My final goal is this scenario:

- Service struggles
-> HM restarts the service and informs Admin about it (via Email)
--> this one we still got in use and is working fine!
- if Admin has to do Maintenance work and has forgotten to inform HM-Admins to disable checks, he should has the possibility to disable services via Email (because of no access to HM).
--> if HM restarts the service, in this info email about it Admin should be able to disable the check manually for a dedicated time. (via Reply,Hyperlink, ...)

In our understanding HMS could be the right way because of working with variables.
The way with external script is good, but the Admins should not (and don´t want to... :) ) create a new mail with dedicated subject and maybe the service in Mailbody.
Best practice would be to just reply to the HM info email to stop it again. (and disable the schedule for time X)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Best practice would be to just:
"reply to the HM info email" = "Send new E-mail"
Correct ?
Then you may use HTML e-mail fot notification with mailto tag:
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand&body=mysql">Stop MySQL Service</a>
In such case, your Admins will see only link Stop MySQL Service. This link will create new e-mail with parameters you need.
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

Then you may use HTML e-mail fot notification with mailto tag:
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand&body=mysql">Stop MySQL Service</a>
here i can use variables like %ServiceComp% and %ServiceName%, that´s a good beginning. So the right Servername and Servicename would be in the Hyperlink. Then we could use this email for more then only one service check!!

when i send this email back to HM, can HMS take the variables and do a command like
PauseTest %HostName% %TestName% ?

:)
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

EDIT:

i have forgotten, HMS needs this syntax:
PauseTest <TestName> <time_minutes> [<Comment>]

so, like i said before, our Tests are named "Servername\Servicename".

If the Reply message contains

<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand&body=%ServiceComp%\%ServiceName%">Stop MySQL Service</a>

HMS would interpret that as <TestName> and can start this correctly, right?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Email with content:
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand&body=%ServiceComp%\%ServiceName%">Stop MySQL Service</a>
will be generaged by Service test that has filed.
variables %ServiceComp% and %ServiceName% will be evaluated by Service test.
If you need to disable test item (that had triggered the Action), you may use %Testname% instead of using %ServiceComp% and %ServiceName%:
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand_PAUSE_TEST&body=%22%TestName%%22%2010">PAUSE %TestName% test for 10 min</a>

<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand_PAUSE_TEST&body=%22%TestName%%22%2020">PAUSE %TestName% test for 20 min</a>

Here %22 is doublequote symbol , %20 is space symbol.
EMail test with check for subject HMCommand_PAUSE_TEST and start HMS script action. HMS Script may contain the following command:
PauseTest %MailBody%
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

- if Admin has to do Maintenance work and has forgotten to inform HM-Admins to disable checks, he should has the possibility to disable services via Email (because of no access to HM)
...
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand&body=%ServiceComp%\%ServiceName%">Stop MySQL Service</a>
1) As I said its not very good idea to use %MailBody% variable for such actions because it may contain some empty lines, etc. Sometimes it will work fine, sometimes not, depending on e-mail client, etc.
We will add several new variable in next version (next week).

2) If you want to stop service, use "Execute external program" action with command line like net stop "%MailLine1%"
There is no %MailLine1% variable yet, please wait till next week.

3) If you want to stop service on remote system then you need 2 parameters for command line, e.g. sc "%MailLine1%" stop "%MailLine2%"
Or use custom powershell script that will parse single parameter like host\service and stop specified service on target host.
--> if HM restarts the service, in this info email about it Admin should be able to disable the check manually for a dedicated time. (via Reply,Hyperlink, ...)
Here you should use HM Script and here you may use %MailBody% variable (e.g. your can send entire command like PauseTestByID 345 15 in e-mail because it does not contain StartProgram or ExecuteProgram commands that considered unsafe and will not be executed as part of email body).
However new variables can be usefull in this case as well.

I just do not understand why do you want to pause test if service was restarted and everyhting is fine?

Regards
Alex
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

will be generaged by Service test that has filed.
variables %ServiceComp% and %ServiceName% will be evaluated by Service test.
If you need to disable test item (that had triggered the Action), you may use %Testname% instead of using %ServiceComp% and %ServiceName%:
<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand_PAUSE_TEST&body=%22%TestName%%22%2010">PAUSE %TestName% test for 10 min</a>

<a href="mailto:hostmon.commandsmail@gmail.com?subject=HMCommand_PAUSE_TEST&body=%22%TestName%%22%2020">PAUSE %TestName% test for 20 min</a>

Here %22 is doublequote symbol , %20 is space symbol.
EMail test with check for subject HMCommand_PAUSE_TEST and start HMS script action. HMS Script may contain the following command:
PauseTest %MailBody%
works perfect !!! thank you!
1) As I said its not very good idea to use %MailBody% variable for such actions because it may contain some empty lines, etc. Sometimes it will work fine, sometimes not, depending on e-mail client, etc.
this shouldn´t happen because it´s completely HTML code. :)
And it´s even better then executing external program stuff.
I just do not understand why do you want to pause test if service was restarted and everyhting is fine?
i want to catch the forgetfulness of my colleagues... 8)
Seriously, sometimes when Admins patch their systems (in the Night) they forget to inform us to pause the Services and they have no access or don´t want to have access to HM, so they couldn´t pause it on theirself.
Because this mails will be send on standby service (24x7) we have to get up and pause the services. Kind of education, but if these Admins will get emails every 5 minutes, maybe they will pause the services?! :wink:

i thank both of you, also for your patience with a Newbie... :D
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Now I understand. Thank you for explanation :)
We will add new variables anyway (actually we already did, testing them).

Regards
Alex
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

Hi,

one more thig i´d like to ask:

we use Outlook 2010 / Exchange 2010 and want to query different subfolders in Email test.

Config for Email test:
Port 993, TLS Implicit, Protocol IMAP, Mailbox "Inbox"

If i change "Inbox" to "Inbox\HM\..." Status will be "Unknown" with failure "NO Inbox\HM\... doesn´t exist."

Is it possible?
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

...can i execute HMS script manually to check if they are working?

i´m getting an Action result "56 errors detected", but can´t find any informations in LOGs about it. any ideas?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

dbissbort wrote:...can i execute HMS script manually to check if they are working?
HostMonitor menu File->Execute script
(HostMonitor, not RCC)
i´m getting an Action result "56 errors detected", but can´t find any informations in LOGs about it. any ideas?
Option #1: check system log file using any viewer (or menu View->System log)
Option #2: menu View -> Auditing Tool -> Recent systlog

Regards
Alex
dbissbort
Posts: 16
Joined: Wed Mar 13, 2013 4:59 am

Post by dbissbort »

thank you so far!

i now did the following configuration (maybe for someone else interessting):

- HM tests a dedicated service
-> Bad status: HM will restarts the service and checks host again
-> Good status: check host again and send an email to dedicated Admins

--> Alert Profile - Email Body Template:
Service%20%22%ServiceName%%22%20on%20Host%20%22%HostAddrB%%22%20was%20restarted.
%0A%0APause%20the%20Service%20for%2030%20minutes:
%0A%0A
<a href="mailto:ADMIN@company.de?subject=HMCommand_PAUSE_TEST&body=%22%HostAddrB%%5C%ServiceName%%22%2030%20%22Paused%20for%2030%20minutes%20via%20Script%22">PAUSE %TestName% for 30 minutes</a>

Good status email will look like this:
Image

...if you click on Hyperlink:
Image


- Then we have an email test:
-> Bad mail checks subject for "HMCommand_PAUSE_TEST"
-> Good mail checks subject for "HMCommand_START_TEST" (not fully implemented yet)

--> Alert Profile - Execute HMS:
-> Bad status: HMS will start script on local HM server
---> Code in HMS script: PauseTest %MailBody%

and here is our problem:
email with HM Pause command ist HTML formatted, if HMS execution will read %Mailbody% we`ll get 56 errors. If i create manually this email it´s working fine.

Is HMS reading the whole HTML code inside the mail instead of only this one line? Do i have to change something?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

As I said
1) its not a good idea to use %MailBody% in HMScript
2) if you are using HTML format for e-mail, then its not just "not good" idea, this is pretty bad idea to use this variable for your script
3) we implemented new variables for you. Please wait couple days for release

Regards
Alex
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Port 993, TLS Implicit, Protocol IMAP, Mailbox "Inbox"
If i change "Inbox" to "Inbox\HM\..." Status will be "Unknown" with failure "NO Inbox\HM\... doesn´t exist."
Is it possible?
Works for us.
Looks like you are using wrong slash symbol. Should be Inbox/HM

Regards
Alex
Post Reply