导出GTM的wideip:
1、tmsh list gtm wideip one-line | awk '{print $0"\n"}' >/var/tmp/wideip.txt
2、tmsh list gtm wideip | awk '/wideip/{printf "%s,",$4;printf "\n"}' > wideip.csv
导出WIDEIP详细信息:
Export GTM/DNS Configuration in CSV - tmsh cli script
使用命令创建脚本
tmsh
create cli script gtm-config-parser
脚本内容如下:
create script gtm-config-parser {
## 粘贴proc那段脚本,注意大括号,不要多了或者少了 ##
}
wq 保存退出
q! 不保存退出
注:列出 gtm pool时,必须指定与pool关联的记录类型(a ,aaaa,cname ,mx、naptr 或 srv)。如需输出AAAA记录,将上述代码标红部分改为
aaaa即可,其余部分无需改动。
2)创建完gtm-config-parser脚本后,如需修改脚本内容,可在通过如下命令对脚本进行编辑
tmsh edit cli script gtm-config-parser 修改cli脚本
生成a记录表:tmsh run cli script gtm-config-parser > /var/tmp/gtm-a.csv
//wideip a 类型的如下:
proc script::run {} {
puts "WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL"
foreach { obj } [tmsh::get_config gtm wideip a all-properties] {
set wipname [tmsh::get_name $obj]
set wippools [tmsh::get_field_value $obj pools]
set lbmode [tmsh::get_field_value $obj "pool-lb-mode"]
set lastresort [tmsh::get_field_value $obj "last-resort-pool"]
foreach { status } [tmsh::get_status gtm wideip a $wipname] {
set wipstatus [tmsh::get_field_value $status "status.availability-state"]
set wipstate [tmsh::get_field_value $status "status.enabled-state"]
}
foreach wippool $wippools {
set pool_name [tmsh::get_name $wippool]
set pool_configs [tmsh::get_config /gtm pool a $pool_name all-properties]
foreach pool_config $pool_configs {
set pool_lb [tmsh::get_field_value $pool_config "load-balancing-mode"]
set pool_fb [tmsh::get_field_value $pool_config "fallback-mode"]
if { [catch { set member_name [tmsh::get_field_value $pool_config "members" ]} err] } {
set pool_member $err
} else {
set pool_member ""
set member_name [tmsh::get_field_value $pool_config "members"]
foreach member $member_name {
append pool_member "[lindex $member 1] "
}
}
puts "$wipname,$lbmode,$wipstatus,$wipstate,$pool_name,$pool_lb,$pool_member,$pool_fb,$lastresort"
}
}
}
}
生成aaaa记录表:tmsh run cli script gtm-config-parser > /var/tmp/gtm-aaaa.csv
//wideip aaaa 类型的如下:
proc script::run {} {
puts "WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL"
foreach { obj } [tmsh::get_config gtm wideip aaaa all-properties] {
set wipname [tmsh::get_name $obj]
set wippools [tmsh::get_field_value $obj pools]
set lbmode [tmsh::get_field_value $obj "pool-lb-mode"]
set lastresort [tmsh::get_field_value $obj "last-resort-pool"]
foreach { status } [tmsh::get_status gtm wideip aaaa $wipname] {
set wipstatus [tmsh::get_field_value $status "status.availability-state"]
set wipstate [tmsh::get_field_value $status "status.enabled-state"]
}
foreach wippool $wippools {
set pool_name [tmsh::get_name $wippool]
set pool_configs [tmsh::get_config /gtm pool aaaa $pool_name all-properties]
foreach pool_config $pool_configs {
set pool_lb [tmsh::get_field_value $pool_config "load-balancing-mode"]
set pool_fb [tmsh::get_field_value $pool_config "fallback-mode"]
if { [catch { set member_name [tmsh::get_field_value $pool_config "members" ]} err] } {
set pool_member $err
} else {
set pool_member ""
set member_name [tmsh::get_field_value $pool_config "members"]
foreach member $member_name {
append pool_member "[lindex $member 1] "
}
}
puts "$wipname,$lbmode,$wipstatus,$wipstate,$pool_name,$pool_lb,$pool_member,$pool_fb,$lastresort"
}
}
}
}