Today is: 8 January, 2012
Check todays hot topics

MountedFS Plugin for Spine (http://code.ticketmaster.com)

# -*- mode: perl; cperl-continued-brace-offset: -4; indent-tabs-mode: nil; -*-
# vim:shiftwidth=2:tabstop=8:expandtab:textwidth=78:softtabstop=4:ai:
 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# (C) Copyright Ticketmaster, Inc. 2008
#
 
use strict;
 
package Spine::Plugin::MountedFS;
use base qw(Spine::Plugin);
use Spine::Constants qw(:plugin);
 
our ($VERSION, $DESCRIPTION, $MODULE);
 
$VERSION = sprintf("%d.%02d", q$Revision: 50 $ =~ /(\d+)\.(\d+)/);
$DESCRIPTION = "Spine::Plugin skeleton";
 
$MODULE = { author => 'taylor@linuxhq.org',
            description => $DESCRIPTION,
            version => $VERSION,
            hooks => { 'DISCOVERY/populate' => [ {  name => 'mounted_fs',
                                                    code => \&mounted_fs } ]
                     },
          };
 
 
sub mounted_fs
{
    my $c = shift;
    my $proc_mounts = "/proc/mounts";
    my @mountedfs;
 
    return PLUGIN_FATAL unless ( -f $proc_mounts );
 
    my $fh = new IO::File("< $proc_mounts");
 
    unless ( defined($fh) )
    {
        $c->error("Couldn't open $proc_mounts: $!", 'err');
        return PLUGIN_FATAL;
    }
 
    while ( <$fh> )
    {
        my ($src, $dst, $type, $opt_str) = split(" ", $_);
        my @opts = split(",", $opt_str);
 
        my %hash =  ( 
                        dst => $dst,
                        src => $src,
                        type => $type,
                        opts => \@opts,
                    );
 
        push(@mountedfs, \%hash);
    }
 
    $fh->close();
 
    return PLUGIN_SUCCESS if ( $c->set('mountedfs', \@mountedfs) );
    return PLUGIN_FATAL;
}
 
1;