#!/bin/bash
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

if [ -z "${OMD_SITE}" ]; then
    echo "This script is only executable as site user."
    exit 1
fi

if ! [ -S "${OMD_ROOT}"/tmp/run/live ]; then
    echo "The Checkmk site must be running, when using this script."
    exit 1
fi

find "${OMD_ROOT:?}/tmp/check_mk/piggyback" -mindepth 1 | while read -r entry; do
    h="${entry##*/}"
    lq "GET hosts\nColumns: address name\nFilter: address = $h\nFilter: name = $h\nOr: 2" | grep -q . || echo "$h"
done
