The xMulator! Mwahahahahah

Introducing the xMulator! Mwahahahah. Yes, you need to have the maniacal laugh after saying the name.

Ever been stuck on a plane with no wifi (or desert oasis, Mars, quiet mountain cabin, the nineteenth century, etc) and you just need to do some final tweaks to an integration? I feel your pain my friends. I worked in the lab with my furry Igor and it lives!! The xMulator! Mwahahahaha will dominate the world can help you out. It is a simple and light weight Node.js web server that returns a random event id. Note, this is xkcd random, not like you know, real random. Just take these steps (before boarding the plane/caravan/spaceship/car/time machine) and you will have a fully functional web server for testing integrations.

Node.js is javascript engine for building fast and scalable network applications. Think of it as a server side javascript. No PCP PHP needed.

First, download Node.js for your environment here: node.js.

Then, download the attached zip file and deploy into a local folder, let's call it xMulator. (xMatters Emulator?)

Next, navigate a command line to the xMulator and run "node index.js":

C:\Users\tdepuy\Dropbox\Tinkering\NodeJS\xMulator>node index.js  
Server has started. Reach me on:  

It helpfully iterates through all the external IPs of the host machine and displays urls. In theory any of these urls should work, but I use the .253.1 for when I communicate from my VMs.

The final step is to test it. If you have a linux system, cUrl works great:

boba@service-desk-plus:~$ curl -H "Content-Type: application/json" -d "{  \"properties\": {   \"TicketId\": \"BT100023\"  }, \"recipients\": [ { \"targetName\": \"tdepuy\" } ]}" --user Jaster.Mereel:635f06b840  

Or SOAPUI, despite its misleading name will do the same:

The files are pretty simple:

index.js The "runner" file. This sets up the request handling and starts the server
requestHandler.js This contains the functions that handle the requests. When a particular route is requested from index.js, the corresponding function is called from here.
server.js Starts the web server. Also has the port (8888), so port conflicts can be resolved here.
router.js Does the actual routing and returns a 404 for stuff not properly routed. Can be ignored.

So, cool you say. Now, how do I make another route if I wanted to simulate another relevance engine, you say? Piece of javacake.

Crack open the requestHandler.js and create a new function that takes two arguments, response andpostData. These represent the outgoing response to the client and the incoming data. Make sure to export the function at the end with the exports.functionName. See the otherNewOne function for an example. Then, crack open the index.js and map the url route to the new function. For example, for otherNewOne, map the route as follows:

handle["/otherNewOne"] = reqHandler.otherNewOne;  

Save everything and restart the server.

Hit me up for any feature requests or other suggestions.

xMatters Reference

Blog- Originally created by Travis Depuy

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk