{% extends 'admin/master.html' %} {% block body %}

Checkmk Rule Optimization

← back to the Setup Rules

When a Setup Rule outcome matches on Condition Host with {{ '{{HOSTNAME}}' }} and nothing else, the export merges every matching host into one Checkmk rule that lists every hostname. Those rules are hard to read, slow to match, and get rewritten whenever a single host joins or leaves. This page finds them and the host attribute that covers exactly the same hosts.

The analysis reads the Syncer database only — nothing is sent to Checkmk. It walks every host twice, so it runs in the background.

With an account the report is narrowed to what that account would export: its project and folder scope, its object filter.
hosts upwards
{% if not analysis %}
No analysis for this scope yet. Start one above.
{% elif analysis.state == 'running' and not stale %}
Analysis running since {{ analysis.started_at.strftime('%Y-%m-%d %H:%M') }}. This page refreshes itself every 10 seconds.
{# Only while a run is in flight — a finished page must not keep reloading under the operator's hands. #} {% elif stale %}
An analysis has been marked running since {{ analysis.started_at.strftime('%Y-%m-%d %H:%M') }} and never finished — the process was most likely restarted. Start a new one.
{% elif analysis.state == 'failed' %}
The analysis failed: {{ analysis.error }}
{% else %}

Analysed {{ analysis.finished_at.strftime('%Y-%m-%d %H:%M') }}, rules from {{ analysis.min_hosts }} hosts upwards. The findings describe the rules as they were then.

{% if not analysis.findings %}
No Setup Rule builds a condition out of that many hostnames. Nothing to optimize.
{% endif %} {% for finding in analysis.findings %} {% set finding_index = loop.index0 %}
{% for name, _index in finding.syncer_rules %} {{ name }} {% else %} unknown Setup Rule {% endfor %} {{ finding.hosts }} hosts in one condition

ruleset {{ finding.ruleset }} · folder {{ finding.folder }} {% if finding.comment %} · {{ finding.comment }}{% endif %}
{{ finding.value }}

{% if not finding.label_condition_kept %}
Checkmk discards host label conditions in this ruleset, so a label cannot replace the host list here — the rule would end up matching every host.
{% elif finding.outcome_rules and finding.outcome_rules > 1 %}
This Setup Rule outcome produces {{ finding.outcome_rules }} different Checkmk rules — its outcome is rendered per host — but it has only one condition. A label here would apply to the other rules as well, and every host carrying it would collect all of their values. Keep the host list, or split the outcome so each group has its own.
{% elif not finding.outcome_rules %}
This result predates the check for outcomes that feed several rules. Run the analysis again before applying anything.
{% else %} {% for label in finding.exact %}
Use the host label {{ label.key }}:{{ label.value }} — covers all {{ finding.hosts }} hosts and no other host. {% if label.source %}
{{ label.source }} is no usable label on its own, so {{ label.key }} is a hash of it. Applying creates the Rewrite rule that builds it. {% endif %} {% if label.needs_filter %}
{{ label.key }} does not pass the export filter yet. Applying lets it through. {% endif %} {% if loop.first %}
{% endif %}
{% endfor %} {% endif %} {% for label in finding.wider %}
{{ label.key }}:{{ label.value }} covers all {{ finding.hosts }} hosts, but {{ label.outside }} more host(s) would get the rule too.
{% endfor %} {% for label in finding.partial %}
{{ label.key }}:{{ label.value }} covers {{ label.inside }} of {{ finding.hosts }} hosts and no other host — {{ finding.hosts - label.inside }} would lose the rule.
{% endfor %} {% if finding.label_condition_kept and not finding.exact and not finding.wider and not finding.partial %}
No attribute comes close — these hosts share nothing the others do not. A Rewrite rule setting a label on exactly them would give the Setup Rule something to match on.
{% endif %}
{% endfor %} {% endif %}
{% endblock %}