[%
    bad_chars = '[`~!$%^&*|\'"<>?,=]';
    maxlength = 63;

    seen = {};
    negative_maxlength = 0 - maxlength;

    FOR host IN hosts;
        FOR interface IN host.interfaces;

            NEXT IF interface.AdminStatus != 1;
            NEXT IF interface.Alias.search('\bfrei\b');
            NEXT UNLESS interface.Descr.search('\bSeri');

            SET description = interface.Alias or "an $interface.Descr";
            description = "Standleitung $description";
            description = description.replace('\(','[')
                                     .replace('\)',']')
                                     .replace(bad_chars, '')
                                     .chunk(maxlength).0;

            WHILE seen.exists(description);
                description = "$description [Nr. $interface.Index]";
                description = description.replace(bad_chars, '')
                                         .chunk(negative_maxlength).-1;
            END;
            seen.$description = 1
-%]
define service {
	use			generic-service
	service_description	[% description %]
	host_name		[% host.name %]
	check_command		check_interface_status![% host.community %]![% interface.Index %]!1
	contact_groups		incident-prio3,hotline,support
}

[%
        END;
    END
-%]
