aboutsummaryrefslogtreecommitdiffstats
path: root/SiteSummary.pm
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2006-08-26 09:49:59 +0000
committerPetter Reinholdtsen <pere@hungry.com>2006-08-26 09:49:59 +0000
commit28c12356ac2e3c2578dc0b330ed6bb1245a8eeeb (patch)
tree1e20a8fd262efc828d0a97920bdb2d7d81aa0820 /SiteSummary.pm
parentd4eb01b361e7910a2e64346665dffeda2f8d76be (diff)
downloadsitesummary-28c12356ac2e3c2578dc0b330ed6bb1245a8eeeb.tar.gz
sitesummary-28c12356ac2e3c2578dc0b330ed6bb1245a8eeeb.tar.bz2
sitesummary-28c12356ac2e3c2578dc0b330ed6bb1245a8eeeb.tar.xz
The system is now operational.
Diffstat (limited to 'SiteSummary.pm')
-rw-r--r--SiteSummary.pm118
1 files changed, 118 insertions, 0 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm
new file mode 100644
index 0000000..fefb947
--- /dev/null
+++ b/SiteSummary.pm
@@ -0,0 +1,118 @@
+#
+# Support library for scripts parsing the sitesummary files.
+#
+
+package SiteSummary;
+require Exporter;
+
+our $VERSION = 0.01;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(
+ for_all_hosts
+ get_filepath_current
+ get_site
+ get_sitecontact
+ get_linux_kernel_ver
+ );
+
+my $pwd = "/var/lib/sitesummary/entries"; # Path to the entries
+
+sub get_filepath_current {
+ my ($hostid, $file) = @_;
+ return "$pwd/$hostid$file";
+}
+
+#
+# Return the site string
+#
+sub get_site {
+ my $hostid = shift;
+ my $path = get_filepath_current($hostid, "/siteinfo/site");
+ my $site;
+ if (open (FILE, $path)) {
+ while(<FILE>) {
+ chomp;
+ s/\#.+$//;
+ next if (/^\s*$/);
+ $site = $_;
+ }
+ close(FILE);
+ return $site;
+ } else {
+ return undef;
+ }
+}
+
+#
+# Return list with the mail addresses listed in sitecontact.
+#
+sub get_sitecontact {
+ my $hostid = shift;
+ my $path = get_filepath_current($hostid, "/siteinfo/sitecontact");
+ my @addr = ();
+ if (open (FILE, $path)) {
+ while(<FILE>) {
+ chomp;
+ s/\#.+$//;
+ next if (/^\s*$/);
+ push(@addr, split(/,\s*/, $_));
+ }
+ close(FILE);
+ return @addr;
+ } else {
+ return undef;
+ }
+}
+
+#
+# Return Linux kernel version for the machines using Linux.
+#
+sub get_linux_kernel_ver {
+ my $hostid = shift;
+ my $path = get_filepath_current($hostid, "/system/uname-smr");
+ my $kver;
+ if (open (FILE, $path)) {
+ while(<FILE>) {
+ chomp;
+ s/\#.+$//;
+ next if (/^\s*$/);
+ my @f = (split(/\s+/, $_));
+ $kver = $f[1] if ("Linux" eq $f[0]);
+ }
+ close(FILE);
+ return $kver;
+ } else {
+ return undef;
+ }
+}
+
+sub for_all_hosts {
+ my $callback = shift;
+
+ if ( ! -d $pwd ) {
+ print STDERR "error: Missing $pwd directory.\n";
+ return undef;
+ }
+ opendir(DIR, $pwd) or die "$!: $pwd\nDied";
+ my $count = 0;
+ foreach (readdir(DIR)) {
+ chomp;
+ next if m/^$/ || m/^.$/ || m/^..$/;
+ my $hostid = $_;
+ if ( -d "$pwd/$hostid" ) {
+ $count ++ if ($callback->($hostid));
+ } else {
+ print STDERR "warning: Junk in filelog: $pwd/$hostid\n";
+ }
+ }
+ closedir(DIR);
+ return $count;
+}
+
+1;
+
+########################################################################
+# Local Variables:
+# mode: perl
+# End:
+########################################################################