Ad Widget

Collapse

UserParameter with Powershell script not returning a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WishfulThinking
    Junior Member
    • Jul 2018
    • 4

    #1

    UserParameter with Powershell script not returning a value

    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.
    Last edited by WishfulThinking; 11-09-2019, 19:14.
  • WishfulThinking
    Junior Member
    • Jul 2018
    • 4

    #2
    *** SOLVED ***

    Thanks to splitek for the input.

    After further troubleshooting i found the cause:
    Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again. Adding the "-UseBasicParsing" to the Invoke-WebRequest command did the trick. Now: $response = Invoke-WebRequest -UseBasicParsing -Uri $URI -ErrorAction Stop

    Comment

    Working...