10 May 2023 04:19 PM - last edited on 10 May 2023 08:41 PM by Karolina_Linda
I want to create a monitor for a specific Windows service running on a specific VM, and I want to do it through the API. Reasons are reusability and scale; we implement new customers regularly and must set up this monitoring manually. I want to automate it.
I am able to retrieve a list of OS Service Monitor from the /api/v2/settings/objects endpoint, passing schemaIds=builtin:os-services-monitoring on the querystring and it returns the list of objects I expect. However, the individual entries in the list do NOT include any information as to what host the monitor runs on:
{
"objectId": "vu9U3hXa3q0AAAABAB5idWlsdGluOm9zLXNlcnZpY2VzLW1vbml0b3JpbmcABEhPU1QAEDE3Njk2OEE2NEE3ODg3NkUAJGQ4NWU4ODE0LTJmN2MtM2UwZC1hMzYwLTMwMWMzZTY2NTQ5ZL7vVN4V2t6t",
"value": {
"enabled": true,
"system": "WINDOWS",
"name": "Production SERVICENAME",
"monitoring": false,
"alerting": true,
"notInstalledAlerting": false,
"statusConditionWindows": "$not($eq(running))",
"alertActivationDuration": 30,
"detectionConditionsWindows": [
{
"property": "ServiceName",
"condition": "$eq(SERVICENAME)"
}
],
"metadata": []
}
}
I am able to add an OS Service Monitor with a POST to the same endpoint. I get a 200 response, and if I do a subsequent GET, I see the new OS Service Monitory in the list. But it's not associated with a specific host/VM.
The API documentation doesn't appear to address this: How do I create an OS Service Monitor via this endpoint and specify the VM where the service to be monitored is running?
Solved! Go to Solution.
11 May 2023 03:42 PM - edited 12 May 2023 12:01 PM
Hi @DuaneRoelands,
you can use the scope to be retrieved in the fields and you will be able to get the host Id
/api/v2/settings/objects?schemaIds=builtin:os-services-monitoring&fields=objectId,value,scope
the default values are objectId and value
and to POST OS service to a specific host you can add the host id same as the following sample:
[
{
"schemaId": "builtin:os-services-monitoring",
"scope": "HOST-",
"value": {
"enabled": true,
"system": "WINDOWS",
"name": "Production SERVICENAME",
"monitoring": false,
"alerting": true,
"notInstalledAlerting": false,
"statusConditionWindows": "$not($eq(running))",
"alertActivationDuration": 30,
"detectionConditionsWindows": [
{
"property": "ServiceName",
"condition": "$eq(SERVICENAME)"
}
],
"metadata": []
}
}
]