target_counters.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:2k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. #include <net-snmp/net-snmp-config.h>
  2. #if HAVE_STRING_H
  3. #include <string.h>
  4. #else
  5. #include <strings.h>
  6. #endif
  7. #include <net-snmp/net-snmp-includes.h>
  8. #include <net-snmp/agent/net-snmp-agent-includes.h>
  9. #include "target_counters.h"
  10. #include <net-snmp/agent/instance.h>
  11. static oid   unavailable_context_oid[] = { 1, 3, 6, 1, 6, 3, 12, 1, 4 };
  12. static oid   unknown_context_oid[]     = { 1, 3, 6, 1, 6, 3, 12, 1, 5 };
  13. void
  14. init_target_counters(void)
  15. {
  16.     DEBUGMSGTL(("target_counters", "initializingn"));
  17.     /*
  18.      * unknown contexts
  19.      */
  20.     netsnmp_register_scalar(
  21.         netsnmp_create_handler_registration("snmpUnknownContexts",
  22.                                          get_unknown_context_count,
  23.                                          unknown_context_oid,
  24.                                          OID_LENGTH(unknown_context_oid),
  25.                                          HANDLER_CAN_RONLY));
  26.     /*
  27.      * unavailable contexts
  28.      */
  29.     netsnmp_register_scalar(
  30.         netsnmp_create_handler_registration("snmpUnavailableContexts",
  31.                                          get_unavailable_context_count,
  32.                                          unavailable_context_oid,
  33.                                          OID_LENGTH(unavailable_context_oid),
  34.                                          HANDLER_CAN_RONLY));
  35. }
  36. int
  37. get_unknown_context_count(netsnmp_mib_handler *handler,
  38.                           netsnmp_handler_registration *reginfo,
  39.                           netsnmp_agent_request_info *reqinfo,
  40.                           netsnmp_request_info *requests)
  41. {
  42.     /*
  43.      * we're only called for GETs of the right node, so this is easy: 
  44.      */
  45.     u_long          long_ret =
  46.         snmp_get_statistic(STAT_SNMPUNKNOWNCONTEXTS);
  47.     snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
  48.                              (u_char *) & long_ret, sizeof(long_ret));
  49.     return SNMP_ERR_NOERROR;
  50. }
  51. int
  52. get_unavailable_context_count(netsnmp_mib_handler *handler,
  53.                               netsnmp_handler_registration *reginfo,
  54.                               netsnmp_agent_request_info *reqinfo,
  55.                               netsnmp_request_info *requests)
  56. {
  57.     /*
  58.      * we're only called for GETs of the right node, so this is easy: 
  59.      */
  60.     u_long          long_ret =
  61.         snmp_get_statistic(STAT_SNMPUNAVAILABLECONTEXTS);
  62.     snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
  63.                              (u_char *) & long_ret, sizeof(long_ret));
  64.     return SNMP_ERR_NOERROR;
  65. }