summaryrefslogtreecommitdiff
path: root/agent/mibgroup/target/target_counters.c
blob: 010997494996b2ad35dadde7875063df0acb95a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <net-snmp/net-snmp-config.h>

#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif

#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

#include "target_counters.h"
#include <net-snmp/agent/instance.h>

void
init_target_counters(void)
{
    const oid unavailable_context_oid[] = { 1, 3, 6, 1, 6, 3, 12, 1, 4 };
    const oid unknown_context_oid[]     = { 1, 3, 6, 1, 6, 3, 12, 1, 5 };

    DEBUGMSGTL(("target_counters", "initializing\n"));

    /*
     * unknown contexts
     */

    netsnmp_register_scalar(
        netsnmp_create_handler_registration("snmpUnknownContexts",
                                         get_unknown_context_count,
                                         unknown_context_oid,
                                         OID_LENGTH(unknown_context_oid),
                                         HANDLER_CAN_RONLY));

    /*
     * unavailable contexts
     */

    netsnmp_register_scalar(
        netsnmp_create_handler_registration("snmpUnavailableContexts",
                                         get_unavailable_context_count,
                                         unavailable_context_oid,
                                         OID_LENGTH(unavailable_context_oid),
                                         HANDLER_CAN_RONLY));

}


int
get_unknown_context_count(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info *reqinfo,
                          netsnmp_request_info *requests)
{
    /*
     * we're only called for GETs of the right node, so this is easy: 
     */

    u_long          long_ret =
        snmp_get_statistic(STAT_SNMPUNKNOWNCONTEXTS);
    snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
                             (u_char *) & long_ret, sizeof(long_ret));
    return SNMP_ERR_NOERROR;
}


int
get_unavailable_context_count(netsnmp_mib_handler *handler,
                              netsnmp_handler_registration *reginfo,
                              netsnmp_agent_request_info *reqinfo,
                              netsnmp_request_info *requests)
{
    /*
     * we're only called for GETs of the right node, so this is easy: 
     */

    u_long          long_ret =
        snmp_get_statistic(STAT_SNMPUNAVAILABLECONTEXTS);
    snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
                             (u_char *) & long_ret, sizeof(long_ret));
    return SNMP_ERR_NOERROR;
}