Use at will, just leave top comments in.
#!/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