Changeset 898

Show
Ignore:
Timestamp:
04/04/05 05:12:48 (7 years ago)
Author:
ilmari
Message:

Convert generic/snmpif(_err) to Munin::Plugin::SNMP.

Files:

Legend:

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

    r864 r898  
    8484 
    8585use strict; 
    86 use Net::SNMP; 
     86use Munin::Plugin::SNMP; 
    8787 
    8888my $DEBUG = 0; 
    89  
    90 my $host      = $ENV{host}      || undef; 
    91 my $port      = $ENV{port}      || 161; 
    92 my $community = $ENV{community} || "public"; 
    93 my $iface     = $ENV{interface} || undef; 
    9489 
    9590my $response; 
     
    10499} 
    105100 
    106 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_(.+)$/) 
    107 
    108         $host  = $1; 
    109         $iface = $2; 
    110         if ($host =~ /^([^:]+):(\d+)$/) 
    111         { 
    112                 $host = $1; 
    113                 $port = $2; 
    114         } 
    115 
    116 elsif (!defined($host)) 
    117 
    118         print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; 
    119         die "# Error: couldn't understand what I'm supposed to monitor."; 
    120 
    121  
    122 my $ifEntryDescr     = "1.3.6.1.2.1.2.2.1.2.$iface";  
    123 my $ifEntrySpeed     = "1.3.6.1.2.1.2.2.1.5.$iface"; 
    124 my $ifEntryStatus    = "1.3.6.1.2.1.2.2.1.8.$iface"; 
    125 my $ifEntryInOctets  = "1.3.6.1.2.1.2.2.1.10.$iface"; 
    126 my $ifEntryOutOctets = "1.3.6.1.2.1.2.2.1.16.$iface"; 
    127  
    128 my ($session, $error) = Net::SNMP->session( 
    129                 -hostname  => $host, 
    130                 -community => $community, 
    131                 -port      => $port 
    132         ); 
     101my ($session, $error) = Munin::Plugin::SNMP->session(); 
    133102 
    134103if (!defined ($session)) 
     
    137106} 
    138107 
     108my $iface = $session->args()->[0] || $ENV{interface}; 
     109 
     110die "# No interface specified\n" unless length $iface; 
     111 
     112my $info = $session->get_hash(-baseoid => "1.3.6.1.2.1.2.2.1", 
     113                              -rows   => [ $iface ], 
     114                              -cols    => { 
     115                                           2 => 'descr', 
     116                                           5 => 'speed', 
     117                                           8 => 'status', 
     118                                           10 => 'recv', 
     119                                           16 => 'send', 
     120                                          }, 
     121                             ) 
     122  or die "# Can't get interface info\n"; 
     123 
     124$info = $info->{$iface}; 
     125 
    139126if ($ARGV[0] and $ARGV[0] eq "config") 
    140127{ 
    141         print "host_name $host\n"; 
    142         if (!defined ($response = $session->get_request($ifEntryDescr))) 
    143         { 
    144                 die "Croaking: " . $session->error(); 
    145         } 
    146         my $name = $response->{$ifEntryDescr}; 
     128        print 'host_name ', $session->hostname(), "\n"; 
     129        my $name = $info->{'descr'}; 
    147130        $name =~ s/[^\w\s]//g; 
    148131        my $warn = undef; 
    149         if (defined ($response = $session->get_request($ifEntrySpeed))
     132        if (defined $info->{'speed'}
    150133        { 
    151                 $warn = $response->{$ifEntrySpeed}/8; 
     134                $warn = $info->{'speed'}/8; 
    152135        } 
    153136        if (length ($name) > 15) 
     
    182165} 
    183166 
    184 my $status = 1; 
    185 if (defined ($response = $session->get_request($ifEntryStatus))) 
    186 
    187         $status = $response->{$ifEntryStatus}; 
    188 
    189  
    190 if ($status == 2) 
     167if ($info->{'status'} == 2) 
    191168{ 
    192169        print "recv.value U\n"; 
     
    195172} 
    196173 
    197 if (defined ($response = $session->get_request($ifEntryInOctets))) 
     174for my $key (qw(recv send)) 
    198175{ 
    199         print "recv.value ", $response->{$ifEntryInOctets}, "\n"; 
     176    if (defined $info->{$key}) 
     177    { 
     178        print "$key.value ", $info->{$key}, "\n"; 
     179    } 
     180    else 
     181    { 
     182        print "$key.value U\n"; 
     183    } 
    200184} 
    201 else 
    202 { 
    203         print "recv.value U\n"; 
    204 } 
    205  
    206 if (defined ($response = $session->get_request($ifEntryOutOctets))) 
    207 { 
    208         print "send.value ", $response->{$ifEntryOutOctets}, "\n"; 
    209 } 
    210 else 
    211 { 
    212         print "send.value U\n"; 
    213 } 
  • people/ilmari/modularisation-branch/node/node.d/snmp__if_err_.in

    r864 r898  
    8787 
    8888use strict; 
    89 use Net::SNMP; 
     89use Munin::Plugin::SNMP; 
    9090 
    9191my $DEBUG = 0; 
    92  
    93 my $host      = $ENV{host}      || undef; 
    94 my $port      = $ENV{port}      || 161; 
    95 my $community = $ENV{community} || "public"; 
    96 my $iface     = $ENV{interface} || undef; 
    9792 
    9893my $response; 
     
    107102} 
    108103 
    109 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_err_(.+)$/) 
    110 
    111         $host  = $1; 
    112         $iface = $2; 
    113         if ($host =~ /^([^:]+):(\d+)$/) 
    114         { 
    115                 $host = $1; 
    116                 $port = $2; 
    117         } 
    118 
    119 elsif (!defined($host)) 
    120 
    121         print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; 
    122         die "# Error: couldn't understand what I'm supposed to monitor."; 
    123 
    124  
    125 my $ifEntryDescr     = "1.3.6.1.2.1.2.2.1.2.$iface";  
    126 my $ifEntrySpeed     = "1.3.6.1.2.1.2.2.1.5.$iface"; 
    127 my $ifEntryStatus    = "1.3.6.1.2.1.2.2.1.8.$iface"; 
    128 my $ifEntryInErrors  = "1.3.6.1.2.1.2.2.1.14.$iface"; 
    129 my $ifEntryOutErrors = "1.3.6.1.2.1.2.2.1.20.$iface"; 
    130  
    131 my ($session, $error) = Net::SNMP->session( 
    132                 -hostname  => $host, 
    133                 -community => $community, 
    134                 -port      => $port 
    135         ); 
     104my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'if_err'); 
    136105 
    137106if (!defined ($session)) 
     
    140109} 
    141110 
     111my $iface = $session->args()->[0] || $ENV{interface}; 
     112 
     113die "# No interface specified\n" unless length $iface; 
     114 
     115my $info = $session->get_hash(-baseoid => "1.3.6.1.2.1.2.2.1", 
     116                              -rows   => [ $iface ], 
     117                              -cols    => { 
     118                                           2 => 'descr', 
     119                                           5 => 'speed', 
     120                                           8 => 'status', 
     121                                           14 => 'recv', 
     122                                           20 => 'send', 
     123                                          }, 
     124                             ) 
     125  or die "# Can't get interface info\n"; 
     126 
     127$info = $info->{$iface}; 
     128 
    142129if ($ARGV[0] and $ARGV[0] eq "config") 
    143130{ 
    144         print "host_name $host\n"; 
    145         if (!defined ($response = $session->get_request($ifEntryDescr))) 
    146         { 
    147                 die "Croaking: " . $session->error(); 
    148         } 
    149         my $name = $response->{$ifEntryDescr}; 
     131        print 'host_name ', $session->hostname(), "\n"; 
     132        my $name = $info->{'descr'}; 
    150133        $name =~ s/[^\w\s]//g; 
    151134        my $warn = undef; 
    152         if (defined ($response = $session->get_request($ifEntrySpeed))
     135        if (defined $info->{'speed'}
    153136        { 
    154                 $warn = $response->{$ifEntrySpeed}/8; 
     137                $warn = $info->{'speed'}/8; 
    155138        } 
    156139        if (length ($name) > 15) 
     
    185168} 
    186169 
    187 my $status = 1; 
    188 if (defined ($response = $session->get_request($ifEntryStatus))) 
    189 
    190         $status = $response->{$ifEntryStatus}; 
    191 
    192  
    193 if ($status == 2) 
     170if ($info->{'status'} == 2) 
    194171{ 
    195172        print "recv.value U\n"; 
     
    198175} 
    199176 
    200 if (defined ($response = $session->get_request($ifEntryInErrors))) 
     177for my $key (qw(recv send)) 
    201178{ 
    202         print "recv.value ", $response->{$ifEntryInErrors}, "\n"; 
     179    if (defined $info->{$key}) 
     180    { 
     181        print "$key.value ", $info->{$key}, "\n"; 
     182    } 
     183    else 
     184    { 
     185        print "$key.value U\n"; 
     186    } 
    203187} 
    204 else 
    205 { 
    206         print "recv.value U\n"; 
    207 } 
    208  
    209 if (defined ($response = $session->get_request($ifEntryOutErrors))) 
    210 { 
    211         print "send.value ", $response->{$ifEntryOutErrors}, "\n"; 
    212 } 
    213 else 
    214 { 
    215         print "send.value U\n"; 
    216 }