Hello @sieuwe , first of all welcome to the forum
I see you are using $COMPUTERNAME
, however i do not see it defined in the code you posted.
Also if it is filled via other means, does it contain the FQDN ?
I have tested a triggered refresh on/via Postman with the following config:
With payload on the body:
{
"host_name": "test01.mydomain.tld",
"mode": "refresh"
}
Result was a 200: OK
Interesting returns from the call:
"domainType": "service_discovery_run",
"id": "service_discovery-test01.mydomain.tld",
"title": "Service discovery background job service_discovery-test01.mydomain.tld is running",
"members": {},
"extensions": {
"active": true,
"state": "running",
"logs": {
"result": [],
"progress": [
"Starting job..."
]
}
}
This was performed on a 2.1.0p36 setup.
Now i’m not ‘into’ poweshell, as i have a Linux-only env, so i’m trying to reproduce/learn as i go.
First of all, as soon as i take the last part ( the $BODY
-part out of the final call ( in a command-line-only call i dont get issues with unauthorised.
Invoke-RestMethod https://monitor.mydomain.tld/mysite/check_mk/api/1.0/domain-types/service_discovery_run/actions/start/invoke -method Post -Headers @{ "Authorization" = "Bearer automation MySuperSecretPAssword";"Accept" = "application/json";"Content-Type" = "application/json"}
Instead i get(as it should):
Invoke-RestMethod : {"title": "Bad Request", "status": 400, "detail": "These fields have problems: host_name", "fields": {"host_name": ["Missing data for required field."]}}
At line:1 char:1
If i extend the call with the needed/wanted/required payload in the body:
Invoke-RestMethod https://monitormydomain.tld/mysite/check_mk/api/1.0/domain-types/service_discovery_run/actions/start/invoke -method Post -Headers @{ "Authorization" = "Bearer automation MySuperSecretPAssword";"Accept" = "application/json";"Content-Type" = "application/json"} -Body (@{ "host_name" = "test01.mydomain.tld"}|ConvertTo-Json)
i get back a 200:OK
with additional info:
links : {@{domainType=link; rel=self; href=http://monitor.mydomain.tld/mysite/check_mk/api/1.0/objects/service_discovery/service_discovery-test01.mydomain.tld; method=GET;
type=application/json}}
domainType : service_discovery
id : service_discovery-test01.mydomain.tld
title : Service discovery result of host test01.mydomain.tld
members :
extensions : @{check_table=; host_labels=; vanished_labels=; changed_labels=}
However as soon as i add the mode
to the commandline:
Invoke-RestMethod https://monitor.mydomain.tld/comsolve/check_mk/api/1.0/domain-types/service_discovery_run/actions/start/invoke -method Post -Headers @{ "Authorization" = "Bearer automation MySuperSecretPAssword";"Accept" = "application/json";"Content-Type" = "application/json"} -Body (@{ "host_name"="test01.mydomain.tld";"mode"="refresh" }|ConvertTo-Json)
It will throw me the authentication-error:
Invoke-RestMethod : {"title": "You need to be authenticated to use the REST API.", "status": 401}
At line:1 char:1
+ Invoke-RestMethod https://monitor.mydomain.tld/comsolve/check_mk/api/1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
So somewhere in this breakdown it seems that PowerShell is not playing nicely (if it were my guess)
… out of curiosity, as the default mode behaviour is fix_all
… (apart from the fact is should work) why are you only going for a refresh?