Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Getting the hostname

I'd like to get the fully qualfield F5 hostname into an iapp variable.

 

set hostname [tmsh::get config /sys global-settings hostname] works, however returns

sys global-settings {

hostname F5.com

}

Tcl commands like findstr and getfield don't work. I'd like to get just F5.com into my variable.

Any tips?

 

 

 

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
There are a few ways to get at this data, but the preferred way is to use tmsh::get_field_value to pull the value of the 'hostname' field out of the first entry of the list that is returned from your command to tmsh::get_config. A full example is:

set hostname [tmsh::get_config /sys global-settings hostname]
puts [tmsh::get_field_value [lindex $hostname 0] hostname]


The call to lindex is needed because tmsh::get_config returns a list (in this case with just one element, but a list nonetheless), so you have to explicitly descend into it to get at something that tmsh::get_field_value can work with.

You can also treat the data that tmsh::get_config returns as a string and operate on it with standard string/list tools. If you go that route though, you should probably be using tmsh::list instead because the data that tmsh::get_config returns isn't really a string - Tcl just makes it into one when you try to access it that way. The config text that you get back is easily parsed directly by Tcl once you notice a few things. First, the tmsh config syntax is composed of nested values surrounded by curly braces, making it naturally consumable using commands like lindex, foreach, etc to pick through it. Secondly, most (though not all) of the tmsh config syntax just happens to be in "array set" format, which makes it fairly easy to parse and store as a hash in most cases. With that said, the example I gave above is easiest.

For the sake of completeness, you should also consider whether the configured hostname in "sys global" is actually what you want, or whether you need to dig through "cm device-group" to get at that data.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

that's absolutely fantastic.. thanks

0