Forum Discussion
soymanue
Nimbostratus
Oct 12, 2012Hostname split
Hello
I need to split a hostname into three parts ( ..).
This can be done al least on two ways:
1) scan [HTTP::host] %\[^.\].%\[^.\].%s prefix host suffix
2) set prefix [ge...
nitass
Employee
Oct 12, 2012this is mine but i think it is not efficient anyway. 🙂
[root@ve10:Active] config b rule myrule list
rule myrule {
when RULE_INIT {
set hostname "f5.com"
set last_dot [string last "." $hostname]
set second_dot [string last "." $hostname [expr {$last_dot -1}]]
set suffix [string range $hostname [expr {$last_dot + 1}] end]
set host [string range $hostname [expr {$second_dot + 1}] [expr {$last_dot - 1}]]
set prefix [string range $hostname 0 [expr {$second_dot - 1}]]
log local0. "hostname=$hostname | prefix=$prefix | host=$host | suffix=$suffix"
set hostname "www.f5.com"
set last_dot [string last "." $hostname]
set second_dot [string last "." $hostname [expr {$last_dot -1}]]
set suffix [string range $hostname [expr {$last_dot + 1}] end]
set host [string range $hostname [expr {$second_dot + 1}] [expr {$last_dot - 1}]]
set prefix [string range $hostname 0 [expr {$second_dot - 1}]]
log local0. "hostname=$hostname | prefix=$prefix | host=$host | suffix=$suffix"
set hostname "xxx.yyy.f5.com"
set last_dot [string last "." $hostname]
set second_dot [string last "." $hostname [expr {$last_dot -1}]]
set suffix [string range $hostname [expr {$last_dot + 1}] end]
set host [string range $hostname [expr {$second_dot + 1}] [expr {$last_dot - 1}]]
set prefix [string range $hostname 0 [expr {$second_dot - 1}]]
log local0. "hostname=$hostname | prefix=$prefix | host=$host | suffix=$suffix"
}
}
[root@ve10:Active] config tail -f /var/log/ltm
Oct 12 19:25:48 local/ve10 err mcpd[3815]: 01020066:3: The requested rule (myrule) already exists in partition Common.
Oct 12 19:25:48 local/tmm info tmm[7926]: Rule myrule : hostname=f5.com | prefix= | host=f5 | suffix=com
Oct 12 19:25:48 local/tmm info tmm[7926]: Rule myrule : hostname=www.f5.com | prefix=www | host=f5 | suffix=com
Oct 12 19:25:48 local/tmm info tmm[7926]: Rule myrule : hostname=xxx.yyy.f5.com | prefix=xxx.yyy | host=f5 | suffix=com
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects