Checking ITM6 Situation startup

Posted by on Nov 24, 2012 in Tivoli | No Comments

Checking that situations have started on the ITM6 agent can be done by looking in the LG0 file for the ITM6 agent. This holds the status of the distributions of the situations for the agent.
The following script will show you the status of the Situations for the ITM6 agents, it will find all LG0 files from 3 directories down from the current directory.

#!/usr/bin/perl

my $debug = 1;

my $lparName = `hostname`;
$lparName =~ s/^\s*|\s*$|\n//g;

my @lgFiles;
my @fsCheck;

my @foundLG = `find ../../../ -name ''*LG0'' 2>/dev/null`;
foreach(@foundLG) {
  s/^\s*|\s*$|\n//g;
  push(@lgFiles,$_);
}

foreach my $lgLog (@lgFiles) {
  my $agentName = $lgLog;
  $agentName =~ s/^.*\/(\S+)\.LG0$/$1/g;
  print "Agent\t$agentName\n";
  open(LGFILE, "$lgLog");

  my %sitHashDist;
  my %sitHash;

  while (<LGFILE>) {
    my $lgLine = $_;
    $lgLine =~ s/^\s*|\s*$|\n|Enterprise situation //g;
    if ($lgLine =~ /(\d{16,16})KRAIRA\d+\s*(Stopping|Starting)\s+(\S+)\s+<(\d+),(\d+)>.+(on|for)\s+(\S+)\./) {
      my $sitDistTime = $1;
      my $status = $2;                                              # assign status
      my $sitName = $3;                                             # assign situation name
      my $sitDistID = $4;
      my $sitID = $7;                                               # assign situation id

      #print "DEBUG:$sitName:$status:$sitDistID:$sitID:$sitDistTime\n" if $debug;

      if ( ($sitName =~ /_Z_|UADVISOR|HEARTBEAT/) || ($status=~/RPC call Sample/) ) {next;} # skip of we are not interested in the situation

      my $sitKey = $sitName . "," . $sitDistID;
      if (exists($sitHashDist{$sitKey})) {
        if ($sitHashDist{$sitKey} =~  /Starting/) {
          delete $sitHashDist{$sitKey};
        } else {
          $sitHashDist{$sitKey} = $status  . "," . $sitDistTime;
        }
      } else {
        $sitHashDist{$sitKey} = $status . "," . $sitDistTime ;
      }

      if ( ($sitName =~ /_Z_|UADVISOR|HEARTBEAT/) || ($status=~/RPC call Sample/) ) {next;} # skip of we are not interested in the situation
      $sitHash{$sitName} = $status . ":" . $sitID;                  # add situation details to the hash
    }
  }

  foreach my $sitName (keys(%sitHash)) {
    if ($sitHash{$sitName} =~ /Stopping/) {
      my $lastStatus = "";
      my $lastStatusDate = 0;
      foreach my $sitNameDist (keys(%sitHashDist)) {
        if ($sitNameDist =~ /$sitName/) {
          my ($sitStatus, $sitDistTime) = split(/,/,$sitHashDist{$sitNameDist});
          if ($sitDistTime > $lastStatusDate) {
            if ($sitLGDebug) {
              print ">>$sitName -> $sitNameDist : $sitHashDist{$sitNameDist}\n";
            }
            $lastStatusDate = $sitDistTime;
            $lastStatus = $sitStatus;
          }
        }
      }
      if ($lastStatus ne "") {
        $sitHash{$sitName} =~ s/Starting|Stopping/$lastStatus/g;
      }
    }
  }

  foreach(keys(%sitHash)) {
    my ($sitStatus, $junk) = split(/:/,$sitHash{$_});
    if ($sitStatus =~ /Starting/) {
      print "$sitStatus\t$_\n";
    } else {
      print "$$sitStatus\t$_\n";
    }
  }
}

Leave a Reply