[% USE date %]

[% SET message = n.message.substr(13) %]
[% options = message.split(';') %]

[% state_color = 'grey' %]
[% IF n.type == 'SERVICE NOTIFICATION' %]
    [% SET level = options.3 %]
    [%    IF level == 'OK'              %][% level = 'OK'        statusclass = 'OK' state_color = 'green' %]
    [% ELSIF level == 'RECOVERY'        %][% level = 'OK'        statusclass = 'OK' state_color = 'green' %]
    [% ELSIF level == 'WARNING'         %][% level = 'WARNING'   statusclass = 'WARNING' state_color = 'yellow' %]
    [% ELSIF level == 'CRITICAL'        %][% level = 'CRITICAL'  statusclass = 'CRITICAL' state_color = 'red' %]
    [% ELSIF level.match('CUSTOM\ \(') %][%                      statusclass = 'CUSTOM' %]
    [% ELSIF level.match('ACKNOWLEDGEMENT\ \(') %][%             statusclass = 'ACKNOWLEDGEMENT' %]
    [% ELSIF level.match('FLAPPINGSTART\ \(')   %][% level = 'FLAPPING START' statusclass = 'UNKNOWN' %]
    [% ELSIF level.match('FLAPPINGSTOP\ \(')    %][% level = 'FLAPPING STOP'  statusclass = 'UNKNOWN' %]
    [% ELSE                                      %][%   statusclass = 'UNKNOWN' %]
    [% END %]
    [% IF !n.defined('command_name') %][% n.command_name = options.4 %][% END %]
    [% n.plugin_output = log_line_plugin_output(n) %]
[% ELSE %]
    [% SET level = options.2 %]
    [%    IF level == 'UP'          %][% level = 'HOST UP'          statusclass = 'UP' state_color = 'green' %]
    [% ELSIF level == 'RECOVERY'    %][% level = 'HOST UP'          statusclass = 'UP' state_color = 'green' %]
    [% ELSIF level == 'DOWN'        %][% level = 'HOST DOWN'        statusclass = 'DOWN' state_color = 'red' %]
    [% ELSIF level == 'UNREACHABLE' %][% level = 'HOST UNREACHABLE' statusclass = 'UNREACHABLE' state_color = 'red' %]
    [% ELSIF level.match('CUSTOM\ \(') %][%                        statusclass = 'CUSTOM' %]
    [% ELSIF level.match('ACKNOWLEDGEMENT\ \(') %][%               statusclass = 'ACKNOWLEDGEMENT' %]
    [% ELSIF level.match('FLAPPINGSTART\ \(')   %][% level = 'FLAPPING START' statusclass = 'UNKNOWN' %]
    [% ELSIF level.match('FLAPPINGSTOP\ \(')    %][% level = 'FLAPPING STOP'  statusclass = 'UNKNOWN' %]
    [% ELSE                                      %][%    statusclass = 'UNKNOWN' %]
    [% END %]
    [% IF !n.defined('command_name') %][% n.command_name = options.3 %][% END %]
    [% n.plugin_output = log_line_plugin_output(n) %]
[% END %]
