the variable $returnCode only “lives” in the function “Get-WebStatus”. You could make the function return the code with return $returnCode and exit the script with the result of the function:
return $returnCode
}
exit (Get-WebStatus $url)
Also the catch branch does not change the variable $returnCode.
Is there a reason why you use a powershell script? You could also use check_http to check URLs from a linux machine.
What do you mean by ‘logged in based urls’?
You will have to add performance data to the script. Link
Also the catch branch does not change the variable $returnCode.
can you please exaplain in brief?
Is there a reason why you use a powershell script? You could also use [check_http](https://www.monitoring-plugins.org/doc/man/check_http.html) to check URLs from a linux machine.
Actually the clients requirement is to monitor developer laptops which they have to logged in to some url’s and monitor their productivity
So what exactly i want is whether they are logged in to these website and track the number of hours their developers worked ? Can we achieve with icinga?
contains no reference to set $returnCode - what value do you expect it to have
if this section of the code is executed?
Actually the clients requirement is to monitor developer laptops which they
have to logged in to some url’s and monitor their productivity
Firstly, this strikes me a something better measured from the server end - the
URLs that are being logged into, rather than the machines which are being used
to log in from.
Secondly, though, what is the definition of “productivity”?
Are you simply looking for a measurement of how many hours there are between
someone logging and logging out of a website?
Does it matter what they do in the intervening time?
And, are you certain that they need to log out at all - if not, how do you
know when they stop working?
1.The reason for using powershell script is because all the hosts and clients(laptops) are of Windows
2.The user basically would like to know if the URL is accessible from the laptop
It is difficult to measure from server end
I know it is difficult to get the output from icinga .Its Ok for the time being I just want to check whether some url’s are working or not
changed my powershell script like below still I am not getting the correct exit codes
also where exactly need to add the performance metrics (graphs are coming not sure what values should give but plugin output showing some errors)
It would really help if you format your script. It is really hard to read.
There are a few things:
It looks like the return statement is outside of the function.
The exit statement requires an Integer (see this Link).
So return should only return the exit code in your case. You could add the plugin output with Write-Host before returning.
The catch statement will catch any exception. Maybe you could add the exception message to the plugin output.
There are lots of powershell plugins on the icinga exchange which may give you a good idea on developing your own plugins.
Also: If you plan on using the icinga powershell framework, there’s a full step-by-step tutorial on how to write custom plugins for it.