Changeset 897

Show
Ignore:
Timestamp:
04/04/05 05:09:56 (7 years ago)
Author:
ilmari
Message:

Add an args() method to Munin::Plugin::SNMP for getting symlink name
arguments.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • people/ilmari/modularisation-branch/node/SNMP.pm.in

    r896 r897  
    7171sub session { 
    7272    my $class = shift; 
     73    my %args = @_; 
    7374    my $host      = $ENV{host}      || undef; 
    7475    my $port      = $ENV{port}      || 161; 
     
    8788    } 
    8889 
    89     return $class->SUPER::session(-hostname  => $host, 
    90                                   -community => $community, 
    91                                   -port      => $port, 
    92                                   ($version ? (-version => $version) : ())); 
     90    my $self = $class->SUPER::session(-hostname  => $host, 
     91                                      -community => $community, 
     92                                      -port      => $port, 
     93                                      ($version ? (-version => $version) : ())); 
     94 
     95    $self->{_munin_args} = \%args; 
     96    return $self; 
     97
     98 
     99=head2 args() - get plugin commandline arguments 
     100 
     101  $args = $session->args(); 
     102 
     103This method returns command line (symlink name) arguments for the 
     104plugin. 
     105 
     106The plugin name is taken from the C<-name> argument to C<session()> or 
     107assumed to be a single word if unspecified. 
     108 
     109=cut 
     110 
     111sub args { 
     112    my $self = shift; 
     113    my $n = shift; 
     114    my $args = $self->{'_munin_args'}; 
     115    my $name = $args->{'-name'}; 
     116 
     117    if (!exists $args->{'_args'}) { 
     118        if (defined $name) { 
     119            $re = qr/^(?:.*\/)?snmp_(?:[^_]*)_\Q$name\E_(.*)/; 
     120        } else { 
     121            $re = qr/^(?:.*\/)?snmp_(?:[^_]*)_[^_]+_(.*)/; 
     122        } 
     123 
     124        if ($0 =~ $re) { 
     125            $args->{'_args'} = [ split('_', $1) ]; 
     126        } else { 
     127            $args->{'_args'} = []; 
     128        } 
     129    }     
     130     
     131    return $args->{'_args'}; 
    93132} 
    94133