11-Jan-2012 20:59 - edited 02-Oct-2023 10:59
Several months ago I wrote up the v10 formatting for internal and external datagroups: iRules Data Group Formatting Rules. In v11, however, there is a change to the format of the internal data group and the data group reference to external class files (the formatting in the external class file itself is unchanged). The formatting rules in v11 for data groups more closely resembles the tmsh commands necessary to build the class at the CLI (these command attributes are masked if you are using the GUI). I’ll follow the same format as the original write-up in showing the various data group types. The format is the same among internal data group types. If there is no value associated with the key, there is a curly bracket pair trailing the key on the same line. If there is an associated value with a key, the curly bracket opens the value, followed by a newline with the keyword data and the value, then another newline with the closing curly bracket. After the records are listed, the type is specified. For external data groups, the file name and the type are specified. If the filename is in /var/class, the path is omitted from the filename reference.
ltm data-group internal addr_testclass { records { 192.168.1.1/32 { } 192.168.1.2/32 { data "host 2" } 192.168.2.0/24 { } 192.168.3.0/24 { data "network 2" } } type ip }
ltm data-group external addr_testclass_ext { external-file-name addr_testclass.class type ip }
ltm data-group internal int_testclass { records { 1 { data "test 1" } 2 { data "test 2" } } type integer }
ltm data-group external int_testclass_ext { external-file-name int_testclass type integer }
ltm data-group internal str_testclass { records { str1 { data "value 1" } str2 { data "value 2" } } type string }
ltm data-group external str_testclass_ext { external-file-name str_testclass.class type string }
Beginning in v11, external datagroups are imported into a local filestore rather than simply existing someplace on the file system (/config/filestore). However, this filestore is not meant to edited manually. Please follow the steps below for creating or modifying external datagroups. Thanks to hoolio for the steps in this external datagroup section.
1. Create or copy over to LTM a temporary file containing the external data group contents. If copying, make sure the line terminators are \n only not \r\n.
# cat /var/tmp/string_name_value_external_dg.txt "name1" := "value1", "name2" := "value2", "name3" := "value3",
2. Create the new external data group file
tmsh create /sys file data-group string_name_value_external_dg_file separator ":=" source-path file:/var/tmp/string_name_value_external_dg.txt type string
3. Create the external data group referencing the file
tmsh create /ltm data-group external string_name_value_external_dg external-file-name string_name_value_external_dg_file
1. Create a new temporary file containing the updated external data group contents
# cat /var/tmp/string_name_value_external_v2_dg.txt "name1" := "valueA", "name2" := "valueB", "name3" := "valueC",
2. Import the new data group file
tmsh create /sys file data-group string_name_value_external_v2_dg_file separator ":=" source-path file:/var/tmp/string_name_value_external_v2_dg.txt type string
3. Modify the data group definition to reference the new external data group file
tmsh modify /ltm data-group external string_name_value_external_dg external-file-name string_name_value_external_v2_dg_file
4. Delete the old data group file if it’s unneeded
tmsh delete sys file data-group string_name_value_external_dg_file
Whether imporing external datagroups in the GUI or from the CLI, the system does not accept files with \r\n line terminators, it only accepts \n. If you copy files over from windows, most likely you have the wrong terminator in your file format. To check, you can use the od command.
[root@golgotha:Active] data_group_d # od -c /var/tmp/string_name_value_external_dg.txt 0000000 " n a m e 1 " : = " v a l u 0000020 e 1 " , \n " n a m e 2 " : = 0000040 " v a l u e 2 " , \n " n a m e 3 0000060 " : = " v a l u e 3 " , \n 0000077
[root@golgotha:Active] data_group_d # od -c /var/tmp/notepad_dg.txt 0000000 " n a m e 1 " : = " v a l u 0000020 e 1 " , \r \n " n a m e 2 " : = 0000040 " v a l u e 2 " , \r \n " n a m 0000060 e 3 " : = " v a l u e 3 " , 0000100
If your line terminators are incorrect, you can use the tr command to remove the \r's.
[root@golgotha:Active] tmp # cat /var/tmp/notepad_dg.txt | tr -d '\r' > /var/tmp/notepad_dg_update.txt [root@golgotha:Active] tmp # od -c /var/tmp/notepad_dg_update.txt 0000000 " n a m e 1 " : = " v a l u 0000020 e 1 " , \n " n a m e 2 " : = 0000040 " v a l u e 2 " , \n " n a m e 3 0000060 " : = " v a l u e 3 " , 0000076
http://devcentral.f5.com/tabid/53/aft/1184918/Default.aspx
In v11 to use an external file, you need to import it first. Here are the steps:
1. Create a text file containing the data group contents. Here is a sample string data group file:
"name1" := "value1",
"name2" := "value2",
"name3" := "value3",
2. If you're on Windows, use a utility like dos2unix.exe to convert the line endings from CRLF to LF (https://encrypted.google.com/search?q=dos2unix.exe). If you don't do this, you will get an error on import:
01070627:3: The string data group external file (/config/filestore/.stage_d/55_d/Common_d/data_group_d/:Common:name_value_external_dg_1) has an invalid format, line: 2.
3. Navigate to System | File Management | Data Group File List | Import
4. Specify a filename. Example:
File Name: C:\tmp\name_value_external_dg.dos.txt
Name: name_value_external_dg
File Contents: string
Key / Value Pair Seperator: =:
5. Navigate to Local Traffic | iRules | Data Group List | Create
6. Specify a data group name. Example:
Name: name_value_external_dg
Type: External (File)
File Name: name_value_external_dg
Aaron
Thanks!
when HTTP_REQUEST {
set redirecthost [class search -value $::ListeShwebredir equals [string tolower [HTTP::host]]]
if { $redirecthost ne "" } {
HTTP::redirect "$redirecthost"
log local0. "DEBUG-REDIR [HTTP::host][HTTP::uri] redirection vers : $redirecthost"
unset redirecthost
return
}
}
But, it doesn't work in version 11. We received this error message :
Nov 21 08:20:59 tmm err tmm[7850]: 01220001:3: TCL error: /Common/Shwebredir-iRule - can't read "::ListeShwebredir": no such variable while executing "class search -value $::ListeShwebredir equals [string tolower [HTTP::host]]"
Does any body know a solution for it?
Yves
 
 
Yes, remove the $:: prefix from the data group name: 
 
https://clouddocs.f5.com/api/irules/class.html 
 
Note that you should not use a $:: or :: prefix on the datagroup name when using the class command (or in any datagroup reference on 9.4.4 or later). 
 
In v9.4.4 - 10, using $::datagroup_name will work but demote the virtual server from running on all TMMs. For details, see the CMP compatibility page. 
 
In v11, using $::datagroup_name will result in a TCL runtime error and a reset being sent to the client!
On 11.3 I'm trying to modify an existing external datagroup as per the example above, but I get this error:-
[root@L22RRZPEP12:/S1-green-P:Active] tmp tmsh modify /ltm data-group external externaldg external-file-name list2
Syntax Error: "external-file-name" may not be specified in the context of the "modify" command. "external-file-name" may be specified using the following commands: create, list
[root@L22RRZPEP12:/S1-green-P:Active] tmp
Any ideas how I can modify the group without deleting and re-creating it?
Thanks,
Jon
Using the example above, you simple need to re-read the external file. This works:-
tmsh modify /sys file data-group string_name_value_external_dg_file separator ":=" source-path file:/var/tmp/string_name_value_external_dg_new_file.txt
I wonder how the external file format looks like to be used for importing external address data group in v11.3.
Compete example similar to importing string would be beneficial.
New to these stuff and hope to get the guidance along.
Thanks!
Joe
I've read through this thread, get to thinking I understand it but still no success. I've read older threads with script suggestions - I figured this would be a pretty simple process. I'm running 12.1.1. I have an existing Address type data group, I need to add about 250 IP addresses to the group.
Can I add/import into my existing Address type data group? Can I use the File Management function to do so?
Can you give an example of loading an external datagroup file non-interactively with the type "ip" please? All of the combinations I've tried thus far give me the error, "0107169a:3: The data group external file (/config/filestore/.stage_d/...) has an invalid format, line: 1.". Thank you.
Ok - turns out the format is similar to the V10 rules. The following worked - note that if you give the CIDR you have to use "network" and not "host" even if it's a 32-bit netmask.
network 192.168.1.1/32,
network 192.168.1.2/32,