Technical Article

Exporting LTM Configuration Into XML

A question came up on an internal mailing list regarding getting the configuration off of the LTM into a format that can be parsed by an external tool. In this case, the request was for an XML format of the BIG-IP configuration. With iControl, It’s fairly simple to query configuration objects and it’s just a matter of throwing in a few print statements to build a XML document of the object hierarchy.

This article will show you how to query the list of LTM virtual servers and their child properties and objects and then export the values into XML.

Initialization

I’ve implemented this sample in Perl, but it just as easily could have been written in any language you prefer. The benefit of perl is that it can be run from the command prompt on the BIG-IP itself.

the script starts with the normal perl declaration and variable assignments. The input parameters are validated and then the SOAP specific typecasting is specified to tell the SOAP parser about the native iControl enumeration types.

Creating An Interface Object

Since I’m using several interfaces, I found it easier to write a wrapper subroutine to instantiate the appropriate iControl interface object, assign it the user credentials, and return to the caller. This saves a lot of space when you are working multiple iControl interfaces.

Querying The Configuration

The following code shows all the iControl calls needed to query the virtual servers configuration. First, the LocalLB.get_list() method is called to get a list of virtual servers. That list is then passed into the get_destination(), get_type(), get_rule(), get_profile(), get_persistence_profile(), and get_default_pool_name() methods. The pool name list returned from the get_default_pool_name() method is then used as the input for the Pool.get_member(), get_lb_method(), and get_monitor_association() methods.

1: $LocalLBVirtualServer = &GetInterface("LocalLB", "VirtualServer");

2: $LocalLBPool = &GetInterface("LocalLB", "Pool");

3: $LocalLBPoolMember = &GetInterface("LocalLB", "PoolMember");

4:

5: # VS List

6: $soapResponse = $LocalLBVirtualServer->get_list();

7: &checkResponse($soapResponse);

8: @vs_list = @{$soapResponse->result};

9:

10: # Destination

11: $soapResponse = $LocalLBVirtualServer->get_destination(

12: SOAP::Data->name (virtual_servers => [@vs_list])

13: );

14: &checkResponse($soapResponse);

15: @destination_list = @{$soapResponse->result};

16:

17: # Type

18: $soapResponse = $LocalLBVirtualServer->get_type(

19: SOAP::Data->name (virtual_servers => [@vs_list])

20: );

21: &checkResponse($soapResponse);

22: @vstype_list = @{$soapResponse->result};

23:

24: # iRules

25: $soapResponse = $LocalLBVirtualServer->get_rule(

26: SOAP::Data->name (virtual_servers => [@vs_list])

27: );

28: &checkResponse($soapResponse);

29: @rule_listA = @{$soapResponse->result};

30:

31: # Profiles

32: $soapResponse = $LocalLBVirtualServer->get_profile(

33: SOAP::Data->name(virtual_servers => [@vs_list])

34: );

35: &checkResponse($soapResponse);

36: @profile_listA = @{$soapResponse->result};

37:

38: $soapResponse = $LocalLBVirtualServer->get_persistence_profile(

39: SOAP::Data->name(virtual_servers => [@vs_list])

40: );

41: &checkResponse($soapResponse);

42: @persistenceprofile_listA = @{$soapResponse->result};

43:

44: # Pools

45: $soapResponse = $LocalLBVirtualServer->get_default_pool_name(

46: SOAP::Data->name (virtual_servers => [@vs_list])

47: );

48: &checkResponse($soapResponse);

49: @pool_list = @{$soapResponse->result};

50:

51: # Pool Members

52: $soapResponse = $LocalLBPool->get_member(

53: SOAP::Data->name(pool_names => [@pool_list])

54: );

55: &checkResponse($soapResponse);

56: @member_listA = @{$soapResponse->result};

57:

58: # LB Method

59: $soapResponse = $LocalLBPool->get_lb_method(

60: SOAP::Data->name(pool_names => [@pool_list])

61: );

62: &checkResponse($soapResponse);

63: @lbmethod_list = @{$soapResponse->result};

64:

65: $soapResponse = $LocalLBPool->get_monitor_association(

66: SOAP::Data->name(pool_names => [@pool_list])

67: );

68: &checkResponse($soapResponse);

69: @monitor_list = @{$soapResponse->result};

At this point, we have the configuration stored in the various local variables and we are ready to print it in an XML format.

Generating the XML

The code below creates the XML declaration and the various elements that consist of the virtual server configuration. We iterate through the virtual server list in the $vs_list variable to add an element for each virtual server. The name, destination, and type are all stored as attributes of the element.

Then we iterate through the list of iRules associated with the given virtual server and output an element for each one containing the iRule name and priority. This is followed by the list of profiles and persistence profiles for the current virtual server.

Next we will go through the pool members in the pool for the current virtual server. An element is created for each pool containing the name and lb_method. For each pool element, the pool members are then displayed as a child element with their address and port.

Finally, the monitors associated with the virtual server are presented. The type of monitor association is given along with the quorum value and child entries for each monitor template is added.

Parsing With External Tools

In the following example, I’ll pipe the output from the perl script directly into an XML variable in PowerShell. PowerShell supports XML as a native type, so it’s very easy to look at the configuration like the following example:

1: PS> [xml]$x = perl .\LtmConfigToXml.pl bigip user pass

2: PS> $x.BIGIPConfig.LTM.virtual_server

3:

4: name : dc-sea-web

5: destination : :

6: type : RESOURCE_TYPE_POOL

7: profile : {http, tcp}

8: pool : pool

9:

10: name : xpbert-ssh

11: destination : 10.10.10.202:80

12: type : RESOURCE_TYPE_POOL

13: profile : profile

14: pool : pool

15:

16: name : xpbert-http

17: destination : 10.10.10.149:22

18: type : RESOURCE_TYPE_POOL

19: rule : rule

20: profile : {my_http, tcp, ts_reputation}

21: persistenceprofile : persistenceprofile

22: pool : pool

Extending This Script

I’ve only scratched the surface with the configuration on the BIG-IP. I picked a couple of the components of a virtual server so you may want to add to this for additional configuration objects that I omitted. Also, other high level products like GTM could easily be added to this logic to create a more expansive coverage of the BIG-IP configuration.

Newbie at scripting on F5s...not sure if I did something wrong:syntax error at /PerlLtmConfigToXml.pl line 54, near "sub SOAP::Transport::HTTP::Client::get_basic_credentials--"Execution of /PerlLtmConfigToXml.pl aborted due to compilation errors.

Excellent script and guide.I did notice a slight error in the full source code at line 217print " \n";

Should actually read:print " \n";Otherwise your output will show no ip/port for the first vip and each subsequent vip will actually show the last member pool from the previous vip.Hope this helps. Had me confused for sometime.

Despite having Remote Access, I will not know until tomorrow when I am back at work how the Output of your Scripts may help me.

I currently have this Post with the Title as shown Below;

F5 Command Line to display VIP Details and Status to export to *.csv Table?

Ideally I would like to either have the Text Output to be edited within Notepad++ or Excel vbs to Show the Following;
1: VIP Name.
2: VIP IP Address.
3: VIP Protocol.
4: VIP Pool Name.
5: VIP Pool Members IP Address.
6: VIP Pool Members Port.
7: VIP Pool Member Status? [Up, Down, Disabled or Unknown]
8: VIP Pool Member Last Contact if Down or Unknown?

I have been able to get all of this information with 2 different Scripts, BUT...
The Output Format is going to be a challenge to merge the 2 Outputs in to 1 *.csv Table for clarity.

I will look forward to your feedback on this.

+++ If you have any Tips for F5 LTM SolarWinds Monitoring, Reporting and Alerting?

Thank you in advance to your F5 Scripts.

Kind Regards,

Dan

0

About DevCentral

We are a community of 300,000+ technical peers who solve problems together.