Back to OP5 Monitor FAQ

How to use PowerShell with OP5 Monitor HTTP API

Version Copied

This article was written for version 7.3.14 of OP5 Monitor or later.

Articles in the Community-Space are not supported by OP5 Support.

Introduction Copied

This how-to will guide you to invoke POST and GET requests to the OP5 API.

POST request Copied

This request will create a host over the API.

create_host.ps1

$endpoint = "https://<url_to_op5>/api/config/host"$username = "<op5 username>"$password = "<op5 password>"$host = @{    "host_name" = "<hostname>"    "address" = "<ip of host>" }$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json $host) -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json"

GET request Copied

This request will retrieve all hosts monitored in OP5 over the API.

get_hosts.ps1

$endpoint = "https://<url_to_op5>/api/config/host"$username = "<op5 username>"$password = "<op5 password>"$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))Invoke-RestMethod -Method Get -Uri "$endpoint" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

Note:

The invidivual code blocks above are intended to be saved in files and then executed over powershell.

["Geneos"] ["FAQ"]

Was this topic helpful?