diff options
| author | Petter Reinholdtsen <pere@hungry.com> | 2010-01-19 09:36:20 +0000 | 
|---|---|---|
| committer | Petter Reinholdtsen <pere@hungry.com> | 2010-01-19 09:36:20 +0000 | 
| commit | 4f5fe5139130a682f4e416d0361792cda42f812c (patch) | |
| tree | 0c01d45907dce24a4846ad15069a66b5f2707613 | |
| parent | 8c4919e83635d06ffb55566f213bf06f96176aef (diff) | |
| download | sitesummary-4f5fe5139130a682f4e416d0361792cda42f812c.tar.gz sitesummary-4f5fe5139130a682f4e416d0361792cda42f812c.tar.bz2 sitesummary-4f5fe5139130a682f4e416d0361792cda42f812c.tar.xz | |
Move some generic functions to the sitesummary perl library.
| -rw-r--r-- | SiteSummary.pm | 41 | ||||
| -rwxr-xr-x | sitesummary-nodes | 37 | 
2 files changed, 41 insertions, 37 deletions
| diff --git a/SiteSummary.pm b/SiteSummary.pm index f86bb3d..4db2953 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -9,6 +9,7 @@ our $VERSION = 0.01;  our @ISA     = qw(Exporter);  our @EXPORT  = qw(                    for_all_hosts +                  get_default_route                    get_filepath_current                    get_hostclass                    get_site @@ -22,6 +23,8 @@ our @EXPORT  = qw(                    get_debian_edu_profile                    get_debian_edu_ver                    get_hardware_info +                  is_laptop +                  is_pkg_installed                    );  my $pwd = "/var/lib/sitesummary/entries";  # Path to the entries @@ -122,6 +125,22 @@ sub get_macaddresses {      }  } +# Return current default route used on host +sub get_default_route { +    my $hostid = shift; +    my $path = get_filepath_current($hostid, "/system/route-n"); +    if (open(my $fh, $path)) { +        while (<$fh>) { +            if (m/^0.0.0.0\s+(\S+)\s+/) { +                close($fh); +                return $1; +            } +        } +        close($fh); +    } +    return undef; +} +  #  # Return the IP address on the primary network interface  # @@ -262,6 +281,28 @@ sub get_hardware_info {      }  } +sub is_pkg_installed { +    my ($hostid, $pkgname) = @_; +    # Check debian/dpkg-l for 'ii *pkgname ' +    my $path = get_filepath_current($hostid, "/debian/dpkg-l"); +    if (open (my $fh, $path)) { +        while(<$fh>) { +            if (m/^ii *$pkgname /) { +                close($fh); +                return 1 +            } +        } +        close($fh); +    } +    return undef; +} + +sub is_laptop { +    my $hostid = shift; +    my $path = get_filepath_current($hostid, "/system/laptop"); +    return -e $path; +} +  sub for_all_hosts {      my $callback = shift; diff --git a/sitesummary-nodes b/sitesummary-nodes index 77c0f8b..f05d4f7 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -54,37 +54,6 @@ sub print_list {      }  } -sub is_pkg_installed { -    my ($hostid, $pkgname) = @_; -    # Check debian/dpkg-l for 'ii *pkgname ' -    my $path = get_filepath_current($hostid, "/debian/dpkg-l"); -    if (open (my $fh, $path)) { -        while(<$fh>) { -            if (m/^ii *$pkgname /) { -                close($fh); -                return 1 -            } -        } -        close($fh); -    } -    return undef; -} - -sub get_default_route { -    my $hostid = shift; -    my $path = get_filepath_current($hostid, "/system/route-n"); -    if (open(my $fh, $path)) { -        while (<$fh>) { -            if (m/^0.0.0.0\s+(\S+)\s+/) { -                close($fh); -                return $1; -            } -        } -        close($fh); -    } -    return undef; -} -  # Get an IP address, try to resolve it in DNS , and return the IP  # address if no DNS reverse entry was found.  sub get_dnsnameorip { @@ -107,12 +76,6 @@ sub is_nagios_client {          is_pkg_installed($hostid, "nagios3");  } -sub is_laptop { -    my $hostid = shift; -    my $path = get_filepath_current($hostid, "/system/laptop"); -    return -e $path; -} -  sub print_munin_list {      for my $hostname (sort keys %hostnames) {          next unless (is_munin_client($hostnames{$hostname})); | 
