'Returns a status string for business rules based items formatted
using business_rule_output_template attribute as template.
The template may embed output formatting for itself, and for its child
(dependant) itmes. Childs format string is expanded into the $( and )$,
using the string between brackets as format string.
Any business rule based item or child macros may be used. In addition,
the $STATUS$, $SHORTSTATUS$ and $FULLNAME$ macro which name is common
to hosts and services may be used to ease template writing.
Caution: only childs in state not OK are displayed.
Example:
A business rule with a format string looking like
"$STATUS$ [ $($TATUS$: $HOSTNAME$,$SERVICEDESC$ )$ ]"
Would return
"CRITICAL [ CRITICAL: host1,srv1 WARNING: host2,srv2  ]"'

def get_business_rule_output(self):

    got_business_rule = getattr(self, 'got_business_rule', False)
    if ((got_business_rule is False) or (self.business_rule is None)):
        return ''
    output_template = self.business_rule_output_template
    if (not output_template):
        return ''
    m = MacroResolver()
    elts = re.findall('\\$\\((.*)\\)\\$', output_template)
    if (not len(elts)):
        child_template_string = ''
    else:
        child_template_string = elts[0]
    children_output = ''
    ok_count = 0
    items = self.business_rule.list_all_elements()
    for item in items:
        if (item.last_hard_state_id == 0):
            ok_count += 1
            continue
        data = item.get_data_for_checks()
        children_output += m.resolve_simple_macros_in_string(child_template_string, data)
    if (ok_count == len(items)):
        children_output = 'all    checks    were    successful.'
    template_string = re.sub('\\$\\(.*\\)\\$', children_output, output_template)
    data = self.get_data_for_checks()
    output = m.resolve_simple_macros_in_string(template_string, data)
    return output.strip()
