Tip: Script to find double ports assignments

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tip: Script to find double ports assignments

  • Creator
    Topic
  • #47524
    Anonymous
    Participant

      Anybody having larger sites and without a proper port registration, might appreciate this script. It was written for all platforms, but only tested on Linux and Windows. It is tested on Cloverleaf Platform V, but it should work for all versions, theoretically.

      Use at will, just leave top comments in.

      Code:

      #!/quovadx/qdx5.2/integrator/bin/hcitcl

      proc initVersion {} {
         global HciRootDir sitecontrol
         set module [lindex [info level 0] 0]

         # Initialize sitecontrol array
         if { [windows_platform] } { set sitecontrol(windows) 1 } else { set sitecontrol(windows) 0 }

         set sitecontrol(vers) -1
         set sitecontrol(type) “”
         if { [catch {set rh [open $HciRootDir/rootInfo r]} err] } { return “-1” }
         while { [eof $rh] == 0 } {
             set line [gets $rh]
             set key [lindex [split $line =] 0]
             set value [lindex [split $line =] 1]
             switch -exact — $key {
                 releasenum {  set sitecontrol(vers) $value ; # 3.7.1, 5.1 etc. }
                 releasetype { set sitecontrol(type) $value ; # B or P }
             }
         }
         close $rh

         # make sure it’s three positions. This allows for numerical
         # comparison, e.g. $control(vers) < 500    regsub -all -nocase -- [a-z\.] $sitecontrol(vers) "" sitecontrol(vers)    append sitecontrol(vers) "000"    set sitecontrol(vers) [crange $sitecontrol(vers) 0 2]    switch -exact -- $sitecontrol(vers) {        371 {            set sitecontrol(service) "HIE Cloverleaf"            set sitecontrol(serviceport) 13004        }        380 {            set sitecontrol(service) "HIE CloverleafConX 3.8.0"            set sitecontrol(serviceport) 13005        }        381 {            set sitecontrol(service) "QDX Integrator 381"            set sitecontrol(serviceport) 13006        }        500 {            set sitecontrol(service) "QDX Integrator 50"            set sitecontrol(serviceport) 13007        }        510 {            set sitecontrol(service) "QDX Integrator 51"            set sitecontrol(serviceport) 13008        }        520 {            set sitecontrol(service) "QDX(TM) Integration Services 52"            set sitecontrol(serviceport) 13009        }        530 {            set sitecontrol(service) "QDX(TM) Integration Services 53"            set sitecontrol(serviceport) 13010        }        default {            error "This version '$sitecontrol(vers)$sitecontrol(type)' is not supported."        }    }    set r [getSiteList]    return $r } proc getSiteList {} {    global HciRootDir HciSiteDir sitecontrol    set module [lindex [info level 0] 0]    if { ![info exists sitecontrol(vers)] } {        #puts stderr "$module: Warning: need to initialize first by calling initVersion"        initVersion    }    if { [cequal $sitecontrol(vers) "371"] } {        set serverIni $HciRootDir/../server/server.ini    } else {        set serverIni $HciRootDir/server/server.ini    }    set siteList {}    set serverIniContent [split [read_file $serverIni] n]    set environsLine [lindex [lmatch -regexp ${serverIniContent} "^environs="] 0]    set sitePathList [split [lindex [split $environsLine =] 1] ;]    foreach sitePath $sitePathList {        lappend siteList [file tail $sitePath]    }    set sitecontrol(sites) $siteList    if { ![llength $siteList] } {        return -1    } else {        return 1    } } proc setSite { site } {    global HciRootDir HciSiteDir HciProcessesDir HciSite env sitecontrol    set module [lindex [info level 0] 0]    if { [cequal $HciSite $site] } { return 1 }    set previousSite ${env(HCISITEDIR)}    set l [expr [clength $previousSite]-1]    set env(HCISITE)    "$site"    set env(HCISITEDIR) "[file nativename [file join $env(HCIROOT) $site]]"    set env(DBTMP)      "[file nativename [file join $env(HCISITEDIR) exec databases]]"    if { $sitecontrol(vers) < 500 } {        set env(LOCKMGR)    "lm_[file nativename $HciRootDir]_$site"    } else {        set env(LOCKMGR)    "lm_[file tail [file dirname $HciRootDir]]_$site"    }    set newPathList {}    foreach path [split $env(PATH) ;] {        if { [cequal [crange ${path} 0 $l] ${previousSite}] } {            set path [file nativename [file join $env(HCISITEDIR) [crange ${path} [llength $previousSite] end]]]        }        lappend newPathList ${path}    }    set env(PATH) [join $newPathList ;]    set HciSite         $env(HCISITE)    set HciSiteDir      [file join $env(HCIROOT) $env(HCISITE)]    set HciProcessesDir [file join $env(HCISITEDIR) exec processes]    if { [catch {getRootAndSiteInfo} err] } {        return -1    } else {        return 1    } } global HciRootDir HciSiteDir HciSite sitecontrol if { [initVersion] == 0 } {    puts stderr "Error loading environments from server.ini...exiting"    exit } set portfile "[file join $HciRootDir portfile.txt]" set fo "[open $portfile w+]" set portList {} puts stdout "Doing sites:" ; flush stdout foreach site $sitecontrol(sites) {    if { [setSite $site] == 0 } {        puts stderr "Error in site $site. Skipping this one...." ; flush stderr    } else {        puts -nonewline stdout "$site..." ; flush stdout        set loaded 0        if { [catch {set loaded [netcfgLoad]} err] || $loaded == 0 } {            puts stderr "nError loading NetConfig, skipping this one..." ; flush stderr            continue        }        set processesList [netcfgGetProcList]        foreach process $processesList {            set threadsList [netcfgGetProcConns $process]            foreach thread $threadsList {                set connData  [netcfgGetConnData $thread]                set protoInfo [keylget connData PROTOCOL]                set protoType [keylget protoInfo TYPE]                switch -exact -- $protoType {                    file - fileset - upoc - http-client - pdl-async {}                    tcpip - pdl-tcpip {                        puts -nonewline $fo "$HciSitet$processt$threadt$protoType"                        if { [keylget protoInfo ISSERVER] == 1 } {                            puts -nonewline $fo "tserver"                            puts $fo "t[keylget protoInfo PORT]"                            if { [lsearch -glob $portList "[keylget protoInfo PORT] *"] == -1 } {                                lappend portList [list [keylget protoInfo PORT] $HciSite $thread]                            } else {                                lappend doublePorts [list [keylget protoInfo PORT] $HciSite $thread]                            }                        } else {                            puts -nonewline $fo "tclient"                            puts $fo "t[keylget protoInfo HOST]:[keylget protoInfo PORT]"                        }                    }                    default { echo Unsupported type: $protoType }                }            }        }    } } flush $fo close $fo if { [info exists doublePorts] } {    set portList    [lsort -dictionary $portList]    set doublePorts [lsort -dictionary $doublePorts]    set prevPort ""    puts stdout "nDouble server port report:" ; flush stdout    foreach portInfo $doublePorts {        lassign $portInfo port site thread        puts stderr "Site: $site, Thread: $thread, Port: $port"        if { ![cequal $port $prevPort] } {            set otherPortInfo [lindex $portList [lsearch -glob $portList "$port *"]]            lassign $otherPortInfo port site thread            puts stdout "Site: $site, Thread: $thread, Port: $port" ; flush stdout        }    } } puts stdout "Find full overview in [file nativename $portfile]" ; flush stdout exit

    Viewing 5 reply threads
    • Author
      Replies
      • #56008
        Paul Johnston
        Participant

          I have just tried this script and it works within my environment.

          Using HPUX 11.i with 3.8.1P

          The resulting file Portfile.txt is not formatted for best viewing as the

          column information is not lined up but I am not complaining just an

          observation. It could be my HPUX Text editor that displays it incorrectly.

          All the Port   information is there.

          Just one note that I think is obvious . Before running the script change the

          TCL directory to match your version.

          🙂  ðŸ™‚

        • #56009
          Julie Kimmel
          Participant

            Hello,

            I am new in creating tcl/hcitcl scripts, and I was wondering,

            where do commands such as

                 netcfgGetProcConns

            come from?

            They seem to work, but I can not find where they come from.

            I looked in the hcitcl help and other documentation…but did not find any references to them.

            Thanks,

            Julie K.

          • #56010
            Charlie Bursell
            Participant

              $HCIROOT/tcl/lib/cloverleaf/netData.tlib

            • #56011
              Julie Kimmel
              Participant

                Silly question, I know…

                but is this ok to run while process engines are running?

                I just want to double check.

                Thanks,

                Julie

              • #56012
                Charlie Bursell
                Participant

                  Yep   💡

                • #56013
                  Russ Ross
                  Participant

                    I like your post and agree with you that it is necessary to have a way to check if a port is already defined to prevent duplication.

                    We have many sites so I wrote something to list ports defined in all our NetConfigs, too.

                    I can pipe that to a file or grep to check if that port is already defined.

                    We also define many ports in the /etc/services file so we have to search that file too.

                    At one point we discussed using the /etc/serviecs file exclusively so all ports would be defined in a central location but that never came to pass.

                    We have also found it benificail to require all ports to be unique across all our cloverleaf servers for both test and prodcution.

                    In fact, this is one of our in-house standards it has been so benificial.

                    Here is the script I wrote that we have been using to list what ports are defined in all our NetConfigs

                    Code:

                    # Begin Module Header ==============================================================================
                    #
                    #——
                    # Name:
                    #——
                    #
                    # list_ports.ksh
                    #
                    #———
                    # Purpose:
                    #———
                    #
                    # list all the ports defined in the NetConfig for all sites
                    #
                    #——-
                    # Notes:
                    #——-
                    #
                    # Assumption:
                    #
                    # – all sites have a NetConfig file
                    #
                    # Normal Usage:
                    #
                    # list_ports.ksh > x.x
                    #
                    #———
                    # History:
                    #———
                    #
                    # 2001.01.30 Russ Ross
                    #          – wrote initial version
                    #
                    # End of Module Header =============================================================================

                    saveDir=`pwd`
                    siteList=`list_sites.ksh`

                    cd $HCIROOT
                    for site in $siteList; do
                      cd $site
                      echo ” ”
                      echo “———————————”
                      echo “Ports defined in $HCIROOT/$site”
                      echo “———————————”
                      echo ” ”
                      portList=`grep “{ PORT [0-9].* }” NetConfig | awk ‘{print $3}’ |sort -n`
                      for port in $portList; do
                         echo $port
                      done
                      cd – $1>/dev/null
                    done
                    cd $saveDir

                    echo ” “

                    Code:

                    #!/usr/bin/ksh

                    # Begin Module Header ==============================================================================
                    #
                    #——
                    # Name:
                    #——
                    #
                    # list_sites.ksh
                    #
                    #———
                    # Purpose:
                    #———
                    #
                    # List all the sites for the current $HCIROOT
                    #
                    #——–
                    # Inputs:
                    #——–
                    #
                    # none
                    #
                    #——-
                    # Notes:
                    #——-
                    #
                    # This script assumes the proper environment is set when it is called
                    # and all sites are symbolic links at the $HCIROOT level
                    #
                    #———
                    # History:
                    #———
                    #
                    # 2001.02.22 Russ Ross
                    #          – wrote initial version.
                    #
                    # 2001.07.25 Russ Ross
                    #          – modified to look for $HCIROOT/*/siteInfo files to determine the list of sites,
                    #            previously had looked for symbolic links in the $HCIROOT directory which only
                    #            works if everyone follows MDACC conventions
                    #
                    # 2003.11.17 Russ Ross
                    #          – modified to execlude siteProto from the list of sites
                    #
                    # End of Module Header =============================================================================

                    #—————————————————————————————–
                    # get a list of all the sites for the current $HCIROOT
                    # (Note:  there is an assumption that all sites are a symbolic link at the $HCIROOT level)
                    #—————————————————————————————–

                    (cd $HCIROOT; ls ./*/siteInfo 2>/dev/null) | awk -F/ ‘{print $2}’ | grep -v siteProto | sort

                    Russ Ross
                    RussRoss318@gmail.com

                Viewing 5 reply threads
                • The forum ‘Cloverleaf’ is closed to new topics and replies.