Retrieve the summary of a service from CheckMK API

I am new using the CheckMK API and I am trying to retrieve the summary of specific services of a specific host
2024-07-10 16_04_05-Checkmk Local site test_mon - Service CheckMK-Server, System OS Details

Using the below api call I have manage to get only the below information for the Service called System OS Details and obviously no the value (summary of the service).

API Call

$request_uri = "http://<checmk-server-ip>/test_mon/check_mk/api/1.0/objects/host/CheckMK-Server/actions/show_service/invoke?service_description=System OS Details"

$get_headers=@{
    Authorization = 'Bearer automation <secret key>'
    Accept = 'application/json'
}

$content = Invoke-RestMethod -Uri $request_uri -Method GET -Headers $get_headers | ConvertTo-Json

Output

{
    "links":  [
                  {
                      "domainType":  "link",
                      "rel":  "self",
                      "href":  "http://3.77.42.139/test_mon/check_mk/api/1.0/objects/service/CheckMK-Server-System%2520OS%2520Details",
                      "method":  "GET",
                      "type":  "application/json"
                  }
              ],
    "domainType":  "service",
    "id":  "CheckMK-Server-System OS Details",
    "title":  "Service System OS Details",
    "members":  {

                },
    "extensions":  {
                       "description":  "System OS Details",
                       "host_name":  "CheckMK-Server",
                       "state_type":  1,
                       "state":  0,
                       "last_check":  1720616748
                   }
}

Any ideas how to get the service summary instead of the status?

Thanks

Did you take a look at the documentation for the Rest API? It should explain about how to add columns if you use the service api endpoint

Also you did expose your public available checkmk server running in AWS in your output… :slight_smile:

Thanks for noticing the IP address :slight_smile: I have already changed the IP address of the server.
Although, adding columns was my main difficulty when using the poweshell command - Invoke-RestMethod.
Can you please recommend any examples that will assist me?
I have already went through the API documentation but it is still not clear how to use them to get additional information.

From https://domain/site/check_mk/openapi/:

Host and service table both have:

Column name 	 	Type 	Description
long_plugin_output 	string 	Long (extra) output of the last check
plugin_output 	 	string 	Output of the last check

plugin_output is probably the summary you’re looking for.

Hello again,

Yggy you were right about the column name long_plugin_output, so the only thing I had to understand is how to use the query to get to that column

query = {“op”: “and”, “expr”: [{“op”: “=”, “left”: “host_name”, “right”: “CheckMK-Server”},{“op”: “=”, “left”: “description”, “right”: “System Timezone”}]}’
columns = ‘long_plugin_output’

$request_uri = "http://checkmk-server-ip/checkmk-site/check_mk/api/1.0/domain-types/service/collections/all"

$get_headers=@{
    Authorization = 'Bearer automation <secret-key>'
    Accept = 'application/json'
}

$body=@{
        host_name = 'CheckMK-Server'
        query = '{"op": "and", "expr": [{"op": "=", "left": "host_name", "right": "CheckMK-Server"},{"op": "=", "left": "description", "right": "System Timezone"}]}'
        columns = 'long_plugin_output'
        
}

$content = Invoke-Restmethod -Uri $request_uri -Method Get -Headers $get_headers -Body $body | ConvertTo-Json
#$content = Invoke-RestMethod -Uri $request_uri -Method GET -Headers $get_headers | ConvertTo-Json

Write-Host $content

Therefore I have managed to get the below json output, which gave the value of the System Timezone.

{
    "links":  [
                  {
                      "domainType":  "link",
                      "rel":  "self",
                      "href":  "http://checkmk-server-ip/checkmk-site/check_mk/api/1.0/domain-types/service/collections/all",
                      "method":  "GET",
                      "type":  "application/json"
                  }
              ],
    "id":  "service",
    "domainType":  "service",
    "value":  [
                  {
                      "links":  "",
                      "domainType":  "dict",
                      "id":  "CheckMK-Server:System Timezone",
                      "title":  "System Timezone on CheckMK-Server",
                      "members":  "",
                      "extensions":  "@{host_name=CheckMK-Server; description=System Timezone; long_plugin_output=UTC}"
                  }
              ],
    "extensions":  {

                   }
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.