--- mon.cgi	Thu Mar  7 11:51:57 2002
+++ mon.cgi.sev	Thu Mar  7 11:54:36 2002
@@ -25,6 +25,7 @@
 #  enhancements by Andrew Ryan <andrewr@nam-shub.com>.
 #  Downtime logging contributed by Martha H Greenberg <marthag@mit.edu>
 #  Site-specific customization routines contributed by Ed Ravin <eravin@panix.com>
+#  Severity level support added by Dan Urist <durist@world.std.com>
 #
 # ----------------------------------------------------------------------
 # $Id: mon.cgi,v 1.52 2001/05/22 21:27:23 andrewr Exp $
@@ -146,10 +147,10 @@
 	    $required_mon_client_version);
 # Formatting-related global vars
 use vars qw($BGCOLOR $TEXTCOLOR $LINKCOLOR $VLINKCOLOR 
-	    $greenlight_color $redlight_color $unchecked_color 
-	    $yellowlight_color $disabled_color 
+	    $greenlight_color $redlight_color $amberlight_color $unchecked_color 
+	    $yellowlight_color $pinklight_color $disabled_color 
 	    $fixed_font_face $sans_serif_font_face 
-	    $dtlog_max_failures_per_page);
+	    $dtlog_max_failures_per_page %SeverityColors);
 # Security-related global vars
 use vars qw($must_login $app_secret %loginhash $des $has_prompted_for_auth $destroy_auth_cookie $default_username $default_password);
 $has_prompted_for_auth = "";        #this must always be cleared for mod_perl
@@ -233,14 +234,41 @@
     $LINKCOLOR = "yellow";			        # Link color
     $VLINKCOLOR = "#00FFFF";			# Visited link color (default is teal)
 
-    $greenlight_color = "#009900";                # color of "good" status events
-    $redlight_color = "red";                      # color of "bad" status events
     $unchecked_color = "#000033";                   # color of "unknown" status events
     $disabled_color="#999999";                  # color of "disabled" items
-    $yellowlight_color = "#FF9933";             # color of "going bad" status events
+    $greenlight_color = "#00CC00";              # color of "good" status events
+    $redlight_color = "#FF0000";                # color of sev 1 "bad" status events
+    $amberlight_color = "#FF6600";              # color of sev 2 "bad" status events
+    $yellowlight_color = "#FFFF33";             # color of sev 3 "bad" status events
+    $pinklight_color = "#CC00FF";               # color for monintor/protocol errors
 
     # Maximum dtlog entries to show per page
     $dtlog_max_failures_per_page = "100";
+
+    # Mapping of severity levels to colors and messages
+    %SeverityColors = (
+		       '1' => {
+			       'color' => $redlight_color,
+			       'msg' => "Failed, Severity 1",
+			      },
+		       '2' => {
+			       'color' => $amberlight_color,
+			       'msg' => "Failed, Severity 2",
+			      },
+		       '3' => {
+			       'color' => $yellowlight_color,
+			       'msg' => "Failed, Severity 3",
+			      },
+		       '9' => {
+			       'color' => $pinklight_color,
+			       'msg' => "Monitor/Protocol Error",
+			      },
+		       'default' => {
+				     'color' => $redlight_color,
+				     'msg' => "Failed, Unknown Severity",
+				    },
+		      );
+
 }
 
 ###############################################################
@@ -1010,8 +1038,6 @@
     my ($detail_level, %op) = (@_);
     my (%group_list, $group, $service, $s, $g, $h);
     my (@time);
-    my $bg_fail = $redlight_color ; 
-    my $bg_fail_noalerts = $yellowlight_color ; 
     my $bg_ok = $greenlight_color;
     my $td_bg_color;
     my $face = $sans_serif_font_face;
@@ -1114,20 +1140,13 @@
 		$webpage->print("</td>\n");
 
 	    } elsif ($s->{"opstatus"} == $OPSTAT{"fail"}) {
-		# Check to see if the service has issued any alerts.
-		# If not, then we call this service "failing" instead
-		# of failed, on the assumption that if it hasn't
-		# generated an alert yet, it isn't "really" important,
-		# although you'd still like to know about it.
-		if ( $s->{"alerts_sent"} == 0 ) {
-		    $td_bg_color = $bg_fail_noalerts ;
-		    $failure_string = "FAILED,NOALERTS" ;
-		} else {
-		    $td_bg_color = $bg_fail ;
-		    $failure_string = "FAILED" ;
-		    # Also give the # of alerts if "full" view was selected
+	        # Set color and message based on severity of last alert
+	        my $sev = $s->{last_alert_severity};
+	        my $key = defined( $SeverityColors{$sev} ) ? $sev : "default";
+		$td_bg_color = $SeverityColors{$key}->{color};
+		$failure_string = $SeverityColors{$key}->{msg};
 		    $failure_string .= ",alerts_sent=" . $s->{"alerts_sent"} if $detail_level eq "full";
-		}
+
 		$td_bg_color = ($service_disabled_string eq "") ? $td_bg_color : $disabled_color ;
 		$webpage->print("<td align=left bgcolor=\"$td_bg_color\">");
 		$webpage->print("$service_disabled_string<a href=\"$url?${monhost_and_port_args}command=svc_details&amp;args=$group,$service\">");
@@ -1403,12 +1422,13 @@
 	    $msg="(status: OK)";
 	} elsif ($s->{"opstatus"} == $OPSTAT{"fail"}) {
 	    unless ($bgcolor) {
-		if ( $s->{"alerts_sent"} == 0 ) {
-		    $bgcolor = "$yellowlight_color";
-		    $msg=": $s->{'last_summary'}<br>(status: FAILED,NOALERTS)";
-		} else {
-		    $bgcolor = "$redlight_color";
-		    $msg=": $s->{'last_summary'}<br>(status: FAILED)";
+	        if( defined $SeverityColors{$s->{last_alert_severity}} ){
+		  $bgcolor = $SeverityColors{$s->{last_alert_severity}}->{color};
+		  $msg = $SeverityColors{$s->{last_alert_severity}}->{msg};
+	        }
+		else{
+		  $bgcolor = $SeverityColors{default}->{color};
+		  $msg = $SeverityColors{default}->{msg};
 		}
 		if ( $s->{'ackcomment'} ne "" ) {
                     $msg .= "(ACKED: $s->{'ackcomment'})";
@@ -1572,7 +1592,10 @@
 	# at the top. Yes, it's buried down in the middle of the page, but
 	# it's important enough to take up screen real estate with and 
 	# bring it to the top.
-	$font_color = ($op{$group}{$service}{'alerts_sent'} == 0) ? $yellowlight_color : $redlight_color ;
+        $font_color = ( defined $SeverityColors{$op{$group}{$service}{last_alert_severity}} ) ?
+	  $SeverityColors{$op{$group}{$service}{last_alert_severity}}->{color}
+	    : $SeverityColors{default}->{color};
+
 	$webpage->print("<table width=\"$table_width\" border=0 align=center cellpadding=2 cellspacing=2>\n");
 	$webpage->print("<tr><td colspan=2>");
     $webpage->print("<center>");
@@ -3242,19 +3265,6 @@
 sub moncgi_print_service_table_legend {
     my ($service_table_width) = (@_);
 
-    # Old way to draw table
-    if (1 == 0 ) {
-	$webpage->print("<table align=center border=1 width=\"$service_table_width\">");
-	$webpage->print
-	    ("<tr><td><font color=$TEXTCOLOR>Service color legend:</font></td>\n");
-	$webpage->print("<td><font color=$unchecked_color>Unchecked</font></td>\n");
-	$webpage->print("<td><font color=$greenlight_color>Good</font></td>\n ");
-	$webpage->print("<td><font color=$yellowlight_color>Failed<br>(no alerts sent)</font></td>\n");
-	$webpage->print("<td><font color=$redlight_color>Failed<br>(alerts sent)</font></td>\n");
-	$webpage->print("<td><font color=$disabled_color>Disabled</font></td>\n");
-	$webpage->print("</tr></table>");
-    }
-    
     # New way to draw table
     $webpage->print("<a name=\"legend\"></a>");
     $webpage->print("<table align=center border=1 width=\"$service_table_width\">");
@@ -3262,14 +3272,18 @@
 	("<tr><td rowspan=2><font size=+1 color=$TEXTCOLOR>Service color legend:</font><br><a href=\"$url#opstatus_tbl\">(top of table)</a></td>\n");
     $webpage->print("<td><font>Unchecked</font></td>\n");
     $webpage->print("<td><font>Good</font></td>");
-    $webpage->print("<td><font>Failed<br>(no alerts sent)</font></td>");
-    $webpage->print("<td><font>Failed<br>(alerts sent)</font></td>");
+    $webpage->print("<td><font>Failed<br>(monitor error)</font></td>");
+    $webpage->print("<td><font>Failed<br>(severity 3)</font></td>");
+    $webpage->print("<td><font>Failed<br>(severity 2)</font></td>");
+    $webpage->print("<td><font>Failed<br>(severity 1)</font></td>");
     $webpage->print("<td><font>Disabled</font></td>");
     $webpage->print("</tr>\n");
     $webpage->print("<tr>");
     $webpage->print("<td bgcolor=$unchecked_color><font color=$unchecked_color>$unchecked_color</font></td>");
     $webpage->print("<td bgcolor=$greenlight_color><font color=$greenlight_color>$greenlight_color</font></td>");
+    $webpage->print("<td bgcolor=$pinklight_color><font color=$pinklight_color>$pinklight_color</font></td>");
     $webpage->print("<td bgcolor=$yellowlight_color><font color=$yellowlight_color>$yellowlight_color</font></td>");
+    $webpage->print("<td bgcolor=$amberlight_color><font color=$amberlight_color>$amberlight_color</font></td>");
     $webpage->print("<td bgcolor=$redlight_color><font color=$redlight_color>$redlight_color</font></td>");
     $webpage->print("<td bgcolor=$disabled_color><font color=$disabled_color>$disabled_color</font></td>");
 
@@ -3565,8 +3579,12 @@
 		    $greenlight_color = $val;
 		} elsif ($key eq "redlight_color") {
 		    $redlight_color = $val;
+		} elsif ($key eq "amberlight_color") {
+		    $redlight_color = $val;
 		} elsif ($key eq "yellowlight_color") {
 		    $yellowlight_color = $val;
+		} elsif ($key eq "pinklight_color") {
+		    $redlight_color = $val;
 		} elsif ($key eq "unchecked_color") {
 		    $unchecked_color = $val;
 		} elsif ($key eq "dtlog_max_failures_per_page") {
