Changeset 8234 for lang/perl/App-MadEye
- Timestamp:
- 03/21/08 11:03:26 (8 months ago)
- Location:
- lang/perl/App-MadEye/trunk/lib/App/MadEye
- Files:
-
- 2 modified
-
Plugin/Agent/SNMP/Process.pm (modified) (3 diffs)
-
Util.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/App-MadEye/trunk/lib/App/MadEye/Plugin/Agent/SNMP/Process.pm
r8155 r8234 3 3 use warnings; 4 4 use App::MadEye::Plugin::Agent::Base; 5 use Net::SNMP; 5 use App::MadEye::Util; 6 use List::Util qw/first/; 6 7 7 8 my $hrSWRunPath = '.1.3.6.1.2.1.25.4.2.1.4'; … … 12 13 my $process = $self->config->{config}->{process} or die "missing process"; 13 14 14 my $response = $self->snmp_session( 15 my $response = snmp_session( 16 $self, 15 17 $host => sub { 16 18 my $session = shift; … … 22 24 ); 23 25 24 my $process_cnt = scalar grep { $_ eq $process } values %$response; 25 26 App::MadEye->context->log(debug => "$host has $process_cnt $process"); 27 28 if ($process_cnt > 0) { 26 if (first { $_ eq $process } values %$response) { 29 27 return; # alive 30 28 } else { 31 return $process_cnt; 32 } 33 } 34 35 sub snmp_session { 36 my ($self, $host, $callback, ) = @_; 37 38 my $community = $self->config->{config}->{community} or die "missing community"; 39 my $port = $self->config->{config}->{port} || 161; 40 my $timeout = $self->config->{config}->{timeout} || 10; 41 42 my ($session, $error) = Net::SNMP->session( 43 -hostname => $host, 44 -community => $community, 45 -port => $port, 46 -timeout => $timeout, 47 ); 48 49 if (not defined($session)) { 50 die "ERROR: $error.\n"; 51 } else { 52 my $response = $callback->($session); 53 $session->close(); 54 return $response; 29 return "404 $process not found"; 55 30 } 56 31 } -
lang/perl/App-MadEye/trunk/lib/App/MadEye/Util.pm
r8154 r8234 4 4 use base qw/Exporter/; 5 5 6 our @EXPORT = qw/timeout log_stopwatch get_schema_from_pod/;6 our @EXPORT = qw/timeout get_schema_from_pod snmp_session/; 7 7 8 8 use Sys::Syslog qw/:DEFAULT/; … … 11 11 use YAML (); 12 12 use Time::HiRes qw/gettimeofday/; 13 use Net::SNMP; 13 14 14 15 sub timeout($$&) { ## no critic. … … 48 49 } 49 50 51 sub snmp_session { 52 my ($agent, $host, $callback, ) = @_; 53 54 my $community = $agent->config->{config}->{community} or die "missing community"; 55 my $port = $agent->config->{config}->{port} || 161; 56 my $timeout = $agent->config->{config}->{timeout} || 10; 57 58 my ($session, $error) = Net::SNMP->session( 59 -hostname => $host, 60 -community => $community, 61 -port => $port, 62 -timeout => $timeout, 63 ); 64 65 if (not defined($session)) { 66 die "ERROR: $error.\n"; 67 } else { 68 my $response = $callback->($session); 69 $session->close(); 70 return $response; 71 } 72 } 73 74 50 75 1;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)