Пример #1
0
void snmp_process(void) {
    int nfds = 0;
    int block = 1;
    fd_set fdset;
    struct timeval timeout;

	if (snmp_repeaterinfo_received) {
		snmp_repeaterinfo_received = 0;
		if (snmp_session_repeaterinfo != NULL) {
			snmp_close(snmp_session_repeaterinfo);
			snmp_session_repeaterinfo = NULL;
		}
	}

	if (snmp_rssi_received) {
		snmp_rssi_received = 0;
		if (snmp_session_rssi != NULL) {
			snmp_close(snmp_session_rssi);
			snmp_session_rssi = NULL;
		}
	}

	FD_ZERO(&fdset);
	if (snmp_select_info(&nfds, &fdset, &timeout, &block) <= 0)
		return;
	// Timeout is handled by daemon-poll.
	daemon_poll_setmaxtimeout(timeout.tv_sec*1000+timeout.tv_usec/1000);
	// As timeout is handled by daemon-poll, we want select() to return immediately here.
	timeout.tv_sec = timeout.tv_usec = 0;
	nfds = select(nfds, &fdset, NULL, NULL, &timeout);
	if (nfds > 0)
		snmp_read(&fdset);
	else
		snmp_timeout();
}
Пример #2
0
int set_snmp(void *precord, const char *sval)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  SNMP_INFO *snmpinfo = (SNMP_INFO*)psnmp->dpvt;

  char type = 'i';

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
    return -1;
  };

  snmpinfo->setreq = snmp_pdu_create(SNMP_MSG_SET);	/* send the first GET */
  if (! snmpinfo->setreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
    return -1;
  }

  snmp_add_var(snmpinfo->setreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen, type, sval);       //snmp_add_var(netsnmp_pdu *, const oid *, size_t, char, const char *)

  if (snmp_send(snmpinfo->sess, snmpinfo->setreq))
    hosts++;
  else {
    snmp_perror("snmp_getsend");
    snmp_free_pdu(snmpinfo->setreq);
    return -1;
  }

  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
  return 0;
}
Пример #3
0
void get_snmp(void *precord)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  SNMP_INFO *snmpinfo = (SNMP_INFO*)psnmp->dpvt;

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
  };

  snmpinfo->getreq = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
  if (! snmpinfo->getreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
  }

  snmp_add_null_var(snmpinfo->getreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen);

  if (snmp_send(snmpinfo->sess, snmpinfo->getreq))
    hosts++;
  else {
    snmp_perror("snmp_setsend");
    snmp_free_pdu(snmpinfo->getreq);
  }

  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
}
Пример #4
0
/*
 * check a session validity for connectivity to the master agent.  If
 * not functioning, close and start attempts to reopen the session
 */
void agentx_check_session (unsigned int clientreg, void *clientarg)
{
    netsnmp_session *ss = (netsnmp_session *) clientarg;

    if (!ss)
    {
        if (clientreg)
            snmp_alarm_unregister (clientreg);
        return;
    }
    DEBUGMSGTL (("agentx/subagent", "checking status of session %p\n", ss));

    if (!agentx_send_ping (ss))
    {
        snmp_log (LOG_WARNING, "AgentX master agent failed to respond to ping.  Attempting to re-register.\n");
        /*
         * master agent disappeared?  Try and re-register.
         * close first, just to be sure .
         */
        agentx_unregister_callbacks (ss);
        agentx_close_session (ss, AGENTX_CLOSE_TIMEOUT);
        snmp_alarm_unregister (clientreg);    /* delete ping alarm timer */
        snmp_call_callbacks (SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_INDEX_STOP, (void *) ss);
        register_mib_detach ();
        if (main_session != NULL)
        {
            remove_trap_session (ss);
            snmp_close (main_session);
            /*
             * We need to remove the callbacks attached to the callback
             * session because they have a magic callback data structure
             * which includes a pointer to the main session
             *    (which is no longer valid).
             *
             * Given that the main session is not responsive anyway.
             * it shoudn't matter if we lose some outstanding requests.
             */
            if (agentx_callback_sess != NULL)
            {
                snmp_close (agentx_callback_sess);
                agentx_callback_sess = NULL;

                subagent_init_callback_session ();
            }
            main_session = NULL;
            agentx_reopen_session (0, NULL);
        }
        else
        {
            snmp_close (main_session);
            main_session = NULL;
        }
    }
    else
    {
        DEBUGMSGTL (("agentx/subagent", "session %p responded to ping\n", ss));
    }
}
Пример #5
0
int ups_mib_mgr_get_upsBypassEntry(struct snmp_session *s, upsBypassEntry_t **upsBypassEntry)
{
    struct snmp_session *peer;
    struct snmp_pdu *request, *response;
    struct variable_list *vars;
    int status;

    request = snmp_pdu_create(SNMP_MSG_GETNEXT);
    snmp_add_null_var(request, upsBypassVoltage, sizeof(upsBypassVoltage)/sizeof(oid));
    snmp_add_null_var(request, upsBypassCurrent, sizeof(upsBypassCurrent)/sizeof(oid));
    snmp_add_null_var(request, upsBypassPower, sizeof(upsBypassPower)/sizeof(oid));

    peer = snmp_open(s);
    if (!peer) {
        return -1;
    }

    status = snmp_synch_response(peer, request, &response);
    if (status != STAT_SUCCESS) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -2;
    }

    *upsBypassEntry = (upsBypassEntry_t *) malloc(sizeof(upsBypassEntry_t));
    if (! *upsBypassEntry) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -4;
    }

    for (vars = response->variables; vars; vars = vars->next_variable) {
        if (vars->name_length > sizeof(upsBypassVoltage)/sizeof(oid)
            && memcmp(vars->name, upsBypassVoltage, sizeof(upsBypassVoltage)) == 0) {
            (*upsBypassEntry)->__upsBypassVoltage = *vars->val.integer;
            (*upsBypassEntry)->upsBypassVoltage = &((*upsBypassEntry)->__upsBypassVoltage);
        }
        if (vars->name_length > sizeof(upsBypassCurrent)/sizeof(oid)
            && memcmp(vars->name, upsBypassCurrent, sizeof(upsBypassCurrent)) == 0) {
            (*upsBypassEntry)->__upsBypassCurrent = *vars->val.integer;
            (*upsBypassEntry)->upsBypassCurrent = &((*upsBypassEntry)->__upsBypassCurrent);
        }
        if (vars->name_length > sizeof(upsBypassPower)/sizeof(oid)
            && memcmp(vars->name, upsBypassPower, sizeof(upsBypassPower)) == 0) {
            (*upsBypassEntry)->__upsBypassPower = *vars->val.integer;
            (*upsBypassEntry)->upsBypassPower = &((*upsBypassEntry)->__upsBypassPower);
        }
    }

    if (response) snmp_free_pdu(response);

    if (snmp_close(peer) == 0) {
        return -5;
    }

    return 0;
}
Пример #6
0
int ups_mib_mgr_get_upsOutput(struct snmp_session *s, upsOutput_t **upsOutput)
{
    struct snmp_session *peer;
    struct snmp_pdu *request, *response;
    struct variable_list *vars;
    int status;

    request = snmp_pdu_create(SNMP_MSG_GETNEXT);
    snmp_add_null_var(request, upsOutputSource, sizeof(upsOutputSource)/sizeof(oid));
    snmp_add_null_var(request, upsOutputFrequency, sizeof(upsOutputFrequency)/sizeof(oid));
    snmp_add_null_var(request, upsOutputNumLines, sizeof(upsOutputNumLines)/sizeof(oid));

    peer = snmp_open(s);
    if (!peer) {
        return -1;
    }

    status = snmp_synch_response(peer, request, &response);
    if (status != STAT_SUCCESS) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -2;
    }

    *upsOutput = (upsOutput_t *) malloc(sizeof(upsOutput_t));
    if (! *upsOutput) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -4;
    }

    for (vars = response->variables; vars; vars = vars->next_variable) {
        if (vars->name_length > sizeof(upsOutputSource)/sizeof(oid)
            && memcmp(vars->name, upsOutputSource, sizeof(upsOutputSource)) == 0) {
            (*upsOutput)->__upsOutputSource = *vars->val.integer;
            (*upsOutput)->upsOutputSource = &((*upsOutput)->__upsOutputSource);
        }
        if (vars->name_length > sizeof(upsOutputFrequency)/sizeof(oid)
            && memcmp(vars->name, upsOutputFrequency, sizeof(upsOutputFrequency)) == 0) {
            (*upsOutput)->__upsOutputFrequency = *vars->val.integer;
            (*upsOutput)->upsOutputFrequency = &((*upsOutput)->__upsOutputFrequency);
        }
        if (vars->name_length > sizeof(upsOutputNumLines)/sizeof(oid)
            && memcmp(vars->name, upsOutputNumLines, sizeof(upsOutputNumLines)) == 0) {
            (*upsOutput)->__upsOutputNumLines = *vars->val.integer;
            (*upsOutput)->upsOutputNumLines = &((*upsOutput)->__upsOutputNumLines);
        }
    }

    if (response) snmp_free_pdu(response);

    if (snmp_close(peer) == 0) {
        return -5;
    }

    return 0;
}
Пример #7
0
void snmp_deinit(void) {
	console_log("snmp: deinit\n");

	iconv_close(conv_utf16_utf8);

	if (snmp_session_repeaterinfo != NULL) {
		snmp_close(snmp_session_repeaterinfo);
		snmp_session_repeaterinfo = NULL;
	}

	if (snmp_session_rssi != NULL) {
		snmp_close(snmp_session_rssi);
		snmp_session_rssi = NULL;
	}
}
Пример #8
0
static void
free_trap_session(struct trap_sink *sp)
{
    DEBUGMSGTL(("trap", "freeing callback trap session (%p, %p)\n", sp, sp->sesp));
    snmp_close(sp->sesp);
    free(sp);
}
Пример #9
0
/*
 * simple synchronous loop
 */
void synchronous (void)
{
  struct host *hp;

  for (hp = hosts; hp->name; hp++) {
    struct snmp_session ss, *sp;
    struct oid *op;

    snmp_sess_init(&ss);			/* initialize session */
    ss.version = SNMP_VERSION_2c;
    ss.peername = strdup(hp->name);
    ss.community = strdup(hp->community);
    ss.community_len = strlen(ss.community);
    if (!(sp = snmp_open(&ss))) {
      snmp_perror("snmp_open");
      continue;
    }
    for (op = oids; op->Name; op++) {
      struct snmp_pdu *req, *resp;
      int status;
      req = snmp_pdu_create(SNMP_MSG_GET);
      snmp_add_null_var(req, op->Oid, op->OidLen);
      status = snmp_synch_response(sp, req, &resp);
      if (!print_result(status, sp, resp)) break;
      snmp_free_pdu(resp);
    }
    snmp_close(sp);
  }
}
Пример #10
0
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_sel_close(handle->selcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		/* Should we free handle->config? */
		/* windows32 specific net-snmp cleanup (is a noop on unix) */
		snmp_close(custom_handle->ss);
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup str2event hash table */
	str2event_use_count--;
	if (str2event_use_count == 0) 
		str2event_hash_free();

}
Пример #11
0
/**
 * snmp_bc_close: 
 * @hnd: Pointer to handler structure.
 * 
 * Close an SNMP BladeCenter/RSA plugin handler instance.
 *
 * Returns:
 * Void
 **/
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_el_close(handle->elcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		/* FIXME:: Should we free handle->config - same question on A.1.1 code? */
		snmp_close(custom_handle->ss);
		/* Windows32 specific net-snmp cleanup (noop on unix) */
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup str2event hash table */
	/* FIXME:: Add RSA free here */
	bc_xml2event_hash_use_count--;
	if (bc_xml2event_hash_use_count == 0) {
		xml2event_hash_free(&bc_xml2event_hash);
	}
}
Пример #12
0
/**
 * snmp_bc_close: 
 * @hnd: Pointer to handler structure.
 * 
 * Close an SNMP BladeCenter/RSA plugin handler instance.
 *
 * Returns:
 * Void
 **/
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_el_close(handle->elcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		snmp_close(custom_handle->ss);
		/* Windows32 specific net-snmp cleanup (noop on unix) */
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup errlog2event_hash table */
	errlog2event_hash_use_count--;
	if (errlog2event_hash_use_count == 0) {
		errlog2event_hash_free();
	}
}
Пример #13
0
static struct snmp_pdu *
snmp_get_item(char *host, char *community, char *mib_item)
{
	struct snmp_session session, *ss;
	struct snmp_pdu *request = NULL, *result = NULL;
	oid Oid[MAX_OID_LEN];
	unsigned int oid_len = MAX_OID_LEN;

	/* initialize the SNMP session */
	snmp_sess_init(&session);
	session.peername = host;
	session.community = (uchar_t *)community;
	session.community_len = strlen((const char *)session.community);
	session.version = SNMP_VERSION_1;
	session.retries = 0;

	if ((ss = snmp_open(&session)) == NULL)
		return (NULL);

	/* add the requested data */
	if (!read_objid(mib_item, Oid, &oid_len))
		snmp_perror(mib_item);

	/* initialize the request PDU */
	request = snmp_pdu_create(SNMP_MSG_GET);
	snmp_add_null_var(request, Oid, oid_len);

	(void) snmp_synch_response(ss, request, &result);

	snmp_close(ss);

	return (result);
}
Пример #14
0
void snmp_start_read_rssi(char *host) {
	struct snmp_pdu *pdu;
	struct snmp_session session;
	const char *community = "public";

	if (oid_rssi_ts1_length == 0 || oid_rssi_ts2_length == 0)
		return;

	snmp_rssi_received = 0;

	if (snmp_session_rssi != NULL) {
		snmp_close(snmp_session_rssi);
		snmp_session_rssi = NULL;
	}

	snmp_sess_init(&session);
	session.version = SNMP_VERSION_1;
	session.peername = strdup(host);
	session.community = (unsigned char *)strdup(community);
	session.community_len = strlen(community);
	session.callback = snmp_get_rssi_cb;
	if (!(snmp_session_rssi = snmp_open(&session))) {
		console_log("snmp error: error opening session to host %s\n", host);
		return;
	}

	pdu = snmp_pdu_create(SNMP_MSG_GET);
	snmp_add_null_var(pdu, oid_rssi_ts1, oid_rssi_ts1_length);
	snmp_add_null_var(pdu, oid_rssi_ts2, oid_rssi_ts2_length);
	if (!snmp_send(snmp_session_rssi, pdu))
		console_log("snmp error: error sending rssi request to host %s\n", host);
	free(session.peername);
	free(session.community);
}
Пример #15
0
void perr(struct snmp_pdu *resp) {
    if(resp) fprintf(stderr, "error: %s\n", snmp_errstring(resp->errstat));
    snmp_perror("error");
    snmp_close(ses);
    SOCK_CLEANUP;
    exit(1);
}
Пример #16
0
void prifalias(oid inst) {
    struct snmp_pdu *pdu, *resp;
    oid tmp_oid[] = { 1,3,6,1,2,1,31,1,1,1,18,0 };
    int stat;
    char *tmp;

    if(!extended) {
        fprintf(stderr, "ifalias is only available in eXtended mode\n");
        snmp_close(ses);
        SOCK_CLEANUP;
        exit(1);
    }
    
    tmp_oid[11]=inst;
    pdu=snmp_pdu_create(SNMP_MSG_GET);
    snmp_add_null_var(pdu, tmp_oid, sizeof(tmp_oid)/sizeof(oid));
    stat=snmp_synch_response(ses, pdu, &resp);

    if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR) 
        perr(resp);

    if(resp->variables->val_len && strlen((char *)resp->variables->val.string)) {
        tmp=malloc((resp->variables->val_len+1) * sizeof(char));
        memcpy(tmp, resp->variables->val.string, resp->variables->val_len);
        tmp[resp->variables->val_len]=0;
        printf("  \"%s\"", tmp);
        free(tmp);
    }

    if(resp)
            snmp_free_pdu(resp);

}
Пример #17
0
uint32_t getcntr32(int dir, oid inst) {
    struct snmp_pdu *pdu, *resp;
    oid iftable_oid[]  = { 1,3,6,1,2,1,2,2,1,0,0 };    // dir=9 ; inst=10
    int stat;
    uint32_t tmp;

    pdu=snmp_pdu_create(SNMP_MSG_GET);
    iftable_oid[9]=dir;
    iftable_oid[10]=inst;
    snmp_add_null_var(pdu, iftable_oid, sizeof(iftable_oid)/sizeof(oid));
    
    stat=snmp_synch_response(ses, pdu, &resp);
    if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR) 
        perr(resp);

    if(resp->variables->type != ASN_COUNTER) {
        fprintf(stderr, "\nError: unsupported data type (only 32bit counter is supported in normal mode)\n");
        snmp_close(ses);
        SOCK_CLEANUP;
        exit(1);
    }

    tmp=resp->variables->val.counter64->high;

    if(resp)
        snmp_free_pdu(resp);

    return tmp;
}
Пример #18
0
/*
 * check a session validity for connectivity to the master agent.  If
 * not functioning, close and start attempts to reopen the session 
 */
void
agentx_check_session(unsigned int clientreg, void *clientarg)
{
    netsnmp_session *ss = (netsnmp_session *) clientarg;
    if (!ss) {
        if (clientreg)
            snmp_alarm_unregister(clientreg);
        return;
    }
    DEBUGMSGTL(("agentx/subagent", "checking status of session %p\n", ss));

    if (!agentx_send_ping(ss)) {
        snmp_log(LOG_WARNING,
                 "AgentX master agent failed to respond to ping.  Attempting to re-register.\n");
        /*
         * master agent disappeared?  Try and re-register.
         * close first, just to be sure .
         */
        agentx_unregister_callbacks(ss);
        agentx_close_session(ss, AGENTX_CLOSE_TIMEOUT);
        snmp_alarm_unregister(clientreg);       /* delete ping alarm timer */
        snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                            SNMPD_CALLBACK_INDEX_STOP, (void *) ss);
        snmp_close(main_session);
        main_session = NULL;
        agentx_reopen_session(0, NULL);
    } else {
        DEBUGMSGTL(("agentx/subagent", "session %p responded to ping\n",
                    ss));
    }
}
Пример #19
0
// Need to clean after each SNMP call, otherwise program fails
void cleanup()  {
   if (response)
      snmp_free_pdu(response);
    snmp_close(ss);
    SOCK_CLEANUP;

}
Пример #20
0
/* cleanups session */
void snmp_close_driver(struct ifstat_driver *driver) {
  struct snmp_driver_data *data = driver->data;

  snmp_close(data->session);
  free(data->ifsnmp);
  free(data);
}
Пример #21
0
ENDdbgPrintInstInfo


BEGINisCompatibleWithFeature
CODESTARTisCompatibleWithFeature
	/* we are not compatible with repeated msg reduction feature, so do not allow it */
ENDisCompatibleWithFeature

/* Exit SNMP Session
 * alorbach, 2008-02-12
 */
static rsRetVal
omsnmp_exitSession(wrkrInstanceData_t *pWrkrData)
{
	DEFiRet;

	if(pWrkrData->snmpsession != NULL) {
		DBGPRINTF("omsnmp_exitSession: Clearing Session to '%s' on Port = '%d'\n",
			  pWrkrData->pData->szTarget, pWrkrData->pData->iPort);
		snmp_close(pWrkrData->snmpsession);
		pWrkrData->snmpsession = NULL;
	}

	RETiRet;
}
Пример #22
0
static void
wti_mpc_destroy(StonithPlugin * s)
{
    struct pluginDevice *ad;

    DEBUGCALL;

    VOIDERRIFWRONGDEV(s);

    ad = (struct pluginDevice *) s;

    ad->pluginid = NOTpluginID;

    /* release snmp session */
    if (ad->sptr != NULL) {
        snmp_close(ad->sptr);
        ad->sptr = NULL;
    }

    /* reset defaults */
    if (ad->hostname != NULL) {
        PluginImports->mfree(ad->hostname);
        ad->hostname = NULL;
    }
    if (ad->community != NULL) {
        PluginImports->mfree(ad->community);
        ad->community = NULL;
    }
    ad->num_outlets = 0;

    PluginImports->mfree(ad);
}
Пример #23
0
void * snmp_poll ( void * request_details ) {
	snmp_request_t* req = (snmp_request_t*)request_details;

	struct snmp_session ss, *sp;
	struct oid *op;
 
	snmp_sess_init(&ss);                        /* initialize session */
	ss.version = SNMP_VERSION_2c;
	ss.peername = req->target_host;
	ss.community = req->community;
	ss.community_len = strlen(ss.community);
	snmp_synch_setup(&ss);
	if (!(sp = snmp_open(&ss))) 
		snmp_perror("snmp_open");
	struct snmp_pdu *req2, *resp;
	int status;
	req = snmp_pdu_create(SNMP_MSG_GET);
	snmp_add_null_var(req2, req->oid, strlen(req->oid));
	status = snmp_synch_response(sp, req2, &resp);
	snmp_free_pdu(resp);
	snmp_close(sp);

	// Push the results back to the result queue..
	pthread_mutex_lock ( &result_lock ) ;
	// TODO: create linked array for a result buffer
	pthread_mutex_unlock ( &result_lock ) ;
}
Пример #24
0
int mau_mib_mgr_get_ifJackEntry(struct snmp_session *s, ifJackEntry_t **ifJackEntry)
{
    struct snmp_session *peer;
    struct snmp_pdu *request, *response;
    struct variable_list *vars;
    int status;

    request = snmp_pdu_create(SNMP_MSG_GETNEXT);
    snmp_add_null_var(request, ifJackType, sizeof(ifJackType)/sizeof(oid));

    peer = snmp_open(s);
    if (!peer) {
        snmp_free_pdu(request);
        return -1;
    }

    status = snmp_synch_response(peer, request, &response);
    if (status != STAT_SUCCESS) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -2;
    }

    *ifJackEntry = (ifJackEntry_t *) malloc(sizeof(ifJackEntry_t));
    if (! *ifJackEntry) {
        if (response) snmp_free_pdu(response);
        snmp_close(peer);
        return -4;
    }

    for (vars = response->variables; vars; vars = vars->next_variable) {
        if (vars->name_length > sizeof(ifJackType)/sizeof(oid)
            && memcmp(vars->name, ifJackType, sizeof(ifJackType)) == 0) {
            (*ifJackEntry)->__ifJackType = *vars->val.integer;
            (*ifJackEntry)->ifJackType = &((*ifJackEntry)->__ifJackType);
        }
    }

    if (response) snmp_free_pdu(response);

    if (snmp_close(peer) == 0) {
        return -5;
    }

    return 0;
}
Пример #25
0
void snmp_get(void *precord)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  /* SNMP_INFO *gsnmpInfo = (SNMP_INFO*)psnmp->dpvt;       */

  printf("snmpget()****** Message:%s, version: %s, ip: %s, name: %s, securityname: %s, authpass: %s, privpass: %s, secuauth: %s, secupriv: %s\n", snmpinfo->msg, snmpinfo->ss.version, snmpinfo->ss.peername, snmpinfo->username, snmpinfo->ss.securityName, snmpinfo->authpass, snmpinfo->privpass, snmpinfo->ss.securityAuthKey, snmpinfo->ss.securityPrivKey);

  printf("oids: %s\n", psnmp->oids);

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
  };

  snmpinfo->getreq = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
  if (! snmpinfo->getreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
  }

  snmp_add_null_var(snmpinfo->getreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen);

/* int snmp_async_send(netsnmp_session *, netsnmp_pdu *, netsnmp_callback, void *) */
/* int snmp_send(netsnmp_session *, netsnmp_pdu *) */


  /* if (snmp_async_send(snmpinfo->sess, snmpinfo->getreq, asynch_response, NULL))   */
  /*   { */
  /*     hosts++; */
  /*   } else { */
  /*   snmp_perror("snmp_get->async_Send Error "); */
  /*   snmp_free_pdu(snmpinfo->getreq); */
  /* } */


  if (snmp_send(snmpinfo->sess, snmpinfo->getreq))
    {
      hosts++;
    } else {
    snmp_perror("snmp_get->Send Error ");
    snmp_free_pdu(snmpinfo->getreq);
  }



  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
}
Пример #26
0
void Session::close()
{
	if ( m_session )
	{
		snmp_close(m_session);
		m_session = false;
	}
}
Пример #27
0
void asynchronous(void)
{
  struct session *hs;
  struct host *hp;

  /* startup all hosts */

  for (hs = sessions, hp = hosts; hp->name; hs++, hp++) {
    struct snmp_pdu *req;
    struct snmp_session sess;
    snmp_sess_init(&sess);			/* initialize session */
    sess.version = SNMP_VERSION_2c;
    sess.peername = strdup(hp->name);
    sess.community = strdup(hp->community);
    sess.community_len = strlen(sess.community);
    sess.callback = asynch_response;		/* default callback */
    sess.callback_magic = hs;
    if (!(hs->sess = snmp_open(&sess))) {
      snmp_perror("snmp_open");
      continue;
    }
    hs->current_oid = oids;
    req = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
    snmp_add_null_var(req, hs->current_oid->Oid, hs->current_oid->OidLen);
    if (snmp_send(hs->sess, req))
      active_hosts++;
    else {
      snmp_perror("snmp_send");
      snmp_free_pdu(req);
    }
  }

  /* loop while any active hosts */

  while (active_hosts) {
    int fds = 0, block = 1;
    fd_set fdset;
    struct timeval timeout;

    FD_ZERO(&fdset);
    snmp_select_info(&fds, &fdset, &timeout, &block);
    fds = select(fds, &fdset, NULL, NULL, block ? NULL : &timeout);
    if (fds < 0) {
        perror("select failed");
        exit(1);
    }
    if (fds)
        snmp_read(&fdset);
    else
        snmp_timeout();
  }

  /* cleanup */

  for (hp = hosts, hs = sessions; hp->name; hs++, hp++) {
    if (hs->sess) snmp_close(hs->sess);
  }
}
Пример #28
0
static void
Snmp_dealloc(SnmpObject* self)
{
	if (self->ss)
		snmp_close(self->ss);
	Snmp_updatereactor();
	Py_XDECREF(self->defers);
	self->ob_type->tp_free((PyObject*)self);
}
Пример #29
0
static void
snmptrapd_close_sessions(netsnmp_session * sess_list)
{
    netsnmp_session *s = NULL, *next = NULL;

    for (s = sess_list; s != NULL; s = next) {
        next = s->next;
        snmp_close(s);
    }
}
Пример #30
0
void stophosts(void)
{
	struct req_t *rwalk;

	for (rwalk = reqhead; (rwalk); rwalk = rwalk->next) {
		if (rwalk->sess) {
			snmp_close(rwalk->sess);
		}
	}
}