more on ipmi support for snmp monitoring
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@765 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		@@ -42,7 +42,7 @@ sub start {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # do not turn it on on the service node
 | 
			
		||||
  if (xCAT::Utils->isServiceNode()) { return (0, "");}
 | 
			
		||||
  #if (xCAT::Utils->isServiceNode()) { return (0, "");}
 | 
			
		||||
 | 
			
		||||
  # unless we are running on linux, exit.
 | 
			
		||||
  #unless($^O eq "linux"){      
 | 
			
		||||
@@ -61,9 +61,71 @@ sub start {
 | 
			
		||||
    return (1, "net-snmp is not installed")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  #enable bmcs if any
 | 
			
		||||
  configBMC(1);
 | 
			
		||||
 | 
			
		||||
  #enable MMAs if any
 | 
			
		||||
 | 
			
		||||
  return (0, "started")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#--------------------------------------------------------------------------------
 | 
			
		||||
=head3    configBMC
 | 
			
		||||
      This function configures BMC to setup the snmp destination, enable/disable
 | 
			
		||||
    PEF policy table entry number 1. 
 | 
			
		||||
    Arguments:
 | 
			
		||||
      actioon -- 1 enable PEF policy table. 0 disable PEF policy table.
 | 
			
		||||
    Returns:
 | 
			
		||||
      (return code, message)      
 | 
			
		||||
=cut
 | 
			
		||||
#--------------------------------------------------------------------------------
 | 
			
		||||
sub configBMC {
 | 
			
		||||
  my $action=shift;
 | 
			
		||||
 | 
			
		||||
  #the ips of this node
 | 
			
		||||
  my @hostinfo=xCAT::Utils->determinehostname();
 | 
			
		||||
  #pop(@hostinfo); #remove the host name
 | 
			
		||||
  %iphash=();
 | 
			
		||||
  foreach(@hostinfo) {$iphash{$_}=1;}
 | 
			
		||||
 | 
			
		||||
  my $table=xCAT::Table->new("ipmi");
 | 
			
		||||
  if ($table) {
 | 
			
		||||
    my @tmp1=$table->getAllAttribs(('node','bmc','username', 'password'));
 | 
			
		||||
    if (defined(@tmp1) && (@tmp1 > 0)) {
 | 
			
		||||
      foreach(@tmp1) {
 | 
			
		||||
        my $node=$_->{node};
 | 
			
		||||
        print "node=$node\n";
 | 
			
		||||
        
 | 
			
		||||
        #get the master for node
 | 
			
		||||
        my $master=xCAT::Utils->GetMasterNodeName($node);
 | 
			
		||||
        print "master=$master\n";
 | 
			
		||||
       
 | 
			
		||||
        # handle its childen only
 | 
			
		||||
	if ($iphash{$master}) {
 | 
			
		||||
	  if ($action==1) { #enable
 | 
			
		||||
            # set the snmp destination
 | 
			
		||||
            # suppose all others like username, password, ip, gateway ip are set during the installation
 | 
			
		||||
            my @dip = split /\./, $master;
 | 
			
		||||
	    my $cmd="ipmitool -I lan -H $_->{bmc} -U $_->{username} -P $_->{password} raw 0x0c 0x01 0x01 0x13 0x01 0x00 0x00 $dip[0] $dip[1] $dip[2] $dip[3] 0x00 0x00 0x00 0x00 0x00 0x00";
 | 
			
		||||
	    $result=`$cmd 2>&1`;
 | 
			
		||||
            if ($?) { print "Setting snmp destination ip address for node $node: $result\n"; }
 | 
			
		||||
            #enable PEF policy
 | 
			
		||||
            $cmd="ipmitool -I lan -H $_->{bmc} -U $_->{username} -P $_->{password} raw 0x04 0x12 0x09 0x01 0x18 0x11 0x00";
 | 
			
		||||
	    $result=`$cmd 2>&1`;
 | 
			
		||||
            if ($?) { print "Enabling PEF policy for node $node: $result\n"; }
 | 
			
		||||
	  } else { #disable 
 | 
			
		||||
            #disable PEF policy
 | 
			
		||||
	    my $cmd="ipmitool -I lan -H $_->{bmc} -U $_->{username} -P $_->{password} raw 0x04 0x12 0x09 0x01 0x10 0x11 0x00";
 | 
			
		||||
	    $result=`$cmd 2>&1`;
 | 
			
		||||
            if ($result) { print "Disabling PEF policy for node $node: $result\n"; }
 | 
			
		||||
	  }          
 | 
			
		||||
        }
 | 
			
		||||
      } #foreach 
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#--------------------------------------------------------------------------------
 | 
			
		||||
=head3    configSNMP
 | 
			
		||||
@@ -131,7 +193,6 @@ sub configSNMP {
 | 
			
		||||
  # then stop it and restart it again so that it reads our new
 | 
			
		||||
  # snmptrapd.conf configuration file. Then the process
 | 
			
		||||
  chomp(my $pid= `/bin/ps -ef | /bin/grep snmptrapd | /bin/grep -v grep | /bin/awk '{print \$2}'`);
 | 
			
		||||
  print "pid=$pid here\n";
 | 
			
		||||
  if($pid){
 | 
			
		||||
    `/bin/kill -9 $pid`;
 | 
			
		||||
  }
 | 
			
		||||
@@ -165,7 +226,10 @@ sub stop {
 | 
			
		||||
  print "snmpmon::stop called\n";
 | 
			
		||||
 | 
			
		||||
  # do not turn it on on the service node
 | 
			
		||||
  if (xCAT::Utils->isServiceNode()) { return (0, "");}
 | 
			
		||||
  #if (xCAT::Utils->isServiceNode()) { return (0, "");}
 | 
			
		||||
 | 
			
		||||
  #disable BMC so that it stop senging alerts (PETs) to this node
 | 
			
		||||
  configBMC(0);
 | 
			
		||||
 
 | 
			
		||||
  if (-f "/usr/share/snmp/snmptrapd.conf.orig"){
 | 
			
		||||
    # copy back the old one
 | 
			
		||||
 
 | 
			
		||||
@@ -767,7 +767,7 @@ sub resetbmc {
 | 
			
		||||
 | 
			
		||||
sub setnetinfo {
 | 
			
		||||
	my $subcommand = shift;
 | 
			
		||||
	my $input = shift;
 | 
			
		||||
	my @input = @_;
 | 
			
		||||
 | 
			
		||||
	my $netfun = 0x30;
 | 
			
		||||
	my @cmd;
 | 
			
		||||
@@ -783,7 +783,7 @@ sub setnetinfo {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if($subcommand eq "garp") {
 | 
			
		||||
		my $halfsec = pop(@$input) * 2;
 | 
			
		||||
		my $halfsec = pop(@input) * 2;
 | 
			
		||||
 | 
			
		||||
		if($halfsec > 255) {
 | 
			
		||||
			$halfsec = 255;
 | 
			
		||||
@@ -795,10 +795,22 @@ sub setnetinfo {
 | 
			
		||||
		@cmd = (0x01,$channel_number,0x0b,$halfsec);
 | 
			
		||||
	}
 | 
			
		||||
	elsif($subcommand =~ m/snmpdest(\d+)/ ) {
 | 
			
		||||
		my $dstip = pop(@$input);
 | 
			
		||||
		my $dstip = pop(@input);
 | 
			
		||||
		my @dip = split /\./, $dstip;
 | 
			
		||||
		@cmd = (0x01,$channel_number,0x13,$1,0x00,0x00,$dip[0],$dip[1],$dip[2],$dip[3],0,0,0,0,0,0);
 | 
			
		||||
	}
 | 
			
		||||
	#elsif($subcommand eq "alert" ) {
 | 
			
		||||
	#    my $action=pop(@input);
 | 
			
		||||
            #print "action=$action\n";
 | 
			
		||||
        #    $netfun=0x28; #TODO: not right
 | 
			
		||||
 
 | 
			
		||||
            # mapping alert action to number
 | 
			
		||||
        #    my $act_number=8;   
 | 
			
		||||
        #    if ($action eq "on") {$act_number=8;}  
 | 
			
		||||
        #    elsif ($action eq "off") { $act_number=0;}  
 | 
			
		||||
        #    else { return(1,"unsupported alert action $action");}    
 | 
			
		||||
	#    @cmd = (0x12, $channel_number,0x09, 0x01, $act_number+16, 0x11,0x00);
 | 
			
		||||
	#}
 | 
			
		||||
	else {
 | 
			
		||||
		return(1,"unsupported command setnetinfo $subcommand");
 | 
			
		||||
	}
 | 
			
		||||
@@ -2084,19 +2096,23 @@ sub fruwrite {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub decodealert {
 | 
			
		||||
	my $trap = shift;
 | 
			
		||||
  my $trap = shift;
 | 
			
		||||
  my $skip_sdrinit=0;
 | 
			
		||||
  if ($trap =~ /xCAT_plugin::ipmi/) {
 | 
			
		||||
    $trap=shift;
 | 
			
		||||
    $skip_sdrinit=1;
 | 
			
		||||
  }
 | 
			
		||||
	my $node = shift;
 | 
			
		||||
	my $pet = shift;
 | 
			
		||||
	my @pet = @_;
 | 
			
		||||
	my $rc;
 | 
			
		||||
	my $text;
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    if (!$skip_sdrinit) { 
 | 
			
		||||
	($rc,$text) = initsdr();
 | 
			
		||||
	if($rc != 0) {
 | 
			
		||||
		return($rc,$text);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	my $type;
 | 
			
		||||
	my $desc;
 | 
			
		||||
@@ -2126,7 +2142,7 @@ sub decodealert {
 | 
			
		||||
		printf("reserved:   %02xh\n",$reserved);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	my @hex = (0,@$pet);
 | 
			
		||||
	my @hex = (0,@pet);
 | 
			
		||||
	my $pad = $hex[0];
 | 
			
		||||
	my @uuid = @hex[1..16];
 | 
			
		||||
	my @seqnum = @hex[17,18];
 | 
			
		||||
@@ -4509,7 +4525,7 @@ sub process_request {
 | 
			
		||||
      unless (defined $child) { die "Fork failed" };
 | 
			
		||||
	  if ($child == 0) { 
 | 
			
		||||
        close($cfd);
 | 
			
		||||
        donode($pfd,$_->[0],$_->[1],$_->[2],$_->[3],$ipmitimeout,$ipmitrys,$command,-args=>@exargs);
 | 
			
		||||
        donode($pfd,$_->[0],$_->[1],$_->[2],$_->[3],$ipmitimeout,$ipmitrys,$command,-args=>\@exargs);
 | 
			
		||||
        close($pfd);
 | 
			
		||||
		exit(0);
 | 
			
		||||
	  }
 | 
			
		||||
@@ -4557,7 +4573,8 @@ sub donode {
 | 
			
		||||
  my $command = shift;
 | 
			
		||||
  my %namedargs=@_;
 | 
			
		||||
  my $transid = $namedargs{-transid};
 | 
			
		||||
  my @exargs=$namedargs{-args};
 | 
			
		||||
  my $extra=$namedargs{-args};
 | 
			
		||||
  my @exargs=@$extra;
 | 
			
		||||
  my ($rc,@output) = ipmicmd($bmcip,623,$user,$pass,$timeout,$retries,0,$command,@exargs);
 | 
			
		||||
  my @outhashes;
 | 
			
		||||
  foreach(@output) {
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ use Sys::Syslog;
 | 
			
		||||
use xCAT::Table;
 | 
			
		||||
use xCAT_plugin::ipmi;
 | 
			
		||||
use xCAT_monitoring::monitorctrl;
 | 
			
		||||
use Socket;
 | 
			
		||||
 | 
			
		||||
#-------------------------------------------------------------------------------
 | 
			
		||||
=head1  xcat_traphandler  
 | 
			
		||||
@@ -45,10 +46,12 @@ if ($r) { %hashR=parseSettings($r); }
 | 
			
		||||
# read host name
 | 
			
		||||
my $host=<STDIN>; 
 | 
			
		||||
chomp($host);
 | 
			
		||||
print "host=$host\n";
 | 
			
		||||
 | 
			
		||||
# read the host ip
 | 
			
		||||
my $ip=<STDIN>;
 | 
			
		||||
chomp($ip);
 | 
			
		||||
print "ip=$ip\n";
 | 
			
		||||
 | 
			
		||||
# read uptime
 | 
			
		||||
my $uptimeline=<STDIN>;
 | 
			
		||||
@@ -160,12 +163,32 @@ while ($temp=<STDIN>) {
 | 
			
		||||
    $node1=$host;
 | 
			
		||||
    $node1 =~ s/(-(eth|man)\d+)?(\..*)?$//;
 | 
			
		||||
 | 
			
		||||
    $ip1=$ip;
 | 
			
		||||
    $ip1 =~ /(\d+\.\d+\.\d+\.\d+)/;
 | 
			
		||||
    $ip1=$1;
 | 
			
		||||
 | 
			
		||||
    # get the host name if it is unknown
 | 
			
		||||
    if ($node1 =~/<UNKNOWN>/) {
 | 
			
		||||
      my $iaddr = inet_aton("9.114.47.225");
 | 
			
		||||
      my ($name) = gethostbyaddr($iaddr, AF_INET);
 | 
			
		||||
      if ($name) {$node1=$name; $host=$name;}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #node1 is the bmc name, we need the node that bmc connects to to call xCAT
 | 
			
		||||
    my $realnode;
 | 
			
		||||
    my $ipmitab = xCAT::Table->new('ipmi');
 | 
			
		||||
    if (defined($ipmitab)) {
 | 
			
		||||
      ($tmp)=$ipmitab->getAttribs({'bmc'=>$node1},'node');
 | 
			
		||||
       if (defined($tmp)) { $realnode=$tmp->{node}; }   
 | 
			
		||||
    }
 | 
			
		||||
    if ($realnode) {$node1=$realnode;}
 | 
			
		||||
 | 
			
		||||
    # make the vlaue into a hex array for decoding
 | 
			
		||||
    $value =~ s/\"//g;
 | 
			
		||||
    my @varray=split(/ /, $value);
 | 
			
		||||
    #print "\n\n\ntrapid=$trapid\nhost=$host\npet=$value\n";
 | 
			
		||||
    my $error = xCAT_plugin::ipmi->decodealert($trapid, $host, \@varray);
 | 
			
		||||
    my @varray=split(/\s+/, $value);
 | 
			
		||||
    foreach (@varray) { $_=hex($_); }
 | 
			
		||||
    my $error = xCAT_plugin::ipmi->decodealert($trapid, $node1, @varray);
 | 
			
		||||
    $briefmsg .= $error;
 | 
			
		||||
    #print "error=$error\n";
 | 
			
		||||
 | 
			
		||||
    #severity value from decodealert are: 
 | 
			
		||||
    #LOG,INFORMATION,OK,CRITICAL,NON-RECOVERABLE,MONITOR and UNKNOWN-SEVERITY
 | 
			
		||||
@@ -173,8 +196,8 @@ while ($temp=<STDIN>) {
 | 
			
		||||
    if ($error) {
 | 
			
		||||
      @tempArray=split(/\:/, $error);  
 | 
			
		||||
      $severity=$tempArray[0];
 | 
			
		||||
      if ($severity eq "LOG") {
 | 
			
		||||
        $severity_type="Informational";
 | 
			
		||||
      if ($severity eq "LOG") {#in fact this is called "unspecifiled"
 | 
			
		||||
        $severity_type="Warning";
 | 
			
		||||
      } 
 | 
			
		||||
      elsif($severity eq  "INFORMATION") {
 | 
			
		||||
        $severity_type="Informational";
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user