Changeset 898
- Timestamp:
- 04/04/05 05:12:48 (7 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
people/ilmari/modularisation-branch/node/node.d/snmp__if_.in
r864 r898 84 84 85 85 use strict; 86 use Net::SNMP;86 use Munin::Plugin::SNMP; 87 87 88 88 my $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;94 89 95 90 my $response; … … 104 99 } 105 100 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 ); 101 my ($session, $error) = Munin::Plugin::SNMP->session(); 133 102 134 103 if (!defined ($session)) … … 137 106 } 138 107 108 my $iface = $session->args()->[0] || $ENV{interface}; 109 110 die "# No interface specified\n" unless length $iface; 111 112 my $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 139 126 if ($ARGV[0] and $ARGV[0] eq "config") 140 127 { 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'}; 147 130 $name =~ s/[^\w\s]//g; 148 131 my $warn = undef; 149 if (defined ($response = $session->get_request($ifEntrySpeed)))132 if (defined $info->{'speed'}) 150 133 { 151 $warn = $ response->{$ifEntrySpeed}/8;134 $warn = $info->{'speed'}/8; 152 135 } 153 136 if (length ($name) > 15) … … 182 165 } 183 166 184 my $status = 1; 185 if (defined ($response = $session->get_request($ifEntryStatus))) 186 { 187 $status = $response->{$ifEntryStatus}; 188 } 189 190 if ($status == 2) 167 if ($info->{'status'} == 2) 191 168 { 192 169 print "recv.value U\n"; … … 195 172 } 196 173 197 if (defined ($response = $session->get_request($ifEntryInOctets)))174 for my $key (qw(recv send)) 198 175 { 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 } 200 184 } 201 else202 {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 else211 {212 print "send.value U\n";213 }people/ilmari/modularisation-branch/node/node.d/snmp__if_err_.in
r864 r898 87 87 88 88 use strict; 89 use Net::SNMP;89 use Munin::Plugin::SNMP; 90 90 91 91 my $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;97 92 98 93 my $response; … … 107 102 } 108 103 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 ); 104 my ($session, $error) = Munin::Plugin::SNMP->session(-name => 'if_err'); 136 105 137 106 if (!defined ($session)) … … 140 109 } 141 110 111 my $iface = $session->args()->[0] || $ENV{interface}; 112 113 die "# No interface specified\n" unless length $iface; 114 115 my $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 142 129 if ($ARGV[0] and $ARGV[0] eq "config") 143 130 { 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'}; 150 133 $name =~ s/[^\w\s]//g; 151 134 my $warn = undef; 152 if (defined ($response = $session->get_request($ifEntrySpeed)))135 if (defined $info->{'speed'}) 153 136 { 154 $warn = $ response->{$ifEntrySpeed}/8;137 $warn = $info->{'speed'}/8; 155 138 } 156 139 if (length ($name) > 15) … … 185 168 } 186 169 187 my $status = 1; 188 if (defined ($response = $session->get_request($ifEntryStatus))) 189 { 190 $status = $response->{$ifEntryStatus}; 191 } 192 193 if ($status == 2) 170 if ($info->{'status'} == 2) 194 171 { 195 172 print "recv.value U\n"; … … 198 175 } 199 176 200 if (defined ($response = $session->get_request($ifEntryInErrors)))177 for my $key (qw(recv send)) 201 178 { 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 } 203 187 } 204 else205 {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 else214 {215 print "send.value U\n";216 }
