From 20e1e7213c5397165f9d92b2bf264bdc73275cda Mon Sep 17 00:00:00 2001 From: cxhong Date: Thu, 28 Sep 2017 23:07:55 -0400 Subject: [PATCH] Support config snmpv1/2 community string for Mellanox switches during discovery phase (#4030) * Support config snmpv1/2 community string for Mellanox switches during discovery phase * checking snmpversion defined in the switches table --- xCAT-server/share/xcat/scripts/configMellanox | 30 +++++++++++++------ xCAT/postscripts/enablesnmp | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index b92dd57d0..ecadfe257 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -269,21 +269,39 @@ sub config_snmp { my $snmp_user; my $snmp_passwd; my $snmp_auth; + my $snmp_version; + my $cmd; my $switchtab = xCAT::Table->new('switches'); - my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername','username','password','auth','privacy']); - foreach my $switch (@nodes) { + my $switchhash = $switchtab->getNodesAttribs(\@nodes,['snmpversion','sshusername','sshpassword','username','password','auth','privacy']); + foreach my $switch (@nodes) + { + #enable snmp function on the switch + $cmd=`rspconfig $switch snmpcfg=enable`; + my $user = $switchhash->{$switch}->[0]->{sshusername}; if (!$user) { print "switch ssh username is not defined, use default one\n"; $user="admin"; } + $snmp_version = $switchhash->{$switch}->[0]->{snmpversion}; + $snmp_passwd = $switchhash->{$switch}->[0]->{password}; + + #config snmpv1 with community string defined in the switches table + unless ($snmp_version =~ /3/) { + if ($snmp_passwd) { + $cmd=`rspconfig $switch community=$snmp_passwd`; + print "config snmp community string $snmp_passwd\n"; + next; + } + } + + #config snmpv3 defined in the switches table $snmp_user = $switchhash->{$switch}->[0]->{username}; if (!$snmp_user) { print "No snmp user defined for switch $switch. Will not configure snmpv3\n"; next; } - $snmp_passwd = $switchhash->{$switch}->[0]->{password}; $snmp_auth = $switchhash->{$switch}->[0]->{auth}; my $snmp_privacy = $switchhash->{$switch}->[0]->{privacy}; @@ -315,12 +333,6 @@ sub run_rspconfig { $master = `hostname -i`; foreach my $switch (@nodes) { my $user= $switchhash->{$switch}->[0]->{sshusername}; - # call rspconfig command to setup switch - # enable ssh - $cmd=`rspconfig $switch sshcfg=enable`; - - # enable snmp function on the switch - $cmd=`rspconfig $switch snmpcfg=enable`; # enable the snmp trap $cmd=`rspconfig $switch alert=enable`; diff --git a/xCAT/postscripts/enablesnmp b/xCAT/postscripts/enablesnmp index 5486c7c39..2d0010955 100755 --- a/xCAT/postscripts/enablesnmp +++ b/xCAT/postscripts/enablesnmp @@ -52,7 +52,7 @@ fi echo "# $xCATSettingsSTART" >> $snmp_conf echo "# $xCATSettingsInfo" >> $snmp_conf -if [ "$snmpversion" = "3" ]; then +if [[ "$snmpversion" =~ "3" ]]; then #set up snmp version 3 if [ -n "$snmpuser" ] && [ -n "$snmpauth" ] && [ -n "$snmppwd" ]; then len=${#snmppwd}