CMK version: Checkmk Raw Edition 2.3.0p6
OS version: CentOS7
Error message: Invalid CSRF token
I have a feature to fetch the latest value of service through “Poll Service Data” where I am trying to call Reschedule “Check_Mk” Service API copied from checkmk and executing through python script but it raise invalid CSRF token with user automation.
I tried multiple ways to get latest CSRF token but non of them worked for me. How to get it?
Below is my poll service data script
import requests
from requests.auth import HTTPBasicAuth
# Define the URL
url = "http://192.168.100.61:9000/cmk/check_mk/ajax_reschedule.py?_ajaxid=0"
# Define the username and password
username = "automation"
password = "nms1234567"
# Define the data
data = {
"request": '{"site":"slave1","host":"254","service":"","wait_svc":""}',
"csrf_token": "cda06970-c24f-457b-9696-3be408546315"
}
# Send the POST request with basic auth
response = requests. Post(url, data=data, auth=HTTPBasicAuth(username, password), verify=False)
# Print the response status code and body
print(response.status_code)
print(response. Text)
Output:
200
{“result_code”: 1, “result”: “Invalid CSRF token (‘cda06970-c24f-457b-9696-3be408546315’) for Session (‘3764b205-c472-4a94-bce0-a7a0f688b299’)”, “severity”: “error”}
