有没有一种方法可以使用PHP或任何其他语言从F5 big-ip conf文件中获取数据?

时间:2019-03-05 17:46:24

标签: php python automation f5 big-ip

我对网络不熟悉,但是我有一个要求,我必须读取big-ip conf文件并将虚拟ltm数据存储在文件中。

conf文件示例:

> ltm virtual /Common/vs_test {
>     destination /Common/10.01.01.111:80
>     ip-protocol tcp
>     mask 255.255.255.255
>     policies {
>          /Common/adt_vs_test {}
>     }
>     profile {
>        /Common/ADT_DSS_A_G { }
>     }
>     rules {
>        ....
>     }
>     security {
>         ....
>     } 
  }

从此文件中,我需要

  

虚拟服务器名称-vs_test

     

IP:10.01.01.111

     

端口:80

     

安全策略:DSS_A_G

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您可以编写一个tmsh脚本,以在BIG-IP上本地使用该脚本来查询该信息,也可以使用iControl REST接口来查询该信息。当概要文件和策略埋在父虚拟服务器对象的子集合中时,您可能最终会获得多个查询以精确地查询正确的信息。但是,在一个查询中,您可以使用curl或Postman之类的工具来拉回名称,目的地(虚拟服务器的IP +端口)和配置文件收集项:

https://ltm3.test.local/mgmt/tm/ltm/virtual?$select=name,destination,profilesReference&expandSubcollections=true

这将以以下json格式返回仅包含名称,ip +端口和配置文件信息的所有虚拟服务器(仅出于简洁起见显示了具有策略的虚拟服务器):

{
    "kind": "tm:ltm:virtual:virtualcollectionstate",
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual?$select=name%2Cdestination%2CprofilesReference&expandSubcollections=true&ver=14.0.0",
    "items": [
        {
            "name": "bigvip_443",
            "destination": "/Common/192.168.102.60:443",
            "profilesReference": {
                "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles?ver=14.0.0",
                "isSubcollection": true,
                "items": [
                    {
                        "kind": "tm:ltm:virtual:profiles:profilesstate",
                        "name": "ASM_asm_test_policy",
                        "partition": "Common",
                        "fullPath": "/Common/ASM_asm_test_policy",
                        "generation": 569,
                        "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles/~Common~ASM_asm_test_policy?ver=14.0.0",
                        "context": "all",
                        "nameReference": {
                            "link": "https://localhost/mgmt/tm/security/bot-defense/asm-profile/~Common~ASM_asm_test_policy?ver=14.0.0"
                        }
                    },
                    {
                        "kind": "tm:ltm:virtual:profiles:profilesstate",
                        "name": "clientssl",
                        "partition": "Common",
                        "fullPath": "/Common/clientssl",
                        "generation": 553,
                        "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles/~Common~clientssl?ver=14.0.0",
                        "context": "clientside",
                        "nameReference": {
                            "link": "https://localhost/mgmt/tm/ltm/profile/client-ssl/~Common~clientssl?ver=14.0.0"
                        }
                    },
                    {
                        "kind": "tm:ltm:virtual:profiles:profilesstate",
                        "name": "http",
                        "partition": "Common",
                        "fullPath": "/Common/http",
                        "generation": 553,
                        "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles/~Common~http?ver=14.0.0",
                        "context": "all",
                        "nameReference": {
                            "link": "https://localhost/mgmt/tm/ltm/profile/http/~Common~http?ver=14.0.0"
                        }
                    },
                    {
                        "kind": "tm:ltm:virtual:profiles:profilesstate",
                        "name": "tcp",
                        "partition": "Common",
                        "fullPath": "/Common/tcp",
                        "generation": 553,
                        "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles/~Common~tcp?ver=14.0.0",
                        "context": "all",
                        "nameReference": {
                            "link": "https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp?ver=14.0.0"
                        }
                    },
                    {
                        "kind": "tm:ltm:virtual:profiles:profilesstate",
                        "name": "websecurity",
                        "partition": "Common",
                        "fullPath": "/Common/websecurity",
                        "generation": 568,
                        "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~bigvip_443/profiles/~Common~websecurity?ver=14.0.0",
                        "context": "all",
                        "nameReference": {
                            "link": "https://localhost/mgmt/tm/ltm/profile/web-security/~Common~websecurity?ver=14.0.0"
                        }
                    }
                ]
            }
        },

如果您使用自己选择的语言编写脚本以仅从虚拟服务器返回所需的数据,则此方法更加清洁,并且可以通过远程计算机针对拥有的许多大IP设备进行此操作。< / p>