Applies To:
Show VersionsBIG-IP LTM
- 12.1.6, 12.1.5, 12.1.4, 12.1.3, 12.1.2, 12.1.1, 12.1.0
Referencing an External File from within an iRule
Overview: Referencing an external file from an iRule
Using the BIG-IP® Configuration utility or tmsh, you can import a file or URL from another system to the BIG-IP system, with content that you want an iRule to return to a client, based on some iRule event. Possible uses for this feature are:
- To send a web page other than the page that the client requested. For example, you might want the system to send a maintenance page instead of the requested page.
- To send an image.
- To use a file as a template and modify the file in the iRule before sending the file.
- To download policy information from an external server and merge that data with a locally-stored policy.
The file that an iRule accesses is known as an iFile, and can be any type of file, such as a binary file or a text file. These files are read-only files.
This example shows an iRule that references an iFile named ifileURL, in partition Common:
ltm rule ifile_rule { when HTTP_RESPONSE { # return a list of iFiles in all partitions set listifiles [ifile listall] log local0. "list of ifiles: $listifiles" # return the attributes of an iFile specified array set array_attributes [ifile attributes "/Common/ifileURL"] foreach {array attr} [array get array_attributes ] { log local0. "$array : $attr" } # serve an iFile when http status is 404. set file [ifile get "/Common/ifileURL"] log local0. "file: $file" if { [HTTP::status] equals "404" } { HTTP::respond 200 ifile "/Common/ifileURL" } } }
iRule commands for iFiles
This list shows the commands available for referencing an iFile within an iRule. All of these commands return a string, except for the command [ifile attributes IFILENAME], which returns an array.
Available iRule commands for referencing an iFile
[ifile get IFILENAME] [ifile listall] [ifile attributes IFILENAME] [ifile size IFILENAME] [ifile last_updated_by IFILENAME] [ifile last_update_time IFILENAME] [ifile revision IFILENAME] [ifile checksum IFILENAME] [ifile attributes IFILENAME]
Task summary
You can import an existing file to the BIG-IP® system, create an iFile that is based on the imported file, and then write an iRule that returns the content of that file to a client system, based on an iRule event.
Task list
Importing a file for an iRule
Creating an iFile
Writing an iRule that references an iFile
Implementation result
You now have an iRule that accesses a file on the BIG-IP®system, based on a particular iRule event.