On Tue, Oct 4, 2011 at 3:57 PM, <[email protected]> wrote: > From Bart's statement below it is suggested that I can directly obtain the > value of sysUpTime from my SubAgent - How do I obtain this from my Perl > module? > > What the Perl SNMP module does is to include the time elapsed since system > startup in a trap if the uptime has not been specified explicitly. If you > want that value to match the sysUptime of the SNMP agent on the same > system, > I propose that you query that value before sending a trap. >
Does the function uptime() defined in the attached patch help (not tested) ?
It can be used e.g. as follows:
C:\Perl\bin\perl -e "use SNMP; use NetSNMP::agent; $SNMP::dump_packet=1; my
$agent = new NetSNMP::agent(); my $session = new SNMP::TrapSession(Community
=> \"trap\", Port => 162, Version => \"2c\"); $session->trap(oid =>
\"warmStart\", uptime => $agent->uptime());"
[PATCH] CHANGES: perl: Add agent::uptime()
---
perl/agent/agent.pm | 6 ++++++
perl/agent/agent.xs | 7 +++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/perl/agent/agent.pm b/perl/agent/agent.pm
index 6135443..4ffd3ea 100644
--- a/perl/agent/agent.pm
+++ b/perl/agent/agent.pm
@@ -199,6 +199,12 @@ sub agent_check_and_process {
__agent_check_and_process($blocking || 0);
}
+sub uptime {
+ my ($self) = @_;
+ $self->maybe_init_lib();
+ return _uptime();
+}
+
bootstrap NetSNMP::agent $VERSION;
# Preloaded methods go here.
diff --git a/perl/agent/agent.xs b/perl/agent/agent.xs
index ee77d50..b81886f 100644
--- a/perl/agent/agent.xs
+++ b/perl/agent/agent.xs
@@ -239,6 +239,13 @@ __agent_check_and_process(block = 1)
OUTPUT:
RETVAL
+int
+_uptime()
+ CODE:
+ RETVAL = netsnmp_get_agent_uptime();
+ OUTPUT:
+ RETVAL
+
void
init_mib()
CODE:
--
1.7.5.1
0001-CHANGES-perl-Add-agent-uptime.patch
Description: Binary data
------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
