本文整理汇总了C++中snmp_errstring函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_errstring函数的具体用法?C++ snmp_errstring怎么用?C++ snmp_errstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_errstring函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: net_snmp_failure
SaErrorT 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,代码来源:snmp_client_utils.c
示例2: perr
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);
}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:7,代码来源:ttg-snmp.cpp
示例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,代码来源:snmp.c
示例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,代码来源:snmp.c
示例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,代码来源:WIENER_SNMP.cpp
示例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,代码来源:WIENER_SNMP.cpp
示例7: return_data
int 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,代码来源:snmpAsync_v3_problem.c
示例8: errHandles
// handle err if connection fails
void 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,代码来源:snmp.c
示例9: collect
netsnmp_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,代码来源:snmpdf.c
示例10: snmp_pdu_create
bool 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,代码来源:session.cpp
示例11: snmp_getn_bulk
SaErrorT 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,代码来源:snmp_utils.c
示例12: MPC_write
/*
* write value of given oid
*/
static int
MPC_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,代码来源:wti_mpc.c
示例13: snmp_synch_response
char *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,代码来源:snmp_layer.c
示例14: snmp_pdu_create
char *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,代码来源:snmp_layer.c
示例15: snmp_get_nextif
static 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,代码来源:snmp.c
示例16: print_result
int 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,代码来源:rtgsnmp.c
示例17: ml
bool 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,代码来源:session.cpp
示例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,代码来源:xymon-snmpcollect.c
示例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,代码来源:checks_snmp.c
示例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,代码来源:snmp.c
注:本文中的snmp_errstring函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论