1 package NetSNMP::agent;
10 use NetSNMP::default_store (':all');
11 use NetSNMP::agent::default_store (':all');
12 use NetSNMP::OID (':all');
13 use NetSNMP::agent::netsnmp_request_infoPtr;
15 use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD);
17 @ISA = qw(Exporter AutoLoader DynaLoader);
19 # Items to export into callers namespace by default. Note: do not export
20 # names by default without a very good reason. Use EXPORT_OK instead.
21 # Do not simply export all your public functions/methods/constants.
23 # This allows declaration use NetSNMP::agent ':all';
24 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
26 %EXPORT_TAGS = ( 'all' => [ qw(
39 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
56 # This AUTOLOAD is used to 'autoload' constants from the constant()
57 # XS function. If a constant is not found then control is passed
58 # to the AUTOLOAD in AutoLoader.
61 ($constname = $AUTOLOAD) =~ s/.*:://;
62 croak "& not defined" if $constname eq 'constant';
63 my $val = constant($constname, @_ ? $_[0] : 0);
65 if ($! =~ /Invalid/ || $!{EINVAL}) {
66 $AutoLoader::AUTOLOAD = $AUTOLOAD;
67 goto &AutoLoader::AUTOLOAD;
70 croak "Your vendor has not defined NetSNMP::agent macro $constname";
75 # Fixed between 5.005_53 and 5.005_61
76 # if ($] >= 5.00561) {
77 # *$AUTOLOAD = sub () { $val };
80 *$AUTOLOAD = sub { $val };
89 sub mark_init_agent_done {
93 sub maybe_init_agent {
94 return if ($haveinit);
97 snmp_enable_stderrlog();
99 if ($flags->{'AgentX'}) {
100 netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
102 init_agent($flags->{'Name'} || "perl");
103 if ($flags->{'Ports'}) {
104 netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PORTS, $flags->{'Ports'});
113 sub mark_init_lib_done {
118 return if ($haveinit);
122 init_snmp($flags->{'Name'} || "perl");
123 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) != 1) {
134 if ($self->{'dont_init_agent'}) {
135 $self->mark_init_agent_done();
137 $self->maybe_init_agent();
139 if ($self->{'dont_init_lib'}) {
140 $self->mark_init_lib_done();
146 my ($self, $name, $oid, $sub) = @_;
147 my $reg = NetSNMP::agent::netsnmp_handler_registration::new($name, $oid, $sub);
148 $reg->register() if ($reg);
155 $self->agent_check_and_process(1);
159 sub agent_check_and_process {
160 my ($self, $blocking) = @_;
161 $self->maybe_init_lib();
162 __agent_check_and_process($blocking || 0);
165 bootstrap NetSNMP::agent $VERSION;
167 # Preloaded methods go here.
169 # Autoload methods go after =cut, and are processed by the autosplit program.
173 # Below is stub documentation for your module. You better edit it!
177 NetSNMP::agent - Perl extension for the net-snmp agent.
182 my $agent = new NetSNMP::agent('Name' -> 'my_agent_name');
183 $agent->register("a_name", ".1.3.6.1.2.1", \&myhandler);
186 --- or, within the net-snmp snmpd.conf file: ---
188 perl $agent->register("a_name", ".1.3.6.1.2.1", \&myhandler);
192 This module implements a snmp agent and/or can be embedded within the
197 Please mail the net-snmp-users@lists.sourceforge.net mailing list for
198 help, questions or comments about this module.
200 Wes Hardaker, hardaker@users.sourceforge.net