Find unknown tags / no longer existing tags in rules

CMK version: 2.4.0p32
OS version: RHEL 9.7

Error message: Unknown tag: Host has the tag all_admin_something

Hi,

not really sure if this is the correct catagory, sorry if not.

I had to change some tag IDs. When I clicked on Save, there was a warning:

looked good, Checkmk sees where changes have to be made and fixes it for me.

BUT: not all rules where “fixed”. When I had a look in “Assignment of hosts to host groups” after activating changes, there was one rule where Checkmk indeed did made the change for me, but there was another rule with an unknown host tag. Instead of the host tag name it displayed the ild tag ID:

image(I did cut of the name here)

in the rule it looks like this:

image

While in “Assignment of hosts to host groups” I stumbled upon another rule with such an unknown tag. In that case the tag did not exist at all anymore and was probably removed some time ago by someone else.

So of course it would be nice if Checkmk would change all rules where a changes tag is used. But also I wonder, is there a way to find rules with unknown host tags?
I tried the rulesearch but there is no match when searching for “all_admin” or “unknown”.

When checking an affected rule via API there is no error, it just shows the old tag, like:

"host_tags": [
        {
          "key": "all_admin",
          "operator": "one_of",
          "value": [
            "all_admin_some_tag",
            "all_admin_some_old_tag"
          ]

I know I could write an API script to find used tags that don’t exist anymore, but I was hoping there would be an easier way.

so, is there?

Thanks and best regards
Andre

I think there is only one easy way →

cd ~/etc/check_mk/conf.d/wato/ 
grep -R "all_admin_some_old_tag" *

to find all places where this old tag is referenced.

Hi Andreas,

thank you, you brought me on the right track.

I was able to find old tags using grep and regex, like this

cd ~/etc/check_mk/conf.d/wato/
grep -RP ‘all_admin_(?!(?:tag1|tag2|tag3)(?![[:alnum:]]|_|-.))’ rules.mk

all the tags I’m looking for start with ‘all_admin_’ followed e.g. by ‘tag1’, ‘tag2’, ‘tag3’.

so the regex looks for ‘all_admin’ but excludes the tags in the first inner brackets except they are followed by something else (letters, numbers, ‘_’ or ‘-’)

In the end it might have been faster to create an API script :sweat_smile:

Maybe some other time to see if the regex missed something.

BR
Andre

The target of your search should not be only the “rules.mk” inside ~/etc/check_mk/conf.d/wato/. You should search the whole folder tree.

Thanks for the hint.

I used rules.mk for testing and stayed with it.
I ran the command again using * the look at al files