Move host to another folder via HTTP API

Hi all.
I’m using Checkmk 1.6.0p22 and I’m trying to figure out if it’s possible to move host into another folder using HTTP API. I’ve tried using edit_host command, but seems like it doesn’t allow to modify neither folder nor path.

Hi Artem,
I don’t have an example for the 1.6 web api but using the 2.0 REST-API, you can use the following example from within bash:

function movehost {
src=$1
hst=$2
tgt=$3
secret="$(cat $OMD_ROOT/var/check_mk/web/automation/automation.secret)"

# Abruf eines Hostes, hier z.B. für ETag Auslesen
etag="$(curl \
    -k -i -I -s -X 'GET' \
    --header "Authorization: Bearer automation ${secret}" \
    "https://localhost/${inst}/check_mk/api/1.0/objects/host_config/${hst}" \
    | grep "ETag: " | cut -d " " -f 2 | tr -d "\"\r\n" )"

if [ -z "${etag}" ]; then
    echo "No Etag found or host not found"
    exit 2
fi

#echo "E${etag}E"

# Host verschieben
out=$(curl \
    -k -s -X 'POST' \
    "https://localhost/${inst}/check_mk/api/1.0/objects/host_config/${hst}/actions/move/invoke" \
    --header "Authorization: Bearer automation ${secret}" \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --header "If-Match: $etag" \
    --write-out "\move-status_code=%{http_code}\n" \
    --data "{ \"target_folder\": \"${new_folder}\" }")

resp=$( echo "${out}" | grep "move-status_code" | cut -d "=" -f 2)
if [ "$resp" != "200" ]; then
    echo "FAILED: ${resp} ${out}"
    exit 1
fi
echo "OK"  

}

1 Like

Hi,
it’s not possible to move the host from one folder to another using the HTTP API. If you update to Checkmk 2.0 you can use the REST API - as @gstolz mentioned.

Karl

1 Like

Thanks for your replies, I’ll definitely consider updating to 2.0.

Just one thing to mention, I’ve tried to simply recreate host under new path:
delete host → add it with the same name and IP but under new path → run service discovery → apply
and I’ve noticed old metrics are displayed fine with such approach. Is this expected? I mean, Checkmk doesn’t delete metrics immediately after host is deleted and they could be reached from a new host with the same hostname and IP?

Hi @artem.timchenko, welcome to the forum!

Indeed, that is expected. The default setting to automatically clean up “abandoned host files” (RRDs and HW/SW Inventories as per the options’ inline help) is 30 days. This parameter can be modified in the “Global Settings” under “Site Management” → " Automatic disk space cleanup"

HTH,
Thomas

EDIT Please let me add that this option exists on both versions 1.6 or 2.0

1 Like

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