예제 #1
0
void setup_tree (void)
{
#ifdef USING_AGENTX_SUBAGENT_MODULE
  int role;

  role = ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE);
  ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE, MASTER_AGENT);
#endif

  register_mib("", NULL, 0, 0,
	root_subtrees[0].name,  root_subtrees[0].namelen);
  register_mib("", NULL, 0, 0,
	root_subtrees[1].name,  root_subtrees[1].namelen);
  register_mib("", NULL, 0, 0,
	root_subtrees[2].name,  root_subtrees[2].namelen);

  /* Support for 'static' subtrees (subtrees_old) has now been dropped */

  /* No longer necessary to sort the mib tree - this is inherent in
     the construction of the subtree structure */

#ifdef USING_AGENTX_SUBAGENT_MODULE
  ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE, role);
#endif
}
예제 #2
0
void
snmp_agent_init(oid *myoid, int len, char *name, struct variable *variables,
		int varsize, int varlen)
{
	log_message(LOG_INFO, "Starting SNMP subagent");
	netsnmp_enable_subagent();
	snmp_disable_log();
	snmp_enable_calllog();
	snmp_register_callback(SNMP_CALLBACK_LIBRARY,
			       SNMP_CALLBACK_LOGGING,
			       snmp_keepalived_log,
			       NULL);

	/* Do not handle persistent states */
	netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
	    NETSNMP_DS_LIB_DONT_PERSIST_STATE, TRUE);
	/* Do not load any MIB */
	setenv("MIBS", "", 1);
	/* Ping AgentX less often than every 15 seconds: pinging can
	   block keepalived. We check every 2 minutes. */
	netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
			   NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, 120);
	/* We also register a callback to modify default timeout and
	   retries value. */
	snmp_register_callback(SNMP_CALLBACK_LIBRARY,
			       SNMP_CALLBACK_SESSION_INIT,
			       snmp_setup_session_cb, NULL);

	init_agent(name);
	if (register_mib(name, (struct variable *) variables, varsize,
			 varlen, myoid, len) != MIB_REGISTERED_OK)
		log_message(LOG_WARNING, "Unable to register MIB");
	register_mib("Keepalived", (struct variable *) global_vars,
		     sizeof(struct variable8),
		     sizeof(global_vars)/sizeof(struct variable8),
		     global_oid, OID_LENGTH(global_oid));
	init_snmp(name);

	register_sysORTable(global_oid, OID_LENGTH(global_oid) - 1,
			    "The MIB module for Keepalived");
}
예제 #3
0
void
extensible_parse_config(const char *token, char *cptr)
{
    struct extensible *ptmp, **pp;
    char           *tcptr;
    int            scount;

    /*
     * allocate and clear memory structure 
     */
    ptmp = (struct extensible *) calloc(1, sizeof(struct extensible));
    if (ptmp == NULL)
        return;                 /* XXX memory alloc error */

    if (*cptr == '.')
        cptr++;
    if (isdigit(*cptr)) {
        /*
         * its a relocatable extensible mib 
         */
        config_perror("WARNING: This output format is not valid, and is only retained for backward compatibility - Please consider using the 'extend' directive instead" );
        for (pp = &relocs, numrelocs++; *pp; pp = &((*pp)->next));
        (*pp) = ptmp;
        pp = &relocs; scount = numrelocs;

    } else {
        /*
         * it goes in with the general extensible table 
         */
        for (pp = &extens, numextens++; *pp; pp = &((*pp)->next));
        (*pp) = ptmp;
        pp = &extens; scount = numextens;
    }

    /*
     * the rest is pretty much handled the same 
     */
    if (!strncasecmp(token, "sh", 2))
        ptmp->type = SHPROC;
    else
        ptmp->type = EXECPROC;
    if (isdigit(*cptr)) {
        ptmp->miblen = parse_miboid(cptr, ptmp->miboid);
        while (isdigit(*cptr) || *cptr == '.')
            cptr++;
    }

    /*
     * name 
     */
    cptr = skip_white(cptr);
    copy_nword(cptr, ptmp->name, sizeof(ptmp->name));
    cptr = skip_not_white(cptr);
    cptr = skip_white(cptr);
    /*
     * command 
     */
    if (cptr == NULL) {
        config_perror("No command specified on line");
    } else {
        /*
         * Support multi-element commands in shell configuration
         *   lines, but truncate after the first command for 'exec'
         */
        for (tcptr = cptr; *tcptr != 0 && *tcptr != '#'; tcptr++)
            if (*tcptr == ';' && ptmp->type == EXECPROC)
                break;
        sprintf(ptmp->command, "%.*s", (int) (tcptr - cptr), cptr);
    }
#ifdef NETSNMP_EXECFIXCMD
    sprintf(ptmp->fixcmd, NETSNMP_EXECFIXCMD, ptmp->name);
#endif
    if (ptmp->miblen > 0) {
      /*
       * For relocatable "exec" entries,
       * register the new (not-strictly-valid) MIB subtree...
       */
        register_mib(token,
                     (struct variable *) extensible_relocatable_variables,
                     sizeof(struct variable2), 
                     sizeof(extensible_relocatable_variables) /
                     sizeof(*extensible_relocatable_variables),
                     ptmp->miboid, ptmp->miblen);

      /*
       * ... and ensure the entries are sorted by OID.
       * This isn't needed for entries in the main extTable (which
       * don't have MIB OIDs explicitly associated with them anyway)
       */
      if (scount > 1 && pp != &extens) {
        int i;
        struct extensible **etmp = (struct extensible **)
            malloc(((sizeof(struct extensible *)) * scount));
        if (etmp == NULL)
            return;                 /* XXX memory alloc error */
        for (i = 0, ptmp = *pp;
             i < scount && ptmp != 0; i++, ptmp = ptmp->next)
            etmp[i] = ptmp;
        qsort(etmp, scount, sizeof(struct extensible *),
              pass_compare);
        *pp = (struct extensible *) etmp[0];
        ptmp = (struct extensible *) etmp[0];

        for (i = 0; i < scount - 1; i++) {
            ptmp->next = etmp[i + 1];
            ptmp = ptmp->next;
        }
        ptmp->next = NULL;
        free(etmp);
      }
    }
}
예제 #4
0
파일: snmp_agent.c 프로젝트: philwil/ssds
// This is in agent/mib_modules.c
void
init_ssds(void)
{
    /*
     * Define the OID pointer to the top of the mib tree that we're
     * registering underneath
     */

    /*
     * register ourselves with the agent to handle our mib tree
     */
    int num_vars;
    int num_oids;
    char * descr;
    int ssds_fd;
    int num_classes;
    int num_fields;
    int num_items;
    int i,j,k;
    int oid1;
    int id;
    int ret;


    printf("SDCS init_ssds xxx called ...\n");
    ssds_fd = ssds_snmp_open();
    //printf("SDCS init_ssds ssds_fd %d...\n", ssds_fd);
    if(ssds_fd>0) {
      ssds_reset_rbuf();

      num_classes = ssds_get_num_classes(ssds_fd);
      //printf("SDCS init_ssds num classes %d...\n", num_classes);
      for (i=0;i<num_classes;i++) {
	ssds_reset_rbuf();
	cl_db = 0;
	oid1 = ssds_get_class_id(ssds_fd, i);
	//printf("SDCS init_ssds class %d id %d...\n", i, oid1);
	num_fields = ssds_get_num_class_fields(ssds_fd, i);
	num_items  = ssds_get_num_class_items(ssds_fd, i);
	if(0)
	  printf(
	       "SDCS init_ssds class %d oid %d num_fields %d num_items %d\n",
	       i, oid1, num_fields, num_items);
      }
    }

    //cl_db = 1;
    ssds_reset_rbuf();
    if(0) {
      id = ssds_get_item_id(ssds_fd, 1, 0);
      printf("SDCS get_item_id %d \n", id);
      cl_db = 1;
      ssds_reset_rbuf();
      id = ssds_get_field_id(ssds_fd, 1, 0);
      printf("SDCS get_field_id %d \n", id);
      id = ssds_get_field_tid(ssds_fd, 1, 0);
      printf("SDCS get_field_tid %d \n", id);
      id = ssds_get_field_len(ssds_fd, 1, 0);
      printf("SDCS get_field_len %d \n", id);
    }
    num_vars = ssds_set_up_oids(ssds_fd);
    ssds_num_vars = num_vars;
    //printf("SDCS num_vars %d \n", num_vars);
    ret = init_ssds_vars(num_vars);
    //printf("SDCS init_ssds_vars %d \n", ret);

    num_oids = sizeof(ssds_variables_oid)/sizeof(oid);
    descr = "ssds";
    if(register_mib( descr
		    , (struct variable *)ssds_vars
		    , sizeof(struct variable7)
		    , num_vars
		    , ssds_variables_oid
		    , num_oids) != MIB_REGISTERED_OK)
      DEBUGMSGTL(("register_mib", "%s registration failed\n", descr));
    printf("SDCS init_ssds yyy done ...\n");
}
예제 #5
0
파일: extensible.c 프로젝트: Einheri/wl500g
void extensible_parse_config(char *token, char* cptr)
{

  struct extensible **pptmp;
  struct extensible **pprelocs = &relocs;
  struct extensible **ppexten = &extens;
  char *tcptr;
  
  if (*cptr == '.') cptr++;
  if (isdigit(*cptr)) {
    /* its a relocatable extensible mib */
    while(*pprelocs != NULL)
      pprelocs = &((*pprelocs)->next);
    numrelocs++;
    (*pprelocs) = (struct extensible *) malloc(sizeof(struct extensible));
    pptmp = pprelocs;
  } else {
    /* it goes in with the general extensible table */
    while(*ppexten != NULL)
      ppexten = &((*ppexten)->next);
    numextens++;
    (*ppexten) =
      (struct extensible *) malloc(sizeof(struct extensible));
    pptmp = ppexten;
  }
  /* the rest is pretty much handled the same */
  if (!strncasecmp(token,"sh",2)) 
    (*pptmp)->type = SHPROC;
  else
    (*pptmp)->type = EXECPROC;
  if (isdigit(*cptr)) {
    (*pptmp)->miblen = parse_miboid(cptr,(*pptmp)->miboid);
    while (isdigit(*cptr) || *cptr == '.') cptr++;
  }
  else {
    (*pptmp)->miboid[0] = 0;
    (*pptmp)->miblen = 0;
  }
  /* name */
  cptr = skip_white(cptr);
  copy_word(cptr,(*pptmp)->name);
  cptr = skip_not_white(cptr);
  cptr = skip_white(cptr);
  /* command */
  if (cptr == NULL) {
    config_perror("No command specified on line");
    (*pptmp)->command[0] = 0;
  } else {
    for(tcptr=cptr; *tcptr != 0 && *tcptr != '#' && *tcptr != ';';
        tcptr++);
    strncpy((*pptmp)->command,cptr,tcptr-cptr);
    (*pptmp)->command[tcptr-cptr] = 0;
    (*pptmp)->next = NULL;
  }
#ifdef PROCFIXCMD
  sprintf((*pptmp)->fixcmd, EXECFIXCMD, (*pptmp)->name);
#endif
  if ((*pptmp)->miblen > 0) {
    register_mib(token, (struct variable *) extensible_relocatable_variables,
                 sizeof(struct variable2),
                 6, (*pptmp)->miboid, (*pptmp)->miblen);
  }
}