Ejemplo n.º 1
0
/*
*  Read incoming packets
*/
static void serverRead(nbCELL context,int serverSocket,void *handle){
  NB_MOD_Snmptrap *snmptrap=handle;
  unsigned char buffer[NB_BUFSIZE];
  size_t buflen=NB_BUFSIZE;
  int  len;
  unsigned short rport;
  char daddr[40],raddr[40];
  char cmd[NB_BUFSIZE];
  size_t cmdlen=NB_BUFSIZE;
  char *msg;
  char *handlerName=NULL;

  nbIpGetSocketAddrString(serverSocket,daddr);
  len=nbIpGetDatagram(context,serverSocket,&snmptrap->sourceAddr,&rport,buffer,buflen);
  if(snmptrap->trace) nbLogMsg(context,0,'I',"Datagram %s:%5.5u -> %s len=%d\n",nbIpGetAddrString(raddr,snmptrap->sourceAddr),rport,daddr,len);
  if(snmptrap->dump) nbLogDump(context,buffer,len);
  msg=translate(snmptrap,buffer,len,cmd,cmdlen,&handlerName);
  if(msg!=NULL){
    nbLogMsg(context,0,'E',msg);
    return;
    }
  if(snmptrap->trace && !snmptrap->echo) nbLogMsg(context,0,'I',cmd);
  if(handlerName){
    *(cmd+5)=':'; // convert to node command, stepping over "alert" verb
    nbNodeCmd(context,handlerName,cmd+5);
    }
  else nbCmd(context,cmd,snmptrap->echo);
  }
Ejemplo n.º 2
0
// Read commands from child
int nbCmdMsgReader(nbPROCESS process,int pid,void *session,char *msg){
  nbCELL context=(nbCELL)session;
  if(!(((NB_Node *)((NB_Term *)context)->def)->cmdopt&NB_CMDOPT_HUSH)){
    if(process->status&NB_MEDULLA_PROCESS_STATUS_BLOCKING) outPut("[%d: %s\n",process->pid,msg);
    else outMsg(0,'I',"[%d: %s",process->pid,msg);
    }
  nbCmd(context,msg,0);
  return(0);
  }
Ejemplo n.º 3
0
// read a command and pass it to the interpreter
int cmdMsgReader(nbPROCESS process,int pid,void *session,char *msg){
  nbServant *servant=session;
  //nbLogMsg(servant->context,0,'T',"cmdMsgReader called");
  nbCmd(servant->context,msg,1);
  return(0);
  }
Ejemplo n.º 4
0
int main( int argc, char *argv[] )
{
	nbCELL context;
        nbCELL xCell;
	nbCELL synapseAlertCell;
	nbCELL synapseAlarmCell;
	int i;

	context = nbStart( argc, argv );

	TEST( "Testing a synapse alert - response to cell change" );

        nbCmd( context, "define x cell a + b;", NB_CMDOPT_ECHO );
        nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO );
        nbCmd( context, "assert a=13,b=100;", NB_CMDOPT_ECHO );
        nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO );

        showTermValue( context, "x" );
        xCell = nbTermLocate( context, "x" );
        if( xCell == NULL )
        {
                nbLogMsg( context, 0, 'E', "Unable to local x cell" );
                return( 1 );
        }

        synapseAlertCell = nbSynapseOpen( context, NULL, NULL, xCell, myAlert );

        nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO );
        nbCmd( context, "assert a=14;", NB_CMDOPT_ECHO );
        nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO );

	TEST( "Testing synapse alert on time condition along with a synapse alarm" );

        nbCmd( context, "assert x==~(4s);", NB_CMDOPT_ECHO );

        synapseAlarmCell = nbSynapseOpen( context, NULL, NULL, NULL, myAlarm );
        nbSynapseSetTimer( context, synapseAlarmCell, 3 );

	// because we have not called nbServe yet, we need to tell the rule engine about advancing time

	for(i=0;i<20;i++)
	{
		sleep(1);
		nbClockAlert();  // WARNING: This function is deprecated and will be replaced in 0.9.04
	}         

	TEST( "Testing a synapse alert and alarm with the rule engine in control of time" );

	nbCmd( context, "define EndIt when(~(10s)):stop;", NB_CMDOPT_ECHO );

        nbSynapseSetTimer( context, synapseAlarmCell, 5 );

        char *argvServe[2]={"eSynapse","-s"};

        nbServe( context, 2, argvServe );

        nbSynapseClose( context, synapseAlertCell );  // release the synapse
        nbSynapseClose( context, synapseAlarmCell );  // release the synapse

	return ( nbStop( context ) );
}