这篇教程C++ snmp_errstring函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中snmp_errstring函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_errstring函数的具体用法?C++ snmp_errstring怎么用?C++ snmp_errstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了snmp_errstring函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: net_snmp_failureSaErrorT net_snmp_failure(struct snmp_client_hnd *custom_handle, int snmp_status, struct snmp_pdu *response){ if (snmp_status == STAT_SUCCESS) { dbg("Error in packet, Whilst getting Resources/nReason: %s", snmp_errstring(response->errstat)); dbg("ERROR: net_snmp_failure %s", snmp_errstring(response->errstat)); } else { snmp_sess_perror("snmpget", custom_handle->ss); dbg("ERROR: net_snmp_failure"); } return(SA_ERR_HPI_ERROR);}
开发者ID:openhpi1,项目名称:testrepo,代码行数:15,
示例2: perrvoid 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);}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:7,
示例3: snmp_get_ifcount/* report the value interfaces.ifNumber.0, actually the number of interfaces */static int snmp_get_ifcount(struct snmp_session *ss) { int nifaces = -1; oid ifcount[] = { 1, 3, 6, 1, 2, 1, 2, 1, 0 }; struct snmp_pdu *pdu; struct snmp_pdu *response = NULL; int status; if ((pdu = snmp_pdu_create(SNMP_MSG_GET)) == NULL) { ifstat_error("snmp_pdu_create: %s", snmp_api_errstring(snmp_errno)); return -1; } snmp_add_null_var(pdu, ifcount, sizeof(ifcount) / sizeof(oid)); if ((status = snmp_synch_response(ss, pdu, &response)) != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR || response->variables == NULL || response->variables->type != ASN_INTEGER) { if (status == STAT_SUCCESS) ifstat_error("snmp: Error: %s", snmp_errstring(response->errstat)); else ifstat_error("snmpget(interfaces.ifNumber.0): %s", snmp_sess_errstring(ss)); if (response) snmp_free_pdu(response); return -1; } nifaces = *(response->variables->val.integer); snmp_free_pdu(response); if (nifaces < 0) return -1; return nifaces;}
开发者ID:RaonControl,项目名称:siteApps,代码行数:34,
示例4: snmpStoreResult/* * simple printing of returned data */int snmpStoreResult (tSession *session, struct snmp_pdu *pdu, char **result){ char buf[RESULTSIZE]; struct variable_list *vp; struct snmp_session *sp = session->sess; unsigned int o = session->current_oid; unsigned int i,j; *result = (char*)calloc(RESULTSIZE+1, sizeof(char)); vp = pdu->variables; if (pdu->errstat == SNMP_ERR_NOERROR) { while (vp) { snprint_value(*result, RESULTSIZE, vp->name, vp->name_length, vp); // tolower & remove spaces and linebreaks for (i=0, j=0; i<strlen(*result); i++) { if ((*result)[i] > 0x22) { if ((*result)[i] >= 0x41 && (*result)[i] <= 0x5A) { (*result)[j] = (*result)[i] + 0x20; } else { (*result)[j] = (*result)[i]; } j++; } } (*result)[j] = 0; // fix lancom snr if (session->oidList.oid[o].id_oidtype == 12 && ( session->oidList.oid[o].id_type == 2 || session->oidList.oid[o].id_type == 5 || session->oidList.oid[o].id_type == 9 || session->oidList.oid[o].id_type == 24 )) { snprintf(*result, RESULTSIZE, "%.0f", atoi(*result) * 0.64); } snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp); syslog(LOG_DEBUG, "snmpStoreResult: %s: %s", sp->peername, buf); vp = vp->next_variable; } return 1; } else { if (vp) { snprint_objid(buf, sizeof(buf), vp->name, vp->name_length); } else { strcpy(buf, "(empty buf)"); } syslog(LOG_ERR, "snmpStoreResult: %s: %s: (%s)", sp->peername, buf, snmp_errstring(pdu->errstat)); if (pdu->errstat == SNMP_ERR_NOSUCHNAME) { snprintf(*result, RESULTSIZE, "U"); return 1; } return 0; }}
开发者ID:fbn-dd,项目名称:netplan,代码行数:62,
示例5: setMainSwitch/** Write on/off status*/double setMainSwitch(HSNMP m_sessp,float value) { struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_SET); // prepare set-request pdu pdu->community = (u_char*)strdup(writeCommunity); pdu->community_len = strlen(writeCommunity); // for(each SET request to one crate) { int v = (int) value; snmp_pdu_add_variable(pdu,oidSysMainSwitch,lengthSysMainSwitch,ASN_INTEGER,(u_char*)&v,sizeof(v)); // } // endfor struct snmp_pdu* response; int status = snmp_sess_synch_response(m_sessp,pdu,&response); /* * Process the response. */ if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) { /* * SUCCESS: Print the result variables */ struct variable_list *vars; // debug print //for(vars = response->variables; vars; vars = vars->next_variable) // print_variable(vars->name, vars->name_length, vars); /* manipuate the information ourselves */ for(vars = response->variables; vars; vars = vars->next_variable) { if (vars->type == ASN_OPAQUE_FLOAT) { // 0x78 value = *vars->val.floatVal; } else if (vars->type == ASN_OPAQUE_DOUBLE) { // 0x79 value = *vars->val.doubleVal; } else if(vars->type == ASN_INTEGER) { // 0x02 value = (double)*vars->val.integer; } } } else { /* * FAILURE: print what went wrong! */ if (status == STAT_SUCCESS) fprintf(stderr, "Error in packet/nReason: %s/n", snmp_errstring(response->errstat)); else snmp_sess_perror("snmpget",snmp_sess_session(m_sessp)); return 0; } snmp_free_pdu(response); return value;}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:58,
示例6: getCurrentMeasurement/** Get current from power supply*/double getCurrentMeasurement(HSNMP m_sessp, int channel) { double value; struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET); // prepare get-request pdu // for(each GET request to one crate) { snmp_add_null_var(pdu,oidOutputMeasurementCurrent[channel],lengthOutputMeasurementCurrent[channel]); // generate request data // } // endfor struct snmp_pdu* response; int status = snmp_sess_synch_response(m_sessp,pdu,&response); /* * Process the response. */ if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) { /* * SUCCESS: Print the result variables */ struct variable_list *vars; // debug print //for(vars = response->variables; vars; vars = vars->next_variable) // print_variable(vars->name, vars->name_length, vars); /* manipuate the information ourselves */ for(vars = response->variables; vars; vars = vars->next_variable) { if (vars->type == ASN_OPAQUE_FLOAT) { // 0x78 value = *vars->val.floatVal; } else if (vars->type == ASN_OPAQUE_DOUBLE) { // 0x79 value = *vars->val.doubleVal; } else if(vars->type == ASN_INTEGER) { // 0x02 value = (double)*vars->val.integer; } } } else { /* * FAILURE: print what went wrong! */ if (status == STAT_SUCCESS) fprintf(stderr, "Error in packet/nReason: %s/n", snmp_errstring(response->errstat)); else snmp_sess_perror("snmpget",snmp_sess_session(m_sessp)); return 0; } snmp_free_pdu(response); return value;}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:57,
示例7: return_dataint return_data(int status, struct snmp_session *sp, struct snmp_pdu *pdu){ char buf[1024]; struct variable_list *vp; int ix; char *getdata = NULL; switch (status) { case STAT_SUCCESS: vp = pdu->variables; if (pdu->errstat == SNMP_ERR_NOERROR) { while (vp) { snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp); /*mjpark------------------------------------------*/ getdata = (char *)malloc(1 + vp->val_len); memcpy(getdata, vp->val.string, vp->val_len); getdata[vp->val_len] = '/0';#if 0 //Data over flow... int nVal; memcpy((void *)&nVal, getdata, 4);#else unsigned long int nVal; memcpy((void *)&nVal, getdata, sizeof(unsigned long int));#endif gpSnmp->val = nVal; //debug print /* printf("data length(%d), unsigned long int size(%d), int(%d)/n",vp->val_len, sizeof(unsigned long int), sizeof(int)); */ printf("snmpVal(%d), psnmp(%p)/n", nVal, gpSnmp); /*------------------------------------------------*/ vp = vp->next_variable; } free(getdata); } else { for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++); if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length); else strcpy(buf, "(none)"); fprintf(stdout, "%s: %s: %s/n", sp->peername, buf, snmp_errstring(pdu->errstat)); } return 1; case STAT_TIMEOUT: fprintf(stdout, "%s: Timeout/n", sp->peername); return 0; case STAT_ERROR: snmp_perror(sp->peername); return 0; } return 0;}
开发者ID:RaonControl,项目名称:siteLibs,代码行数:54,
示例8: errHandles// handle err if connection failsvoid errHandles(int stat) { if (status == STAT_SUCCESS) fprintf(stderr, "Error in packet/nReason: %s/n", snmp_errstring(response->errstat)); else if (status == STAT_TIMEOUT) fprintf(stderr, "Timeout: No response from %s./n", session.peername); else snmp_sess_perror("snmpdemoapp", ss);}
开发者ID:kenchan13579,项目名称:SNMP,代码行数:12,
示例9: collectnetsnmp_variable_list *collect(netsnmp_session * ss, netsnmp_pdu *pdu, oid * base, size_t base_length){ netsnmp_pdu *response; int running = 1; netsnmp_variable_list *saved = NULL, **vlpp = &saved; int status; while (running) { /* * gotta catch em all, gotta catch em all! */ status = snmp_synch_response(ss, pdu, &response); if (status != STAT_SUCCESS || !response) { snmp_sess_perror("snmpdf", ss); exit(1); } if (response->errstat != SNMP_ERR_NOERROR) { fprintf(stderr, "snmpdf: Error in packet: %s/n", snmp_errstring(response->errstat)); exit(1); } if (response && snmp_oid_compare(response->variables->name, SNMP_MIN(base_length, response->variables-> name_length), base, base_length) != 0) running = 0; else { /* * get response */ *vlpp = response->variables; (*vlpp)->next_variable = NULL; /* shouldn't be any, but just in case */ /* * create the next request */ pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); snmp_add_null_var(pdu, (*vlpp)->name, (*vlpp)->name_length); /* * finish loop setup */ vlpp = &((*vlpp)->next_variable); response->variables = NULL; /* ahh, forget about it */ } snmp_free_pdu(response); } return saved;}
开发者ID:ColdStart,项目名称:SNMPD,代码行数:52,
示例10: snmp_pdu_createbool Session::getVariables(const QStringList &oids, QValueVector<QVariant> &retvars, uint32_t &status, int startIndex){ struct snmp_pdu *response = NULL; if ( ! m_session ) { status = 0xFFFFFFFF; return false; } struct snmp_pdu *pdu = snmp_pdu_create(SNMP_MSG_GET); u_long anOID[MAX_OID_LEN]; QStringList::const_iterator it = oids.begin(); for(int i = 0; i < startIndex; i++) it++; // rough hack, but works for(int i = 0; it != oids.end() && i < 5; it++, i++ ) { size_t anOID_len = MAX_OID_LEN; get_node((*it).latin1(), anOID, &anOID_len); snmp_add_null_var(pdu, anOID, anOID_len); } status = snmp_synch_response(m_session, pdu, &response); //! @todo Error handling should be changed in a more OO way. if ( status != STAT_SUCCESS ) { snmp_sess_perror("snmpget", m_session); return false; } if ( response->errstat != SNMP_ERR_NOERROR ) { kdWarning() << "Error in packet: " << snmp_errstring(response->errstat) << endl; snmp_free_pdu(response); return false; } variable_list *var = response->variables; int i = startIndex; while( var ) { retvars[i] = snmpvarToVariant(var); i++; var = var->next_variable; } snmp_free_pdu(response); return true;}
开发者ID:Flameeyes,项目名称:libksnmp,代码行数:52,
示例11: snmp_getn_bulkSaErrorT snmp_getn_bulk( struct snmp_session *ss, oid *bulk_objid, size_t bulk_objid_len, struct snmp_pdu *bulk_pdu, struct snmp_pdu **bulk_response, int num_repetitions ){ int status; SaErrorT rtncode = SA_OK;// struct variable_list *vars; bulk_pdu = snmp_pdu_create(SNMP_MSG_GETBULK); bulk_pdu->non_repeaters = 0; bulk_pdu->max_repetitions = num_repetitions; snmp_add_null_var(bulk_pdu, bulk_objid, bulk_objid_len); /* Send the Request out.*/ status = snmp_synch_response(ss, bulk_pdu, bulk_response); /* * Process the response. */#if 0 if (status == STAT_SUCCESS) { vars = (*bulk_response)->variables; if ((*bulk_response)->errstat == SNMP_ERR_NOERROR) { if (!CHECH_END(vars->type)) { /* This is one of the exception condition */ rtncode = SA_ERR_HPI_NOT_PRESENT; dbg("snmp exception %d /n",vars->type); } } else { fprintf(stderr, "Error in packet %s/nReason: %s/n", (char *)bulk_objid, snmp_errstring((*bulk_response)->errstat)); if ((*bulk_response)->errstat == SNMP_ERR_NOSUCHNAME) (*bulk_response)->errstat = SNMP_NOSUCHOBJECT; rtncode = (SaErrorT) (SA_ERR_SNMP_BASE - (*bulk_response)->errstat); } } else { snmp_sess_perror("snmpset", ss); rtncode = (SaErrorT) (SA_ERR_SNMP_BASE - status); }#endif return(rtncode);}
开发者ID:openhpi1,项目名称:testrepo,代码行数:49,
示例12: MPC_write/* * write value of given oid */static intMPC_write(struct snmp_session *sptr, const char *objname, char type, char *value){ oid name[MAX_OID_LEN]; size_t namelen = MAX_OID_LEN; struct snmp_pdu *pdu; struct snmp_pdu *resp; DEBUGCALL; /* convert objname into oid; return FALSE if invalid */ if (!read_objid(objname, name, &namelen)) { LOG(PIL_CRIT, "%s: cannot convert %s to oid.", __FUNCTION__, objname); return (FALSE); } /* create pdu */ if ((pdu = snmp_pdu_create(SNMP_MSG_SET)) != NULL) { /* add to be written value to pdu */ snmp_add_var(pdu, name, namelen, type, value); /* send pdu and get response; return NULL if error */ if (snmp_synch_response(sptr, pdu, &resp) == STAT_SUCCESS) { /* go through the returned vars */ if (resp->errstat == SNMP_ERR_NOERROR) { /* request successful done */ snmp_free_pdu(resp); return (TRUE); } else { LOG(PIL_CRIT, "%s: error in response packet, reason %ld [%s]." , __FUNCTION__, resp->errstat, snmp_errstring(resp->errstat)); } } else { MPC_error(sptr, __FUNCTION__, "error sending/receiving pdu"); } /* free pdu (again: necessary?) */ snmp_free_pdu(resp); } else { MPC_error(sptr, __FUNCTION__, "cannot create pdu"); } /* error */ return (FALSE);}
开发者ID:ingted,项目名称:cluster-glue,代码行数:51,
示例13: snmp_synch_responsechar *session_query(struct snmp_session *ss, struct snmp_pdu *pdu) { struct snmp_pdu *response; struct variable_list *vars; int status; char buf[SPRINT_MAX_LEN]; char *rbuffer=NULL; /* Send the Request */ status = snmp_synch_response(ss, pdu, &response); /* Process the response */ if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR ) { /* Success: Print the results */ /* for (vars=response->variables; vars; vars=vars->next_variable) { */ vars=response->variables; if (vars!=NULL && vars->type <ASN_LONG_LEN) { if (vars->type == ASN_INTEGER) { sprintf(buf,"%ld",*vars->val.integer); rbuffer=malloc(sizeof(char)*(strlen(buf)+1)); memset(rbuffer,'/0',strlen(buf)+1); strncpy(rbuffer,buf,strlen(buf)); } else { snprint_variable(buf, sizeof (buf), vars->name, vars->name_length, vars); rbuffer=malloc(sizeof(char)*(strlen(buf)+1)); memset(rbuffer,'/0',strlen(buf)+1); strncpy(rbuffer,buf,strlen(buf)); } } else rbuffer = NULL; } else { /* Failure: print what went wrong */ if (status == STAT_SUCCESS) fprintf(stderr,"Error in packet./nReason: %s/n", snmp_errstring(response->errstat)); else snmp_sess_perror("snmpget ", ss); } /* Clean up */ if (response) snmp_free_pdu(response);// printf("Result : %s/n",rbuffer); return rbuffer;}
开发者ID:Ancient,项目名称:NetGuard,代码行数:46,
示例14: snmp_pdu_createchar *session_set( struct snmp_session *ss,const char *name, const char *value ) { struct snmp_pdu *pdu, *response; oid anOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN; struct variable_list *vars; int status; char buf[SPRINT_MAX_LEN]; char *rbuffer=NULL; /* create PDU for request */ pdu = snmp_pdu_create(SNMP_MSG_SET); get_node(name, anOID, &anOID_len); snmp_add_var(pdu, anOID, anOID_len,'i',value);// snmp_add_null_var(pdu, anOID, anOID_len); /* Send the Request */ status = snmp_synch_response(ss, pdu, &response); /* Process the response */ if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) { /* Success: Print the results */ /* for (vars=response->variables; vars; vars=vars->next_variable) { */ vars=response->variables; if (vars!=NULL) { snprint_variable(buf, sizeof (buf), vars->name, vars->name_length, vars); rbuffer=malloc(sizeof(char)*(strlen(buf)+1)); memset(rbuffer,'/0',strlen(buf)+1); strncpy(rbuffer,buf,strlen(buf)); } else rbuffer = NULL; } else { /* Failure: print what went wrong */ if (status == STAT_SUCCESS) fprintf(stderr,"Error in packet./nReason: %s/n", snmp_errstring(response->errstat)); else snmp_sess_perror("snmpset", ss); } /* Clean up */ /* if (pdu) snmp_free_pdu(pdu); */ if (response) snmp_free_pdu(response); return rbuffer;}
开发者ID:Ancient,项目名称:NetGuard,代码行数:45,
示例15: snmp_get_nextifstatic int snmp_get_nextif(struct snmp_session *ss, int index) { oid ifindex[] = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 0 }; int len = sizeof(ifindex) / sizeof(oid); struct snmp_pdu *pdu; struct snmp_pdu *response = NULL; struct variable_list *vars; int status; if (index >= 0) ifindex[len - 1] = index; if ((pdu = snmp_pdu_create(SNMP_MSG_GETNEXT)) == NULL) { ifstat_error("snmp_pdu_create: %s", snmp_api_errstring(snmp_errno)); return -1; } snmp_add_null_var(pdu, ifindex, (index < 0) ? len - 1 : len); if ((status = snmp_synch_response(ss, pdu, &response)) != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR || response->variables == NULL) { if (status == STAT_SUCCESS) ifstat_error("snmp: Error: %s", snmp_errstring(response->errstat)); else ifstat_error("snmpgetnext(interfaces.ifTable.ifEntry.ifIndex...): %s", snmp_sess_errstring(ss)); if (response != NULL) snmp_free_pdu(response); return -1; } for(vars = response->variables; vars; vars = vars->next_variable) { /* check that the variable is under the base oid */ if (vars->name_length != len) continue; if (memcmp(ifindex, vars->name, sizeof(ifindex) - sizeof(oid)) != 0) continue; index = vars->name[vars->name_length - 1]; snmp_free_pdu(response); return index; } snmp_free_pdu(response); return -1;}
开发者ID:RaonControl,项目名称:siteApps,代码行数:45,
示例16: print_resultint print_result(int status, struct snmp_session *sp, struct snmp_pdu *pdu){ char buf[1024]; struct variable_list *vp; int ix; struct timeval now; struct timezone tz; struct tm *tm; gettimeofday(&now, &tz); tm = localtime(&now.tv_sec); fprintf(stdout, "%.2d:%.2d:%.2d.%.6d, status: %d, ", tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec, status); switch (status) { case STAT_SUCCESS: vp = pdu->variables; if (pdu->errstat == SNMP_ERR_NOERROR) { while (vp) { snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp); fprintf(stdout, ":%s: %s/n", sp->peername, buf); vp = vp->next_variable; } } else { for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++) ; if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length); else strcpy(buf, "(none)"); fprintf(stdout, ":%s: %s: %s/n", sp->peername, buf, snmp_errstring(pdu->errstat)); } return 1; case STAT_TIMEOUT: fprintf(stdout, ":%s: Timeout/n", sp -> peername); return 0; case STAT_ERROR: snmp_perror(sp->peername); return 0; } return 0;}
开发者ID:hdimov,项目名称:rtg.phoenix,代码行数:42,
示例17: mlbool Session::getVariable(const QString &oid, QVariant &retvar, uint32_t &status){ QMutexLocker ml(&m_mutex); struct snmp_pdu *response = NULL; if ( ! m_session ) { status = 0xFFFFFFFF; return false; } // Buffer requestd for net-snmp library u_long anOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN; // Prepare the PDU for a GET command struct snmp_pdu *pdu = snmp_pdu_create(SNMP_MSG_GET); get_node(oid.latin1(), anOID, &anOID_len); snmp_add_null_var(pdu, anOID, anOID_len); status = snmp_synch_response(m_session, pdu, &response); //! @todo Error handling should be changed in a more OO way. if ( status != STAT_SUCCESS ) { snmp_sess_perror("snmpget", m_session); return false; } if ( response->errstat != SNMP_ERR_NOERROR ) { kdWarning() << "Error in packet: " << snmp_errstring(response->errstat) << endl; snmp_free_pdu(response); return false; } retvar = snmpvarToVariant(response->variables); snmp_free_pdu(response); return true;}
开发者ID:Flameeyes,项目名称:libksnmp,代码行数:40,
示例18: print_result//.........这里部分代码省略......... */ vp = pdu->variables; len = 0; sprint_realloc_value(&valstr, &valsz, &len, 1, vp->name, vp->name_length, vp); len = 0; sprint_realloc_objid(&oidstr, &oidsz, &len, 1, vp->name, vp->name_length); dbgprintf("Got key-oid '%s' = '%s'/n", oidstr, valstr); for (kwalk = req->currentkey, done = 0; (kwalk && !done); kwalk = kwalk->next) { /* Skip records where we have the result already, or that are not keyed */ if (kwalk->indexoid || (kwalk->indexmethod != req->currentkey->indexmethod)) { continue; } keyoidlen = strlen(req->currentkey->indexmethod->keyoid); switch (kwalk->indexmethod->idxtype) { case MIB_INDEX_IN_OID: /* Does the key match the value we just got? */ if (*kwalk->key == '*') { /* Match all. Add an extra key-record at the end. */ keyrecord_t *newkey; newkey = (keyrecord_t *)calloc(1, sizeof(keyrecord_t)); memcpy(newkey, kwalk, sizeof(keyrecord_t)); newkey->indexoid = strdup(oidstr + keyoidlen + 1); newkey->key = valstr; valstr = NULL; newkey->next = kwalk->next; kwalk->next = newkey; done = 1; } else if (strcmp(valstr, kwalk->key) == 0) { /* Grab the index part of the OID */ kwalk->indexoid = strdup(oidstr + keyoidlen + 1); done = 1; } break; case MIB_INDEX_IN_VALUE: /* Does the key match the index-part of the result OID? */ if (*kwalk->key == '*') { /* Match all. Add an extra key-record at the end. */ keyrecord_t *newkey; newkey = (keyrecord_t *)calloc(1, sizeof(keyrecord_t)); memcpy(newkey, kwalk, sizeof(keyrecord_t)); newkey->indexoid = valstr; valstr = NULL; newkey->key = strdup(oidstr + keyoidlen + 1); newkey->next = kwalk->next; kwalk->next = newkey; done = 1; } else if ((*(oidstr+keyoidlen) == '.') && (strcmp(oidstr+keyoidlen+1, kwalk->key)) == 0) { /* * Grab the index which is the value. * Avoid a strdup by grabbing the valstr pointer. */ kwalk->indexoid = valstr; valstr = NULL; valsz = 0; done = 1; } break; } } break; case GET_DATA: owalk = req->curr_oid; vp = pdu->variables; while (vp) { valsz = len = 0; sprint_realloc_value((unsigned char **)&owalk->result, &valsz, &len, 1, vp->name, vp->name_length, vp); owalk = owalk->next; vp = vp->next_variable; } break; } if (valstr) xfree(valstr); if (oidstr) xfree(oidstr); } else { errorcount++; errprintf("ERROR %s: %s/n", req->hostip[req->hostipidx], snmp_errstring(pdu->errstat)); } return 1; case STAT_TIMEOUT: timeoutcount++; dbgprintf("%s: Timeout/n", req->hostip); if (req->hostip[req->hostipidx+1]) { req->hostipidx++; startonehost(req, 1); } return 0; case STAT_ERROR: errorcount++; snmp_sess_perror(req->hostip[req->hostipidx], req->sess); return 0; } return 0;}
开发者ID:gvsurenderreddy,项目名称:xymon-2,代码行数:101,
示例19: get_value_snmp//.........这里部分代码省略......... if(p) { ip = vars->val.string; zbx_snprintf(p,MAX_STRING_LEN-1,"%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); SET_STR_RESULT(value, p); } else { zbx_snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory"); zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); } } } else {/* count is not really used. Has to be removed */ count++; zbx_snprintf(error,sizeof(error),"OID [%s] value #%d has unknow type [%X]", item->snmp_oid, count, vars->type); zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); ret = NOTSUPPORTED; } } } else { if (status == STAT_SUCCESS) { zabbix_log( LOG_LEVEL_WARNING, "SNMP error in packet. Reason: %s/n", snmp_errstring(response->errstat)); if(response->errstat == SNMP_ERR_NOSUCHNAME) { zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat)); zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); ret=NOTSUPPORTED; } else { zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat)); zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); ret=NOTSUPPORTED; } } else if(status == STAT_TIMEOUT) { zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]", session.peername);/* snmp_sess_perror("snmpget", ss);*/ zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); ret = NETWORK_ERROR; } else { zbx_snprintf(error,sizeof(error),"SNMP error [%d]", status); zabbix_log( LOG_LEVEL_ERR, "%s", error); SET_MSG_RESULT(value, strdup(error)); ret=NOTSUPPORTED; } } if (response) { snmp_free_pdu(response); } snmp_close(ss); SOCK_CLEANUP; return ret;}
开发者ID:Shmuma,项目名称:z,代码行数:101,
示例20: php_snmp//.........这里部分代码省略......... if (array_init(return_value) == FAILURE) { php_error(E_WARNING, "Cannot prepare result array"); RETURN_FALSE; } } while(keepwalking) { keepwalking=0; if (st == 1) { pdu = snmp_pdu_create(SNMP_MSG_GET); name_length = MAX_NAME_LEN; if ( !read_objid(objid, name, &name_length) ) { php_error(E_WARNING,"Invalid object identifier: %s/n", objid); RETURN_FALSE; } snmp_add_null_var(pdu, name, name_length); } else if (st == 11) { pdu = snmp_pdu_create(SNMP_MSG_SET); if (snmp_add_var(pdu, name, name_length, type, value)) { php_error(E_WARNING,"Could not add variable: %s/n", name); RETURN_FALSE; } } else if (st >= 2) { pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); snmp_add_null_var(pdu, name, name_length); } retry: status = snmp_synch_response(ss, pdu, &response); if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { for (vars = response->variables; vars; vars = vars->next_variable) { if (st >= 2 && st != 11 && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { continue; /* not part of this subtree */ } if (st != 11) { sprint_value(buf,vars->name, vars->name_length, vars); }#if 0 Debug("snmp response is: %s/n",buf);#endif if (st == 1) { RETVAL_STRING(buf,1); } else if (st == 2) { add_next_index_string(return_value,buf,1); /* Add to returned array */ } else if (st == 3) { sprint_objid(buf2, vars->name, vars->name_length); add_assoc_string(return_value,buf2,buf,1); } if (st >= 2 && st != 11) { if (vars->type != SNMP_ENDOFMIBVIEW && vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) { memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid)); name_length = vars->name_length; keepwalking = 1; } } } } else { if (st != 2 || response->errstat != SNMP_ERR_NOSUCHNAME) { php_error(E_WARNING,"Error in packet./nReason: %s/n", snmp_errstring(response->errstat)); if (response->errstat == SNMP_ERR_NOSUCHNAME) { for (count=1, vars = response->variables; vars && count != response->errindex; vars = vars->next_variable, count++); if (vars) { sprint_objid(buf,vars->name, vars->name_length); } php_error(E_WARNING,"This name does not exist: %s/n",buf); } if (st == 1) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) { goto retry; } } else if (st == 11) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) { goto retry; } } else if (st >= 2) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) { goto retry; } } RETURN_FALSE; } } } else if (status == STAT_TIMEOUT) { php_error(E_WARNING,"No Response from %s/n", (*a1)->value.str.val); RETURN_FALSE; } else { /* status == STAT_ERROR */ php_error(E_WARNING,"An error occurred, Quitting.../n"); RETURN_FALSE; } if (response) { snmp_free_pdu(response); } } /* keepwalking */ snmp_close(ss);}
开发者ID:jehurodrig,项目名称:PHP-4.0.6-16-07-2009,代码行数:101,
示例21: main//.........这里部分代码省略......... fprintf (stderr, "snmpbulkget: need more objects than <nonrep>/n"); exit (1); } namep = name = (struct nameStruct *) calloc (names, sizeof (*name)); while (arg < argc) { namep->name_len = MAX_OID_LEN; if (snmp_parse_oid (argv[arg], namep->name, &namep->name_len) == NULL) { snmp_perror (argv[arg]); exit (1); } arg++; namep++; } SOCK_STARTUP; /* * open an SNMP session */ ss = snmp_open (&session); if (ss == NULL) { /* * diagnose snmp_open errors with the input netsnmp_session pointer */ snmp_sess_perror ("snmpbulkget", &session); SOCK_CLEANUP; exit (1); } /* * create PDU for GETBULK request and add object name to request */ pdu = snmp_pdu_create (SNMP_MSG_GETBULK); pdu->non_repeaters = non_repeaters; pdu->max_repetitions = max_repetitions; /* fill the packet */ for (arg = 0; arg < names; arg++) snmp_add_null_var (pdu, name[arg].name, name[arg].name_len); /* * do the request */ status = snmp_synch_response (ss, pdu, &response); if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { /* * check resulting variables */ for (vars = response->variables; vars; vars = vars->next_variable) print_variable (vars->name, vars->name_length, vars); } else { /* * error in response, print it */ if (response->errstat == SNMP_ERR_NOSUCHNAME) { printf ("End of MIB./n"); } else { fprintf (stderr, "Error in packet./nReason: %s/n", snmp_errstring (response->errstat)); if (response->errindex != 0) { fprintf (stderr, "Failed object: "); for (count = 1, vars = response->variables; vars && (count != response->errindex); vars = vars->next_variable, count++) /*EMPTY*/; if (vars) fprint_objid (stderr, vars->name, vars->name_length); fprintf (stderr, "/n"); } exitval = 2; } } } else if (status == STAT_TIMEOUT) { fprintf (stderr, "Timeout: No Response from %s/n", session.peername); exitval = 1; } else { /* status == STAT_ERROR */ snmp_sess_perror ("snmpbulkget", ss); exitval = 1; } if (response) snmp_free_pdu (response); snmp_close (ss); SOCK_CLEANUP; return exitval;}
开发者ID:274914765,项目名称:C,代码行数:101,
示例22: main//.........这里部分代码省略......... || (memcmp(root, vars->name, rootlen * sizeof(oid)) != 0)) { /* * not part of this subtree */ running = 0; continue; } numprinted++; print_variable(vars->name, vars->name_length, vars); if ((vars->type != SNMP_ENDOFMIBVIEW) && (vars->type != SNMP_NOSUCHOBJECT) && (vars->type != SNMP_NOSUCHINSTANCE)) { /* * not an exception value */ if (check && snmp_oid_compare(name, name_length, vars->name, vars->name_length) >= 0) { fprintf(stderr, "Error: OID not increasing: "); fprint_objid(stderr, name, name_length); fprintf(stderr, " >= "); fprint_objid(stderr, vars->name, vars->name_length); fprintf(stderr, "/n"); running = 0; exitval = 1; } /* * Check if last variable, and if so, save for next request. */ if (vars->next_variable == NULL) { memmove(name, vars->name, vars->name_length * sizeof(oid)); name_length = vars->name_length; } } else { /* * an exception value, so stop */ running = 0; } } } else { /* * error in response, print it */ running = 0; if (response->errstat == SNMP_ERR_NOSUCHNAME) { printf("End of MIB/n"); } else { fprintf(stderr, "Error in packet./nReason: %s/n", snmp_errstring(response->errstat)); if (response->errindex != 0) { fprintf(stderr, "Failed object: "); for (count = 1, vars = response->variables; vars && count != response->errindex; vars = vars->next_variable, count++) /*EMPTY*/; if (vars) fprint_objid(stderr, vars->name, vars->name_length); fprintf(stderr, "/n"); } exitval = 2; } } } else if (status == STAT_TIMEOUT) { fprintf(stderr, "Timeout: No Response from %s/n", session.peername); running = 0; exitval = 1; } else { /* status == STAT_ERROR */ snmp_sess_perror("snmpbulkwalk", ss); running = 0; exitval = 1; } if (response) snmp_free_pdu(response); } if (numprinted == 0 && status == STAT_SUCCESS) { /* * no printed successful results, which may mean we were * pointed at an only existing instance. Attempt a GET, just * for get measure. */ snmp_get_and_print(ss, root, rootlen); } snmp_close(ss); if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_WALK_PRINT_STATISTICS)) { printf("Variables found: %d/n", numprinted); } SOCK_CLEANUP; return exitval;}
开发者ID:RasmusKoldsoe,项目名称:performand.k70.2,代码行数:101,
示例23: build_valuetable//.........这里部分代码省略......... taggetOID_len = objfound->expObjectIDLen; int status; struct snmp_session *ss; /* * Initialize the SNMP library */ /* * set the SNMP version number */ session.version = expstorage->pdu_version; /* * set the SNMPv1 community name used for authentication */ session.community = expstorage->pdu_community; session.community_len = expstorage->pdu_community_len; /* * Open the session */ SOCK_STARTUP; ss = snmp_open(&session); /* establish the session */ if (!ss) { snmp_perror("ack"); snmp_log(LOG_ERR, "something horrible happened!!!/n"); exit(2); } next_OID = targetOID; next_OID_len = taggetOID_len; do { index = calloc(1, MAX_OID_LEN); pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); snmp_add_null_var(pdu, next_OID, next_OID_len); /* * Send the Request out. */ status = snmp_synch_response(ss, pdu, &response); /* * Process the response. */ if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) { /* * SUCCESS: Print the result variables */ if (((response->variables->type >= SNMP_NOSUCHOBJECT && response->variables->type <= SNMP_ENDOFMIBVIEW) || snmp_oid_compare(targetOID, taggetOID_len, response->variables->name, taggetOID_len) != 0)) { break; } /* add to expValueTable */ *index = 0; *(index + 1) = 0; memcpy(index + 2, response->variables->name + taggetOID_len, (response->variables->name_length - taggetOID_len) * sizeof(oid)); expValueTable_add(expstorage, objfound->expExpressionOwner, objfound->expExpressionOwnerLen, objfound->expExpressionName, objfound->expExpressionNameLen, index, response->variables->name_length - taggetOID_len + 2); next_OID = response->variables->name; next_OID_len = response->variables->name_length; } else { /* * FAILURE: print what went wrong! */ if (status == STAT_SUCCESS) fprintf(stderr, "Error in packet/nReason: %s/n", snmp_errstring(response->errstat)); else snmp_sess_perror("snmpget", ss); } } while (TRUE); } }}
开发者ID:a5216652166,项目名称:rcp100,代码行数:101,
示例24: printfvoid *poller(void *thread_args){ worker_t *worker = (worker_t *) thread_args; crew_t *crew = worker->crew; target_t *entry = NULL; void *sessp = NULL; struct snmp_session session; struct snmp_pdu *pdu = NULL; struct snmp_pdu *response = NULL; oid anOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN; struct variable_list *vars = NULL; unsigned long long result = 0; unsigned long long last_value = 0; unsigned long long insert_val = 0; int status = 0, bits = 0, init = 0; char query[BUFSIZE]; char storedoid[BUFSIZE]; char result_string[BUFSIZE]; if (set.verbose >= HIGH) printf("Thread [%d] starting./n", worker->index); if (MYSQL_VERSION_ID > 40000) mysql_thread_init(); else my_thread_init(); while (1) { if (set.verbose >= DEVELOP) printf("Thread [%d] locking (wait on work)/n", worker->index); PT_MUTEX_LOCK(&crew->mutex); while (current == NULL) { PT_COND_WAIT(&crew->go, &crew->mutex); } if (set.verbose >= DEVELOP) printf("Thread [%d] done waiting, received go (work cnt: %d)/n", worker->index, crew->work_count); if (current != NULL) { if (set.verbose >= HIGH) printf("Thread [%d] processing %s %s (%d work units remain in queue)/n", worker->index, current->host, current->objoid, crew->work_count); snmp_sess_init(&session); if (set.snmp_ver == 2) session.version = SNMP_VERSION_2c; else session.version = SNMP_VERSION_1; session.peername = current->host; session.remote_port = set.snmp_port; session.community = current->community; session.community_len = strlen(session.community); sessp = snmp_sess_open(&session); anOID_len = MAX_OID_LEN; pdu = snmp_pdu_create(SNMP_MSG_GET); read_objid(current->objoid, anOID, &anOID_len); entry = current; last_value = current->last_value; init = current->init; insert_val = 0; bits = current->bits; strncpy(storedoid, current->objoid, sizeof(storedoid)); current = getNext(); } if (set.verbose >= DEVELOP) printf("Thread [%d] unlocking (done grabbing current)/n", worker->index); PT_MUTEX_UNLOCK(&crew->mutex); snmp_add_null_var(pdu, anOID, anOID_len); if (sessp != NULL) status = snmp_sess_synch_response(sessp, pdu, &response); else status = STAT_DESCRIP_ERROR; /* Collect response and process stats */ PT_MUTEX_LOCK(&stats.mutex); if (status == STAT_DESCRIP_ERROR) { stats.errors++; printf("*** SNMP Error: (%s) Bad descriptor./n", session.peername); } else if (status == STAT_TIMEOUT) { stats.no_resp++; printf("*** SNMP No response: (%[email C++ snmp_fold_field函数代码示例 C++ snmp_delete_iprteidx_tree函数代码示例
|