We're trying to set up monitoring of a large number of http services on networks only accessible from hosts, not the Zabbix server.
I have a Powershell script which return http status code when querying an URL.
It works exactly as intended when run manually in a command prompt from a host. Running the exact same script as UserParameter on the host, however, does not return a status code.
CheckURL.ps1 script:
$URI=$args[0]
try
{
$response = Invoke-WebRequest -Uri $URI -ErrorAction Stop
# This will only execute if the Invoke-WebRequest is successful.
$StatusCode = $Response.StatusCode
}
catch
{
$StatusCode = $_.Exception.Response.StatusCode.value__
}
Write-Output $StatusCode
Example of manual run:
C:\>powershell C:\scripts\CheckURL.ps1 http://myserver/Tas.ServiceBus/index.htm
200
Status code 200 is being returned - exactly as expected.
When run by Zabbix, no return value is received.
We've tried to add some logging in the script, to make sure the URL is known by the script, and it is.
http://myserver/Tas.ServiceBus/index.htm Status: # Zabbix run
http://myserver/Tas.ServiceBus/index.htm Status: 200 # Manual run
Zabbix Server and agent both V4.2.6.
The host is configured as an active Zabbix agent.
Running passive agent is not an option for security reasons.
UserParameter configuration:
UserParameter=CheckWebService[*], powershell C:\scripts\CheckURL.ps1 $1
Item configuration in Zabbix:
Type: Zabbix_agent (active)
Key: CheckWebService[http://myserver/Tas.ServiceBus/index.htm]
Type of information: Text
Powershell is version 4.
We have of course tested several options, but no luck so far.
I would appreciate if someone could tell me what is wrong. Suggestions on how to analyse the problem further are appreciated as well.
I have a Powershell script which return http status code when querying an URL.
It works exactly as intended when run manually in a command prompt from a host. Running the exact same script as UserParameter on the host, however, does not return a status code.
CheckURL.ps1 script:
$URI=$args[0]
try
{
$response = Invoke-WebRequest -Uri $URI -ErrorAction Stop
# This will only execute if the Invoke-WebRequest is successful.
$StatusCode = $Response.StatusCode
}
catch
{
$StatusCode = $_.Exception.Response.StatusCode.value__
}
Write-Output $StatusCode
Example of manual run:
C:\>powershell C:\scripts\CheckURL.ps1 http://myserver/Tas.ServiceBus/index.htm
200
Status code 200 is being returned - exactly as expected.
When run by Zabbix, no return value is received.
We've tried to add some logging in the script, to make sure the URL is known by the script, and it is.
http://myserver/Tas.ServiceBus/index.htm Status: # Zabbix run
http://myserver/Tas.ServiceBus/index.htm Status: 200 # Manual run
Zabbix Server and agent both V4.2.6.
The host is configured as an active Zabbix agent.
Running passive agent is not an option for security reasons.
UserParameter configuration:
UserParameter=CheckWebService[*], powershell C:\scripts\CheckURL.ps1 $1
Item configuration in Zabbix:
Type: Zabbix_agent (active)
Key: CheckWebService[http://myserver/Tas.ServiceBus/index.htm]
Type of information: Text
Powershell is version 4.
We have of course tested several options, but no luck so far.
I would appreciate if someone could tell me what is wrong. Suggestions on how to analyse the problem further are appreciated as well.
Comment