require 'restclient'
# See app auth for headers function
def log_usage_data( params )
missingParams = [ :ip,
:url,
:relative_url,
:application_name
] - params.keys
raise "Missing #{ missingParams }" if missingParams.any?
payload = JSON.dump( params )
RestClient.post("https://example.performancebridge.com/pb/api/usage", payload, self.headers(payload))
end
usage_data = {
ip: "10.0.0.1",
url: "http://www.example.com",
platform: "string",
username: "primary/username",
browser_name: "examplebrowser",
relative_url: "/example/rel/url",
browser_version: "1.0.0",
query_parameters: "id=1&limit=10&f=json",
application_name: "Example Application",
message_event_time: "1628707453350"
}
log_usage_data(usage_date)
import requests
import json
import datetime
import hashlib
# See app auth for headers function
def audit(audit_record):
body = json.dumps(audit_record)
# You'll need to change the url here to the platform's hostname
r = requests.post("https://example.performancebridge.com/pb/api/usage",data=body,headers=headers(body))
if r.status_code != 200:
return "HTTP Error " + str(r.status_code) + ": " + r.content
return r.json()
# example usage
audit_record = {
"request_info": "http://performancebridge.example.com/service-tools/view?exam=1",
"requesting_ip": "127.0.0.1",
"user_login": "bridgeadm",
"user_domain": "realm",
"table_name": "rad_exams",
"ids": [1,2,3],
}
audit(audit_record)
const request = require('sync-request');
// See note below for request headers setup
const headers = require('../headers.js')
exports.log_usage = function(data, params) {
if (params == undefined) { params = [] };
var args = {
body: JSON.stringify(data),
headers: headers(JSON.stringify(data)),
};
var res = request('POST', process.env.PB_API_URL + "/usage", args);
return JSON.parse(res.body.toString());
}
// Usage example
const usage_data = {
ip: "10.0.0.1",
url: "http://www.example.com",
platform: "string",
username: "primary/username",
browser_name: "examplebrowser",
relative_url: "/example/rel/url",
browser_version: "1.0.0",
query_parameters: "id=1&limit=10&f=json",
application_name: "Example Application",
message_event_time: "1628707453350"
}
const response = usage_api.log_usage(usage_data) // POST to '/usage'
console.log(response);