• This topic has 3 replies, 2 voices, and was last updated November 10, 2021 by Phillip P.

Zabbix Discovery Script stopped working

  • Good Day. I am hoping someone can assist. We have a customer with two zvm’s in two regions. The one works fine with a the zabbix script and reports as it should. (This server has 50VPG’s). The second server only has 2 Vpg’s but is not working anymore.

    I am new to both systems so I am not even sure which part is broken…

    Error:

    Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character ‘{‘ or ‘[‘ at: ‘Invoke-RestMethod : The remote server returned an error: (404) Not Found.
    At C:\Zabbix\ZertoMonitoringAPI.ps1:40 char:11
    + … $data = Invoke-Res

    From days of searching and trying all sorts if things, most forums have pointed to powershell.

    Current version of windows powershell – 5.1 Also tried running the scripts using powershell 7 (get a different errors there).

    The working server also uses 5.1 (but a slightly newer build)

    Steps Tried:

    Tried updating Windows Powershell V5.1 to the higher build, but cant find an update or install file. Tried PS7 with no success. Rebooted the server multiple times. Reinstalled the script with a fresh and clean one (same error).Checked and confirmed all the data works (IP’s and credentials). Installed the latest version of Zerto,commandlets.

    Note: When I run the script manually it works with no errors.

    Thanks

     

    Hi Phillip,

    What Zerto version are you using? And could you share the relevant lines of code (and enough surrounding context) for that call to the Invoke-RestMethod? From the error message, it sounds like there’s an issue with calling the relevant API method and/or its arguments and it may or may not be dependent on the Zerto version you’re using.

    As for the latest version of the Zerto commandlets, those may not be relevant if you’re making the Rest API calls directly through Powershell. However, in case you are expecting to use them somewhere, please know that starting Zerto 9.0, you’ll want to use the official Zerto.ZVM.Commandlets module found in Powershell Gallery instead of the old SnapIn.

    Mike

     

    Hi Michael, thanks for your reply. We actually went down the path yesterday to confirm versions between the two servers. (working one and faulty one).

    The one in question = Ver 8.5 update 2.

    The error above mentions line 40. I have highlighted the line 40 in the original script where it calls the API request / “vpgs”

    # Setup some variables, in the future this could be adapted to accommodate Zabbix macros
    $ZertoServer = “”
    $ZertoPort = “9669”
    $ZertoUser = “”
    $ZertoPassword = “”
    $vCenterServer = “”
    $vCenterUser = “”
    $vCenterPassword = “”

    # Allow self-signed certificates
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

    $progressPreference = “silentlyContinue”

    # Building Zerto API string and invoking API
    $baseURL = “https://” + $ZertoServer + “:”+$ZertoPort+”/v1/”
    # Authenticating with Zerto APIs
    $xZertoSessionURI = $baseURL + “session/add”
    $authInfo = (“{0}:{1}” -f $ZertoUser,$ZertoPassword)
    $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
    $authInfo = [System.Convert]::ToBase64String($authInfo)
    $headers = @{Authorization=(“Basic {0}” -f $authInfo)}
    $sessionBody = ‘{“AuthenticationMethod”: “1”}’
    $contentType = “application/json”
    $xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURI -Headers $headers -Method POST -Body $sessionBody -ContentType $contentType
    #Extracting x-zerto-session from the response, and adding it to the actual API
    $xZertoSession = $xZertoSessionResponse.headers.get_item(“x-zerto-session”)
    #$xZertoSession

    $ITEM = [string]$args[0] $VpgIdentifier = [string]$args[1]

    switch ($ITEM) {
    “Discovery” {
    $vpgListApiUrl = $baseURL+”/vpgs”
    # $data = Invoke-RestMethod -Uri $vpgListApiUrl -Header @{ “x-zerto-session” = $xZertoSession } | foreach {
    # [PSCustomObject]@{VpgIdentifier=$_.VpgIdentifier;}
    # } | convertTo-JSON
    # $data.Replace(“VpgIdentifier”,”{#VpgIdentifier}”)
    $data = Invoke-RestMethod -Uri $vpgListApiUrl -Header @{ “x-zerto-session” = $xZertoSession }
    $data = $data | Select-Object -Property VpgIdentifier, VpgName | convertTo-JSON
    $data = $data.Replace(“VpgIdentifier”,”{#VPGIDENTIFIER}”)
    $data = $data.Replace(“VpgName”,”{#VPGNAME}”)
    $data = ‘{“data”: ‘+$data+’}’
    $data

    HI Mike,

    It looks like i managed to get this working. Your thoughts pointed me in the right direction. I confirmed the version was 8.5 compared to other servers 7.5 . I then looked at the API guide and found a small change here: $vpgListApiUrl = $baseURL+”/vpgs” (this being the old one). I made the changes and our zabbix started pulling through the info. 

    Thanks again for taking the time to respond to my query.

     

    Thanks

The forum ‘Scripting and APIs’ is closed to new topics and replies.