1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $
4 */
5 /* Portions of this file are subject to the following copyright(s). See
6 * the Net-SNMP's COPYING file for more details and other copyrights
7 * that may apply:
8 */
9 /*
10 * Portions of this file are copyrighted by:
11 * Copyright (C) 2007 Apple, Inc. All rights reserved.
12 * Use is subject to license terms specified in the COPYING file
13 * distributed with the Net-SNMP package.
14 */
15
16 #include <net-snmp/net-snmp-config.h>
17 #include <net-snmp/net-snmp-includes.h>
18 #include <net-snmp/agent/net-snmp-agent-includes.h>
19 #include <net-snmp/data_access/swrun.h>
20 #include "hrSWRunPerfTable.h"
21 #include "data_access/swrun.h"
22
23 #define MYTABLE "hrSWRunPerfTable"
24
25 /** Initializes the hrSWRunPerfTable module */
26 void
init_hrSWRunPerfTable(void)27 init_hrSWRunPerfTable(void)
28 {
29 /*
30 * here we initialize all the tables we're planning on supporting
31 */
32 initialize_table_hrSWRunPerfTable();
33 }
34
35 void
shutdown_hrSWRunPerfTable(void)36 shutdown_hrSWRunPerfTable(void)
37 {
38 shutdown_table_hrSWRunPerfTable();
39 }
40
41 extern oid hrSWRunTable_oid[];
42 extern size_t hrSWRunTable_oid_len;
43 static netsnmp_table_registration_info *table_info;
44
45 /** Initialize the hrSWRunPerfTable table by defining its contents and how it's structured */
46 void
initialize_table_hrSWRunPerfTable(void)47 initialize_table_hrSWRunPerfTable(void)
48 {
49 static oid hrSWRunPerfTable_oid[] =
50 { 1, 3, 6, 1, 2, 1, 25, 5, 1 };
51 size_t hrSWRunPerfTable_oid_len =
52 OID_LENGTH(hrSWRunPerfTable_oid);
53 netsnmp_handler_registration *reg;
54 netsnmp_mib_handler *handler = NULL;
55
56 reg =
57 netsnmp_create_handler_registration("hrSWRunPerfTable",
58 hrSWRunPerfTable_handler,
59 hrSWRunPerfTable_oid,
60 hrSWRunPerfTable_oid_len,
61 HANDLER_CAN_RONLY);
62 if (NULL == reg) {
63 snmp_log(LOG_ERR,"error creating handler registration for "
64 MYTABLE "\n");
65 goto bail;
66 }
67
68 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
69 if (NULL == table_info) {
70 snmp_log(LOG_ERR,"error allocating table registration for "
71 MYTABLE "\n");
72 goto bail;
73 }
74 netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: hrSWRunIndex */
75 0);
76 table_info->min_column = COLUMN_HRSWRUNPERFCPU;
77 table_info->max_column = COLUMN_HRSWRUNPERFMEM;
78
79 /*************************************************
80 *
81 * inject container_table helper
82 */
83 handler = netsnmp_container_table_handler_get(table_info, netsnmp_swrun_container(),
84 TABLE_CONTAINER_KEY_NETSNMP_INDEX);
85 if (NULL == handler) {
86 snmp_log(LOG_ERR,"error allocating table registration for "
87 MYTABLE "\n");
88 goto bail;
89 }
90 if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
91 snmp_log(LOG_ERR,"error injecting container_table handler for "
92 MYTABLE "\n");
93 goto bail;
94 }
95 handler = NULL; /* reg has it, will reuse below */
96
97 /*************************************************
98 *
99 * inject cache helper
100 */
101
102 handler = netsnmp_cache_handler_get(netsnmp_swrun_cache());
103 if (NULL == handler) {
104 snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n");
105 goto bail;
106 }
107
108 if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
109 snmp_log(LOG_ERR,"error injecting cache handler for "
110 MYTABLE "\n");
111 goto bail;
112 }
113 handler = NULL; /* reg has it*/
114
115 if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
116 snmp_log(LOG_ERR,"error registering table handler for "
117 MYTABLE "\n");
118 reg = NULL; /* it was freed inside netsnmp_register_table */
119 goto bail;
120 }
121
122 return; /* ok */
123
124
125 bail: /* not ok */
126
127 if (handler)
128 netsnmp_handler_free(handler);
129
130 if (table_info)
131 netsnmp_table_registration_info_free(table_info);
132
133 if (reg)
134 netsnmp_handler_registration_free(reg);
135 }
136
137 void
shutdown_table_hrSWRunPerfTable(void)138 shutdown_table_hrSWRunPerfTable(void)
139 {
140 if (table_info) {
141 netsnmp_table_registration_info_free(table_info);
142 table_info = NULL;
143 }
144 }
145
146 /** handles requests for the hrSWRunPerfTable table */
147 int
hrSWRunPerfTable_handler(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * reqinfo,netsnmp_request_info * requests)148 hrSWRunPerfTable_handler(netsnmp_mib_handler *handler,
149 netsnmp_handler_registration *reginfo,
150 netsnmp_agent_request_info *reqinfo,
151 netsnmp_request_info *requests)
152 {
153
154 netsnmp_request_info *request;
155 netsnmp_table_request_info *table_info;
156 netsnmp_swrun_entry *table_entry;
157
158 switch (reqinfo->mode) {
159 /*
160 * Read-support (also covers GetNext requests)
161 */
162 case MODE_GET:
163 for (request = requests; request; request = request->next) {
164 if (request->processed)
165 continue;
166 table_entry = (netsnmp_swrun_entry *)
167 netsnmp_container_table_extract_context(request);
168 table_info = netsnmp_extract_table_info(request);
169 if ((NULL == table_entry) || (NULL == table_info)) {
170 snmp_log(LOG_ERR, "could not extract table entry or info for "
171 MYTABLE "\n");
172 snmp_set_var_typed_value(request->requestvb,
173 SNMP_ERR_GENERR, NULL, 0);
174 continue;
175 }
176
177 switch (table_info->colnum) {
178 case COLUMN_HRSWRUNPERFCPU:
179 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
180 table_entry->hrSWRunPerfCPU);
181 break;
182 case COLUMN_HRSWRUNPERFMEM:
183 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
184 table_entry->hrSWRunPerfMem);
185 break;
186 default:
187 /*
188 * An unsupported/unreadable column (if applicable)
189 */
190 snmp_set_var_typed_value(request->requestvb,
191 SNMP_NOSUCHOBJECT, NULL, 0);
192 }
193 }
194 break;
195
196 }
197 return SNMP_ERR_NOERROR;
198 }
199