Forum Discussion

JN's avatar
JN
Icon for Nimbostratus rankNimbostratus
May 22, 2019

irule to write to file (not local, not syslog)

First, whoever designed the migration of devcentral, um, just wow. Literally all the links everywhere are broken.

 

Anyway, trying to write a basic irule that will write the client ip to a file on the F5. I don't want it going to the ltm log, nor to syslog. I ran across one article that I think put it into syslog then added a custom syslog rule to capture that filter...seems very heavy. Is there a link (working) that gives all of the logging parameters I can use if it's possible?

If this isn't possible, i could probably write a python script that does what I need. How would I call that from an irule and pass it a variable?

6 Replies

  • Ok so here we go.

    First you need an iRule that passes the client IP address into iRules LX (you'll want to put the LX call in a catch for a prod environment)

    when CLIENT_ACCEPTED {
        set rpcHandle  [ILX::init "fs-pl" "fs-ex"]
        set result [ILX::call $rpcHandle "writeFile" "[IP::client_addr]"]
        log local0. "$result"
    }

    Then this is a simple iRules LX script that will write out a test file with the value of the IP you passed in.

    It will write out the file to the extension folder which will vary.. it will also change slightly each time it executes

    For example, my file was located here:

    /var/sdm/plugin_store/plugins/:Common:fs-pl_83750_4/extensions/fs-ex/test.txt

    the next time, it was located here:

    /var/sdm/plugin_store/plugins/:Common:fs-pl_83750_5/extensions/fs-ex/test.txt

    var f5 = require('f5-nodejs');
    var ilx = new f5.ILXServer();
    var fs = require('fs');
     
    function writeFile(req, res) {
        var ip = req.params()[0];
        fs.writeFile('test.txt', ip, function (err) {
            if (err) {
                res.reply(err);
            } else {
                res.reply("file written successfully");
            }
        });
    }
     
    ilx.addMethod('writeFile', writeFile);
    ilx.listen();

    Hope that helps

    Lee

  • The file handler for TCL has been disabled for traditional iRules.

    I thought I could get round this by using node.js in iRules LX by using the 'fs' module. But looks like this may also be restricted as I'm getting the following error; "errno -2 code ENOENT path /var/tmp/test.txt"

     

    when running the fs.writeFile.. function

     

    There may be another way, but not one that I know of.

    Sorry I can't be more helpful.

     

  • JN's avatar
    JN
    Icon for Nimbostratus rankNimbostratus

    I HATE it when product designers decide to remove the most basic functions.

    I appreciate the effort. Is there any way to make it go to the same folder/file? I'm trying to not have to aggregate or parse data from multiple locations.

    Plus I don't have LX provisioned, :(

  • Yeah it's a pain but I get why they did it, it woudn't take too effort to fill up a volume and break the system.

    Anway, I don't think there is a way from iRules LX to write to another location, I tried writting to /var/tmp/ initially but looks like youre restricted to the ILX extension.

     

    You'd need to copy it from that location to wherever you want it with a shell script or something.

    Not ideal I know