$self->{'hosthash'} = \%hosts;
$self->{'hostnames'} = [ @names ];
+ $self->{'sorted_hostnames'} = [ sort byname @names ];
bless $self;
return $self;
}
+# Sort the list of hostnames by hostname.
+sub byname {
+ # Work out the display-name attrib if it's defined.
+ my ($display_a) = $main::HOSTS{$a}->{'display_name'};
+ my ($display_b) = $main::HOSTS{$b}->{'display_name'};
+ if ( ! $display_a ) {
+ # Otherwise use the hostname if $WWW_FQDN or short name
+ $display_a = $main::WWW_FQDN ? $a : (split( /\./, $a ))[0];
+ }
+ if ( ! $display_b ) {
+ # Otherwise use the hostname if $WWW_FQDN or short name
+ $display_b = $main::WWW_FQDN ? $b : (split( /\./, $b ))[0];
+ }
+
+ return lc($display_a) cmp lc($display_b);
+}
+
+
# Get/Set methods, hostnames() is a little fancy in that it return a list
# rather then just the list reference (easier for others to deal with). The
if( defined $_[1] ) { $_[0]->{$var} = $_[1]; } return $_[0]->{$var}; }
sub hostnames { my $var = 'hostnames';
if( defined $_[1] ) { $_[0]->{$var} = $_[1]; } return @{$_[0]->{$var}}; }
+sub sorted_hostnames { my $var = 'sorted_hostnames';
+ if( defined $_[1] ) { $_[0]->{$var} = $_[1]; } return @{$_[0]->{$var}}; }
# Some specific functions that get at and manipulate the data in the instance
# vars in more convenient ways
return @tmp;
}
+sub sorted_hosts {
+ my $self = shift;
+ my( @tmp );
+
+ foreach( $self->sorted_hostnames() ) { push( @tmp, $self->host( $_ ) ); }
+ return @tmp;
+}
+
sub add {
my( $self, $host ) = @_;
my $name = $host->name();
$self->{'hosthash'}->{$name} = $host;
push( @{$self->{'hostnames'}}, $name );
+ push( @{ $self->{'sorted_hostnames'} }, $name);
+ $self->{'sorted_hostnames'} = [ sort byname @{ $self->{'sorted_hostnames'} } ];
}
# Calculate summary color for a service
# Now go through each host, and fill in the table.
- foreach $host ( $self->hosts() ) {
+ foreach $host ( $self->sorted_hosts() ) {
my $hostname = $host->name();
# Use display-name attrib if defined
my $display = $main::HOSTS{$hostname}->{'display_name'};
# of the problem services, date/time the problem occurred, and contact
# information (as well as acknowledgments if they are available).
- foreach $host ( $self->hosts() ) {
+ foreach $host ( $self->sorted_hosts() ) {
$host->display_problem( "html" ); print "\n";
}
}
}
-
# These methods all display summary information about only those machines
# that are currently registering a problem, or that have services that have
# not been updated (showing purple) - it also relays information about