|
| 以 PDF 格式下载本书
Handling Error Reports
6
- If you received an error report, you should pass a pointer to a Netmgt_error buffer to the function netmgt_fetch_error(3n), which will return your buffer with the error information. The first field of the buffer, <service_error> may be NETMGT_SUCCESS, which means no problems.
6.1 Agent-Specific Errors
- If <service_error> is NETMGT_WARNING or NETMGT_FATAL, the agent has come across an agent-specific condition it has previously anticipated. The agent-specific error is given in <agent_error>. The value contained in <agent_error> corresponds to an error/text pair in the agent's schema file, in the agentErrors record. The third field in the error buffer is the <error_message> for specific information about where the error occurred, like the name of an interface.
- You should look up the text string corresponding to the error code in the agentErrors agent schema record and present it to the user with the specific error given in <error_message>. (The agent sends back a number rather than a string so the corresponding string can be edited by the local user -- for example, to change it to a different language.)
6.2 Generic Errors
- A <service_error> larger than NETMGT_FATAL--a "generic" error code--is defined in netmgt_errno.h. An error like NETMGT_RPCTIMEDOUT indicates an error while contacting the agent. If you got this error while sending a request, you may wish to try and re-send the request. Otherwise, you can call netmgt_sperror(3n) to get the error message associated with <service_error>. Sometimes <error_message> contains additional information about the error.
6.3 Sample Code
- The following code fragment is an example of how to handle errors. Note that the routine retry_request referenced in the example is a routine that you would write that retries the request.
-
Netmgt_error errbuf;
char agentMsg[NETMGT_NAMESIZ]; /* agent message */
(void) netmgt_fetch_error(&errbuf); /* get error info */
if ((int)errbuf.service_error > (int)NETMGT_FATAL) { /* generic error */
if ((int)errbuf.service_error == (int)NETMGT_RPCTIMEDOUT)
retry_request(); /* retry request */
else
fprintf(stderr, "Generic error: %s, %s\n",
netmgt_sperror(), errbufmessage);
} else { /* agent error */
/* get error message from agent schema */
get_agentError(errbuf.agent_error, agentMsg);
fprintf(stderr, "Agent %s: %s, %s\n", /* print message */
(errbuf.service_error == NETMGT_FATAL) ? "error" : "warning",
agentMsg, errbuf.message);
}
return errbuf.service_error;
|
|
|