Changeset 903

Show
Ignore:
Timestamp:
04/04/05 22:08:32 (7 years ago)
Author:
ilmari
Message:

Convert the remaining plugins to Munin::Plugin::SNMP

Files:

Legend:

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

    r864 r903  
    6868 
    6969use strict; 
    70 use Net::SNMP; 
     70use Munin::Plugin::SNMP; 
    7171 
    7272my $DEBUG = 0; 
    7373my $MAXLABEL = 20; 
    74  
    75 my $host      = $ENV{host}      || undef; 
    76 my $port      = $ENV{port}      || 161; 
    77 my $community = $ENV{community} || "public"; 
    78 my $iface     = $ENV{interface} || undef; 
    7974 
    8075my $response; 
     
    8681        print "require 1.3.6.1.2.1.25.2.3.1.5. [1-9]\n"; # Size > 0 
    8782        exit 0; 
    88 } 
    89  
    90 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_df$/) 
    91 { 
    92         $host  = $1; 
    93         if ($host =~ /^([^:]+):(\d+)$/) 
    94         { 
    95                 $host = $1; 
    96                 $port = $2; 
    97         } 
    98 } 
    99 elsif (!defined($host)) 
    100 { 
    101         print "# Debug: $0 -- $1\n" if $DEBUG; 
    102         die "# Error: couldn't understand what I'm supposed to monitor."; 
    10383} 
    10484 
     
    120100 
    121101 
    122 my ($session, $error) = Net::SNMP->session( 
    123                 -hostname  => $host, 
    124                 -community => $community, 
    125                 -port      => $port 
    126         ); 
     102my ($session, $error) = Munin::Plugin::SNMP->session(); 
    127103 
    128104if (!defined ($session)) 
     
    193169if (defined $ARGV[0] and $ARGV[0] eq "config") 
    194170{ 
    195         print "host_name $host\n"; 
     171        print "host_name ", $session->hostname(), "\n"; 
    196172        print "graph_title Filesystem usage (in %)\n"; 
    197173        print "graph_args --upper-limit 100 -l 0\n"; 
  • people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_.in

    r864 r903  
    7575 
    7676use strict; 
    77 use Net::SNMP; 
     77use Munin::Plugin::SNMP; 
    7878 
    7979my $DEBUG = 0; 
    80  
    81 my $host      = $ENV{host}      || undef; 
    82 my $port      = $ENV{port}      || 161; 
    83 my $community = $ENV{community} || "public"; 
    84 my $iface     = $ENV{interface} || undef; 
    8580 
    8681my $response; 
     
    9590} 
    9691 
    97 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_fc_if_(.+)$/) 
    98 
    99         $host  = $1; 
    100         $iface = $2; 
    101         if ($host =~ /^([^:]+):(\d+)$/) 
    102         { 
    103                 $host = $1; 
    104                 $port = $2; 
    105         } 
    106 
    107 elsif (!defined($host)) 
    108 
    109         print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; 
    110         die "# Error: couldn't understand what I'm supposed to monitor."; 
    111 
     92my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'fc_if'); 
     93 
     94my $iface = $session->args()->[0] || $ENV{interface}; 
    11295 
    11396my $fcEntryDescr     = "1.3.6.1.2.1.8888.1.1.6.1.16.16.0.8.0.136.3.52.64.0.0.0.0.0.0.0.0.$iface";  
     
    118101my $fcPhysPort       = "1.3.6.1.2.1.8888.1.1.6.1.17.16.0.8.0.136.3.52.64.0.0.0.0.0.0.0.0.$iface"; 
    119102 
    120 my ($session, $error) = Net::SNMP->session( 
    121                 -hostname  => $host, 
    122                 -community => $community, 
    123                 -port      => $port, 
    124                 -version   => "2c" 
    125         ); 
    126  
    127103if (!defined ($session)) 
    128104{ 
     
    132108if ($ARGV[0] and $ARGV[0] eq "config") 
    133109{ 
    134         print "host_name $host\n"; 
     110        print "host_name ", $session->hostname(), "\n"; 
    135111        if (!defined ($response = $session->get_request($fcEntryDescr))) 
    136112        { 
  • people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_err_.in

    r864 r903  
    7575 
    7676use strict; 
    77 use Net::SNMP; 
     77use Munin::Plugin::SNMP; 
    7878 
    7979my $DEBUG = 0; 
    80  
    81 my $host      = $ENV{host}      || undef; 
    82 my $port      = $ENV{port}      || 161; 
    83 my $community = $ENV{community} || "public"; 
    84 my $iface     = $ENV{interface} || undef; 
    8580 
    8681my $response; 
     
    9590} 
    9691 
    97 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_fc_if_err_(.+)$/) 
    98 
    99         $host  = $1; 
    100         $iface = $2; 
    101         if ($host =~ /^([^:]+):(\d+)$/) 
    102         { 
    103                 $host = $1; 
    104                 $port = $2; 
    105         } 
    106 
    107 elsif (!defined($host)) 
    108 
    109         print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; 
    110         die "# Error: couldn't understand what I'm supposed to monitor."; 
    111 
     92my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'fc_if_err'); 
     93 
     94my $iface = $session->args()->[0] || $ENV{interface}; 
    11295 
    11396my $fcEntryDescr     = "1.3.6.1.2.1.8888.1.1.6.1.16.16.0.8.0.136.3.52.64.0.0.0.0.0.0.0.0.$iface";  
     
    11699my $fcEntryErrs      = "1.3.6.1.2.1.8888.1.3.1.1.2.16.0.8.0.136.3.52.64.0.0.0.0.0.0.0.0.$iface"; 
    117100my $fcPhysPort       = "1.3.6.1.2.1.8888.1.1.6.1.17.16.0.8.0.136.3.52.64.0.0.0.0.0.0.0.0.$iface"; 
    118  
    119 my ($session, $error) = Net::SNMP->session( 
    120                 -hostname  => $host, 
    121                 -community => $community, 
    122                 -port      => $port, 
    123                 -version   => "2c" 
    124         ); 
    125101 
    126102if (!defined ($session)) 
     
    131107if ($ARGV[0] and $ARGV[0] eq "config") 
    132108{ 
    133         print "host_name $host\n"; 
     109        print "host_name ", $session->hostname(), "\n"; 
    134110        if (!defined ($response = $session->get_request($fcEntryDescr))) 
    135111        { 
  • people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_fan.in

    r864 r903  
    4343 
    4444use strict; 
    45 use Net::SNMP; 
     45use Munin::Plugin::SNMP; 
    4646 
    4747my $DEBUG = 0; 
    4848my $MAXLABEL = 20; 
    4949 
    50 my $host      = $ENV{host}      || undef; 
    51 my $port      = $ENV{port}      || 161; 
    52 my $community = $ENV{community} || "public"; 
    53  
    54 my $response; 
     50my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 
    5551 
    5652if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    5753{ 
    58         print "index   1.3.6.1.4.1.9600.1.10.6.1.1.\n"; 
    59         print "require 1.3.6.1.4.1.9600.1.10.6.1.3. 3\n"; # Type=fan 
    60         print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 0 
    61         print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 0 
     54        print "index   $mbmSensorBase.1.\n"; 
     55        print "require $mbmSensorBase.3. 3\n"; # Type=fan 
     56        print "require $mbmSensorBase.7. [1-9]\n"; # Low value != 0 
     57        print "require $mbmSensorBase.9. [1-9]\n"; # High value != 0 
    6258 
    6359        exit 0; 
    6460} 
    6561 
    66 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_sensors_mbm_fan$/) 
    67 
    68         $host  = $1; 
    69         if ($host =~ /^([^:]+):(\d+)$/) 
    70         { 
    71                 $host = $1; 
    72                 $port = $2; 
    73         } 
    74 
    75 elsif (!defined($host)) 
    76 
    77         print "# Debug: $0 -- $1\n" if $DEBUG; 
    78         die "# Error: couldn't understand what I'm supposed to monitor."; 
    79 
    80  
    81 # The OIDs we're after 
    82 my $mbmDeviceType    = "1.3.6.1.4.1.9600.1.10.6.1.3."; # Should be 3 (fan) 
    83 my $mbmHighWatermark = "1.3.6.1.4.1.9600.1.10.6.1.7."; # Should be non-zero 
    84 my $mbmLowWatermark  = "1.3.6.1.4.1.9600.1.10.6.1.9."; # Should be non-zero 
    85 my $mbmName          = "1.3.6.1.4.1.9600.1.10.6.1.2."; # Name of sensor 
    86 my $mbmValue         = "1.3.6.1.4.1.9600.1.10.6.1.6."; # Data point 
    87  
    88 my ($session, $error) = Net::SNMP->session( 
    89                 -hostname  => $host, 
    90                 -community => $community, 
    91                 -port      => $port 
    92         ); 
     62my ($session, $error) = Munin::Plugin::SNMP->session(); 
    9363 
    9464if (!defined ($session)) 
     
    9767} 
    9868 
    99 # First we want to find the harddisks... 
    100 my $correct_type      = get_by_regex ($session, $mbmDeviceType, "^3\$"); 
    101 my $correct_high      = get_by_regex ($session, $mbmHighWatermark, "[1-9]"); 
    102 my $correct_low       = get_by_regex ($session, $mbmLowWatermark, "[1-9]"); 
     69# Get sensor info 
     70my $sensors = $session->get_hash(-baseoid => '$mbmSensorBase', 
     71                                 -cols    => { 
     72                                              3 => 'type', 
     73                                              7 => 'high', 
     74                                              9 => 'low', 
     75                                              2 => 'label', 
     76                                              3 => 'value', 
     77                                             }, 
     78                                ) 
     79  or die "# Can't get sensor info\n"; 
    10380 
    104 my @keep = (); 
    105  
    106 foreach my $id (keys %$correct_type) 
     81# Only keep fan sensors with max/min values 
     82foreach my $id (keys %$sensors) 
    10783{ 
    108         if (exists $correct_high->{$id} and 
    109             exists $correct_low->{$id}) 
    110         { 
    111             push (@keep, $id); 
    112         } 
    113 
    114  
    115 my %sensors; 
    116  
    117 foreach my $kept (@keep) # For each temp sensor... 
    118 
    119     $sensors{$kept}{name} = get_single ($session, $mbmName . "$kept"); 
     84    unless ($sensors->{$id}->{type} == 3 && 
     85            $sensors->{$id}->{high} =~ /[1-9]/ && 
     86            $sensors->{$id}->{low} =~ /[1-9]/) { 
     87        delete $sensors->{$id}; 
     88    } 
     89    $sensors->{$id}->{name} = get_name_by_sensor($sensors->{$id}->{label}); 
    12090} 
    12191 
    12292if (defined $ARGV[0] and $ARGV[0] eq "config") 
    12393{ 
    124         print "host_name $host\n"; 
     94        print "host_name ", $session->hostname(), "\n"; 
    12595        print "graph_title Fan speed\n"; 
    12696        print "graph_args --upper-limit 100 -l 0\n"; 
     
    12999        print "graph_info This graph shows the rounds per minute of the fans in the machine.\n"; 
    130100 
    131         foreach my $sensor (keys %sensors) 
     101        foreach my $sensor (values %$sensors) 
    132102        { 
    133                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ")
    134                 print (length($sensors{$sensor}{name})<=$MAXLABEL ? $sensors{$sensor}{name} : "...".substr($sensors{$sensor}{name},-($MAXLABEL-3))); 
     103                print "$sensor->{name}.label "
     104                print (length($sensor->{label})<=$MAXLABEL ? $sensor->{label} : "...".substr($sensor->{label},-($MAXLABEL-3))); 
    135105                print ("\n"); 
    136                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".info RPM readout from the motherboard sensor \"$sensors{$sensor}{name}\".\n"); 
     106                print ("$sensor->{name}.info RPM readout from the motherboard sensor \"$sensor->{name}\".\n"); 
    137107        } 
    138108        exit 0; 
    139109} 
    140110 
    141 foreach my $sensor (keys %sensors) 
     111foreach my $sensor (values %$sensors) 
    142112{ 
    143     my $val = get_single ($session, $mbmValue . $sensor); 
    144     print (&get_name_by_sensor ($sensors{$sensor}{name}), ".value $val\n"); 
    145 
    146  
    147 sub get_single 
    148 
    149         my $handle = shift; 
    150         my $oid    = shift; 
    151  
    152         print "# Getting single \"$oid\"..." if $DEBUG; 
    153  
    154         $response = $handle->get_request ($oid); 
    155  
    156         if (!defined $response->{$oid}) 
    157         { 
    158             print "undef\n" if $DEBUG; 
    159             return undef; 
    160         } 
    161         else 
    162         { 
    163             print "\"$response->{$oid}\"\n" if $DEBUG; 
    164             return $response->{$oid}; 
    165         } 
    166 
    167  
    168 sub get_by_regex 
    169 
    170         my $handle = shift; 
    171         my $oid    = shift; 
    172         my $regex  = shift; 
    173         my $result = {}; 
    174         my $num    = 0; 
    175         my $ret    = $oid . "0"; 
    176         my $response; 
    177  
    178         print "# Starting browse of $oid...\n" if $DEBUG; 
    179  
    180         while (1) 
    181         { 
    182                 if ($num == 0) 
    183                 { 
    184                         print "# Checking for $ret...\n" if $DEBUG; 
    185                         $response = $handle->get_request ($ret); 
    186                 } 
    187                 if ($num or !defined $response) 
    188                 { 
    189                         print "# Checking for sibling of $ret...\n" if $DEBUG; 
    190                         $response = $handle->get_next_request ($ret); 
    191                 } 
    192                 if (!$response) 
    193                 { 
    194                         return undef; 
    195                 } 
    196                 my @keys = keys %$response; 
    197                 $ret = $keys[0]; 
    198                 print "# Analyzing $ret (compared to $oid)...\n" if $DEBUG; 
    199                 last unless ($ret =~ /^$oid/); 
    200                 $num++; 
    201                 next unless ($response->{$ret} =~ /$regex/); 
    202                 @keys = split (/\./, $ret); 
    203                 $result->{$keys[-1]} = $response->{$ret};; 
    204                 print "# Index $num: ", $keys[-1], " (", $response->{$ret}, ")\n" if $DEBUG; 
    205         }; 
    206         return $result; 
     113    print ("$sensor->{name}.value $sensor->{value}\n"); 
    207114} 
    208115 
  • people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_temp.in

    r864 r903  
    4343 
    4444use strict; 
    45 use Net::SNMP; 
     45use Munin::Plugin::SNMP; 
    4646 
    4747my $DEBUG = 0; 
    4848my $MAXLABEL = 20; 
    4949 
    50 my $host      = $ENV{host}      || undef; 
    51 my $port      = $ENV{port}      || 161; 
    52 my $community = $ENV{community} || "public"; 
    53 my $iface     = $ENV{interface} || undef; 
    54  
    55 my $response; 
     50my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 
    5651 
    5752if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    5853{ 
    59         print "index   1.3.6.1.4.1.9600.1.10.6.1.1.\n"; 
    60         print "require 1.3.6.1.4.1.9600.1.10.6.1.3. 1\n"; # Type=temperature 
    61         print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 0 
    62         print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 0 
     54        print "index   $mbmSensorBase.1.\n"; 
     55        print "require $mbmSensorBase.3. 1\n"; # Type=temperature 
     56        print "require $mbmSensorBase.7. [1-9]\n"; # Low value != 0 
     57        print "require $mbmSensorBase.9. [1-9]\n"; # High value != 0 
    6358 
    6459        exit 0; 
    6560} 
    6661 
    67 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_sensors_mbm_temp$/) 
    68 
    69         $host  = $1; 
    70         if ($host =~ /^([^:]+):(\d+)$/) 
    71         { 
    72                 $host = $1; 
    73                 $port = $2; 
    74         } 
    75 
    76 elsif (!defined($host)) 
    77 
    78         print "# Debug: $0 -- $1\n" if $DEBUG; 
    79         die "# Error: couldn't understand what I'm supposed to monitor."; 
    80 
    81  
    82 # The OIDs we're after 
    83 my $mbmDeviceType    = "1.3.6.1.4.1.9600.1.10.6.1.3."; # Should be 1 (temp) 
    84 my $mbmHighWatermark = "1.3.6.1.4.1.9600.1.10.6.1.7."; # Should be non-zero 
    85 my $mbmLowWatermark  = "1.3.6.1.4.1.9600.1.10.6.1.9."; # Should be non-zero 
    86 my $mbmName          = "1.3.6.1.4.1.9600.1.10.6.1.2."; # Name of sensor 
    87 my $mbmValue         = "1.3.6.1.4.1.9600.1.10.6.1.6."; # Data point 
    88  
    89 my ($session, $error) = Net::SNMP->session( 
    90                 -hostname  => $host, 
    91                 -community => $community, 
    92                 -port      => $port 
    93         ); 
     62my ($session, $error) = Munin::Plugin::SNMP->session(); 
    9463 
    9564if (!defined ($session)) 
     
    9867} 
    9968 
    100 # First we want to find the harddisks... 
    101 my $correct_type      = get_by_regex ($session, $mbmDeviceType, "^1\$"); 
    102 my $correct_high      = get_by_regex ($session, $mbmHighWatermark, "[1-9]"); 
    103 my $correct_low       = get_by_regex ($session, $mbmLowWatermark, "[1-9]"); 
     69# Get sensor info 
     70my $sensors = $session->get_hash(-baseoid => '$mbmSensorBase', 
     71                                 -cols    => { 
     72                                              3 => 'type', 
     73                                              7 => 'high', 
     74                                              9 => 'low', 
     75                                              2 => 'label', 
     76                                              3 => 'value', 
     77                                             }, 
     78                                ) 
     79  or die "# Can't get sensor info\n"; 
    10480 
    105 my @keep = (); 
    106  
    107 foreach my $id (keys %$correct_type) 
     81# Only keep temperature sensors with max/min values 
     82foreach my $id (keys %$sensors) 
    10883{ 
    109         if (exists $correct_high->{$id} and 
    110             exists $correct_low->{$id}) 
    111         { 
    112             push (@keep, $id); 
    113         } 
    114 
    115  
    116 my %sensors; 
    117  
    118 foreach my $kept (@keep) # For each temp sensor... 
    119 
    120     $sensors{$kept}{name} = get_single ($session, $mbmName . "$kept"); 
     84    unless ($sensors->{$id}->{type} == 1 && 
     85            $sensors->{$id}->{high} =~ /[1-9]/ && 
     86            $sensors->{$id}->{low} =~ /[1-9]/) { 
     87        delete $sensors->{$id}; 
     88    } 
     89    $sensors->{$id}->{name} = get_name_by_sensor($sensors->{$id}->{label}); 
    12190} 
    12291 
    12392if (defined $ARGV[0] and $ARGV[0] eq "config") 
    12493{ 
    125         print "host_name $host\n"; 
     94        print "host_name ", $session->hostname(), "\n"; 
    12695        print "graph_title Temperatures\n"; 
    12796        print "graph_args --upper-limit 100 -l 0\n"; 
     
    13099        print "graph_info This graph shows temperatures in the system.\n"; 
    131100 
    132         foreach my $sensor (keys %sensors) 
     101        foreach my $sensor (values %$sensors) 
    133102        { 
    134                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ")
    135                 print (length($sensors{$sensor}{name})<=$MAXLABEL ? $sensors{$sensor}{name} : "...".substr($sensors{$sensor}{name},-($MAXLABEL-3))); 
     103                print "$sensor->{name}.label "
     104                print (length($sensor->{label})<=$MAXLABEL ? $sensor->{label} : "...".substr($sensor->{label},-($MAXLABEL-3))); 
    136105                print ("\n"); 
    137                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".info Temperature readout from the motherboard sensor \"$sensors{$sensor}{name}\".\n"); 
     106                print ("$sensor->{name}.info Temperature readout from the motherboard sensor \"$sensor->{label}\".\n"); 
    138107        } 
    139108        exit 0; 
    140109} 
    141110 
    142 foreach my $sensor (keys %sensors) 
     111foreach my $sensor (values %$sensors) 
    143112{ 
    144     my $val = get_single ($session, $mbmValue . $sensor); 
    145     print (&get_name_by_sensor ($sensors{$sensor}{name}), ".value $val\n"); 
    146 
    147  
    148 sub get_single 
    149 
    150         my $handle = shift; 
    151         my $oid    = shift; 
    152  
    153         print "# Getting single \"$oid\"..." if $DEBUG; 
    154  
    155         $response = $handle->get_request ($oid); 
    156  
    157         if (!defined $response->{$oid}) 
    158         { 
    159             print "undef\n" if $DEBUG; 
    160             return undef; 
    161         } 
    162         else 
    163         { 
    164             print "\"$response->{$oid}\"\n" if $DEBUG; 
    165             return $response->{$oid}; 
    166         } 
    167 
    168  
    169 sub get_by_regex 
    170 
    171         my $handle = shift; 
    172         my $oid    = shift; 
    173         my $regex  = shift; 
    174         my $result = {}; 
    175         my $num    = 0; 
    176         my $ret    = $oid . "0"; 
    177         my $response; 
    178  
    179         print "# Starting browse of $oid...\n" if $DEBUG; 
    180  
    181         while (1) 
    182         { 
    183                 if ($num == 0) 
    184                 { 
    185                         print "# Checking for $ret...\n" if $DEBUG; 
    186                         $response = $handle->get_request ($ret); 
    187                 } 
    188                 if ($num or !defined $response) 
    189                 { 
    190                         print "# Checking for sibling of $ret...\n" if $DEBUG; 
    191                         $response = $handle->get_next_request ($ret); 
    192                 } 
    193                 if (!$response) 
    194                 { 
    195                         return undef; 
    196                 } 
    197                 my @keys = keys %$response; 
    198                 $ret = $keys[0]; 
    199                 print "# Analyzing $ret (compared to $oid)...\n" if $DEBUG; 
    200                 last unless ($ret =~ /^$oid/); 
    201                 $num++; 
    202                 next unless ($response->{$ret} =~ /$regex/); 
    203                 @keys = split (/\./, $ret); 
    204                 $result->{$keys[-1]} = $response->{$ret};; 
    205                 print "# Index $num: ", $keys[-1], " (", $response->{$ret}, ")\n" if $DEBUG; 
    206         }; 
    207         return $result; 
     113    print ("$sensor->{name}.value $sensor->{value}\n"); 
    208114} 
    209115 
  • people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_volt.in

    r864 r903  
    4646 
    4747use strict; 
    48 use Net::SNMP; 
     48use Munin::Plugin::SNMP; 
    4949 
    5050my $DEBUG = 0; 
    5151my $MAXLABEL = 20; 
    5252 
    53 my $host      = $ENV{host}      || undef; 
    54 my $port      = $ENV{port}      || 161; 
    55 my $community = $ENV{community} || "public"; 
    56 my $iface     = $ENV{interface} || undef; 
    57  
    58 my $response; 
     53my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 
    5954 
    6055if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    6156{ 
    62         print "index   1.3.6.1.4.1.9600.1.10.6.1.1.\n"; 
    63         print "require 1.3.6.1.4.1.9600.1.10.6.1.3. 2\n"; # Type=voltage 
    64         print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 0 
    65         print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 0 
     57        print "index   $mbmSensorBase.1.\n"; 
     58        print "require $mbmSensorBase.3. 3\n"; # Type=voltage 
     59        print "require $mbmSensorBase.7. [1-9]\n"; # Low value != 0 
     60        print "require $mbmSensorBase.9. [1-9]\n"; # High value != 0 
    6661 
    6762        exit 0; 
    6863} 
    6964 
    70 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_sensors_mbm_volt$/) 
    71 
    72         $host  = $1; 
    73         if ($host =~ /^([^:]+):(\d+)$/) 
    74         { 
    75                 $host = $1; 
    76                 $port = $2; 
    77         } 
    78 
    79 elsif (!defined($host)) 
    80 
    81         print "# Debug: $0 -- $1\n" if $DEBUG; 
    82         die "# Error: couldn't understand what I'm supposed to monitor."; 
    83 
    84  
    85 # The OIDs we're after 
    86 my $mbmDeviceType    = "1.3.6.1.4.1.9600.1.10.6.1.3."; # Should be 2 (volt) 
    87 my $mbmHighWatermark = "1.3.6.1.4.1.9600.1.10.6.1.7."; # Should be non-zero 
    88 my $mbmLowWatermark  = "1.3.6.1.4.1.9600.1.10.6.1.9."; # Should be non-zero 
    89 my $mbmName          = "1.3.6.1.4.1.9600.1.10.6.1.2."; # Name of sensor 
    90 my $mbmValue         = "1.3.6.1.4.1.9600.1.10.6.1.6."; # Data point 
    91  
    92 my ($session, $error) = Net::SNMP->session( 
    93                 -hostname  => $host, 
    94                 -community => $community, 
    95                 -port      => $port 
    96         ); 
     65my ($session, $error) = Munin::Plugin::SNMP->session(); 
    9766 
    9867if (!defined ($session)) 
     
    10170} 
    10271 
    103 # First we want to find the harddisks... 
    104 my $correct_type      = get_by_regex ($session, $mbmDeviceType, "^2\$"); 
    105 my $correct_high      = get_by_regex ($session, $mbmHighWatermark, "[1-9]"); 
    106 my $correct_low       = get_by_regex ($session, $mbmLowWatermark, "[1-9]"); 
     72# Get sensor info 
     73my $sensors = $session->get_hash(-baseoid => '$mbmSensorBase', 
     74                                 -cols    => { 
     75                                              3 => 'type', 
     76                                              7 => 'high', 
     77                                              9 => 'low', 
     78                                              2 => 'label', 
     79                                              3 => 'value', 
     80                                             }, 
     81                                ) 
     82  or die "# Can't get sensor info\n"; 
    10783 
    108 my @keep = (); 
    109  
    110 foreach my $id (keys %$correct_type) 
     84# Only keep voltage sensors with max/min values 
     85foreach my $id (keys %$sensors) 
    11186{ 
    112         if (exists $correct_high->{$id} and 
    113             exists $correct_low->{$id}) 
    114         { 
    115             push (@keep, $id); 
    116         } 
    117 
    118  
    119 my %sensors; 
    120  
    121 foreach my $kept (@keep) # For each temp sensor... 
    122 
    123     $sensors{$kept}{name} = get_single ($session, $mbmName . "$kept"); 
     87    unless ($sensors->{$id}->{type} == 2 && 
     88            $sensors->{$id}->{high} =~ /[1-9]/ && 
     89            $sensors->{$id}->{low} =~ /[1-9]/) { 
     90        delete $sensors->{$id}; 
     91    } 
     92    $sensors->{$id}->{name} = get_name_by_sensor($sensors->{$id}->{label}); 
    12493} 
    12594 
    12695if (defined $ARGV[0] and $ARGV[0] eq "config") 
    12796{ 
    128         print "host_name $host\n"; 
     97        print "host_name ", $session->hostname(), "\n"; 
    12998        print "graph_title Voltages\n"; 
    13099        print "graph_vlabel Volt\n"; 
     
    132101        print "graph_info This graph shows voltages in the system.\n"; 
    133102 
    134         foreach my $sensor (keys %sensors) 
     103        foreach my $sensor (values %$sensors) 
    135104        { 
    136                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ")
    137                 print (length($sensors{$sensor}{name})<=$MAXLABEL ? $sensors{$sensor}{name} : "...".substr($sensors{$sensor}{name},-($MAXLABEL-3))); 
     105                print "$sensor->{name}.label "
     106                print (length($sensor->{label})<=$MAXLABEL ? $sensor->{label} : "...".substr($sensor->{label},-($MAXLABEL-3))); 
    138107                print ("\n"); 
    139                 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".info Voltage readout from the motherboard sensor \"$sensors{$sensor}{name}\".\n"); 
     108                print ("$sensor->{name}.info Voltage readout from the motherboard sensor \"$sensor->{name}\".\n"); 
    140109        } 
    141110        exit 0; 
    142111} 
    143112 
    144 foreach my $sensor (keys %sensors) 
     113foreach my $sensor (values %$sensors) 
    145114{ 
    146     my $val = get_single ($session, $mbmValue . $sensor); 
    147     print (&get_name_by_sensor ($sensors{$sensor}{name}), ".value $val\n"); 
    148 
    149  
    150 sub get_single 
    151 
    152         my $handle = shift; 
    153         my $oid    = shift; 
    154  
    155         print "# Getting single \"$oid\"..." if $DEBUG; 
    156  
    157         $response = $handle->get_request ($oid); 
    158  
    159         if (!defined $response->{$oid}) 
    160         { 
    161             print "undef\n" if $DEBUG; 
    162             return undef; 
    163         } 
    164         else 
    165         { 
    166             print "\"$response->{$oid}\"\n" if $DEBUG; 
    167             return $response->{$oid}; 
    168         } 
    169 
    170  
    171 sub get_by_regex 
    172 
    173         my $handle = shift; 
    174         my $oid    = shift; 
    175         my $regex  = shift; 
    176         my $result = {}; 
    177         my $num    = 0; 
    178         my $ret    = $oid . "0"; 
    179         my $response; 
    180  
    181         print "# Starting browse of $oid...\n" if $DEBUG; 
    182  
    183         while (1) 
    184         { 
    185                 if ($num == 0) 
    186                 { 
    187                         print "# Checking for $ret...\n" if $DEBUG; 
    188                         $response = $handle->get_request ($ret); 
    189                 } 
    190                 if ($num or !defined $response) 
    191                 { 
    192                         print "# Checking for sibling of $ret...\n" if $DEBUG; 
    193                         $response = $handle->get_next_request ($ret); 
    194                 } 
    195                 if (!$response) 
    196                 { 
    197                         return undef; 
    198                 } 
    199                 my @keys = keys %$response; 
    200                 $ret = $keys[0]; 
    201                 print "# Analyzing $ret (compared to $oid)...\n" if $DEBUG; 
    202                 last unless ($ret =~ /^$oid/); 
    203                 $num++; 
    204                 next unless ($response->{$ret} =~ /$regex/); 
    205                 @keys = split (/\./, $ret); 
    206                 $result->{$keys[-1]} = $response->{$ret};; 
    207                 print "# Index $num: ", $keys[-1], " (", $response->{$ret}, ")\n" if $DEBUG; 
    208         }; 
    209         return $result; 
     115    print ("$sensor->{name}.value $sensor->{value}\n"); 
    210116} 
    211117