aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2006-08-27 21:21:46 +0000
committerPetter Reinholdtsen <pere@hungry.com>2006-08-27 21:21:46 +0000
commit139b4c54cfee7d63bcfc457ecf5978a4d39d5265 (patch)
treeb279d96f98145cf81c29a178dd1a0050a963c1a1
parent8602a0decca0e71668855b789bebd81c48960aa5 (diff)
downloadsitesummary-139b4c54cfee7d63bcfc457ecf5978a4d39d5265.tar.gz
sitesummary-139b4c54cfee7d63bcfc457ecf5978a4d39d5265.tar.bz2
sitesummary-139b4c54cfee7d63bcfc457ecf5978a4d39d5265.tar.xz
* Reduce code duplication in SiteSummary.pm. Add new function
get_sitegroup(). * Extend site-summary script to also entries per sitegroup within a site.
-rw-r--r--SiteSummary.pm35
-rw-r--r--debian/changelog9
-rwxr-xr-xsite-summary5
3 files changed, 40 insertions, 9 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm
index fefb947..bd3107e 100644
--- a/SiteSummary.pm
+++ b/SiteSummary.pm
@@ -9,10 +9,11 @@ our $VERSION = 0.01;
our @ISA = qw(Exporter);
our @EXPORT = qw(
for_all_hosts
- get_filepath_current
+ get_filepath_current
get_site
+ get_sitegroup
get_sitecontact
- get_linux_kernel_ver
+ get_linux_kernel_ver
);
my $pwd = "/var/lib/sitesummary/entries"; # Path to the entries
@@ -23,27 +24,43 @@ sub get_filepath_current {
}
#
-# Return the site string
+# Return the value string from a file, ignoring comments
#
-sub get_site {
- my $hostid = shift;
- my $path = get_filepath_current($hostid, "/siteinfo/site");
- my $site;
+sub get_file_string {
+ my ($hostid, $filename) = @_;
+ my $path = get_filepath_current($hostid, $filename);
+ my $string;
if (open (FILE, $path)) {
while(<FILE>) {
chomp;
s/\#.+$//;
next if (/^\s*$/);
- $site = $_;
+ $string = $_;
}
close(FILE);
- return $site;
+ return $string;
} else {
return undef;
}
}
#
+# Return the site string
+#
+sub get_site {
+ my $hostid = shift;
+ return get_file_string($hostid, "/siteinfo/site");
+}
+
+#
+# Return the sitegroup string
+#
+sub get_sitegroup {
+ my $hostid = shift;
+ return get_file_string($hostid, "/siteinfo/sitegroup");
+}
+
+#
# Return list with the mail addresses listed in sitecontact.
#
sub get_sitecontact {
diff --git a/debian/changelog b/debian/changelog
index 437b66e..6632076 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+sitesummary (0.0.4) UNRELEASED; urgency=low
+
+ * Reduce code duplication in SiteSummary.pm. Add new function
+ get_sitegroup().
+ * Extend site-summary script to also entries per sitegroup within a
+ site.
+
+ -- Petter Reinholdtsen <pere@debian.org> Sun, 27 Aug 2006 22:13:06 +0200
+
sitesummary (0.0.3) terra; urgency=low
* Remove temp file when it is processed by the collector.
diff --git a/site-summary b/site-summary
index 4d0f5e0..8461ef0 100755
--- a/site-summary
+++ b/site-summary
@@ -6,6 +6,7 @@ use warnings;
use SiteSummary;
my %sites;
+my %sitegroups;
for_all_hosts(\&handle_host);
@@ -17,6 +18,7 @@ sub handle_host {
for my $site (get_site($hostid)) {
$site = "" unless defined $site;
$sites{$site}++;
+ $sitegroups{$site}{get_sitegroup($hostid)}++ if get_sitegroup($hostid);
}
}
@@ -24,5 +26,8 @@ sub print_summary {
printf(" %-20s %5s\n", "site", "count");
for my $site (sort keys %sites) {
printf(" %-20s %5d\n", $site, $sites{$site});
+ for my $sitegroup (sort keys %{$sitegroups{$site}}) {
+ printf(" %-18s %5d\n", $sitegroup, $sitegroups{$site}{$sitegroup});
+ }
}
}