warn_ico = "⚠"
error_ico = "❌"
ok_ico = "✅"
question_ico = "❓"
host_ico = '🖥️'
service_ico = '⚙️'
def choose_icon(state):
if state == 'UP':
return ok_ico
elif state == 'DOWN':
return error_ico
elif state == 'UNKNOWN':
return question_ico
elif state == 'OK':
return ok_ico
elif state == 'WARNING':
return warn_ico
elif state == 'CRITICAL':
return error_ico
else:
raise Exception('No state to icon matched.')
def choose_color(state):
if state == 'UP':
return '#44bb77'
elif state == 'DOWN':
return '#ff5566'
elif state == 'UNKNOWN':
return '#aa44ff'
elif state == 'OK':
return '#44bb77'
elif state == 'WARNING':
return '#ffaa44'
elif state == 'CRITICAL':
return '#ff5566'
else:
raise Exception('No state to color matched.')
def newline_to_formatted_html(string):
if '\n' in string:
string = f'
{string}' return string def build_msg(host_name, host_display_name, state, date_str, output, service_name=None, service_display_name='', address='', comment='', author='', icinga2_url=''): if service_name: item = f'**{service_display_name}** on **{host_display_name}**' icon = service_ico else: item = f'**{host_display_name}**' icon = host_ico icon = f'{choose_icon(state)} {icon}' if address: address = f'