Giter Club home page Giter Club logo

node-pxgrid's Introduction

node-pxgrid

npm version Build Information Code Style: Prettier license Published on Cisco Code Exchange

This is a Node.js module for interacting with Cisco PxGrid 2.0 that uses REST and WebSockets along with a STOMP-based messaging protocol. You can read more about how pxGrid works on Cisco DevNet.

It has great performance improvements over using Cisco ISE's standard REST API as well as PxGrid 1.0, as well as the obvious benefits that come with a subscribe/publish model over a general pull model.

Documentation

Please view the documentation here.

Feel free to open an issue or otherwise contact me if you feel the documentation could be improved upon.

Installing

Install using npm:

npm i node-pxgrid
# or save
npm i node-pxgrid --save

Creating a pxGrid account on Cisco ISE

In order to get started, you will need to create a pxGrid account on Cisco ISE. To my knowledge, Cisco ISE is the only pxGrid controller that exists today, but the package should, theoretically, support any other accurate implementation of pxGrid 2.0. This involves getting a certificate for authenticating your client. Please follow the steps here to create an account. Unfortunately, there is no public API that can allow us to do this programmatically at this point.

After you have an account, you can use it in your app. Note, that the initial time it registers, it will need to be approved in the pxGrid controller. If you used the above guide, this will be done automatically. The Control.activate() function will automatically retry every 30 seconds if it's initial state is pending. Sometimes, the auto-approval may take 1 try before completing.

Using in an App

Simplest Setup

const fs = require('fs');
const Pxgrid = require('node-pxgrid');

certs = [];
certs.certPath = './certs/';
certs.clientCert = fs.readFileSync(certs.certPath + 'my-node-app.cer');
certs.clientKey = fs.readFileSync(certs.certPath + 'my-node-app.key');
certs.caBundle = fs.readFileSync(certs.certPath + 'ise-chain.cer');

const options = {
  hosts: ['dnaise.ironbowlab.com'],
  client: 'my-node-app',
  clientCert: certs.clientCert,
  clientKey: certs.clientKey,
  caBundle: certs.caBundle,
  clientKeyPassword: 'Pxgrid123'
};

const client = new Pxgrid.Client(options);

client.connect().then(session =>
  client.subscribeToSessions(session, function(message) {
    console.log(message.body);
  })
);

Note: In version 1.1.0, the Client#connect method was added in order to provide a simpler, non-jargon way to connect the broker. All examples and documentation has been updated to use this method. It was also unnecessary in a previous version to use the Control#activate method; however, it was still in some examples and documentation. This should not have affected usage, but needlessly overcomplicated the examples.

Manually Instantiate Control Class

Note: In v1.2.0, I wanted to simplify the setup of the client Control versus Client pxGrid sessions. You can now pass the options for your client directly into the Client class and it will automatically handle the setup of your client. However, if you need to access the Control class directly, you can still pass the Control instance to Client and it will handle activation if it is not already activated.

const fs = require('fs');
const Pxgrid = require('node-pxgrid');

certs = [];
certs.certPath = './certs/';
certs.clientCert = fs.readFileSync(certs.certPath + 'my-node-app.cer');
certs.clientKey = fs.readFileSync(certs.certPath + 'my-node-app.key');
certs.caBundle = fs.readFileSync(certs.certPath + 'ise-chain.cer');

const pxgridControlOptions = {
  hosts: ['dnaise.ironbowlab.com'],
  client: 'my-node-app',
  clientCert: certs.clientCert,
  clientKey: certs.clientKey,
  caBundle: certs.caBundle,
  clientKeyPassword: 'Pxgrid123'
};

const pxgrid = new Pxgrid.Control(pxgridControlOptions);
const client = new Pxgrid.Client(pxgrid);

client.connect().then(session =>
  client.subscribeToSessions(session, function(message) {
    console.log(message.body);
  })
);

For a full list of functions, please see the documentation. For more example usage, see the examples.

Bugs

For bugs, please open an issue.

License

This module is licensed under the MIT license.

node-pxgrid's People

Contributors

dependabot[bot] avatar rnwolfe avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

randomtable

node-pxgrid's Issues

Need a disconnect method

I'm trying to write a node-red wrapper for the node-pxgrid library and I need a way to disconnect an existing pxgrid session, otherwise a new connection towards ISE is created everytime new flows are deployed; this quickly results in ISE denying new connections to clients.

build tests

Given reliance on upstream PxGrid controller, will have to be executed in an environment with Cisco ISE. I'm not sure the ability to use DevNet Always On Sandbox as a potential backend. Either way, an automated test suite would go far to ensure compatibility with different ISE versions and to validate functionality during changes.

No ETA, but on the radar.

Inactive endpoints

Many thanks for this module,
Is it possible to get inactive endpoints ? Like getSession(), but for inactive endpoints,
I didn't catch this on ERS, MNT or pxGrid API's,
But this is possible via ISE GUI,
Thanks,
Pascal

Stomphandler make a uncaught Exception

Hi Ryan

A little long shot.

I am trying to use the node-pxgrid in my setup.

the goal is to put the code within Node-red as a function.
my node enviroment is v15.12.0.

If i run following code within node - everything is OK .
'''
certs = [];
certs.certPath = './certs/';
certs.clientCert = fs.readFileSync(certs.certPath + 'noderedrd.rd.local_noderedrd.rd.local.cer');
certs.clientKey = fs.readFileSync(certs.certPath + 'noderedrd.rd.local_noderedrd.rd.local.key');
certs.caBundle = fs.readFileSync(certs.certPath + 'CertificateServicesEndpointSubCA-RDISEADM01_.cer');

const pxgridControlOptions = {
host: '10.200.0.231',
client: 'noderedrd',
clientCert: certs.clientCert,
clientKey: certs.clientKey,
caBundle: certs.caBundle,
clientKeyPassword: 'PASSWORD',
retryAttempt: 5
};

const pxgrid = new Pxgrid.Control(pxgridControlOptions);
const client = new Pxgrid.Client(pxgrid);

client.connect({retryAttemt: 5, debug: true}).then(session =>
client.subscribeToSessions(session, function(message) {
console.log();
msg.payload = message.body;
node.send(msg);
})

);
'''

If i try to start it within the Node-red enviroment it's still ok but i am running into a error from time to time.
My hope is that you could help me in the right direction - i suspect there is some error handling
missing - but i am not the smartest devop. in the world ;-)

console-output

Received data
<<< MESSAGE
subscription:sub-0
via:SERVER
message-id:4072036
destination:/topic/com.cisco.ise.session
content-length:2290
content-length:2290

Web Socket Opened...

CONNECT
host:SERVER
accept-version:1.2
heart-beat:4000,4000

Connection closed to wss://SERVER:8910/pxgrid/ise/pubsub
Disconnected from STOMP broker!
FRAME: [object Object]
STOMP: scheduling reconnection in 30000ms

SUBSCRIBE
id:sub-0
destination:/topic/com.cisco.ise.session

21 Apr 14:49:12 - [red] Uncaught Exception:
21 Apr 14:49:12 - Error: WebSocket is not open: readyState 3 (CLOSED)
at WebSocket.send (C:\Users\jsie.node-red\externalModules\node_modules\ws\lib\websocket.js:329:19)
at StompHandler../src/stomp-handler.ts.StompHandler._transmit (C:\Users\jsie.node-red\externalModules\node_modules@stomp\stompjs\bundles\stomp.umd.js:1812:29)
at StompHandler../src/stomp-handler.ts.StompHandler.subscribe (C:\Users\jsie.node-red\externalModules\node_modules@stomp\stompjs\bundles\stomp.umd.js:1882:14)
at Client../src/client.ts.Client.subscribe (C:\Users\jsie.node-red\externalModules\node_modules@stomp\stompjs\bundles\stomp.umd.js:573:35)
at Client._getTopicSubscriber (C:\Users\jsie.node-red\externalModules\node_modules\node-pxgrid\lib\client.js:216:24)
at C:\Users\jsie.node-red\externalModules\node_modules\node-pxgrid\lib\client.js:421:12
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:94:5)

Fully implement HA support

Right now, the library naturally has some HA functionality due to the standard operation of the PxGrid serviceLookup response; however, the library needs to be tweaked to fully leverage HA in the Control and Data facilities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.