Exclude host from service discovery with cmk command line

Hi,

I would like to have nights a daily service discovery to add new discovered services and removing vanished services, without adding a new check to the hosts, which what the Periodic service discovery over WATO does.
So basically I just want to write a script to do cmk -vII for all hosts except for some critical hosts, that should remain untouched if a service vanished or a new one is discovered.

How can I exclude a group of hosts from being inventoried?

Thanks in advanced.
Ghassan

Hi,
you can do the following:
“cmk --checks df … -vII”

Read cmk help for this.

Hello Christian,

I did read the help for this, but this doesn’t solve my problem, when I do cmk -vII this will delete all existing checks, which I don’t want for specific hosts. so basically I am good with this for the majority of my hosts, but I don’t want to delete a vanished service like a network interface check if it is defective and the new inventory cannot find it any more.
I was actually looking for a regex how to exclude a group of hosts when performing cmk -vII and for these hosts just perform cmk -vI.

Thanks

Hi Ghassan,

you can do this with the undocumented WebAPI call “bulk_discovery_start”. You can use the parametres from “discover_service” and send a hostlist as payload. This will handle as backround job. You can check it with "bulk_discovery_status’.

Regards, Christian

Hi Christian,

thank you very much. Will go in to this.

Best regards
Ghassn

Another possibility might be to first list all hosts and then include or exclude some of them via grep and then feed that list into cmk -vII, i.e.:

# process all hosts with "webs" in their name
cmk -l | grep webs | xargs cmk -vII

or

# process all hosts with NO "webs" in their name
cmk -l | grep -v webs | xargs cmk -vII

Of course, the expression for grep can be tweaked to your will.

1 Like

I would recommend to use the livestatus instead to get a list of the hosts.

Hi Dirk,

This is really a simple solution with Linux tools. Didn’t think about it at all, I thought cmk command supports some kind of regex, but this is just great.

Thanks a bunch
Ghassan

Hi tosch,

it seems there are multiple ways of doing this. Dirk’s suggestion is just simple and handy.

Thanks a lot
Ghassan

Yep, @Dirk’s suggestion is simple and handy but limits the possible filter. It’s just usable if you like to filter the hostname. Via livestatus you have plenty of possibilities to filter your hosts and also make it transparent at the web interface with tags. I would recommend to create a tag for your hosts you like to discover and use the livestatus to get out this hosts.

echo -e "GET hosts\nColumns:host_name\nFilter: host_custom_variables ~~ TAGS <YOURTAG>\nFilter: host_name ~~ <HOSTNAMEFILTER>\nAnd: 2" | unixcat /opt/omd/sites/<SITE>/tmp/run/live

You can also run this command with a different user if you use the full path for unixcat too.

@tosch but you can also list the hosts by tag on the command line:

cmk --list-tag mytag

will list all hosts the the tag mytag. You can combine this with grep and xargs.
Still, I see your point. Your suggestion offers far more possibilities but the list/grep solution doesn’t need any further tools or knowledge.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.