From e7d2b737df1f6194af2c652923647dd57280d2df Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Wed, 30 Apr 2008 07:38:55 +0000 Subject: Modifications to send link up/down traps to configured trap-target --- scripts/snmp/vyatta-snmp.pl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'scripts/snmp') diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl index b443eda4..ea77f7b7 100644 --- a/scripts/snmp/vyatta-snmp.pl +++ b/scripts/snmp/vyatta-snmp.pl @@ -34,7 +34,8 @@ use warnings; my $mibdir = '/opt/vyatta/share/snmp/mibs'; my $snmp_init = '/opt/vyatta/sbin/snmpd.init'; my $snmp_conf = '/etc/snmp/snmpd.conf'; - +my $snmp_snmpv3_user_conf = '/usr/share/snmp/snmpd.conf'; +my $snmp_snmpv3_createuser_conf = '/var/lib/snmp/snmpd.conf'; sub snmp_init { # @@ -61,7 +62,6 @@ sub snmp_get_constants { my $date = `date`; chomp $date; $output = "#\n# autogenerated by vyatta-snmp.pl on $date\n#\n"; - $output .= "trap2sink localhost vyatta 51510\n"; $output .= "sysServices 14\n"; $output .= "smuxpeer .1.3.6.1.4.1.3317.1.2.2\n"; # ospfd $output .= "smuxpeer .1.3.6.1.4.1.3317.1.2.5\n"; # bgpd @@ -124,14 +124,38 @@ sub snmp_get_values { $output .= "syslocation \"$location\" \n"; } - my @trap_targets = $config->returnValues("trap-target"); + my @trap_targets = $config->returnValues("trap-target"); + if ($#trap_targets >= 0) { + # code for creating a snmpv3 user, setting access-level for it and use user to do internal snmpv3 requests + snmp_create_snmpv3_user(); + snmp_write_snmpv3_user(); + $output .= "iquerySecName vyatta\n"; + # code to activate link up down traps + $output .= "linkUpDownNotifications yes\n"; + } foreach my $trap_target (@trap_targets) { - $output .= "trapsink $trap_target\n"; + $output .= "trap2sink $trap_target\n"; } return $output; } +sub snmp_create_snmpv3_user { + + my $createuser = "createUser vyatta MD5 \"vyatta\" DES"; + open(my $fh, '>>', $snmp_snmpv3_createuser_conf) || die "Couldn't open $snmp_snmpv3_createuser_conf - $!"; + print $fh $createuser; + close $fh; +} + +sub snmp_write_snmpv3_user { + + my $user = "rwuser vyatta"; + open(my $fh, '>', $snmp_snmpv3_user_conf) || die "Couldn't open $snmp_snmpv3_user_conf - $!"; + print $fh $user; + close $fh; +} + sub snmp_write_file { my ($config) = @_; -- cgit v1.2.3