Script Alerts

by Jul 24, 2015

HI i am trying to create a custom alert that fires an alert to out slack account

 

I have created a .bat file as aware we can not call a .vbs directly from the up.time alert script.

 

“C:/Program Files/uptime software/uptime/scripts/Slackcall.bat”

 

the .bat files simply calls the .vbs by 

 


cscript //nologo “c:Program Filesuptime softwareuptimescriptsSlackNotification.vbs”


 

then the .vbs contains the below

 


Dim WshShell, objEnv

 

Set WshShell = CreateObject(“WScript.Shell”)

Set objEnv = WshShell.Environment(“Process”)

 

UPTIME_ALERTTYPE = objEnv(“UPTIME_ALERTTYPE”)

UPTIME_HOSTNAME = objEnv(“UPTIME_HOSTNAME”)

UPTIME_HOSTSTATUS = objEnv(“UPTIME_HOSTSTATUS”)

UPTIME_MESSAGE = objEnv(“UPTIME_MESSAGE”)

 

sUrl = “https://hooks.slack.com/services/ourslackkey

 

sRequest = “{“”text””: “”” + UPTIME_ALERTTYPE + ” occurred on ” + UPTIME_HOSTNAME + ” of type ” + UPTIME_HOSTSTATUS + ” with the following message: ” + UPTIME_MESSAGE + “””}”

 

HTTPPost sUrl, sRequest

 

Function HTTPPost(sUrl, sRequest)

 set oHTTP = CreateObject(“Microsoft.XMLHTTP”)

 oHTTP.open “POST”, sUrl, false

 oHTTP.setRequestHeader “Content-Type”, “application/json”

 oHTTP.setRequestHeader “Content-Length”, Len(sRequest)

 oHTTP.send sRequest

 HTTPPost = oHTTP.responseText

End Function


 

I have tested the bat calling the .vbs manually and it triggers and sends the alert. However when this is tested in up.time i can see the bat file called in task manager and see the .vbs also called but this never successfully sends out the http request.

 

Any help would be appreciated.