~ubuntu-branches/debian/lenny/net-snmp/lenny

« back to all changes in this revision

Viewing changes to agent/mibgroup/disman/event/mteTriggerThresholdTable.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-10 22:20:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070510222023-3fr07xb9i17xvq32
Tags: upstream-5.3.1
ImportĀ upstreamĀ versionĀ 5.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DisMan Event MIB:
 
3
 *     Implementation of the mteTriggerThresholdTable MIB interface
 
4
 * See 'mteTrigger.c' for active behaviour of this table.
 
5
 *
 
6
 * (based on mib2c.table_data.conf output)
 
7
 */
 
8
 
 
9
#include <net-snmp/net-snmp-config.h>
 
10
#include <net-snmp/net-snmp-includes.h>
 
11
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
12
#include "disman/event/mteTrigger.h"
 
13
#include "disman/event/mteTriggerThresholdTable.h"
 
14
 
 
15
 
 
16
/** Initializes the mteTriggerThresholdTable module */
 
17
void
 
18
init_mteTriggerThresholdTable(void)
 
19
{
 
20
    static oid mteTThreshTable_oid[]   = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 6 };
 
21
    size_t     mteTThreshTable_oid_len = OID_LENGTH(mteTThreshTable_oid);
 
22
    netsnmp_handler_registration    *reg;
 
23
    netsnmp_table_registration_info *table_info;
 
24
 
 
25
    /*
 
26
     * Ensure the (combined) table container is available...
 
27
     */
 
28
    init_trigger_table_data();
 
29
 
 
30
    /*
 
31
     * ... then set up the MIB interface to the mteTriggerThresholdTable slice
 
32
     */
 
33
    reg = netsnmp_create_handler_registration("mteTriggerThresholdTable",
 
34
                                            mteTriggerThresholdTable_handler,
 
35
                                            mteTThreshTable_oid,
 
36
                                            mteTThreshTable_oid_len,
 
37
                                            HANDLER_CAN_RWRITE);
 
38
 
 
39
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
 
40
    netsnmp_table_helper_add_indexes(table_info,
 
41
                                     ASN_OCTET_STR, /* index: mteOwner       */
 
42
                                                    /* index: mteTriggerName */
 
43
                                     ASN_PRIV_IMPLIED_OCTET_STR,
 
44
                                     0);
 
45
 
 
46
    table_info->min_column = COLUMN_MTETRIGGERTHRESHOLDSTARTUP;
 
47
    table_info->max_column = COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT;
 
48
 
 
49
    /* Register this using the (common) trigger_table_data container */
 
50
    netsnmp_tdata_register(reg, trigger_table_data, table_info);
 
51
    DEBUGMSGTL(("disman:event:init", "Trigger Threshold Table\n"));
 
52
}
 
53
 
 
54
 
 
55
/** handles requests for the mteTriggerThresholdTable table */
 
56
int
 
57
mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
 
58
                                 netsnmp_handler_registration *reginfo,
 
59
                                 netsnmp_agent_request_info *reqinfo,
 
60
                                 netsnmp_request_info *requests)
 
61
{
 
62
 
 
63
    netsnmp_request_info       *request;
 
64
    netsnmp_table_request_info *tinfo;
 
65
    struct mteTrigger          *entry;
 
66
    int ret;
 
67
 
 
68
    DEBUGMSGTL(("disman:event:mib", "Threshold Table handler (%d)\n",
 
69
                                     reqinfo->mode));
 
70
 
 
71
    switch (reqinfo->mode) {
 
72
        /*
 
73
         * Read-support (also covers GetNext requests)
 
74
         */
 
75
    case MODE_GET:
 
76
        for (request = requests; request; request = request->next) {
 
77
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
78
            tinfo = netsnmp_extract_table_info(request);
 
79
 
 
80
            /*
 
81
             * The mteTriggerThresholdTable should only contains entries for
 
82
             *   rows where the mteTriggerTest 'threshold(2)' bit is set.
 
83
             * So skip entries where this isn't the case.
 
84
             */
 
85
            if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD ))
 
86
                continue;
 
87
 
 
88
            switch (tinfo->colnum) {
 
89
            case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
 
90
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
91
                                           entry->mteTThStartup);
 
92
                break;
 
93
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
 
94
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
95
                                           entry->mteTThRiseValue);
 
96
                break;
 
97
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
 
98
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
99
                                           entry->mteTThFallValue);
 
100
                break;
 
101
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
 
102
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
103
                                           entry->mteTThDRiseValue);
 
104
                break;
 
105
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
 
106
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
107
                                           entry->mteTThDFallValue);
 
108
                break;
 
109
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
 
110
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
111
                              (u_char *) entry->mteTThObjOwner,
 
112
                                  strlen(entry->mteTThObjOwner));
 
113
                break;
 
114
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
 
115
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
116
                              (u_char *) entry->mteTThObjects,
 
117
                                  strlen(entry->mteTThObjects));
 
118
                break;
 
119
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
 
120
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
121
                              (u_char *) entry->mteTThRiseOwner,
 
122
                                  strlen(entry->mteTThRiseOwner));
 
123
                break;
 
124
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
 
125
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
126
                              (u_char *) entry->mteTThRiseEvent,
 
127
                                  strlen(entry->mteTThRiseEvent));
 
128
                break;
 
129
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
 
130
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
131
                              (u_char *) entry->mteTThFallOwner,
 
132
                                  strlen(entry->mteTThFallOwner));
 
133
                break;
 
134
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
 
135
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
136
                              (u_char *) entry->mteTThFallEvent,
 
137
                                  strlen(entry->mteTThFallEvent));
 
138
                break;
 
139
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
 
140
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
141
                              (u_char *) entry->mteTThDRiseOwner,
 
142
                                  strlen(entry->mteTThDRiseOwner));
 
143
                break;
 
144
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
 
145
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
146
                              (u_char *) entry->mteTThDRiseEvent,
 
147
                                  strlen(entry->mteTThDRiseEvent));
 
148
                break;
 
149
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
 
150
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
151
                              (u_char *) entry->mteTThDFallOwner,
 
152
                                  strlen(entry->mteTThDFallOwner));
 
153
                break;
 
154
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
 
155
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
 
156
                              (u_char *) entry->mteTThDFallEvent,
 
157
                                  strlen(entry->mteTThDFallEvent));
 
158
                break;
 
159
            }
 
160
        }
 
161
        break;
 
162
 
 
163
        /*
 
164
         * Write-support
 
165
         */
 
166
    case MODE_SET_RESERVE1:
 
167
        for (request = requests; request; request = request->next) {
 
168
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
169
            tinfo = netsnmp_extract_table_info(request);
 
170
 
 
171
            /*
 
172
             * Since the mteTriggerThresholdTable only contains entries for
 
173
             *   rows where the mteTriggerTest 'threshold(2)' bit is set,
 
174
             *   strictly speaking we should reject assignments where
 
175
             *   this isn't the case.
 
176
             * But SET requests that include an assignment of the
 
177
             *   'threshold(2)' bit at the same time are valid, so would
 
178
             *    need to be accepted. Unfortunately, this assignment
 
179
             *   is only applied in the COMMIT pass, so it's difficult
 
180
             *   to detect whether this holds or not.
 
181
             *
 
182
             * Let's fudge things for now, by processing assignments
 
183
             *   even if the 'threshold(2)' bit isn't set.
 
184
             */
 
185
            switch (tinfo->colnum) {
 
186
            case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
 
187
                ret = netsnmp_check_vb_int_range(request->requestvb,
 
188
                                                 MTE_THRESH_START_RISE,
 
189
                                                 MTE_THRESH_START_RISEFALL );
 
190
                if (ret != SNMP_ERR_NOERROR) {
 
191
                    netsnmp_set_request_error(reqinfo, request, ret);
 
192
                    return SNMP_ERR_NOERROR;
 
193
                }
 
194
                break;
 
195
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
 
196
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
 
197
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
 
198
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
 
199
                ret = netsnmp_check_vb_int(request->requestvb);
 
200
                if (ret != SNMP_ERR_NOERROR) {
 
201
                    netsnmp_set_request_error(reqinfo, request, ret);
 
202
                    return SNMP_ERR_NOERROR;
 
203
                }
 
204
                break;
 
205
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
 
206
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
 
207
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
 
208
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
 
209
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
 
210
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
 
211
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
 
212
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
 
213
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
 
214
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
 
215
                ret = netsnmp_check_vb_type_and_max_size(
 
216
                          request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
 
217
                if (ret != SNMP_ERR_NOERROR) {
 
218
                    netsnmp_set_request_error(reqinfo, request, ret);
 
219
                    return SNMP_ERR_NOERROR;
 
220
                }
 
221
                break;
 
222
            default:
 
223
                netsnmp_set_request_error(reqinfo, request,
 
224
                                          SNMP_ERR_NOTWRITABLE);
 
225
                return SNMP_ERR_NOERROR;
 
226
            }
 
227
 
 
228
            /*
 
229
             * The Event MIB is somewhat ambiguous as to whether the
 
230
             *  various trigger table entries can be modified once the
 
231
             *  main mteTriggerTable entry has been marked 'active'. 
 
232
             * But it's clear from discussion on the DisMan mailing
 
233
             *  list is that the intention is not.
 
234
             *
 
235
             * So check for whether this row is already active,
 
236
             *  and reject *all* SET requests if it is.
 
237
             */
 
238
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
239
            if (entry &&
 
240
                entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
 
241
                netsnmp_set_request_error(reqinfo, request,
 
242
                                          SNMP_ERR_INCONSISTENTVALUE);
 
243
                return SNMP_ERR_NOERROR;
 
244
            }
 
245
        }
 
246
        break;
 
247
 
 
248
    case MODE_SET_RESERVE2:
 
249
    case MODE_SET_FREE:
 
250
    case MODE_SET_UNDO:
 
251
        break;
 
252
 
 
253
    case MODE_SET_ACTION:
 
254
        for (request = requests; request; request = request->next) {
 
255
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
256
            if (!entry) {
 
257
                /*
 
258
                 * New rows must be created via the RowStatus column
 
259
                 *   (in the main mteTriggerTable)
 
260
                 */
 
261
                netsnmp_set_request_error(reqinfo, request,
 
262
                                          SNMP_ERR_NOCREATION);
 
263
                                      /* or inconsistentName? */
 
264
                return SNMP_ERR_NOERROR;
 
265
            }
 
266
        }
 
267
        break;
 
268
 
 
269
    case MODE_SET_COMMIT:
 
270
        /*
 
271
         * All these assignments are "unfailable", so it's
 
272
         *  (reasonably) safe to apply them in the Commit phase
 
273
         */
 
274
        for (request = requests; request; request = request->next) {
 
275
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
276
            tinfo = netsnmp_extract_table_info(request);
 
277
 
 
278
            switch (tinfo->colnum) {
 
279
            case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
 
280
                entry->mteTThStartup    = *request->requestvb->val.integer;
 
281
                break;
 
282
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
 
283
                entry->mteTThRiseValue  = *request->requestvb->val.integer;
 
284
                break;
 
285
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
 
286
                entry->mteTThFallValue  = *request->requestvb->val.integer;
 
287
                break;
 
288
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
 
289
                entry->mteTThDRiseValue = *request->requestvb->val.integer;
 
290
                break;
 
291
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
 
292
                entry->mteTThDFallValue = *request->requestvb->val.integer;
 
293
                break;
 
294
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
 
295
                memset(entry->mteTThObjOwner, 0, sizeof(entry->mteTThObjOwner));
 
296
                memcpy(entry->mteTThObjOwner, request->requestvb->val.string,
 
297
                                              request->requestvb->val_len);
 
298
                break;
 
299
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
 
300
                memset(entry->mteTThObjects,  0, sizeof(entry->mteTThObjects));
 
301
                memcpy(entry->mteTThObjects,  request->requestvb->val.string,
 
302
                                              request->requestvb->val_len);
 
303
                break;
 
304
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
 
305
                memset(entry->mteTThRiseOwner, 0, sizeof(entry->mteTThRiseOwner));
 
306
                memcpy(entry->mteTThRiseOwner, request->requestvb->val.string,
 
307
                                               request->requestvb->val_len);
 
308
                break;
 
309
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
 
310
                memset(entry->mteTThRiseEvent, 0, sizeof(entry->mteTThRiseEvent));
 
311
                memcpy(entry->mteTThRiseEvent, request->requestvb->val.string,
 
312
                                               request->requestvb->val_len);
 
313
                break;
 
314
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
 
315
                memset(entry->mteTThFallOwner, 0, sizeof(entry->mteTThFallOwner));
 
316
                memcpy(entry->mteTThFallOwner, request->requestvb->val.string,
 
317
                                               request->requestvb->val_len);
 
318
                break;
 
319
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
 
320
                memset(entry->mteTThFallEvent, 0, sizeof(entry->mteTThFallEvent));
 
321
                memcpy(entry->mteTThFallEvent, request->requestvb->val.string,
 
322
                                               request->requestvb->val_len);
 
323
                break;
 
324
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
 
325
                memset(entry->mteTThDRiseOwner, 0, sizeof(entry->mteTThDRiseOwner));
 
326
                memcpy(entry->mteTThDRiseOwner, request->requestvb->val.string,
 
327
                                                request->requestvb->val_len);
 
328
                break;
 
329
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
 
330
                memset(entry->mteTThDRiseEvent, 0, sizeof(entry->mteTThDRiseEvent));
 
331
                memcpy(entry->mteTThDRiseEvent, request->requestvb->val.string,
 
332
                                                request->requestvb->val_len);
 
333
                break;
 
334
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
 
335
                memset(entry->mteTThDFallOwner, 0, sizeof(entry->mteTThDFallOwner));
 
336
                memcpy(entry->mteTThDFallOwner, request->requestvb->val.string,
 
337
                                                request->requestvb->val_len);
 
338
                break;
 
339
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
 
340
                memset(entry->mteTThDFallEvent, 0, sizeof(entry->mteTThDFallEvent));
 
341
                memcpy(entry->mteTThDFallEvent, request->requestvb->val.string,
 
342
                                                request->requestvb->val_len);
 
343
                break;
 
344
            }
 
345
        }
 
346
        break;
 
347
    }
 
348
    return SNMP_ERR_NOERROR;
 
349
}