IBM

Configuring Revenium Metering for IBM DataPower

APIs being proxied by IBM DataPower instances can be metered by Revenium using a simple GatewayScript configured in a Multi-Protocol Gateway Service as part of a Processing Policy.

Setting up a TLS Client Profile

A TLS Client Profile must be configured for the GatewayScript to communicate with the Revenium Platform API. Start by navigating to Objects -> Crypto Configuration -> Configure TLS Client Profile and create a Client Profile called "revenium-metering":

Configuring a TLS Client Profile

Configuring a Multi-Protocol Gateway Processing Policy

Navigate to Multi-Protocol Gateway and either create or select an existing Multi-Protocol Gateway:

Select Multi-Protocol Gateway
Select an existing or create a new Multi-Protocol Gateway

Select an existing or create a new Processing Policy.

Select an existing or create a new Processing Policy

Add a GatewayScript Action as a new Rule and set the Rule Direction to "Both Directions"

Add a GatewayScript Action as a new Rule

Edit the following GatewayScript and replace the "sourceId" with the ID of the Revenium Source that will be metered with DataPower. Also replace the "x-api-key" field with the Revenium Metering Beacon API Key. Please contact the Revenium Customer Success team if you require an API key.

The sourceId will become an optional field in an upcoming release

var urlopen = require('urlopen');
var hm = require('header-metadata');
var sm = require('service-metadata');

var reveniumURL = "https://api.hypercurrent.io/meter/v1/api/event"
var apiKey = "hak_1234"
var assetId = "lkpkW3:7d877eb7-19df-4b4c-8500-2958a4b1c734"
var sslClientProfile = "revenium-metering"

var ctx = session.name('revenium') || session.createContext('revenium');

if (ctx.getVariable("requestId")) {
    var payload = {
        "requestId": ctx.getVariable("requestId"),
        "eventType": "RESPONSE",
        "currentMillis": Date.now()
    }

    var options = {
        target: reveniumURL,
        sslClientProfile: sslClientProfile,
        method: 'post',
        headers: {'x-api-key': apiKey},
        contentType: 'application/json',
        timeout: 60,
        data: JSON.stringify(payload)
    };

    urlopen.open(options, function (error, response) {
        response.disconnect()
    });

} else {

    ctx.setVariable("requestId", sm.getVar("var://service/global-transaction-id"));

    var payload = {
        "requestId": ctx.getVariable("requestId"),
        "eventType": "REQUEST",
        "assetId": assetId,
        "productKey": hm.current.get("x-revenium-product-key"),
        "uri": sm.getVar("var://service/URL-in"),
        "method": sm.protocolMethod,
        "currentMillis": Date.now()
    }

    var options = {
        target: reveniumURL,
        sslClientProfile: sslClientProfile,
        method: 'post',
        headers: {'x-api-key': apiKey},
        contentType: 'application/json',
        timeout: 60,
        data: JSON.stringify(payload)
    };

    urlopen.open(options, function (error, response) {
        response.disconnect()
    });
}

Finally, upload the script and apply the Policy. Once this is done, this API is successfully set up for Revenium metering.

Last updated

Was this helpful?