nms.js

0.0.53 • Public • Published

nms.js

======== Open source network management system for Node.js

The goal is for nms.js to be a truly distributed, scalable management application platform for all aspects of the FCAPS network management model, much like OpenNMS.

The project relies heavely on a few core modules:

  • keypress - Emits keypress events from any readble stream such as prcoess.stdin.
  • lineman - Line manager listens for keypress events and navigates and emits a line buffer much like readline.
  • sheldon - Sheldon listens for line and keypress events to provide a thin shell around javascript. It uses minimist to parse emited lines into arguments. The first argument is assumed to be the path to a javascript object and is passed to the lodash _.get(sheldon.context, path) function. The TAB key either auto completes the path or returns an array of posible matches. If the typeOf javascipt object is function, the parameter names of the function are read and the rest of the minimist arguments are applied by name or in order to the function and it is called. If any parameter names are missing from the minimist arguments, lineman asks/prompts for those parameters by name. All other objects are formatted with util.inspect and written to a writeable stream such as process.stdout via lineman.
  • nms.js - NMS.js simply adds network management tools to the sheldon.context object. For instance, the ssh client:
sheldon.context.nms = {
    ssh: function(host,username,password){
            var client = new ssh.Client();
            var params = {
                host:host.split(':')[0],
                port:host.split(':')[1],
                username:username,
                password:password
            }
            client.connect(params);
            client.on('error', sheldon.cli.inspect);
            client.on('ready', openShell);
            client.on('end', client.destroy);
            function openShell(){
                client.shell(attach);
            }
            function attach(error,sshStream){
                sheldon.lineman.attach( { 
                    stdin:sshStream, 
                    stdout:sshStream 
                    
                }, error )
            }
            return('connecting to ' + host);
    }
}

minimist agruments applied by lineman prompt:

NMS-HOST#nms.ssh
host:nethack.alt.org
username:nethack
password:
connecting to nethack.alt.org

minimist arguments applied by order:

NMS-HOST#nms.ssh nethack.alt.org nethack guest
connecting to nethack.alt.org

minimist arguments applied by name:

NMS-HOST#nms.ssh --host nethack.alt.org --username nethack --password *****
connecting to nethack.alt.org

resulting in a ssh shell connection to nethack.alt.org

 ## nethack.alt.org - http://nethack.alt.org/
 ##
 ## Games on this server are recorded for in-progress viewing and playback!

  Not logged in.

  l) Login
  r) Register new user
  w) Watch games in progress

  s) server info
  m) MOTD/news (updated: 2015.12.07)

  q) Quit



  =>

sheldon.context:

sheldon.context = {
    os: require('os'),
    /*
    os:{ endianness: [Function: getEndianness],                                        
          hostname: [Function: getHostname],                                            
          loadavg: [Function: getLoadAvg],                                              
          uptime: [Function: getUptime],                                                
          freemem: [Function: getFreeMem],                                              
          totalmem: [Function: getTotalMem],                                            
          cpus: [Function: getCPUs],                                                    
          type: [Function: getOSType],                                                  
          release: [Function: getOSRelease],                                            
          networkInterfaces: [Function: getInterfaceAddresses],                         
          arch: [Function],                                                             
          platform: [Function],                                                         
          tmpdir: [Function],                                                           
          tmpDir: [Function],                                                           
          getNetworkInterfaces: [Function: deprecated],                                 
          EOL: '\r\n' }
    */
    terminal:{
        { width: [Function], length: [Function] } 
    },
    exit: [Funtion]
}

Current tools:

sheldon.context.nms = {
    ssh     :function(host,username,password)...,
    telnet  :function(host)...,
    snmp    :function(request,host,community,oid)...,
    net     :{
                connect:function(path)...,
                listen:function(path)...
    }
}

Install

$ npm install nms.js

Examples

  • cliNMS.js Command line interface into nms.js:
var nms = require('nms.js')
var NMS = new nms(process.stdin, process.stdout)
 var net = require('net'),
    nms = require('../'),
    telnetStream    = require('../lib/telnet-client');

var serverSocket = net.createServer(function(connection) {
        //telnet IAC events
        var telnet = new telnetStream();  
        connection.pipe(telnet.rx)
        telnet.tx.pipe(connection)
        //
        var NMS = new nms(telnet.rx, telnet.tx)
        //terminal dimensions
        telnet.tx.writeDo(telnet.options.indexOf('windowSize'));
});

serverSocket.listen(9999,function(){
    console.log('listening on ', 9999)
});
var shellServer     = require('../lib/shellServer'),
    nms             = require('../'),
    util            = require('util'),
    webNMS          = new shellServer();
    webNMS.on('connection', function (socket) {
        socket.on('TERMINAL', function(stream){
          //hack for socket.io-stream events client bind
          socket.on(stream.id, function(e){
              stream.emit(e.event,e.data)
          });
          stream.on('socket.io',function(e){
              socket.emit(stream.id,e)
          })
          //
          var NMS = new nms(stream);
        })
    })
    webNMS.listen({port:8443});
    username:guest
    password:test13

Package Sidebar

Install

npm i nms.js

Weekly Downloads

0

Version

0.0.53

License

none

Last publish

Collaborators

  • primeeuler