lib/Router.js
function(monitor, callback) {

      callback = callback || function(){};
      var t = this,
          monitorJSON = monitor.toMonitorJSON(),
          probeJSON = null,
          probeClass = monitorJSON.probeClass,
          startTime = Date.now(),
          monitorStr = probeClass + '.' + monitor.toServerString().replace(/:/g, '.');

      // Class name must be set
      if (!probeClass) {
        var errStr = 'probeClass must be set';
        log.error('connectMonitor', errStr);
        return callback(errStr);
      }

      // Determine the connection (or internal), and listen for change events
      t.determineConnection(monitorJSON, true, function(err, connection) {
        if (err) {return callback(err);}

        // Function to run on connection (internal or external)
        var onConnect = function(error, probe) {
          if (error) {return callback(error);}
          probeJSON = probe.toJSON();
          probeJSON.probeId = probeJSON.id; delete probeJSON.id;
          monitor.probe = probe;

          // Perform the initial set silently.  This assures the initial
          // probe contents are available on the connect event,
          // but doesn't fire a change event before connect.
          monitor.set(probeJSON, {silent:true});

          // Watch the probe for changes.
          monitor.probeChange = function(){
            monitor.set(probe.changedAttributes());
            log.info('probeChange', {probeId: probeJSON.probeId, changed: probe.changedAttributes()});
          };
          probe.on('change', monitor.probeChange);

          // Call the callback.  This calls the original caller, issues
          // the connect event, then fires the initial change event.
          callback(null);
        };

        // Connect internally or externally
        if (connection) {
          t.connectExternal(monitorJSON, connection, onConnect);
        } else {
          t.connectInternal(monitorJSON, onConnect);
        }
      });
    }
function(monitor, callback) {

      callback = callback || function(){};
      var t = this,
          monitorJSON = monitor.toMonitorJSON(),
          probeJSON = null,
          probeClass = monitorJSON.probeClass,
          startTime = Date.now(),
          monitorStr = probeClass + '.' + monitor.toServerString().replace(/:/g, '.');

      // Class name must be set
      if (!probeClass) {
        var errStr = 'probeClass must be set';
        log.error('connectMonitor', errStr);
        return callback(errStr);
      }

      // Determine the connection (or internal), and listen for change events
      t.determineConnection(monitorJSON, true, function(err, connection) {
        if (err) {return callback(err);}

        // Function to run on connection (internal or external)
        var onConnect = function(error, probe) {
          if (error) {return callback(error);}
          probeJSON = probe.toJSON();
          probeJSON.probeId = probeJSON.id; delete probeJSON.id;
          monitor.probe = probe;

          // Perform the initial set silently.  This assures the initial
          // probe contents are available on the connect event,
          // but doesn't fire a change event before connect.
          monitor.set(probeJSON, {silent:true});

          // Watch the probe for changes.
          monitor.probeChange = function(){
            monitor.set(probe.changedAttributes());
            log.info('probeChange', {probeId: probeJSON.probeId, changed: probe.changedAttributes()});
          };
          probe.on('change', monitor.probeChange);

          // Call the callback.  This calls the original caller, issues
          // the connect event, then fires the initial change event.
          callback(null);
        };

        // Connect internally or externally
        if (connection) {
          t.connectExternal(monitorJSON, connection, onConnect);
        } else {
          t.connectInternal(monitorJSON, onConnect);
        }
      });
    }
function ( monitor , callback ) { callback = callback || function ( ) { } ; var t = this , monitorJSON = monitor . toMonitorJSON ( ) , probeJSON = null , probeClass = monitorJSON . probeClass , startTime = Date . now ( ) , monitorStr = probeClass + '.' + monitor . toServerString ( ) . replace ( / : / g , '.' ) ; // Class name must be set if ( ! probeClass ) { var errStr = 'probeClass must be set' ; log . error ( 'connectMonitor' , errStr ) ; return callback ( errStr ) ; } // Determine the connection (or internal), and listen for change events t . determineConnection ( monitorJSON , true , function ( err , connection ) { if ( err ) { return callback ( err ) ; } // Function to run on connection (internal or external) var onConnect = function ( error , probe ) { if ( error ) { return callback ( error ) ; } probeJSON = probe . toJSON ( ) ; probeJSON . probeId = probeJSON . id ; delete probeJSON . id ; monitor . probe = probe ; // Perform the initial set silently.  This assures the initial // probe contents are available on the connect event, // but doesn't fire a change event before connect. monitor . set ( probeJSON , { silent : true } ) ; // Watch the probe for changes. monitor . probeChange = function ( ) { monitor . set ( probe . changedAttributes ( ) ) ; log . info ( 'probeChange' , { probeId : probeJSON . probeId , changed : probe . changedAttributes ( ) } ) ; } ; probe . on ( 'change' , monitor . probeChange ) ; // Call the callback.  This calls the original caller, issues // the connect event, then fires the initial change event. callback ( null ) ; } ; // Connect internally or externally if ( connection ) { t . connectExternal ( monitorJSON , connection , onConnect ) ; } else { t . connectInternal ( monitorJSON , onConnect ) ; } } ) ; }
Connect a Monitor object to a remote Probe

This accepts an instance of a Monitor and figures out how to connect it
to a running Probe.

Upon callback the probe data is set into the monitor (unless an error
occurred)

@method connectMonitor
@protected
@param monitor {Monitor} - The monitor requesting to connect with the probe
@param callback {Function(error)} - (optional) Called when connected
Connect a Monitor object to a remote Probe