cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create an OS Service Monitor on a specific host via the API.

DuaneRoelands
Contributor

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?

1 REPLY 1

Mohamed_Hamdy
DynaMight Champion
DynaMight Champion

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

Mohamed_Hamdy_0-1683889204504.png

 

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": []
}
}
]

Certified Dynatrace Professional | Certified Dynatrace Services Delivery - Observability & CloudOps | Dynatrace Partner - yourcompass.ca

Featured Posts