Experiments in Node.js: Querying Oracle Enterprise Operation Monitor
Toby Allen
Solving your customer identity challenges with Auth0 - Senior Solutions Engineer | CISSP | CCSP
I wanted to have a play around with the Enterprise Operations Monitor API. Customer interest in integrations are growing & I wanted to explore some use cases. At the same time I decided it was time to get my hands dirty with Node.js. It has been a while since I worked closely in Javascript and it seems I'd forgotten the joys of asynchronous programming... Callbacks!
I must admit it took me a little while to get my head back around Callbacks. The concepts turn standard procedural programming on its head. It's so hard to intuitively understand that the lovely phrase "Callback Hell" was coined and there is even a website dedicated to it (https://callbackhell.com/).
Anyway, I digress. My objective this week was to play around with the EOM API. EOM if you're not familiar is a VoIP Network monitoring platform providing real time monitoring and troubleshooting for SIP networks. It can drastically reduce the "Mean Time to Finger Pointing" in a voice network. Check out the video at the link below for a brief overview.
EOM now exposes almost all of the information it captures via a REST API. In fact most of the displayed graphs & widgets of call quality and message diagrams are actually displayed on the EOM dashboard leveraging the exact same APIs. The documentation outlines the APIs at a high level and then a process to self discover all of the features and functionality. The process of call the APIs is pretty straightforward. I am sure someone more familiar with Node could've whipped up something pretty powerful in an hour or so. In the case of some requests like grabbing the last 20 calls. Its simply a matter of requesting the correct URL and adding the 'X-API-Key' header to it. For me there it was a little longer. Installing Node (pretty easy), figuring out which library to manage HTTP requests etc. After a little reading and a little playing around I settled on the request-promise library which is a version of request which adds promises support, allowing me to unwind some of callback hell. Eventually I had something like the below.
?function getPagedCalls(domain, api_key){
var options = {
url: domain+'/me/getPagedCalls',
headers: {
'X-API-Key': api_key,
},
rejectUnauthorized: false,
json: true
};
rp(options)
.then(function (body) {
console.log('success? ' + body.success);
if (body.success) {
var calls = body.calls;
//Do stuff to process the calls
})
.catch(function (err) {
// API call failed...
console.log('error:', err); // Print the error if one occurred
});
}
This code snippet when called grabs the last 20 calls received from EOM in JSON format and then let's you process them. This is moderately useful but really only as a first step. We can get something much more useful if we extract a little information from the calls. Such as grabbing the last call from a particular number and then fetching its call diagram. The function below takes a call object, extracts the required id's and then queries EOM for the call diagram. Once received it posts it back as a webpage for viewing (res.send(body)). I used ExpressJS as a simple webserver here.
//Call Diagram is HTML encoded
function getCallDiag(call,domain,api_key,res){
var query = querystring.stringify({
'id': call.id,
'pid': call.pid,
'saved_id': 0,
'format': 'html'
});
var options = {
url: domain+''/me/callDiagram,
headers: {
'X-API-Key': api_key,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(query)
},
rejectUnauthorized: false,
json: true,
body: query,
method: 'post'
};
console.log(options);
rp(options)
.then(function (body) {
console.log('################### Got a Call Diagram ########################');
console.log(body);
res.send(body);
})
.catch(function (err) {
// API call failed...
console.log('error:', err); // Print the error if one occurred
});
}
Here is an example screen shot of the output. As you can see EOM can display a heap of call detail including every message in the flow correlated into a single diagram.
I haven't really begun to scratch the surface of the functionality of the EOM API but I can see some use cases for potential integrations that I'd like to explore such as a Slack/Spark Bot that can grab the last set of calls from EOM and pull the data into a room for all to see.
I used a heap of references and did a load of reading on Node for over the last week. Some of my useful sources include:
- The Node.js Request Module introduction on Stack Abuse
- ExpressJS' Getting Started guide
- A Close Brace guide on setting up an Express Webserver
- The NodeJS page for installation and other information
- Callbackhell.com for getting my head around callbacks again.
- The Art of Node
- And more I've probably forgotten.
As usual my employer Oracle makes me say that the views expressed here are my own and not theirs.
Technical Project Manager
7 年I started using the RESTAPI with OCOM years ago (back when it was still Palladion!). There is a lot of powerful data that you can pull from this system! Great write up on consuming API data with Node.js! More companies need to harness the power of OCOM!