Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37860135
en ru br
Репозитории ALT

Группа :: Разработка/Perl
Пакет: perl-SNMP-Simple

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

SNMP-Simple-0.02/000075500000000000000000000000001174522217200134405ustar00rootroot00000000000000SNMP-Simple-0.02/.releaserc000064400000000000000000000001211174522217200154000ustar00rootroot00000000000000release_subclass Module::Release::IAN
cpan_user IAN
sf_user <none>
passive_ftp y
SNMP-Simple-0.02/Changes000064400000000000000000000002531174522217200147330ustar00rootroot00000000000000Revision history for SNMP-Simple

0.02 Sun Dec 4 20:42:43 EST 2005
* improving Kwalitee

0.01 Tue Jun 1 19:48:46 EDT 2004
* initial public release
SNMP-Simple-0.02/MANIFEST000064400000000000000000000003361174522217200145730ustar00rootroot00000000000000.releaserc
Changes
examples/printerstats.pl
lib/SNMP/Simple.pm
Makefile.PL
MANIFEST This list of files
META.yml Module meta-data (added by MakeMaker)
README
SIGNATURE
t/0-signature.t
t/basic.t
t/pod-coverage.t
t/pod.t
SNMP-Simple-0.02/META.yml000064400000000000000000000005331174522217200147120ustar00rootroot00000000000000# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: SNMP-Simple
version: 0.02
version_from: lib/SNMP/Simple.pm
installdirs: site
requires:
SNMP: 5.1.2

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
SNMP-Simple-0.02/Makefile.PL000064400000000000000000000005371174522217200154170ustar00rootroot00000000000000use ExtUtils::MakeMaker;

WriteMakefile(
'NAME' => 'SNMP::Simple',
'ABSTRACT_FROM' => 'lib/SNMP/Simple.pm',
'VERSION_FROM' => 'lib/SNMP/Simple.pm',
'AUTHOR' => 'Ian Langworth <ian@cpan.org>',
dist => { 'PREOP' => 'pod2text lib/SNMP/Simple.pm >README' },
'PREREQ_PM' => { 'SNMP' => '5.1.2' },
);
SNMP-Simple-0.02/README000064400000000000000000000127721174522217200143310ustar00rootroot00000000000000NAME
SNMP::Simple - shortcuts for when using SNMP

SYNOPSIS
use SNMP::Simple;

$name = $s->get('sysName'); # same as sysName.0
$location = $s->get('sysLocation');

@array = $s->get_list('hrPrinterStatus');
$arrayref = $s->get_list('hrPrinterStatus');

@list_of_lists = $s->get_table(
qw(
prtConsoleOnTime
prtConsoleColor
prtConsoleDescription
)
);

@list_of_hashes = $s->get_named_table(
name => 'prtInputDescription',
media => 'prtInputMediaName',
status => 'prtInputStatus',
level => 'prtInputCurrentLevel',
max => 'prtInputMaxCapacity',
);

DESCRIPTION
This module provides shortcuts when performing repetitive
information-retrieval tasks with SNMP.

Instead of this:

use SNMP;
$vars = new SNMP::VarList( ['prtConsoleOnTime'], ['prtConsoleColor'],
['prtConsoleDescription'], );
my ( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
push @{ $data{lights} },
{
status => ( $light_status ? 0 : 1 ),
color => SNMP::mapEnum( $$vars[1]->tag, $light_color ),
description => $light_desc,
};
( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
}

...you can do this:

use SNMP::Simple;
$data{lights} = $s->get_named_table(
status => 'prtConsoleOnTime',
color => 'prtConsoleColor',
name => 'prtConsoleDescription',
);

SNMP Beginners, read me first!
Please, please, please do not use this module as a starting point for
working with SNMP and Perl. Look elsewhere for starting resources:

* The SNMP module
* The Net-SNMP web site (<http://www.net-snmp.org/>) and tutorial
(<http://www.net-snmp.org/tutorial-5/>)
* Appendix E of Perl for System Administration
(<http://www.amazon.com/exec/obidos/tg/detail/-/1565926099>) by David N.
Blank-Edelman

SNMP Advanced and Intermediate users, read me first!
I'll admit this is a complete slaughtering of SNMP, but my goals were
precise. If you think SNMP::Simple could be refined in any way, feel
free to send me suggestions/fixes/patches.

METHODS
new( @args )
Creates a new SNMP::Simple object. Arguments given are passed directly
to "SNMP::Session->new". See "SNMP::Session" in SNMP for details.

Example:

use SNMP::Simple

my $s = SNMP::Simple->new(
DestHost => 'host.example.com',
Community => 'public',
Version => 1,
) or die "couldn't create session";

...

get( $oid )
Gets the named variable and returns its value. If no value is returned,
"get()" will try to retrieve a list named $name and return its first
vlaue. Thus, for convenience,

$s->get('sysDescr')

..should be the same as:

$s->get('sysDescr.0')

Numbered OIDs are fine, too, with or without a leading dot:

$s->get('1.3.6.1.2.1.1.1.0')

"SNMP::mapEnum()" is automatically used on the result.

get_list( $oid )
Returns leaves of the given OID.

If called in array context, returns an array. If called in scalar
context, returns an array reference.

get_table( @oids )
Given a list of OIDs, this will return a list of lists of all of the
values of the table.

For example, to get a list of all known network interfaces on a machine
and their status:

$s->get_table('ifDescr', 'ifOperStatus')

Would return something like the following:

[ 'lo', 'up' ],
[ 'eth0', 'down' ],
[ 'eth1', 'up' ],
[ 'sit0', 'down' ]

If called in array context, returns an array (of arrays). If called in
scalar context, returns an array reference.

get_named_table( %oids_by_alias )
Like "get_table", but lets you rename ugly OID names on the fly. To get
a list of all known network interfaces on a machine and their status:

$s->get_table( name => 'ifDescr', status => 'ifOperStatus' )

Would return something like the following:

{
status => 'up',
name => 'lo'
},
{
status => 'down',
name => 'eth0'
},
{
status => 'up',
name => 'eth1'
},
{
status => 'down',
name => 'sit0'
}

If called in array context, returns an array (of hashes). If called in
scalar context, returns an array reference.

EXAMPLES
A sample script examples/printerstats.pl is included with this
distribution.

SEE ALSO
SNMP

AUTHOR
Ian Langworth, "<ian@cpan.org>"

BUGS
* There are no real tests.
* I haven't tested this with v3.

Please report any bugs or feature requests to
"bug-snmp-simple@rt.cpan.org", or through the web interface at
<http://rt.cpan.org>. I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE
Copyright 2005 Ian Langworth, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

SNMP-Simple-0.02/SIGNATURE000064400000000000000000000026221174522217200147260ustar00rootroot00000000000000This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.50.

To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:

% cpansign -v

It will check each file's integrity, as well as the signature's
validity. If "==> Signature verified OK! <==" is not displayed,
the distribution may already have been compromised, and you should
not run its Makefile.PL or Build.PL.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SHA1 7fd1daf575e9d6b375fe6c60c8f1fdf509eb812f .releaserc
SHA1 34747060e9ea044e72e15641f9beb7c34c5cedb6 Changes
SHA1 50f15ae881bd393bc53f426f09c27b55e1a1d30d MANIFEST
SHA1 ba6aac2df6dab1db58f1ba9a43b2fd773043fa5c META.yml
SHA1 2cce41ee4f1ab09364fb837407927b1e2239a8e0 Makefile.PL
SHA1 bcbea9374c7588bb58116231574079e3cdffd3c4 README
SHA1 a08471968f6fa5c7a0aca6315616b0c6804bf967 examples/printerstats.pl
SHA1 27b312fa9d213758cc8721c66e11ac19f31dbbe0 lib/SNMP/Simple.pm
SHA1 fba73d30aa3fbe2204e6aa9d54c04b4d608b09c6 t/0-signature.t
SHA1 49b8c0b75e30143e3d3499a73aa2733ddffe5749 t/basic.t
SHA1 5e58be15e8a88509938d1bf2a0621dc203281a4e t/pod-coverage.t
SHA1 0190346d7072d458c8a10a45c19f86db641dcc48 t/pod.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDk6utL3e/8OaAfH4RAs3YAKCT97dG5rez79LOLLj2UZhmseAk/QCfTyxF
HbQx1+iLbci812Vb35K+DWM=
=LQV1
-----END PGP SIGNATURE-----
SNMP-Simple-0.02/examples/000075500000000000000000000000001174522217200152565ustar00rootroot00000000000000SNMP-Simple-0.02/examples/printerstats.pl000064400000000000000000000101651174522217200203600ustar00rootroot00000000000000#!/usr/bin/env perl
use strict;
use warnings;

my @PRINTERS = qw( printer1 printer2 etc );

use SNMP::Simple;

BEGIN {
eval {
require Net::Ping;
require Template;
};
die "This script requires Net::Ping and Template, though
they're not listed as SNMP::Simple's dependancies.\n" if $@;
}

use Net::Ping;
use Template;

$ENV{MIBS} = 'Printer-MIB';

my @printer_data = ();
foreach my $host (@PRINTERS) {
print STDERR "- querying $host...\n";

my %data = ();

unless ( Net::Ping->new->ping( $host, 1 ) ) {
warn "Couldn't ping $host\n";
next;
}

my $s = SNMP::Simple->new(
DestHost => $host,
Community => 'public',
Version => 1,
);
warn "No session for $host" && next unless $s;

$data{name} = $s->get('sysName');
$data{location} = $s->get('sysLocation');
$data{status} = [ $s->get_list('hrPrinterStatus') ]->[0];
$data{model} = [ $s->get_list('hrDeviceDescr') ]->[0];

$data{messages} = $s->get_list('prtConsoleDisplayBufferText');

$data{lights} = $s->get_named_table(
status => 'prtConsoleOnTime',
color => 'prtConsoleColor',
name => 'prtConsoleDescription',
);
$data{trays} = $s->get_named_table(
name => 'prtInputDescription',
media => 'prtInputMediaName',
status => 'prtInputStatus',
level => 'prtInputCurrentLevel',
max => 'prtInputMaxCapacity',
);
$data{supplies} = $s->get_named_table(
name => 'prtMarkerSuppliesMarkerIndex',
type => 'prtMarkerSuppliesType',
description => 'prtMarkerSuppliesDescription',
level => 'prtMarkerSuppliesLevel',
max => 'prtMarkerSuppliesMaxCapacity',
units => 'prtMarkerSuppliesSupplyUnit',
);

push @printer_data, \%data;
}

my $tt = Template->new();
$tt->process( \*DATA, { printers => \@printer_data } ) or die $tt->error;

__DATA__
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="60; url=http://me/printers.html"/>
<title>CCIS Printers</title>
<style type="text/css">
.okay {
background: #9f9;
}
.warning {
background: #ff9;
}
.alert {
background: #f99;
}
.offline {
color: #999;
}
</style>
</head>
<body>
<table cellpadding="10" cellspacing="0" border="1" align="left">
<tr style="background:#eee">
<th>Name &amp; Info</th>
<th>Console</th>
<th>Status Lights</tt>
<th>Paper</tt>
<th>Ink</tt>
</tr>
[% FOREACH printer = printers %]
<tr>
<td>
<h2>[% printer.name %]</h2>
<p>[% printer.model %],<br/>[% printer.location %]</p>
</td>

<td style="background:#000;color:#0F0;white-space:nowrap"><code>
[% FOREACH msg = printer.messages %]
[% msg %]<br/>
[% END %]
</code></td>

<td>
<h3>[% printer.status %]</h3>
<p>
[% FOREACH light = printer.lights %]
[% IF light.status %]
<span style="background:[% light.color %];
color:black;
font-weight:bold;">
[% light.name %]
</span>
[% ELSE %]
<span class="offline">
[% light.name %]
</span>
[% END %]
<br/>
[% END %]
</p>
</td>

<td>
[% FOREACH tray = printer.trays %]
[% IF tray.level <= 0 %]
<span class="warning">
[% ELSE %]
<span class="okay">
[% END %]
<em>[% tray.name %]</em>:
[% tray.media %], [% tray.status %],
[% tray.level %]/[% tray.max %]
</span>
<br/>

[% END %]
</td>

<td>
[% FOREACH supply = printer.supplies %]
<em>Supply [% supply.name %]</em>:
[% supply.type %],
[% supply.level %]/[% supply.max %] [% supply.units %]
<br/>
<small>([% supply.description %])<small>
<br/>
[% END %]
</td>

</tr>
[% END %]
</table>
</body>
</html>

SNMP-Simple-0.02/lib/000075500000000000000000000000001174522217200142065ustar00rootroot00000000000000SNMP-Simple-0.02/lib/SNMP/000075500000000000000000000000001174522217200147635ustar00rootroot00000000000000SNMP-Simple-0.02/lib/SNMP/Simple.pm000064400000000000000000000162261174522217200165610ustar00rootroot00000000000000package SNMP::Simple;
use strict;
use warnings;

use Carp;

=head1 NAME

SNMP::Simple - shortcuts for when using SNMP

=cut

our $VERSION = 0.02;

use SNMP;

$SNMP::use_enums = 1; # can be overridden with new(UseEnums=>0)

=head1 SYNOPSIS

use SNMP::Simple;

$name = $s->get('sysName'); # same as sysName.0
$location = $s->get('sysLocation');

@array = $s->get_list('hrPrinterStatus');
$arrayref = $s->get_list('hrPrinterStatus');

@list_of_lists = $s->get_table(
qw(
prtConsoleOnTime
prtConsoleColor
prtConsoleDescription
)
);

@list_of_hashes = $s->get_named_table(
name => 'prtInputDescription',
media => 'prtInputMediaName',
status => 'prtInputStatus',
level => 'prtInputCurrentLevel',
max => 'prtInputMaxCapacity',
);

=head1 DESCRIPTION

This module provides shortcuts when performing repetitive information-retrieval
tasks with L<SNMP>.

Instead of this:

use SNMP;
$vars = new SNMP::VarList( ['prtConsoleOnTime'], ['prtConsoleColor'],
['prtConsoleDescription'], );
my ( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
push @{ $data{lights} },
{
status => ( $light_status ? 0 : 1 ),
color => SNMP::mapEnum( $$vars[1]->tag, $light_color ),
description => $light_desc,
};
( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
}

...you can do this:

use SNMP::Simple;
$data{lights} = $s->get_named_table(
status => 'prtConsoleOnTime',
color => 'prtConsoleColor',
name => 'prtConsoleDescription',
);

=head2 SNMP Beginners, read me first!

Please, please, B<please> do not use this module as a starting point for
working with SNMP and Perl. Look elsewhere for starting resources:

=over 4

=item * The L<SNMP> module

=item * The Net-SNMP web site (L<http://www.net-snmp.org/>) and tutorial (L<http://www.net-snmp.org/tutorial-5/>)

=item * Appendix E of Perl for System Administration (L<http://www.amazon.com/exec/obidos/tg/detail/-/1565926099>) by David N. Blank-Edelman

=back

=head2 SNMP Advanced and Intermediate users, read me first!

I'll admit this is a complete slaughtering of SNMP, but my goals were precise.
If you think SNMP::Simple could be refined in any way, feel free to send me
suggestions/fixes/patches.

=cut

=head1 METHODS

=head2 new( @args )

Creates a new SNMP::Simple object. Arguments given are passed directly to
C<SNMP::Session-E<gt>new>. See L<SNMP/"SNMP::Session"> for details.

Example:

use SNMP::Simple

my $s = SNMP::Simple->new(
DestHost => 'host.example.com',
Community => 'public',
Version => 1,
) or die "couldn't create session";

...

=cut

sub new {
my ( $class, @args ) = @_;
my $session = SNMP::Session->new(@args)
or croak "Couldn't create session";
bless \$session, $class;
}

=head2 get( $oid )

Gets the named variable and returns its value. If no value is returned,
C<get()> will try to retrieve a list named C<$name> and return its first vlaue.
Thus, for convenience,

$s->get('sysDescr')

..should be the same as:

$s->get('sysDescr.0')

Numbered OIDs are fine, too, with or without a leading dot:

$s->get('1.3.6.1.2.1.1.1.0')

C<SNMP::mapEnum()> is automatically used on the result.

=cut

sub get {
my ( $self, $name ) = @_;
my $result = $$self->get($name) || ( $self->get_list($name) )[0];
my $enum = SNMP::mapEnum( $name, $result );
return defined $enum ? $enum : $result;
}

=head2 get_list( $oid )

Returns leaves of the given OID.

If called in array context, returns an array. If called in scalar context,
returns an array reference.

=cut

sub get_list {
my ( $self, $oid ) = @_;
my @table = $self->get_table($oid);
my @output = map { $_->[0] } @table;
return wantarray ? @output : \@output;
}

=head2 get_table( @oids )

Given a list of OIDs, this will return a list of lists of all of the values of
the table.

For example, to get a list of all known network interfaces on a machine and
their status:

$s->get_table('ifDescr', 'ifOperStatus')

Would return something like the following:

[ 'lo', 'up' ],
[ 'eth0', 'down' ],
[ 'eth1', 'up' ],
[ 'sit0', 'down' ]

If called in array context, returns an array (of arrays). If called in scalar
context, returns an array reference.

=cut

sub get_table {
my ( $self, @oids ) = @_;
my @output = ();

# build our varlist, the fun VarList way
my $vars = new SNMP::VarList( map { [$_] } @oids );

# get our initial results, assume that we should be able to get at least
# *one* row back
my @results = $$self->getnext($vars);
croak $$self->{ErrorStr} if $$self->{ErrorStr};

# dNb's recipe for iteration: make sure that there's no error and that the
# OID name of the first cell is actually what we want
while ( !$$self->{ErrorStr} and $$vars[0]->tag eq $oids[0] ) {
push @output, [@results];
@results = $$self->getnext($vars);
}

return wantarray ? @output : \@output;
}

=head2 get_named_table( %oids_by_alias )

Like L<"get_table">, but lets you rename ugly OID names on the fly. To get
a list of all known network interfaces on a machine and their status:

$s->get_table( name => 'ifDescr', status => 'ifOperStatus' )

Would return something like the following:

{
status => 'up',
name => 'lo'
},
{
status => 'down',
name => 'eth0'
},
{
status => 'up',
name => 'eth1'
},
{
status => 'down',
name => 'sit0'
}

If called in array context, returns an array (of hashes). If called in scalar
context, returns an array reference.

=cut

sub get_named_table {
my $self = shift;
my %oid_to_name = reverse @_;
my @oids = keys %oid_to_name;

# remap table so it's a list of hashes instead of a list of lists
my @table = $self->get_table( keys %oid_to_name );
my @output;
foreach my $row (@table) {
my %data = ();
for ( my $i = 0; $i < @oids; $i++ ) {
$data{ $oid_to_name{ $oids[$i] } } = $row->[$i];
}
push @output, \%data;
}

return wantarray ? @output : \@output;
}

=head1 EXAMPLES

A sample script F<examples/printerstats.pl> is included with this distribution.

=head1 SEE ALSO

L<SNMP>

=head1 AUTHOR

Ian Langworth, C<< <ian@cpan.org> >>

=head1 BUGS

=over 4

=item * There are no real tests.

=item * I haven't tested this with v3.

=back

Please report any bugs or feature requests to
C<bug-snmp-simple@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>. I will be notified, and then you'll automatically be
notified of progress on your bug as I make changes.

=head1 COPYRIGHT & LICENSE

Copyright 2005 Ian Langworth, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

=cut

1;
SNMP-Simple-0.02/t/000075500000000000000000000000001174522217200137035ustar00rootroot00000000000000SNMP-Simple-0.02/t/0-signature.t000064400000000000000000000011551174522217200162300ustar00rootroot00000000000000#!/usr/bin/perl
use strict;
print "1..1\n";

if ( !-s 'SIGNATURE' ) {
print "ok 1 # skip No signature file found\n";
}
elsif ( !eval { require Module::Signature; 1 } ) {
print "ok 1 # skip ",
"Next time around, consider install Module::Signature, ",
"so you can verify the integrity of this distribution.\n";
}
elsif ( !eval { require Socket; Socket::inet_aton('pgp.mit.edu') } ) {
print "ok 1 # skip Cannot connect to the keyserver\n";
}
else {
( Module::Signature::verify() == Module::Signature::SIGNATURE_OK() )
or print "not ";
print "ok 1 # Valid signature\n";
}

__END__
SNMP-Simple-0.02/t/basic.t000064400000000000000000000001421174522217200151460ustar00rootroot00000000000000use Test;
BEGIN { plan tests => 1 };
use SNMP::Simple;
ok(1); # If we made it this far, we're ok.
SNMP-Simple-0.02/t/pod-coverage.t000064400000000000000000000003311174522217200164400ustar00rootroot00000000000000#!perl -T

use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan $@
? (
skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" )
: ( tests => 1 );

pod_coverage_ok( 'SNMP::Simple' );
SNMP-Simple-0.02/t/pod.t000064400000000000000000000002141174522217200146470ustar00rootroot00000000000000#!perl -T

use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
all_pod_files_ok();
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin