Additional Alert options

Need new test, action, option? Post request here.
Post Reply
Malice
Posts: 1
Joined: Tue Jan 19, 2016 8:09 am

Additional Alert options

Post by Malice »

We are starting to use slack https://slack.com/ to create channels for each alerting system to keep track all in one place.

It would be great if hostmon had the ability to plug straight into the Slack API so we don't have to rely on a system such as email which has no guaranteed delivery reliability.

cheers.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You may use "Execure external program" action with the folowing JScript.

Code: Select all

objArgs = WScript.Arguments;
var http = new ActiveXObject("MSXML2.ServerXMLHTTP");
http.setOption(2,13056);
var url = "https://hooks.slack.com/services/T0JSK6152/B0JSBEQG5/mr4w8zwBnfwLrtxvpyHJKL";
var alertmsg = "";
for (i = 0; i < objArgs.length; i++)
{
   alertmsg+=objArgs(i)+' ';
}
http.open("POST", url, false);
http.setRequestHeader("Content-type", "application/json");
try {
data = '{"text":"'+alertmsg+'"}';
http.send(data);
} catch(e) {
  throw new Error(e.message);
  WScript.Quit;
}
var resp = http.responseText;
WScript.StdOut.Write(resp);
Just save script into slack.js, add new "Execute external program" action with the following parameters:
Command line: cmd /c cscript D:\SCRIPTS\slack.js TestName=%TestName% Status=%Status% Reply=%Reply% Recurrences=%Recurrences%
Window mode: WS_HIDE

Please note, url value (Line 4 of this script) should be replaced by your "Webhook URL"

How to get your "Webhook URL":
1. Sign in to Slack
2. Create channel for HostMonitor alerts (e.g. #HostMonitor)
3. Click on your username (top left corner) -> Apps & Custom Integrations
4. Click on "Build your own" button (top right corner)
5. Click on "Make a Custom integration" (Something just for my team)
6. Select Incomming WebHooks
7. Post to Channel: select #HostMonitor
8. Click on "Add incomming WebHooks integration"
9. Copy your "Webhook URL" and paste it to Line 4 of slack.js
10. Review incomming WebHooks settings and click "Save Settings"
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

PS I think we will add new action in future versions

Regards
Alex
eddymicro
Posts: 95
Joined: Wed Nov 13, 2002 6:00 pm

Post by eddymicro »

Alex,

We are going to post some alerts to Slack, is this still the recommended way to do that?
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Depends on your HostMonitor version.
If its not too old (like 10.00) then you may use HTTP Request action
https://www.ks-soft.net/hostmon.eng/mfr ... tm#actHTTP

Regards
Alex
Post Reply