DBD-Sys

 view release on metacpan or  search on metacpan

lib/DBD/Sys.pm  view on Meta::CPAN

package DBD::Sys;

use strict;
use vars qw(@ISA $VERSION $drh);
use base qw(DBI::DBD::SqlEngine);

$VERSION = "0.102";

$drh = undef;    # holds driver handle(s) once initialised

sub driver($;$)
{
    my ( $class, $attr ) = @_;

    $drh->{$class} and return $drh->{$class};

    $attr ||= {};
    {
        no strict "refs";
        $attr->{Version} ||= ${ $class . "::VERSION" };
        $attr->{Name} or ( $attr->{Name} = $class ) =~ s/^DBD\:\://;

lib/DBD/Sys.pm  view on Meta::CPAN


use strict;
use warnings;

use vars qw(@ISA);

use Scalar::Util qw(weaken);

@ISA = qw(DBI::DBD::SqlEngine::Statement);

sub open_table($$$$$)
{
    my ( $self, $data, $table, $createMode, $lockMode ) = @_;

    my $attr_prefix = 'sys_' . lc($table) . '_';
    my $attrs       = {};
    my $meta        = {};
    my $dbh         = $data->{Database};
    foreach my $attr ( keys %{$dbh} )
    {
        next unless ( $attr =~ m/^$attr_prefix(.+)$/ );

lib/DBD/Sys/Plugin/Any.pm  view on Meta::CPAN


=head1 METHODS

=head2 get_priority

Delivers the default priority for the tables for any operating system,
which is 100.

=cut

sub get_priority() { return 100; }

=head1 BUGS & LIMITATIONS

No known bugs at this moment.

The implementation of L<Proc::ProcessTable> is very limited for several
platforms and should improved. L<Net::Interface> lacks MSWin32 support
and needs help porting from autoconf to hints framework.

=head1 AUTHOR

lib/DBD/Sys/Plugin/Any/FileSys.pm  view on Meta::CPAN

user and group settings and permissions.

=head1 METHODS

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_table_name

Returns 'filesystems'

=cut

sub get_table_name() { return 'filesystems'; }

=head2 collect_data

Retrieves the data from L<Sys::Filesystem> and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    unless ( defined($haveSysFs) )
    {
        $haveSysFs = 0;
        eval {
            require Sys::Filesystem;
            $haveSysFs = 1;
        };

lib/DBD/Sys/Plugin/Any/FileSysDf.pm  view on Meta::CPAN

See the information for the C<bper> column.

=head1 METHODS

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { return @colNames }

=head2 get_attributes

Return the attributes supported by this module:

=head3 blocksize

Allows to specify the blocksize of the returned free blocks.
This defaults to 1.

    $dbh->{sys_filesysdf_blocksize} = 512; # use UNIX typical blocksize for df

=cut

sub get_attributes() { return qw(blocksize) }

=head2 collect_data

Retrieves the mountpoints of mounted file systems from L<Sys::Filesystem>
and determine the free space on their devices using L<Filesys::DfPortable>.
The mountpoint and the free space information are put in fetchable rows.

=cut

sub collect_data()
{
    my $self = $_[0];
    my @data;

    unless ( defined($haveFilesysDf) )
    {
        $haveFilesysDf = 0;
        eval {
            require Sys::Filesystem;
            require Filesys::DfPortable;

lib/DBD/Sys/Plugin/Any/NetIfconfigWrapper.pm  view on Meta::CPAN

Comma separated list of the flags.

=head1 METHODS

=head2 get_table_name

Returns 'netint'.

=cut

sub get_table_name() { return 'netint'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_primary_key

Returns 'address'.

=cut

sub get_primary_key() { return [qw(interface address_family address)]; }

=head2 get_priority

Returns 200 to let L<DBD::Sys::Plugin::Any::NetInterface> dominate.

=cut

sub get_priority() { return 200; }

=head2 collect_data

Retrieves the data from L<Net::Interface> and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    unless ( defined($haveNetIfconfigWrapper) )
    {
        $haveNetIfconfigWrapper = 0;
        eval {
            require Net::Ifconfig::Wrapper;
            $haveNetIfconfigWrapper = 1;
        };

lib/DBD/Sys/Plugin/Any/NetInterface.pm  view on Meta::CPAN

Metric for the interface/address.

=head1 METHODS

=head2 get_table_name

Returns 'netint'.

=cut

sub get_table_name() { return 'netint'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_primary_key

Returns 'address'.

=cut

sub get_primary_key() { return [qw(interface address_family address)]; }

my %flagconsts;

sub _getflags
{
    my $flags = $_[0] || 0;
    my $txt = ( $flags & $flagconsts{up} ) ? '<up' : '<down';
    foreach my $nm ( keys %flagconsts )
    {
        $nm eq 'up' and next;

lib/DBD/Sys/Plugin/Any/NetInterface.pm  view on Meta::CPAN

    }
    $txt .= '>';
}

=head2 collect_data

Retrieves the data from L<Net::Interface> and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    unless ( defined($haveNetInterface) )
    {
        $haveNetInterface = 0;
        eval {
            require Net::Interface;
            require Socket6;
            $haveNetInterface = 1;

lib/DBD/Sys/Plugin/Any/Procs.pm  view on Meta::CPAN

Scheduling class name                 #FIX ME!

=head1 METHODS

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_primary_key

Returns 'pid' - which is the process identifier.

=cut

sub get_primary_key() { return 'pid'; }

my %colMap = (
               fulltime => 'time',
               virtsize => 'size',
             );

sub _init_knownCols
{
    my $table = $_[0];
    unless ( 0 == scalar(@$table) )

lib/DBD/Sys/Plugin/Any/Procs.pm  view on Meta::CPAN

        } @colNames;
    }
}

=head2 collect_data

Retrieves the data from L<Proc::ProcessTable> and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    unless ( defined($haveProcProcessTable) )
    {
        $haveProcProcessTable = 0;
        eval {
            require Proc::ProcessTable;
            $haveProcProcessTable = 1;
        };

lib/DBD/Sys/Plugin/Meta.pm  view on Meta::CPAN

require DBD::Sys::Plugin::Meta::AllTables;

my %supportedTables = ( alltables => 'DBD::Sys::Plugin::Meta::AllTables', );

=head2 get_supported_tables

Delivers the supported meta tables.

=cut

sub get_supported_tables() { %supportedTables }

=head2 get_priority

Delivers the default priority for the meta tables, which is 100.

=cut

sub get_priority { return 100; }

=head1 PREREQUISITES

lib/DBD/Sys/Plugin/Meta/AllTables.pm  view on Meta::CPAN

=head2 get_col_names

Returns the column names of the table

=head2 get_priority

Returns 100 - the lowest priority used by DBD::Sys delivered tables.

=cut

sub get_col_names() { @colNames }
sub get_priority    { return 100; }

=head2 collect_data

Collects the data for the table using the plugin manager.
See L<DBD::Sys::PluginManager/get_table_details> for details.

=cut

sub collect_data()
{
    my @data;
    my %tables = $_[0]->{database}->{sys_pluginmgr}->get_table_details();

    while ( my ( $table, $class ) = each(%tables) )
    {
        push( @data,
              [ undef, undef, $table, 'TABLE', _ARRAY($class) ? join( ',', @$class ) : $class ] );
    }

lib/DBD/Sys/Plugin/Unix.pm  view on Meta::CPAN

for details.

=head1 METHODS

=head2 get_priority

Returns the default priority for unix tables, 500.

=cut

sub get_priority() { return 500; }

=head1 PREREQUISITES

This plugin only works on Unix or unixoide environments.

=head1 BUGS & LIMITATIONS

No known bugs at this moment.

=head1 AUTHOR

lib/DBD/Sys/Plugin/Unix/Groups.pm  view on Meta::CPAN

Numerical count of the members in this group

=head1 METHODS

=head2 get_table_name

Returns 'grent'.

=cut

sub get_table_name() { return 'grent'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

my $havegrent = 0;
eval { endgrent(); my @grentry = getgrent(); endgrent(); $havegrent = 1; };

=head2 collect_data

Retrieves the data from the group database and put it into fetchable rows.

=cut

sub collect_data()
{
    my %data;

    if ($havegrent)
    {
        setgrent();    # rewind to ensure we're starting fresh ...
        while ( my ( $name, $grpass, $gid, $members ) = getgrent() )
        {
            if ( defined( $data{$name} ) )    # FBSD seems to have a bug with multiple entries
            {

lib/DBD/Sys/Plugin/Unix/Logins.pm  view on Meta::CPAN

The time in epoch seconds which the record was created.

=head1 METHODS

=head2 get_table_name

Returns 'logins'.

=cut

sub get_table_name() { return 'logins'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_attributes

Return the attributes supported by this module:

=head3 filename

Allows to specify an alternate filename to use. It's unused per default
and will use C<_PATH_UTMP>.

    $dbh->{sys_logins_filename} = q(/var/log/wtmp); # last logings

=cut

sub get_attributes() { return qw(filename) }

=head2 get_primary_key

Returns 'timestamp' - you must be very quick to login twice per second

=cut

sub get_primary_key() { return 'timestamp'; }

=head2 collect_data

Retrieves the data from the utmp database and put it into fetchable rows.

=cut

sub collect_data()
{
    my $self = $_[0];
    my @data;

    unless ( defined($haveSysUtmp) )
    {
        $haveSysUtmp = 0;
        eval {
            require Sys::Utmp;
            $haveSysUtmp = 1;

lib/DBD/Sys/Plugin/Unix/Lsof.pm  view on Meta::CPAN

Mount point of the file system where the file resides

=head1 METHODS

=head2 get_table_name

Returns 'grent'.

=cut

sub get_table_name() { return 'openfiles'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_attributes

Return the attributes supported by this module:

=head3 uids

Allows restricting the user ids (see lsof(8) for the C<-u> parameter).

    $dbh->{sys_openfiles_uids} = [scalar getpwuid $<];

lib/DBD/Sys/Plugin/Unix/Lsof.pm  view on Meta::CPAN


=head3 filesys

Allows restricting the scanned file systems (see lsof(8) for the C<+f>
parameter).

    $dbh->{sys_openfiles_filesys} = [qw(/usr /var)];

=cut

sub get_attributes() { return qw(uids pids filesys) }

my $havelsof;
my $havesysfsmountpoint;

=head2 collect_data

Retrieves the data from the lsof command and put it into fetchable rows.

=cut

sub collect_data()
{
    my $self = $_[0];
    my @data;

    unless ( defined($havelsof) )
    {
        $havelsof = 0;
        eval {
            require Unix::Lsof;
            $havelsof = 1;

lib/DBD/Sys/Plugin/Unix/Users.pm  view on Meta::CPAN

Account expiration time, when available

=head1 METHODS

=head2 get_table_name

Returns 'pwent'.

=cut

sub get_table_name() { return 'pwent'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

my $havepwent = 0;

eval { setpwent(); my @pwentry = getpwent(); endpwent(); $havepwent = 1; };

=head2 collect_data

Retrieves the data from the password database and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    if ($havepwent)
    {
        setpwent();    # rewind to ensure we're starting fresh ...
        while ( my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ) =
                getpwent() )
        {
            push( @data,

lib/DBD/Sys/Plugin/Win32.pm  view on Meta::CPAN

for details.

=head1 METHODS

=head2 get_priority

Returns the default priority for win32 tables, 500.

=cut

sub get_priority() { return 500; }

=head1 PREREQUISITES

This plugin only works on Windows.

=head1 BUGS & LIMITATIONS

No known bugs at this moment.

The implementation of L<Proc::ProcessTable> is very limited for several

lib/DBD/Sys/Plugin/Win32/Groups.pm  view on Meta::CPAN

Numerical count of the members in this group

=head1 METHODS

=head2 get_table_name

Returns 'grent'.

=cut

sub get_table_name() { return 'grent'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 collect_data

Retrieves the data from the group database and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    if ($haveWin32pwent)
    {
        Win32::pwent::endgrent();    # ensure we're starting fresh ...
        while ( my ( $name, $grpass, $gid, $members ) = Win32::pwent::getgrent() )
        {
            push( @data, [ $name, $grpass, $gid, $members ] );
        }

lib/DBD/Sys/Plugin/Win32/Procs.pm  view on Meta::CPAN

my ( $have_win32_process_info, $have_win32_process_commandline );

=head1 METHODS

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 get_primary_key

Returns 'pid' - which is the process identifier.

=cut

sub get_primary_key() { return 'pid'; }

=head2 collect_data

Retrieves the data from L<Win32::Process::Info> and put it into fetchable rows.

=cut

sub collect_data
{
    my $self = $_[0];

lib/DBD/Sys/Plugin/Win32/Users.pm  view on Meta::CPAN

Account expiration time, when available

=head1 METHODS

=head2 get_table_name

Returns 'pwent'.

=cut

sub get_table_name() { return 'pwent'; }

=head2 get_col_names

Returns the column names of the table as named in L</Columns>

=cut

sub get_col_names() { @colNames }

=head2 collect_data

Retrieves the data from the password database and put it into fetchable rows.

=cut

sub collect_data()
{
    my @data;

    if ($haveWin32pwent)
    {
        Win32::pwent::endpwent();    # ensure we're starting fresh ...
        while ( my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ) =
                Win32::pwent::getpwent() )
        {
            push( @data,

lib/DBD/Sys/Table.pm  view on Meta::CPAN

=head1 METHODS

=head2 get_col_names

This method is called during the construction phase of the table. It must be
a I<static> method - the called context is the class name of the constructed
object.

=cut

sub get_col_names() { croak "Abstract method 'get_col_names' called"; }

=head2 collect_data

This method is called when the table is constructed but before the first row
shall be delivered via C<fetch_row()>.

=cut

sub collect_data() { croak "Abstract method 'collect_data' called"; }

=head2 get_primary_key

This method returns the column name of the primary key column. If not
overwritten, the first column name is returned by C<DBD::Sys::Table>.

=cut

sub get_primary_key() { return ( $_[0]->get_col_names() )[0]; }

=head2 get_table_name

Returns the name of the table based on it's class name.
Override it to return another table name.

=cut

sub get_table_name
{

lib/DBD/Sys/Table.pm  view on Meta::CPAN


=head2 get_priority

Returns the default priority of the controlling plugin.

To speed up subsequent get_priority calls, a simple method returning the
value is injected into the class name space.

=cut

sub get_priority()
{
    my $self = $_[0];
    my $proto = blessed($self) || $self;
    ( my $plugin = $proto ) =~ s/(.*)::\p{Word}+$/$1/;
    my $priority = $plugin->get_priority();

    eval sprintf( 'sub %s::get_priority { return %d; }', $proto, $priority );

    return $priority;
}



( run in 0.464 second using v1.01-cache-2.11-cpan-1f129e94a17 )