Export service metric data

I would be interested in developing a script that executes on a monthly basis, retrieving a 30-day dataset of metric information gathered from a specific service. Could you please guide me on how to accomplish this programmatically?

I am aware of the option to perform this task through the user interface, but I am seeking a programmatic solution.

I came across the following resource: Query historical metrics - Checkmk Knowledge Base - Checkmk Knowledge Base. However, it appears that the “get_graph” endpoint mentioned in the documentation is not present in the updated REST API.

Hi,

the “get_graph” endpoint is now more aptly called “POST metric”

See more here (link goes to the side-by-side of Web and REST API): The Checkmk REST API

thank you for the response, can i tried using the post metric command, but its says 404 not found. do you know whats wrong with my python code

import http.client
import ssl
import json
from datetime import datetime

ssl._create_default_https_context = ssl._create_unverified_context


host_name = "CTS01"
site_name = "plugindev01"
domain_ip = "10.1.94.232"
service_name = "memory"
username = "automation"
password = ""
start_date_str = "2022-03-30 04:50"
end_date_str = "2022-03-30 05:50"

start_date_obj = datetime.strptime(start_date_str, "%Y-%m-%d %H:%M")
end_date_obj = datetime.strptime(end_date_str, "%Y-%m-%d %H:%M")
start_date_unix_timestamp = int(start_date_obj.timestamp())
end_date_unix_timestamp = int(end_date_obj.timestamp())

conn = http.client.HTTPSConnection(domain_ip)

time_range = [start_date_unix_timestamp, end_date_unix_timestamp]

payload = {
    "host_name": host_name,
    "service_description": service_name,
    "time_range": time_range,
    "site": site_name
}

data_bytes = json.dumps(payload).encode('utf-8')


headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': f'Bearer {username} {password}'
}


conn.request("POST", f"/{site_name}/check_mk/api/1.0/domain-types/metric/actions/get/invoke", data_bytes, headers)

res = conn.getresponse()
data = res.read()

# Process the response
if res.status == 200:
    print("Changes activated successfully.")
    print("Response content:")
    print(data.decode("utf-8"))
else:
    print("Failed to activate changes. Status code:", res.status)
    print("Response content:")
    print(data.decode("utf-8"))


Let me suggest you use the built-in documentation of our REST API. You can find it in the help menu (the lower left of your) and choose “REST API documentation”. There you will also find code examples, that should get you going.

Could you please verify if the URL {site_name}/check_mk/api/1.0/domain-types/metric/actions/get/invoke is correct? I’m encountering a 404 error.

While going through the documentation, I’m having difficulty comprehending how the URL is constructed and when to utilize ‘domain-types’, ‘host_config’ and so on. In the GUI, the desired endpoint lacks an example.

thanks in advance

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.