#!/usr/local/bin/perl

# show Customer Connectivity objects that are down, and not in override.

use strict;
use CGI qw(:standard);

my $q = new CGI();
my $me = $ENV{'SCRIPT_NAME'};
my $url = 'http://' . $ENV{'HTTP_HOST'} . $me;

my (%override,@objects);

foreach my $object (split /\n/, `/usr/local/sbin/argusctl ovlist`){
	if($object =~ /^Top:Customer_Connectivity:(.*:Ping_.+)/){
		$override{$1} = 1;
	}
}

foreach my $object (split /\n/, `/usr/local/sbin/argusctl getchildrenparam object=Top:Customer_Connectivity param=status`){
	next if($object =~ /:\s+up$/);
	next unless($object =~ /:Ping_/);
	$object =~ s/^Top:Customer_Connectivity://;
	$object =~ s/:\s+.*//;
	next if(exists($override{$object}));

	push @objects, $object;
}

print $q->header(-expires=>'now'),
      $q->start_html(-title=>'Argus: Down Customer Connectivity Objects',
                     -head=>meta({-http_equiv => 'REFRESH',
                                  -content    => "90; URL=$url"})), "\n",
      '<h2>Argus: Down Customer Connectivity Objects</h2>', "\n",
      '<table border="0">', "\n";
my $i;
foreach my $object (@objects){
	print ' <tr';
	print ' bgcolor="#C0C0C0"' if($i % 2);
	print ">\n",
	      "  <td>\n",
	      '   <a href="/cgi-bin/arguscgi?object=Top:Customer_Connectivity:', $object, ';func=page">', "${object}</a>\n",
	      "  </td>\n",
	      " </tr>\n";
	$i++;
}
print "</table>\n",
      $q->end_html();
