Azure REST API in Check_mk

84 Views Asked by At

I was wondering what approach should I take to run my own API request for checkmk. I have already tested retrieving data quota usage information.

Thank you in advanced

Kind regards

I already searched on checkmk site:-

{

  "unit":"Bytes"
  "nextResetTime" : "9999-12-31T23:59:59.999999z"
  "currentValue": 14725120,
  "limit": 5368701200,
  "name" : {
          "value" : "FileSystemStorage",
          "localizedValue": "File System Storage"
   }
}


],
"nextLink" : null,
"id" : null 

}

enter image description here

1

There are 1 best solutions below

0
SiddheshDesai On

Here's a sample code to call an API with python inside the VM or host that runs your checkmk site:-

To call a checkmk API with authorization, Refer the code below:-

import requests


api_token = 'your_api_token_or_username_password'
headers = {
    'Authorization': f'Token {api_token}',
    'Content-Type': 'application/json'
}


endpoint_url = 'https://your_checkmk_instance/api/endpoint'
response = requests.get(endpoint_url, headers=headers)


if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")

Code with a API without any authorization:-

import requests

# Make API request
endpoint_url = 'https://reqres.in/api/users?page=2'
response = requests.get(endpoint_url)

# Check if request was successful
if response.status_code == 200:
    # Parse JSON response
    data = response.json()
    # Process data as needed
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")

Output:-

enter image description here

Also, as an alternative you can directly monitor an Azure service:-

According to this Checkmk Official document, You need to implement authentication for your Rest API through Azure AD by referring this Document:-

In your Azure AD create a new application/service principal for Azure AD like below:-

enter image description here

Then assign this application role to access the File storage by assigning it Contributor role on the Azure storage account that contains your File share or at the Subscription level:-

Azure storage account level:-

enter image description here

enter image description here

Azure Subscription level for the access to all the storage account in multiple resource groups:-

enter image description here

Now create a Client Secret for your Azure AD app and then

navigate to Setup > Agents > VM, Cloud, Container > Microsoft Azure, and establish a rule that specifically targets the newly created Azure host. And add the above Application Subscription Id, Tenant ID, Client ID and Client Secret:- and implement the testing of Azure resource monitoring according to the document above.

You can also use the above application's parameters in postman or by curl like below:-

Create a Post request to obtain access token for the checkmk api:-

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&scope=https://graph.microsoft.com/.default' 'https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token'

And then call the checkmk API with the Access Token above, Given you have added the checkmk API as an API app and provided API permissions to the App above.