Hello,
after reading Dirk Paessler’s excellent blog article on Prowl and the iPhone, I decided to test this feature, owning an iPhone myself. Unbeknownst to me was the fact that although Paessler PRTG Network Monitor 7 is a wonderful program, it unfortunately doesn’t supports passing an “Execute HTTP Action” alert through a proxy.
When you work in secured environments, there’s no way you can evade some policies or make the rules by yourself, therfore you have to act a bit smarter and come up with a relatively elegant solution.
My first thought was to change the credentials upon which PRTG runs by default (LocalSystem) and make it run under a service account that would be granted Internet Access and Proxy rights. This unfortunately didn’t work, so I told myself I would try to find out a program that will go through the proxy then handle the HTTP action.
After a quick googling, I found about CURL, and upon reading its parameters from the command line, I told myself I will make a BAT file, then will set Paessler notification to launch the BAT file and pass parameters to it. Then the BAT file would parse the parameters, handle them to CURL (with appropriate username and proxy settings) and finally push everything to the Prowl Web API.
First try isn’t always best try…
so I’ve installed curl.exe in the Notifications/EXE folder, then I’ve created a BAT file. The EXE sensor passes several variables as an argument to the BAT file, the BAT files processes those and concatenates them into a string (an URL) which is then passed to curl.exe with additional command line parameters to provide curl with a proxy address, username and password of an authorized user to use the proxy (in my case a service account) and finally the HTTP action to perform.
Because this URL is in fact a prowl/growl API command, the URL needs to be passed properly, hence character substitution must be done for & (ampersand) symbols, otherwise the cmd.exe interpreter sees this as an action to run after the first command (command concatenation i.e. run program1.exe & program2.exe & program3.exe)
Passing these variables to the BAT file has one BIG issue though: some of the values passed as parameters to the BAT file by paessler contain spaces, therefore the BAT reads each space as a delimiter to fill the next variable, leading to shifting in the originally desired values. You know something’s gone down, but it’s better when all gets properly parsed.
I decided to let the weekend flow over this, and give it another thought on monday morning at work. When I hooked again onto this, I slapped my forehead and shouted “VBS!”. I was enlightened!
I prepared the little VBS below, it works perfectly so far :
dim x,Params,increment,ArgObj,cmdline
Set ArgObj=Wscript.Arguments
Set WshShell=Wscript.CreateObject(“Wscript.Shell”)
Params=””
For increment=0 to ArgObj.count – 1
Params = Params & ArgObj(increment) & “%20″
Next
cmdline=”-U domain\user:password -k -x myproxy.company.org:80 ”
&”https://prowl.weks.net/publicapi/add?apikey=MY0000API0000KEY&application=My%20Monitoring&event=Alarm&description=”
& params
x = WshShell.Run(“””C:\program files\PRTG Network Monitor\Notifications\EXE
\curl.exe””” & cmdline)
Do not forget to substitute the highlighted elements!
This is just a beginning and you can setup various alerts and levels for alarms, and play with PRTG Network monitor flexible interface to achieve the needed results.
Have a nice week,
Max