###
### display.jacl 
###
###
###  
###  Produce a short summary of some configuration
###  and runtime information about the WebSphere installation. 
###  
###  This is a bi-modal script: it can be included in the wsadmin 
###  command invocation like this:
###     
###     wsadmin.sh -username username -password password -f displayconfig.jacl all
###
###  or the script can be sourced from the wsadmin command line:
###
###     wsadmin> source displayconfig.jacl
###     wsadmin> displayconfig.jacl all
### 
###  The script expects one parameter:
###      arg1 - a flag -- either "all" or "config" 
###
###  This example demonstrates many wsadmin features:
###
###   - Locate running MBeans 
###   - getAttributes from running MBeans 
###   - Invoke operations on running MBeans 
###   - Locate configuration objects        
###   - Display attributes of configuration objects        
###   - Look up a running object.
###   - Look up a config object.
###
###

proc displayconfig {flag} {
  
  if {$flag == "config"} {
     set configonly 1
  } else {
     if {$flag == "all"} {
        set configonly 0
     } else {
        puts "Single argument must be \"all\" or \"config\""
        return
     }
  }



  ###
  ### set up globals
  ###
  global AdminControl
  global AdminConfig
  global AdminApp


  set cells [$AdminConfig list Cell]

  #puts "           "
  #puts "           "

  foreach cell $cells {

     set cname [$AdminConfig showAttribute $cell name]
     set sec [$AdminConfig list Security $cell]
     set enabled [$AdminConfig showAttribute $sec enabled]

     puts " "                
     puts "Cell:                $cname"
     #puts "Cell ID:             $cell"
     #puts "Security:            $sec"
     puts "Security enabled:    $enabled"



     set nodes [$AdminConfig list Node $cell]


     foreach node $nodes {
        set nname [$AdminConfig showAttribute $node name]

        puts "           "
        puts "    Node:            $nname"
        #puts "    Node ID:     $node"


        ###
        ### Get a list of the servers on this node.  Use getObjectName
        ### to see if there is a running server for this config object. 
        ###

        set servs [$AdminConfig list Server $node]

        foreach server $servs {

            set sname [$AdminConfig showAttribute $server name]
        
            puts "           "
            puts "        Server:      $sname"
            #puts "        Server ID:  $server"

            set runserv [$AdminConfig getObjectName $server]

            #puts "runserv:             $runserv"

            if {[llength $runserv] > 0} {
               set state [$AdminControl getAttribute $runserv state]
               puts "        State:       $state"
            } else {
               puts "        State:       Off"
            }
 

            set https [$AdminConfig list HTTPTransport $server]

            #puts "HTTPTransports       $https"

            foreach http $https {

               set add  [$AdminConfig showAttribute $http address]
               set host [$AdminConfig showAttribute $add host]
               set port [$AdminConfig showAttribute $add port]

               #puts "            Address              $host"
               puts "            Port:    $port"
               #puts "            Host                 $host"
            }
        }

        #puts "" 
     }


      #puts "" 

      set clusters [$AdminConfig list ServerCluster $cell]
      #puts "Clusters: $clusters"
 
      foreach cluster $clusters {

         set clname [$AdminConfig showAttribute $cluster name]
         set memberlist [$AdminConfig showAttribute $cluster members]
         set members [lindex $memberlist 0]

         puts " "
         puts "Cluster              $clname "
         #puts "Memberlist:          $memberlist"


         foreach member $members {

            set mname [$AdminConfig showAttribute $member memberName]
            set weight [$AdminConfig showAttribute $member weight]

            puts "    Member:          $mname"
            puts "    Weight:          $weight"
         }
      }
 }



  ###
  ### Get the apps 
  ###

   
   #puts ""
   set apps [$AdminApp list]

   puts " "
   foreach application $apps {
       puts "Application:         $application"
   }
 
   if {$configonly} {
      return
   }


  foreach cell $cells {

     set cname [$AdminConfig showAttribute $cell name]
     set nodes [$AdminConfig list Node $cell]

     puts " "
     puts "Cellname:            $cname"

     foreach node $nodes {

        set nname [$AdminConfig showAttribute $node name]
        set servs [$AdminControl queryNames type=Server,cell=$cname,node=$nname,*]

        #puts "    Node name:           $node"

        foreach server $servs {

           set sname [$AdminControl getAttribute $server name]
           set ptype [$AdminControl getAttribute $server processType]
           set pid   [$AdminControl getAttribute $server pid]
           set state [$AdminControl getAttribute $server state]
           set jvm [$AdminControl queryNames type=JVM,cell=$cname,node=$nname,process=$sname,*]
           set osname [$AdminControl invoke $jvm getProperty os.name]

           puts "                          "
           puts "   Node name:        $nname"
           puts "   Server name:      $sname"
           puts "   Process type:     $ptype"
           puts "   PID:              $pid"
           puts "   State:            $state"
           puts "   JVM:              $jvm"
           puts "   OS:               $osname"

           set configserv [$AdminControl getConfigId $server]

           

           if {[llength $configserv] > 0} {
              #puts "  $sname is configured."
              #puts "   Config ID:       $configserv"
           } else {
              #puts "  $sname is not configured; configuration must have changed after the server was started."
           }


           set apps [$AdminControl queryNames type=Application,cell=$cname,node=$nname,process=$sname,*]

           puts "   Number of apps:   [llength $apps]"


           foreach app $apps {
              set aname [$AdminControl getAttribute $app name]
              puts "   Attribute:        $aname"
           }


           #set svreport [$AdminControl getAttribute $server serverVersion]
           #puts "Server version:             $svreport"
           #puts ""
        } 
     }
  }
}
 


###
### Main
###


if { !($argc == 1) } {
   puts "displayconfig: this script requires 1 parameter: a flag that should be \"all\" or \"config\""
   #puts ""
   puts "e.g.:     displayconfig  all" 
} else { 
   set flag      [lindex $argv 0]  
   displayconfig $flag
}

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.