› Clovertech Forums › Cloverleaf › NetConfig Parse – Basic
Hello – I’m trying to get familiar with how to parse the NetConfig file. Tried the commands below to try and access PORT information, and got errors. I think I’m using the right commands. Any details on what I’m doing wrong or on a better way to access basic NetConfig information are very much appreciated.
[dev_pt_mgmt]$ tcl
tcl>netconfig load
1
tcl>netconfig get version
3.20
tcl>netconfig get connection list
to_masimo_NPE_adt to_collectivemed_adt to_iecg_adt …..
tcl>keylget to_masimo_NPE_adt PROTOCOL.PORT
Error: can’t read “to_masimo_NPE_adt”: no such variable
tcl>keylkeys to_masimo_NPE_adt
Error: can’t read “to_masimo_NPE_adt”: no such variable
tcl>
Attached is a script you can use for reference that pulls connection info from NetConfig. I had to add the .txt extension to get it to upload. Per Infor, future direction to get this type of info is via the Cloverleaf API (CLAPI), but I have not utilized that functionality yet.
Hope this helps.
Jim Cobane, Henry Ford Health
Hello – thanks! Works great! A great reference for sure. Ideally need to capture site, process, source information (name, ip, port) , destination information (name, ip, port), xlate info, tcl info all in one line/record; your script seems like great starting place. Thanks again.
Here is what I coded using the API:
[catch {netconfig load $hciroot/$site_name/NetConfig} err] (use your site name in place of the variable $site_name)
The above loads the NetConfig and uses a catch in case there is an error.
Then:
[catch {set list_thread_names [netconfig get connection list]} err] <– This gets a list of the connections in the NetConfig.
Then:
Inside a foreach (working over the above list of connections)…
[catch {set list_thread_details [netconfig get connection data $thread_name]} err] <– gets the thread details.
set port_elem [keylget list_thread_details PROTOCOL.PORT] <– gets the PORT number/mnemonic
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
Hello! I need to explore this a lot more – thanks for the details.
Hello – thanks! Works great! A great reference for sure. Ideally need to capture site, process, source information (name, ip, port) , destination information (name, ip, port), xlate info, tcl info all in one line/record; your script seems like great starting place. Thanks again.
Hello – found that I was missing one command in the sequence I was originally testing.
Hello – still having some issues with the NetConfig read/parse script that I have been “playing” with. The script is based on feedback/input from this forum and its highly appreciated.
The script is mostly fuctional (?! 🙂 ), but it hits an error when the NetConfig that is being read/parsed has references to global variables. I’ve tried a few suggestions found in the forum, but I can’t get this to work.
For example, if setsite is set to dev_lab, and I ran the script the script throws errors when it reads the NetConfig for the devcb2a site because the NetConfig for devcb2a has references to global variables, but the global variables don’t exist in the dev_lab site or environment (at least that’s what I think the issue is). I believe I need to set the site to the site that corresponds to the NetConfig that is being read/parsed. How can I change or set the site (setsite) environment to the appropriate site? Thanks in advance.
Script segment below:
#!/bin/env tcl
#####################################################################
# need to reditect output to file to capture output
# based on clovertech sample
# Tcl program to obtain Routing info for each thread
# Author: James Cobane
#####################################################################
global hciRoot global hciSite
global siteDir
set hciRoot $env(HCIROOT)
set hciSite $env(HCISITE)
set siteDir $env(HCISITEDIR)
set netConfigName [lindex $argv 0]
netcfgLoad $netConfigName
set connList [lsort [netcfgGetConnList]]
#jd
#headings
puts “Site#Process#SourceThrd#IbHost#IbPort#IbType#IbAutoStrt#IsSrvr#IbDirParseProc#IbFtpDir#SrcInDataProc#SrcOutDataProc#TrxID#RawRtProc#XlPreProc#XlPostProc#XlType#Xlate#DestThrd#ObHost#ObPort#ObType#ObAutoStrt#ObIsSrvr#ObFtpDir#DestInDataProc#DestOutDataProc”
#jd end
#set site1 “dev_misc”
set site1 “devcb2a”
##if ![catch {netcfgLoad} err] {
##NCFG:ChangeSite $site1
##puts “>>>> CHANGING SITE pre netconfig load<<<<<”
##netcfgLoad
##puts “>>>> post netconfig load<<<<<”
##}
##exit
set siteList [lsort $site1]
foreach site $siteList {
if ![catch {netcfgLoad $hciRoot/$site/NetConfig} err] {
NCFG:ChangeSite $site
netcfgLoad
if [string equal $err “1”] {
puts “>>>> $site ERROR HERE?!?! $err <<<<<”
exit
}
.
.
.
Here is how I did it:
#Do the switch
set ret_cd [catch {eval [exec ${::env(HCIROOT)}/sbin/hcisetenv -site tcl $sitename]} err]
if {$ret_cd} {
echo “$module Switch to site >$sitename< failed…”
echo “$module with error >$err<. Aborting!”
return 0
}
return 1
$sitename was gathered elsewhere.
The above code is actually part of a proc invoked by other procs specifically to switch to a specific site for the invoking proc to do its work.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
Hello – thanks for the code. I tried running a test, but still having probs. Below is that I have tested, and the output of the run. I run the script when setsite is “dev_lab”. Running CL version 20.1. Thanks
#!/bin/env tcl
#####################################################################
# need to reditect output to file to capture output
# based on clovertech sample
# Tcl program to obtain Routing info for each thread
# Author: James Cobane
##########################################################
global hciRoot global hciSite
global siteDir
set hciRoot $env(HCIROOT)
set hciSite $env(HCISITE)
set siteDir $env(HCISITEDIR)
set netConfigName [lindex $argv 0]
netcfgLoad $netConfigName
#set connList [lsort [netcfgGetConnList]]
#jd
#headings
puts “Site#Process#SourceThrd#IbHost#IbPort#IbType#IbAutoStrt#IsSrvr#IbDirParseProc#IbFtpDir#SrcInDataProc#SrcOutDataProc#TrxID#RawRtProc#XlPreProc#XlPostProc#XlType#Xlate#DestThrd#ObHost#ObPort#ObType#ObAutoStrt#ObIsSrvr#ObFtpDir#DestInDataProc#DestOutDataProc”
#jd end
#set site1 “dev_misc”
set site1 “devcb2a”
# from clovertech
set ret_cd [catch {eval [exec ${::env(HCIROOT)}/sbin/hcisetenv -site tcl $site1]} err]
sleep 1
if {$ret_cd} {
echo “>>> Switch to site >$site1< failed… EXITING <<<”
exit
}
if ![catch {netcfgLoad $hciRoot/$site1/NetConfig} err] {
if {$err} {
puts “>>> Failed to load NetConfig >$site1< failed EXITING <<< ”
exit
}
set connList [lsort [netcfgGetConnList]]
echo “CONN LIST: ” $connList
}
exit
=== output ====
[hci WIP]$ ./tpsTest.tcl
Site#Process#SourceThrd#IbHost#IbPort#IbType#IbAutoStrt#IsSrvr#IbDirParseProc#IbFtpDir#SrcInDataProc#SrcOutDataProc#TrxID#RawRtProc#XlPreProc#XlPostProc#XlType#Xlate#DestThrd#ObHost#ObPort#ObType#ObAutoStrt#ObIsSrvr#ObFtpDir#DestInDataProc#DestOutDataProc
Global variable name ‘ukg’ not found
Global variable name ‘ukg_login’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘ftp_proview’ not found
Global variable name ‘ftp_gempos’ not found
Global variable name ‘lawprod’ not found
Global variable name ‘ftp_proview’ not found
>>> Failed to load NetConfig >devcb2a< failed EXITING <<<
A lot of superfluous stuff going on 🙂
I have never been able to successfully set sites from a Tcl proc. If you want to do multiple site just use the site.ini file.
set root $::env(HCIROOT)
# read server.ini
set ini [read_file -nonewline [file join $root server server.ini]]
# Get the environs line ( list of sites separated by 😉
set envStr “”
regexp -line {^environs=(.*?)$} $ini {} envStr
# If you want error checking then if envStr empty, something wrong
# Full path of sites in a list
foreach site [split $envStr \;] {
# Note that file join will convert backslashes to forward if on Windows
netcfgLoad [file join $site NetConfig]
set connList [lsort [netcfgGetConnList]]
echo \n\nSite $site Connections:
foreach conn $connList {echo \t$conn}
echo \n
}
I will let you add the code you want to this. I hope it helps
Hello – thank you for the details. I’ll play around with the code, have lots to learn still.