package My::SNMPDevice; use base 'Class::SNMP'; __PACKAGE__->MakeMethods( mib => 'My-Custom-Device-MIB', mib_root => 'mycustomdevice', ); package main; use My::SNMPDevice; my $device = My::SNMPDevice->new( hostname => '192.168.1.25' ); print "Has a " . $device->Uptime . " uptime\n"; print "Port 4 is at speed " . $device->Ports->Entry(4)->Speed . " Mbps\n"; #### use SNMP::Trap; use My::SNMPDevice; # A subclass of Class::SNMP my $trap = SNMP::Trap->parse_snmptrapd_from_stdin(); my $obj_trap = My::SNMPDevice->parse_trap($trap); # expects SNMP::Trap # $obj_trap isa Class::SNMP::Trap + My::SNMPDevice::Trap:: my $success = $obj_trap->dispatch({ alarmWarning => sub { 1 }; _namer => 'trap_%s', _default => \&trap_unhandled, }); if (! $success) { print "Couldn't dispatch for trap:\n" . $obj_trap->describe; } sub trap_alarmCritical { my ($trap) = @_; print $trap->hostname . " is critical: " . $trap->alarmInformation . "\n"; }