Skip to content

H7: Writing HEP Sub Middleware

Lorenzo Mangani edited this page May 10, 2020 · 4 revisions

HEPSUB

HOMER 7.7 does a lot of things, but there are cases where we need to get our own logic "in the loop" to provide users with additional details about the traffic, users, or elements they are working with.

To make this as easy as fun as possible, we have created hepsub, a simple mechanism to attach middleware APIs into the natural HOMER workflow. Each HEPsub Agent will publish its API to HOMER and can act as data provider or proxy to other data it subscribes to.

Quick Example

Here's a quick "hello world" example to display the power of HEPSUB directly on the server.

Requirements

  • Homer 7.7+
  • NodeJS 10+

Setup

As a first step, clone and configure the hepgen hello world example:

cd /usr/src
git clone https://github.com/sipcapture/hepsub
cd hepsub && npm install

Configuration

In order to use HEPSUB you need to create an API key from the HOMER interface: image

Once the key is available, complete the configuration using file config.js

{
  backend: 'http://my.homer.hostname:80/api/v3/agent/subscribe',
  token: 'xEvLmrcXhMKAjIPILgycOJHVVxZfohztYDELNzKjLUeKWIuiksFdVWzZcMHnnmztDMsmkqCCFdypTVYK',
  service: {
        "uuid": '70e57310-92b6-11ea-8014-2b3052014b77', // Math.random().toString(36).substring(7),
        "host":"my.homer.hostname",
        "port": 18088, 
        "protocol": "http", 
        "path": "/get",
        "type": "cdr",
        "ttl": 300,
        "node": "test-endpoint",
        "gid": 10
  },
  "debug": true
}

Once your configuration is ready, run the hepsub agent and watch for subscribe confirmation:

# npm start
API Server started 18088
RESPONSE API: { data:
   { expire_date: '2020-05-10T14:09:46.540826053+02:00',
     expire_ts: 1589112586,
     uuid: '70e57310-92b6-11ea-8014-2b3052014b77' },
  message: 'successfully created agent record' }


Testing

Your hepsub agent should be subscribe and listening. Click any result in the UI and check the Logs tab:

image

Examples

Clone this wiki locally