Skip to main content

Hi,

 

I could use some help getting started with FME Rest API and PowerShell. The goal is to easily get errors from several FME servers using PowerShell.

 

For now I just need some help getting started on the script. This includes:

- Connecting to REST API

- Defining properties

- Write results to HTML

 

Responses I would like displayed in a HTML report:

-FME server status

- Jobs that exceed a specified time in running state

-Failed jobs

 

Do you already have a script doing some of this, or more, I would greatly appreciate some tips and/or snippets to get me started.

 

If anything is unclear please don't hesitate to ask, or even if you have a completely different solution than PowerShell I'm all ears.

 

Best Regards,

Amalie

Hi @amha,

I usually just use FME desktop to do this either querying the REST API or the FME Server database.

A good start on the HTML reporting is to have a look at one of the workspaces creating FME Server dashboards.

Hope this helps,

Itay


I definitely second the dashboard suggestion from @itay

 

 

Using FME makes it easy to configure monitoring processes for FME Server, schedule your dashboard jobs to run every night to get a daily updated.

 

If engines or licenses are a problem for monitoring then powershell could be an alternative, however, you might find more luck on Stack overflow on how to best to write powershell scripts.

 

 

Essentially you will need to use this to make queries: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6

 

Here is the REST API doc for FME Server: https://docs.safe.com/fme/html/FME_REST/apidoc/v3/index.html#

 

You will need to make sure you have a valid token for making requests. 

 

Here's a start which generates a token and then makes a healthcheck call to the defined host.

 

 

#Input Credentails and host here

$user = '<user>'
$password = '<password>'
$hostname = '<fme server hostname>'

#this is the url to the token service - note you will need to enter your hostname
$tokenURI = $hostname+'/fmetoken/service/generate.json'
#set token expiration - I just used one day here
$expiration = 1
#build post body for rest call
$cred_body = @{
    user = $user
    password = $password
    expiration = $expiration
    timeunit = 'day'
    update = 'false'
    }
#send post request and save as respone
$tokenResponse = Invoke-RestMethod -Method 'Post' -Uri $tokenURI -Body $cred_body
#get token from json responce
$token=$tokenResponse.serviceResponse.token
#$token

#################----healthckeck-----######
#healthcheck URI for fme server host
$healthcheckURI = $hostname+'/fmerest/v3/healthcheck'
#$healthcheckURI
$authorizationHeader = @{
authorization = "fmetoken token="+$token
}
#build query
$healthcheck = Invoke-RestMethod -Method 'Get' -Uri $healthcheckURI -Header $authorizationHeader
#configure string for result
$status='FME Server: "'+$hostname+'" status is '+$healthcheck.status
#display status
$status


#this next bit just leave the ps window open
if ($Host.Name -eq "ConsoleHost")
{
    Write-Host "Press any key to continue..."
    $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}

You may want a more secure way for keeping the password.


Reply