Changeset 903
- Timestamp:
- 04/04/05 22:08:32 (7 years ago)
- Files:
-
- people/ilmari/modularisation-branch/node/node.d/snmp__df.in (modified) (4 diffs)
- people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_.in (modified) (4 diffs)
- people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_err_.in (modified) (4 diffs)
- people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_fan.in (modified) (3 diffs)
- people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_temp.in (modified) (3 diffs)
- people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_volt.in (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
people/ilmari/modularisation-branch/node/node.d/snmp__df.in
r864 r903 68 68 69 69 use strict; 70 use Net::SNMP;70 use Munin::Plugin::SNMP; 71 71 72 72 my $DEBUG = 0; 73 73 my $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;79 74 80 75 my $response; … … 86 81 print "require 1.3.6.1.2.1.25.2.3.1.5. [1-9]\n"; # Size > 0 87 82 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.";103 83 } 104 84 … … 120 100 121 101 122 my ($session, $error) = Net::SNMP->session( 123 -hostname => $host, 124 -community => $community, 125 -port => $port 126 ); 102 my ($session, $error) = Munin::Plugin::SNMP->session(); 127 103 128 104 if (!defined ($session)) … … 193 169 if (defined $ARGV[0] and $ARGV[0] eq "config") 194 170 { 195 print "host_name $host\n";171 print "host_name ", $session->hostname(), "\n"; 196 172 print "graph_title Filesystem usage (in %)\n"; 197 173 print "graph_args --upper-limit 100 -l 0\n"; people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_.in
r864 r903 75 75 76 76 use strict; 77 use Net::SNMP;77 use Munin::Plugin::SNMP; 78 78 79 79 my $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;85 80 86 81 my $response; … … 95 90 } 96 91 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 } 92 my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'fc_if'); 93 94 my $iface = $session->args()->[0] || $ENV{interface}; 112 95 113 96 my $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"; … … 118 101 my $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"; 119 102 120 my ($session, $error) = Net::SNMP->session(121 -hostname => $host,122 -community => $community,123 -port => $port,124 -version => "2c"125 );126 127 103 if (!defined ($session)) 128 104 { … … 132 108 if ($ARGV[0] and $ARGV[0] eq "config") 133 109 { 134 print "host_name $host\n";110 print "host_name ", $session->hostname(), "\n"; 135 111 if (!defined ($response = $session->get_request($fcEntryDescr))) 136 112 { people/ilmari/modularisation-branch/node/node.d/snmp__fc_if_err_.in
r864 r903 75 75 76 76 use strict; 77 use Net::SNMP;77 use Munin::Plugin::SNMP; 78 78 79 79 my $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;85 80 86 81 my $response; … … 95 90 } 96 91 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 } 92 my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'fc_if_err'); 93 94 my $iface = $session->args()->[0] || $ENV{interface}; 112 95 113 96 my $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"; … … 116 99 my $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"; 117 100 my $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 );125 101 126 102 if (!defined ($session)) … … 131 107 if ($ARGV[0] and $ARGV[0] eq "config") 132 108 { 133 print "host_name $host\n";109 print "host_name ", $session->hostname(), "\n"; 134 110 if (!defined ($response = $session->get_request($fcEntryDescr))) 135 111 { people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_fan.in
r864 r903 43 43 44 44 use strict; 45 use Net::SNMP;45 use Munin::Plugin::SNMP; 46 46 47 47 my $DEBUG = 0; 48 48 my $MAXLABEL = 20; 49 49 50 my $host = $ENV{host} || undef; 51 my $port = $ENV{port} || 161; 52 my $community = $ENV{community} || "public"; 53 54 my $response; 50 my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 55 51 56 52 if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 57 53 { 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=fan60 print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 061 print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 054 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 62 58 63 59 exit 0; 64 60 } 65 61 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 ); 62 my ($session, $error) = Munin::Plugin::SNMP->session(); 93 63 94 64 if (!defined ($session)) … … 97 67 } 98 68 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 70 my $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"; 103 80 104 my @keep = (); 105 106 foreach my $id (keys %$correct_type) 81 # Only keep fan sensors with max/min values 82 foreach my $id (keys %$sensors) 107 83 { 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}); 120 90 } 121 91 122 92 if (defined $ARGV[0] and $ARGV[0] eq "config") 123 93 { 124 print "host_name $host\n";94 print "host_name ", $session->hostname(), "\n"; 125 95 print "graph_title Fan speed\n"; 126 96 print "graph_args --upper-limit 100 -l 0\n"; … … 129 99 print "graph_info This graph shows the rounds per minute of the fans in the machine.\n"; 130 100 131 foreach my $sensor ( keys %sensors)101 foreach my $sensor (values %$sensors) 132 102 { 133 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ");134 print (length($sensor s{$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))); 135 105 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"); 137 107 } 138 108 exit 0; 139 109 } 140 110 141 foreach my $sensor ( keys %sensors)111 foreach my $sensor (values %$sensors) 142 112 { 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"); 207 114 } 208 115 people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_temp.in
r864 r903 43 43 44 44 use strict; 45 use Net::SNMP;45 use Munin::Plugin::SNMP; 46 46 47 47 my $DEBUG = 0; 48 48 my $MAXLABEL = 20; 49 49 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; 50 my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 56 51 57 52 if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 58 53 { 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=temperature61 print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 062 print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 054 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 63 58 64 59 exit 0; 65 60 } 66 61 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 ); 62 my ($session, $error) = Munin::Plugin::SNMP->session(); 94 63 95 64 if (!defined ($session)) … … 98 67 } 99 68 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 70 my $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"; 104 80 105 my @keep = (); 106 107 foreach my $id (keys %$correct_type) 81 # Only keep temperature sensors with max/min values 82 foreach my $id (keys %$sensors) 108 83 { 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}); 121 90 } 122 91 123 92 if (defined $ARGV[0] and $ARGV[0] eq "config") 124 93 { 125 print "host_name $host\n";94 print "host_name ", $session->hostname(), "\n"; 126 95 print "graph_title Temperatures\n"; 127 96 print "graph_args --upper-limit 100 -l 0\n"; … … 130 99 print "graph_info This graph shows temperatures in the system.\n"; 131 100 132 foreach my $sensor ( keys %sensors)101 foreach my $sensor (values %$sensors) 133 102 { 134 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ");135 print (length($sensor s{$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))); 136 105 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"); 138 107 } 139 108 exit 0; 140 109 } 141 110 142 foreach my $sensor ( keys %sensors)111 foreach my $sensor (values %$sensors) 143 112 { 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"); 208 114 } 209 115 people/ilmari/modularisation-branch/node/node.d/snmp__sensors_mbm_volt.in
r864 r903 46 46 47 47 use strict; 48 use Net::SNMP;48 use Munin::Plugin::SNMP; 49 49 50 50 my $DEBUG = 0; 51 51 my $MAXLABEL = 20; 52 52 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; 53 my $mbmSensorBase = '1.3.6.1.4.1.9600.1.10.6.1'; 59 54 60 55 if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 61 56 { 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=voltage64 print "require 1.3.6.1.4.1.9600.1.10.6.1.7. [1-9]\n"; # Low value != 065 print "require 1.3.6.1.4.1.9600.1.10.6.1.9. [1-9]\n"; # High value != 057 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 66 61 67 62 exit 0; 68 63 } 69 64 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 ); 65 my ($session, $error) = Munin::Plugin::SNMP->session(); 97 66 98 67 if (!defined ($session)) … … 101 70 } 102 71 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 73 my $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"; 107 83 108 my @keep = (); 109 110 foreach my $id (keys %$correct_type) 84 # Only keep voltage sensors with max/min values 85 foreach my $id (keys %$sensors) 111 86 { 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}); 124 93 } 125 94 126 95 if (defined $ARGV[0] and $ARGV[0] eq "config") 127 96 { 128 print "host_name $host\n";97 print "host_name ", $session->hostname(), "\n"; 129 98 print "graph_title Voltages\n"; 130 99 print "graph_vlabel Volt\n"; … … 132 101 print "graph_info This graph shows voltages in the system.\n"; 133 102 134 foreach my $sensor ( keys %sensors)103 foreach my $sensor (values %$sensors) 135 104 { 136 print (&get_name_by_sensor ($sensors{$sensor}{name}), ".label ");137 print (length($sensor s{$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))); 138 107 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"); 140 109 } 141 110 exit 0; 142 111 } 143 112 144 foreach my $sensor ( keys %sensors)113 foreach my $sensor (values %$sensors) 145 114 { 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"); 210 116 } 211 117
