Debian Codegraph @

agent/mibgroup/disman/event/mteTriggerConf.c

raw
1 /*
2 * DisMan Event MIB:
3 * Implementation of the trigger table configure handling
4 */
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-features.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10 #include <net-snmp/agent/agent_callbacks.h>
11 #include "utilities/iquery.h"
12 #include "disman/event/mteObjects.h"
13 #include "disman/event/mteTrigger.h"
14 #include "disman/event/mteTriggerConf.h"
15
16 #include <ctype.h>
17
18 netsnmp_feature_require(iquery);
19
20 /** Initializes the mteTriggerConf module */
21 void
22 init_mteTriggerConf(void)
23 {
24 init_trigger_table_data();
25
26 /*
27 * Register config handler for user-level (fixed) triggers ...
28 */
29 snmpd_register_const_config_handler("monitor",
30 parse_mteMonitor,
31 NULL,
32 "triggername [-I] [-i OID | -o OID]* [-e event] expression ");
33 snmpd_register_const_config_handler("defaultMonitors",
34 parse_default_mteMonitors,
35 NULL, "yes|no");
36 snmpd_register_const_config_handler("linkUpDownNotifications",
37 parse_linkUpDown_traps,
38 NULL, "yes|no");
39
40 /*
41 * ... for persistent storage of various event table entries ...
42 */
43 snmpd_register_config_handler("_mteTTable",
44 parse_mteTTable, NULL, NULL);
45 snmpd_register_config_handler("_mteTDTable",
46 parse_mteTDTable, NULL, NULL);
47 snmpd_register_config_handler("_mteTExTable",
48 parse_mteTExTable, NULL, NULL);
49 snmpd_register_config_handler("_mteTBlTable",
50 parse_mteTBlTable, NULL, NULL);
51 snmpd_register_config_handler("_mteTThTable",
52 parse_mteTThTable, NULL, NULL);
53
54 /*
55 * ... and backwards compatability with the previous implementation.
56 */
57 snmpd_register_config_handler("mteTriggerTable",
58 parse_mteTriggerTable, NULL, NULL);
59
60 /*
61 * Register to save (non-fixed) entries when the agent shuts down
62 */
63 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
64 store_mteTTable, NULL);
65 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
66 SNMPD_CALLBACK_PRE_UPDATE_CONFIG,
67 clear_mteTTable, NULL);
68 }
69
70 /* ==============================
71 *
72 * utility routines
73 *
74 * ============================== */
75
76 /*
77 * Find or create the specified trigger entry
78 */
79 struct mteTrigger *
80 _find_mteTrigger_entry( const char *owner, char *tname )
81 {
82 netsnmp_variable_list owner_var, tname_var;
83 netsnmp_tdata_row *row;
84
85 /*
86 * If there's already an existing entry,
87 * then use that...
88 */
89 memset(&owner_var, 0, sizeof(netsnmp_variable_list));
90 memset(&tname_var, 0, sizeof(netsnmp_variable_list));
91 snmp_set_var_typed_value(&owner_var, ASN_OCTET_STR, owner, strlen(owner));
92 snmp_set_var_typed_value(&tname_var, ASN_PRIV_IMPLIED_OCTET_STR,
93 tname, strlen(tname));
94 owner_var.next_variable = &tname_var;
95 row = netsnmp_tdata_row_get_byidx( trigger_table_data, &owner_var );
96 /*
97 * ... otherwise, create a new one
98 */
99 if (!row)
100 row = mteTrigger_createEntry( owner, tname, 0 );
101 if (!row)
102 return NULL;
103
104 /* return (struct mteTrigger *)netsnmp_tdata_row_entry( row ); */
105 return (struct mteTrigger *)row->data;
106 }
107
108 struct mteTrigger *
109 _find_typed_mteTrigger_entry( const char *owner, char *tname, int type )
110 {
111 struct mteTrigger *entry = _find_mteTrigger_entry( owner, tname );
112 if (!entry)
113 return NULL;
114
115 /*
116 * If this is an existing (i.e. valid) entry of the
117 * same type, then throw an error and discard it.
118 * But allow combined Existence/Boolean/Threshold trigger.
119 */
120 if ( entry &&
121 (entry->flags & MTE_TRIGGER_FLAG_VALID) &&
122 (entry->mteTriggerTest & type )) {
123 config_perror("duplicate trigger name");
124 return NULL;
125 }
126 return entry;
127 }
128
129
130 /* ================================================
131 *
132 * Handlers for user-configured (static) triggers
133 *
134 * ================================================ */
135
136 int
137 _mteTrigger_callback_enable( int majorID, int minorID,
138 void *serverargs, void *clientarg)
139 {
140 struct mteTrigger *entry = (struct mteTrigger *)clientarg;
141 mteTrigger_enable( entry );
142
143 return 0;
144 }
145
146
147 void
148 parse_mteMonitor(const char *token, const char *line)
149 {
150 char buf[ SPRINT_MAX_LEN];
151 char tname[MTE_STR1_LEN+1];
152 const char *cp;
153 long test = 0;
154
155 char ename[MTE_STR1_LEN+1];
156 long flags = MTE_TRIGGER_FLAG_ENABLED |
157 MTE_TRIGGER_FLAG_ACTIVE |
158 MTE_TRIGGER_FLAG_FIXED |
159 MTE_TRIGGER_FLAG_VWILD |
160 MTE_TRIGGER_FLAG_SYSUPT |
161 MTE_TRIGGER_FLAG_VALID;
162 long idx = 0;
163 long startup = 1; /* ??? or 0 */
164 long repeat = 600;
165 netsnmp_session *sess = NULL;
166
167 int seen_name = 0;
168 char oid_name_buf[SPRINT_MAX_LEN];
169 oid name_buf[MAX_OID_LEN];
170 size_t name_buf_len = 0;
171 u_char op = 0;
172 long value = 0;
173
174 struct mteObject *object;
175 struct mteTrigger *entry;
176
177 DEBUGMSGTL(("disman:event:conf", "Parsing disman monitor config (%s)\n", line));
178
179 /*
180 * Before parsing the configuration fully, first
181 * skim through the config line in order to:
182 * a) locate the name for the trigger, and
183 * b) identify the type of trigger test
184 *
185 * This information will be used both for creating the trigger
186 * entry, and registering any additional payload objects.
187 */
188 memset( buf, 0, sizeof(buf));
189 memset( tname, 0, sizeof(tname));
190 memset( ename, 0, sizeof(ename));
191 memset(name_buf, 0, sizeof(name_buf));
192 for (cp = copy_nword_const(line, buf, SPRINT_MAX_LEN);
193 ;
194 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN)) {
195
196 if ( buf[0] == '-' ) {
197 switch (buf[1]) {
198 case 't':
199 /* No longer necessary */
200 break;
201 case 'd':
202 case 'e':
203 case 'o':
204 case 'r':
205 case 'u':
206 /* skip option parameter */
207 cp = skip_token_const( cp );
208 break;
209 case 'D':
210 case 'I':
211 case 's':
212 case 'S':
213 /* flag options */
214 break;
215 case 'i':
216 /*
217 * '-i' can act as a flag or take a parameter.
218 * Handle either case.
219 */
220 if (cp && *cp != '-')
221 cp = skip_token_const( cp );
222 break;
223 case '0':
224 case '1':
225 case '2':
226 case '3':
227 case '4':
228 case '5':
229 case '6':
230 case '7':
231 case '8':
232 case '9':
233 /* accept negative values */
234 case '\0':
235 /* and '-' placeholder value */
236 break;
237 default:
238 config_perror("unrecognised option");
239 return;
240 }
241 } else {
242 /*
243 * Save the first non-option parameter as the trigger name.
244 *
245 * This name will also be used to register entries in the
246 * mteObjectsTable, so insert a distinguishing prefix.
247 * This will ensure combined trigger entries don't clash with
248 * each other, or with a similarly-named notification event.
249 */
250 if ( !tname[0] ) {
251 tname[0] = '_';
252 tname[1] = '_'; /* Placeholder */
253 memcpy( tname+2, buf, MTE_STR1_LEN-2 );
254 } else {
255 /*
256 * This marks the beginning of the monitor expression,
257 * so we don't need to scan any further
258 */
259 break;
260 }
261 }
262 if (!cp)
263 break;
264 }
265
266 /*
267 * Now let's examine the expression to determine the type of
268 * monitor being configured. There are four possible forms:
269 * != OID (or ! OID) (existence test)
270 * OID (existence test)
271 * OID op VALUE (boolean test)
272 * OID MIN MAX (threshold test)
273 */
274 if ( *buf == '!' ) {
275 /*
276 * If the expression starts with '!=' or '!', then
277 * it must be the first style of existence test.
278 */
279 test = MTE_TRIGGER_EXISTENCE;
280 } else {
281 /*
282 * Otherwise the first token is the OID to be monitored.
283 * Skip it and look at the next token (if any).
284 */
285 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
286 if (cp) {
287 /*
288 * If this is a numeric value, then it'll be the MIN
289 * field of a threshold test (the fourth form)
290 * Otherwise it'll be the operation field of a
291 * boolean test (the third form)
292 */
293 if ( isdigit((unsigned char)(buf[0])) || buf[0] == '-' )
294 test = MTE_TRIGGER_THRESHOLD;
295 else
296 test = MTE_TRIGGER_BOOLEAN;
297 } else {
298 /*
299 * If there isn't a "next token", then this
300 * must be the second style of existence test.
301 */
302 test = MTE_TRIGGER_EXISTENCE;
303 }
304 }
305
306 /*
307 * Use the type of trigger test to update the trigger name buffer
308 */
309 switch (test) {
310 case MTE_TRIGGER_BOOLEAN:
311 tname[1] = 'B'; break;
312 case MTE_TRIGGER_THRESHOLD:
313 tname[1] = 'T'; break;
314 case MTE_TRIGGER_EXISTENCE:
315 tname[1] = 'X'; break;
316 }
317
318
319
320 /*
321 * Now start parsing again at the beginning of the directive,
322 * extracting the various options...
323 */
324 for (cp = copy_nword_const(line, buf, SPRINT_MAX_LEN);
325 ;
326 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN)) {
327
328 if (buf[0] == '-' ) {
329 switch (buf[1]) {
330 case 'D': /* delta sample value */
331 flags |= MTE_TRIGGER_FLAG_DELTA;
332 break;
333
334 case 'd': /* discontinuity OID (implies delta sample) */
335 flags |= MTE_TRIGGER_FLAG_DELTA;
336 if (buf[2] != 'i')
337 flags |= MTE_TRIGGER_FLAG_DWILD;
338 memset( oid_name_buf, 0, sizeof(oid_name_buf));
339 memset( name_buf, 0, sizeof( name_buf));
340 name_buf_len = MAX_OID_LEN;
341 cp = copy_nword_const(cp, oid_name_buf, MTE_STR1_LEN);
342 if (!snmp_parse_oid(oid_name_buf, name_buf, &name_buf_len)) {
343 snmp_log(LOG_ERR, "discontinuity OID: %s\n", oid_name_buf);
344 config_perror("unknown discontinuity OID");
345 mteObjects_removeEntries( "snmpd.conf", tname );
346 return;
347 }
348 if ( snmp_oid_compare( name_buf, name_buf_len,
349 _sysUpTime_instance,
350 _sysUpTime_inst_len) != 0 )
351 flags &= ~MTE_TRIGGER_FLAG_SYSUPT;
352 break;
353
354 case 'e': /* event */
355 cp = copy_nword_const(cp, ename, MTE_STR1_LEN);
356 break;
357
358 case 'I': /* value instance */
359 flags &= ~MTE_TRIGGER_FLAG_VWILD;
360 break;
361
362 /*
363 * "instance" flag:
364 * either non-wildcarded mteTriggerValueID
365 * (backwards compatability - see '-I')
366 * or exact payload OID
367 * (c.f. notificationEvent config)
368 */
369 case 'i':
370 if ( *cp == '-' ) {
371 /* Backwards compatibility - now '-I' */
372 flags &= ~MTE_TRIGGER_FLAG_VWILD;
373 continue;
374 }
375 idx++;
376 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
377 object = mteObjects_addOID( "snmpd.conf", tname, idx, buf, 0 );
378 if (!object) {
379 snmp_log(LOG_ERR, "Unknown payload OID: %s\n", buf);
380 config_perror("Unknown payload OID");
381 mteObjects_removeEntries( "snmpd.conf", tname );
382 } else
383 idx = object->mteOIndex;
384 break;
385
386 case 'o': /* object */
387 idx++;
388 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
389 object = mteObjects_addOID( "snmpd.conf", tname, idx, buf, 1 );
390 if (!object) {
391 snmp_log(LOG_ERR, "Unknown payload OID: %s\n", buf);
392 config_perror("Unknown payload OID");
393 mteObjects_removeEntries( "snmpd.conf", tname );
394 } else
395 idx = object->mteOIndex;
396 break;
397
398 case 'r': /* repeat frequency */
399 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
400 repeat = strtoul(buf, NULL, 0);
401 break;
402
403 case 'S': /* disable startup tests */
404 startup = 0;
405 break;
406
407 case 's': /* enable startup tests (default?) */
408 startup = 1;
409 break;
410
411 case 't': /* threshold test - already handled */
412 break;
413
414 case 'u': /* user */
415 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
416 sess = netsnmp_iquery_user_session(buf);
417 if (NULL == sess) {
418 snmp_log(LOG_ERR, "user name %s not found\n", buf);
419 config_perror("Unknown user name\n");
420 mteObjects_removeEntries( "snmpd.conf", tname );
421 return;
422 }
423 break;
424 }
425 } else {
426 /*
427 * Skip the first non-option token - the trigger
428 * name (which has already been processed earlier).
429 */
430 if ( !seen_name ) {
431 seen_name = 1;
432 } else {
433 /*
434 * But the next non-option token encountered will
435 * mark the start of the expression to be monitored.
436 *
437 * There are three possible expression formats:
438 * [op] OID (existence tests)
439 * OID op value (boolean tests)
440 * OID val val [val val] (threshold tests)
441 *
442 * Extract the OID, operation and (first) value.
443 */
444 switch ( test ) {
445 case MTE_TRIGGER_EXISTENCE:
446 /*
447 * Identify the existence operator (if any)...
448 */
449 op = MTE_EXIST_PRESENT;
450 if (buf[0] == '!') {
451 if (buf[1] == '=') {
452 op = MTE_EXIST_CHANGED;
453 } else {
454 op = MTE_EXIST_ABSENT;
455 }
456 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
457 }
458 /*
459 * ... then extract the monitored OID.
460 * (ignoring anything that remains)
461 */
462 memcpy(oid_name_buf, buf, SPRINT_MAX_LEN);
463 cp = NULL; /* To terminate the processing loop */
464 DEBUGMSGTL(("disman:event:conf", "%s: Exist (%s, %d)\n",
465 tname, oid_name_buf, op));
466 break;
467
468 case MTE_TRIGGER_BOOLEAN:
469 /*
470 * Extract the monitored OID, and
471 * identify the boolean operator ...
472 */
473 memcpy(oid_name_buf, buf, SPRINT_MAX_LEN);
474 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
475 if (buf[0] == '!') {
476 op = MTE_BOOL_UNEQUAL;
477 } else if (buf[0] == '=') {
478 op = MTE_BOOL_EQUAL;
479 } else if (buf[0] == '<') {
480 if (buf[1] == '=') {
481 op = MTE_BOOL_LESSEQUAL;
482 } else {
483 op = MTE_BOOL_LESS;
484 }
485 } else if (buf[0] == '>') {
486 if (buf[1] == '=') {
487 op = MTE_BOOL_GREATEREQUAL;
488 } else {
489 op = MTE_BOOL_GREATER;
490 }
491 }
492 /*
493 * ... then extract the comparison value.
494 * (ignoring anything that remains)
495 */
496 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
497 value = strtol(buf, NULL, 0);
498 cp = NULL; /* To terminate the processing loop */
499 DEBUGMSGTL(("disman:event:conf", "%s: Bool (%s, %d, %ld)\n",
500 tname, oid_name_buf, op, value));
501 break;
502
503 case MTE_TRIGGER_THRESHOLD:
504 /*
505 * Extract the monitored OID, and
506 * the first comparison value...
507 */
508 memcpy(oid_name_buf, buf, SPRINT_MAX_LEN);
509 memset( buf, 0, SPRINT_MAX_LEN);
510 cp = copy_nword_const(cp, buf, SPRINT_MAX_LEN);
511 value = strtol(buf, NULL, 0);
512
513 /*
514 * ... then save the rest of the line for later.
515 */
516 strlcpy(buf, cp, sizeof(buf));
517 cp = NULL; /* To terminate the processing loop */
518 DEBUGMSGTL(("disman:event:conf", "%s: Thresh (%s, %ld, %s)\n",
519 tname, oid_name_buf, value, buf));
520 break;
521 }
522 }
523 }
524 if (!cp)
525 break;
526 }
527
528 if (NULL == sess) {
529 sess = netsnmp_query_get_default_session();
530 if (NULL == sess) {
531 config_perror
532 ("You must specify a default user name using the agentSecName token\n");
533 mteObjects_removeEntries( "snmpd.conf", tname );
534 return;
535 }
536 }
537
538 /*
539 * ... and then create the new trigger entry...
540 */
541 entry = _find_typed_mteTrigger_entry( "snmpd.conf", tname+2, test );
542 if (!entry) {
543 /* mteObjects_removeEntries( "snmpd.conf", tname ); */
544 return;
545 }
546
547 /*
548 * ... populate the type-independent fields...
549 * (setting the delta discontinuity OID first)
550 */
551 if ( (flags & MTE_TRIGGER_FLAG_DELTA) &&
552 !(flags & MTE_TRIGGER_FLAG_SYSUPT)) {
553 memset( entry->mteDeltaDiscontID, 0, sizeof(entry->mteDeltaDiscontID));
554 memcpy( entry->mteDeltaDiscontID, name_buf, name_buf_len*sizeof(oid));
555 entry->mteDeltaDiscontID_len = name_buf_len;
556 }
557 name_buf_len = MAX_OID_LEN;
558 if (!snmp_parse_oid(oid_name_buf, name_buf, &name_buf_len)) {
559 snmp_log(LOG_ERR, "trigger OID: %s\n", oid_name_buf);
560 config_perror("unknown monitor OID");
561 mteObjects_removeEntries( "snmpd.conf", tname );
562 return;
563 }
564 entry->session = sess;
565 entry->flags |= flags;
566 entry->mteTriggerTest |= test;
567 entry->mteTriggerFrequency = repeat;
568 entry->mteTriggerValueID_len = name_buf_len;
569 memcpy(entry->mteTriggerValueID, name_buf, name_buf_len*sizeof(oid));
570
571 /*
572 * ... and the relevant test-specific fields.
573 */
574 switch (test) {
575 case MTE_TRIGGER_EXISTENCE:
576 entry->mteTExTest = op;
577 if (op != MTE_EXIST_CHANGED && startup)
578 entry->mteTExStartup = op;
579 if ( idx > 0 ) {
580 /*
581 * Refer to the objects for this trigger (if any)...
582 */
583 memset(entry->mteTExObjOwner, 0, MTE_STR1_LEN+1);
584 memcpy(entry->mteTExObjOwner, "snmpd.conf", 10);
585 memcpy(entry->mteTExObjects, tname, MTE_STR1_LEN+1);
586 }
587 if ( ename[0] ) {
588 /*
589 * ... and the specified event...
590 */
591 memset(entry->mteTExEvOwner, 0, MTE_STR1_LEN+1);
592 if ( ename[0] == '_' )
593 memcpy(entry->mteTExEvOwner, "_snmpd", 6);
594 else
595 memcpy(entry->mteTExEvOwner, "snmpd.conf", 10);
596 memcpy(entry->mteTExEvent, ename, MTE_STR1_LEN+1);
597 } else {
598 /*
599 * ... or the hardcoded default event.
600 */
601 memset(entry->mteTExEvOwner, 0, MTE_STR1_LEN+1);
602 memset(entry->mteTExEvent, 0, MTE_STR1_LEN+1);
603 memcpy(entry->mteTExEvOwner, "_snmpd", 6);
604 memcpy(entry->mteTExEvent, "_mteTriggerFired", 16);
605 }
606 break;
607 case MTE_TRIGGER_BOOLEAN:
608 entry->mteTBoolComparison = op;
609 entry->mteTBoolValue = value;
610 if (!startup)
611 entry->flags &= ~MTE_TRIGGER_FLAG_BSTART;
612 if ( idx > 0 ) {
613 /*
614 * Refer to the objects for this trigger (if any)...
615 */
616 memset(entry->mteTBoolObjOwner, 0, MTE_STR1_LEN+1);
617 memcpy(entry->mteTBoolObjOwner, "snmpd.conf", 10);
618 memcpy(entry->mteTBoolObjects, tname, MTE_STR1_LEN+1);
619 }
620 if ( ename[0] ) {
621 /*
622 * ... and the specified event...
623 */
624 memset(entry->mteTBoolEvOwner, 0, MTE_STR1_LEN+1);
625 if ( ename[0] == '_' )
626 memcpy(entry->mteTBoolEvOwner, "_snmpd", 6);
627 else
628 memcpy(entry->mteTBoolEvOwner, "snmpd.conf", 10);
629 memcpy(entry->mteTBoolEvent, ename, MTE_STR1_LEN+1);
630 } else {
631 /*
632 * ... or the hardcoded default event.
633 */
634 memset(entry->mteTBoolEvOwner, 0, MTE_STR1_LEN+1);
635 memset(entry->mteTBoolEvent, 0, MTE_STR1_LEN+1);
636 memcpy(entry->mteTBoolEvOwner, "_snmpd", 6);
637 memcpy(entry->mteTBoolEvent, "_mteTriggerFired", 16);
638 }
639 break;
640 case MTE_TRIGGER_THRESHOLD:
641 entry->mteTThFallValue = value;
642 value = strtol(buf, NULL, 0);
643 entry->mteTThRiseValue = value;
644 if (!startup)
645 entry->mteTThStartup = 0;
646 if ( idx > 0 ) {
647 /*
648 * Refer to the objects for this trigger (if any)...
649 */
650 memset(entry->mteTThObjOwner, 0, MTE_STR1_LEN+1);
651 memcpy(entry->mteTThObjOwner, "snmpd.conf", 10);
652 memcpy(entry->mteTThObjects, tname, MTE_STR1_LEN+1);
653 }
654 if ( ename[0] ) {
655 /*
656 * ... and the specified event...
657 * (using the same event for all triggers)
658 */
659 memset(entry->mteTThRiseOwner, 0, MTE_STR1_LEN+1);
660 if ( ename[0] == '_' )
661 memcpy(entry->mteTThRiseOwner, "_snmpd", 6);
662 else
663 memcpy(entry->mteTThRiseOwner, "snmpd.conf", 10);
664 memcpy(entry->mteTThRiseEvent, ename, MTE_STR1_LEN+1);
665 memset(entry->mteTThFallOwner, 0, MTE_STR1_LEN+1);
666 if ( ename[0] == '_' )
667 memcpy(entry->mteTThFallOwner, "_snmpd", 6);
668 else
669 memcpy(entry->mteTThFallOwner, "snmpd.conf", 10);
670 memcpy(entry->mteTThFallEvent, ename, MTE_STR1_LEN+1);
671 } else {
672 /*
673 * ... or the hardcoded default events.
674 */
675 memset(entry->mteTThRiseOwner, 0, MTE_STR1_LEN+1);
676 memset(entry->mteTThFallOwner, 0, MTE_STR1_LEN+1);
677 memset(entry->mteTThRiseEvent, 0, MTE_STR1_LEN+1);
678 memset(entry->mteTThFallEvent, 0, MTE_STR1_LEN+1);
679 memcpy(entry->mteTThRiseOwner, "_snmpd", 6);
680 memcpy(entry->mteTThFallOwner, "_snmpd", 6);
681 memcpy(entry->mteTThRiseEvent, "_mteTriggerRising", 17);
682 memcpy(entry->mteTThFallEvent, "_mteTriggerFalling", 18);
683 }
684 cp = skip_token(buf); /* skip riseThreshold value */
685
686 /*
687 * Parse and set (optional) Delta thresholds & events
688 */
689 if ( cp && *cp != '\0' ) {
690 if (entry->flags & MTE_TRIGGER_FLAG_DELTA) {
691 config_perror("Delta-threshold on delta-samples not supported");
692 mteObjects_removeEntries( "snmpd.conf", tname );
693 return;
694 }
695 value = strtol(cp, NULL, 0);
696 entry->mteTThDFallValue = value;
697 cp = skip_token_const(cp);
698 value = strtol(cp, NULL, 0);
699 entry->mteTThDRiseValue = value;
700 /*
701 * Set the events in the same way as before
702 */
703 if ( ename[0] ) {
704 memset(entry->mteTThDRiseOwner, 0, MTE_STR1_LEN+1);
705 if ( ename[0] == '_' )
706 memcpy(entry->mteTThDRiseOwner, "_snmpd", 6);
707 else
708 memcpy(entry->mteTThDRiseOwner, "snmpd.conf", 10);
709 memcpy(entry->mteTThDRiseEvent, ename, MTE_STR1_LEN+1);
710 memset(entry->mteTThDFallOwner, 0, MTE_STR1_LEN+1);
711 if ( ename[0] == '_' )
712 memcpy(entry->mteTThDFallOwner, "_snmpd", 6);
713 else
714 memcpy(entry->mteTThDFallOwner, "snmpd.conf", 10);
715 memcpy(entry->mteTThDFallEvent, ename, MTE_STR1_LEN+1);
716 } else {
717 memset(entry->mteTThDRiseOwner, 0, MTE_STR1_LEN+1);
718 memset(entry->mteTThDFallOwner, 0, MTE_STR1_LEN+1);
719 memset(entry->mteTThDRiseEvent, 0, MTE_STR1_LEN+1);
720 memset(entry->mteTThDFallEvent, 0, MTE_STR1_LEN+1);
721 memcpy(entry->mteTThDRiseOwner, "_snmpd", 6);
722 memcpy(entry->mteTThDFallOwner, "_snmpd", 6);
723 memcpy(entry->mteTThDRiseEvent, "_mteTriggerRising", 17);
724 memcpy(entry->mteTThDFallEvent, "_mteTriggerFalling", 18);
725 }
726 }
727
728 break;
729 }
730 snmp_register_callback(SNMP_CALLBACK_LIBRARY,
731 SNMP_CALLBACK_POST_READ_CONFIG,
732 _mteTrigger_callback_enable, entry );
733 return;
734 }
735
736 void
737 parse_linkUpDown_traps(const char *token, const char *line)
738 {
739 /*
740 * XXX - This isn't strictly correct according to the
741 * definitions in IF-MIB, but will do for now.
742 */
743 if (strncmp( line, "yes", 3) == 0) {
744 DEBUGMSGTL(("disman:event:conf", "Registering linkUpDown traps\n"));
745
746 /* ifOperStatus */
747 parse_mteMonitor("monitor",
748 "-r 60 -S -e _linkUp \"linkUp\" .1.3.6.1.2.1.2.2.1.8 != 2");
749 parse_mteMonitor("monitor",
750 "-r 60 -S -e _linkDown \"linkDown\" .1.3.6.1.2.1.2.2.1.8 == 2");
751 }
752 }
753
754
755 void
756 parse_default_mteMonitors(const char *token, const char *line)
757 {
758 if (strncmp( line, "yes", 3) == 0) {
759 DEBUGMSGTL(("disman:event:conf", "Registering default monitors\n"));
760
761 parse_mteMonitor("monitor",
762 "-o prNames -o prErrMessage \"process table\" prErrorFlag != 0");
763 parse_mteMonitor("monitor",
764 "-o memErrorName -o memSwapErrorMsg \"memory\" memSwapError != 0");
765 parse_mteMonitor("monitor",
766 "-o extNames -o extOutput \"extTable\" extResult != 0");
767 parse_mteMonitor("monitor",
768 "-o dskPath -o dskErrorMsg \"dskTable\" dskErrorFlag != 0");
769 parse_mteMonitor("monitor",
770 "-o laNames -o laErrMessage \"laTable\" laErrorFlag != 0");
771 parse_mteMonitor("monitor",
772 "-o fileName -o fileErrorMsg \"fileTable\" fileErrorFlag != 0");
773 parse_mteMonitor("monitor",
774 "-o snmperrErrMessage \"snmperrs\" snmperrErrorFlag != 0");
775 }
776 return;
777 }
778
779 /* ================================================
780 *
781 * Handlers for loading persistent trigger entries
782 *
783 * ================================================ */
784
785
786
787 /*
788 * Entries for the main mteTriggerTable
789 */
790
791 char *
792 _parse_mteTCols( char *line, struct mteTrigger *entry, int bcomp )
793 {
794 void *vp;
795 size_t tmp;
796 size_t len;
797
798 len = MTE_STR2_LEN; vp = entry->mteTriggerComment;
799 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
800 if ( bcomp ) {
801 /*
802 * The newer style of config directive skips the
803 * mteTriggerTest and mteTriggerSampleType values,
804 * as these are set implicitly from the relevant
805 * config directives.
806 * Backwards compatability with the previous (combined)
807 * style reads these in explicitly.
808 */
809 len = 1;
810 vp = &entry->mteTriggerTest;
811 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
812 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
813 if (tmp == 2)
814 entry->flags |= MTE_TRIGGER_FLAG_DELTA;
815 }
816 vp = entry->mteTriggerValueID;
817 entry->mteTriggerValueID_len = MAX_OID_LEN;
818 line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
819 &entry->mteTriggerValueID_len);
820 if (bcomp) {
821 /*
822 * The newer style combines the various boolean values
823 * into a single field (which comes later).
824 * Backwards compatability means reading these individually.
825 */
826 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
827 if (tmp == TV_TRUE)
828 entry->flags |= MTE_TRIGGER_FLAG_VWILD;
829 }
830 len = MTE_STR2_LEN; vp = entry->mteTriggerTarget;
831 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
832 len = MTE_STR2_LEN; vp = entry->mteTriggerContext;
833 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
834 if (bcomp) {
835 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
836 if (tmp == TV_TRUE)
837 entry->flags |= MTE_TRIGGER_FLAG_CWILD;
838 }
839
840 line = read_config_read_data(ASN_UNSIGNED, line,
841 &entry->mteTriggerFrequency, NULL);
842
843 len = MTE_STR1_LEN; vp = entry->mteTriggerOOwner;
844 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
845 len = MTE_STR1_LEN; vp = entry->mteTriggerObjects;
846 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
847
848 /*
849 * Assorted boolean flag values, combined into a single field
850 */
851 if (bcomp) {
852 /*
853 * Backwards compatability stores the mteTriggerEnabled
854 * and mteTriggerEntryStatus values separately...
855 */
856 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
857 if (tmp == TV_TRUE)
858 entry->flags |= MTE_TRIGGER_FLAG_ENABLED;
859 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
860 if (tmp == RS_ACTIVE)
861 entry->flags |= MTE_TRIGGER_FLAG_ACTIVE;
862 } else {
863 /*
864 * ... while the newer style combines all the assorted
865 * boolean values into this single field.
866 */
867 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
868 entry->flags |= ( tmp &
869 (MTE_TRIGGER_FLAG_VWILD |MTE_TRIGGER_FLAG_CWILD|
870 MTE_TRIGGER_FLAG_ENABLED|MTE_TRIGGER_FLAG_ACTIVE));
871 }
872
873 return line;
874 }
875
876 void
877 parse_mteTTable(const char *token, char *line)
878 {
879 char owner[MTE_STR1_LEN+1];
880 char tname[MTE_STR1_LEN+1];
881 void *vp;
882 size_t len;
883 struct mteTrigger *entry;
884
885 DEBUGMSGTL(("disman:event:conf", "Parsing mteTriggerTable config...\n"));
886
887 /*
888 * Read in the index information for this entry
889 * and create a (non-fixed) data structure for it.
890 */
891 memset( owner, 0, sizeof(owner));
892 memset( tname, 0, sizeof(tname));
893 len = MTE_STR1_LEN; vp = owner;
894 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
895 len = MTE_STR1_LEN; vp = tname;
896 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
897 entry = _find_mteTrigger_entry( owner, tname );
898
899 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
900
901 /*
902 * Read in the accessible (trigger-independent) column values.
903 */
904 line = _parse_mteTCols( line, entry, 0 );
905 /*
906 * XXX - Will need to read in the 'iquery' access information
907 */
908 entry->flags |= MTE_TRIGGER_FLAG_VALID;
909
910 DEBUGMSG(("disman:event:conf", "\n"));
911 }
912
913
914 /*
915 * Entries from the mteTriggerDeltaTable
916 */
917
918 char *
919 _parse_mteTDCols( char *line, struct mteTrigger *entry, int bcomp )
920 {
921 void *vp;
922 size_t tmp;
923
924 entry->mteDeltaDiscontID_len = MAX_OID_LEN;
925 vp = entry->mteDeltaDiscontID;
926 line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
927 &entry->mteDeltaDiscontID_len);
928 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
929 if (bcomp) {
930 if ( tmp == TV_TRUE )
931 entry->flags |= MTE_TRIGGER_FLAG_DWILD;
932 } else {
933 if ( tmp & MTE_TRIGGER_FLAG_DWILD )
934 entry->flags |= MTE_TRIGGER_FLAG_DWILD;
935 }
936 line = read_config_read_data(ASN_UNSIGNED, line,
937 &entry->mteDeltaDiscontIDType, NULL);
938
939 return line;
940 }
941
942 void
943 parse_mteTDTable(const char *token, char *line)
944 {
945 char owner[MTE_STR1_LEN+1];
946 char tname[MTE_STR1_LEN+1];
947 void *vp;
948 size_t len;
949 struct mteTrigger *entry;
950
951 DEBUGMSGTL(("disman:event:conf", "Parsing mteTriggerDeltaTable config... "));
952
953 /*
954 * Read in the index information for this entry
955 * and create a (non-fixed) data structure for it.
956 */
957 memset( owner, 0, sizeof(owner));
958 memset( tname, 0, sizeof(tname));
959 len = MTE_STR1_LEN; vp = owner;
960 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
961 len = MTE_STR1_LEN; vp = tname;
962 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
963 entry = _find_mteTrigger_entry( owner, tname );
964
965 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
966
967 /*
968 * Read in the accessible column values.
969 */
970 line = _parse_mteTDCols( line, entry, 0 );
971
972 entry->flags |= (MTE_TRIGGER_FLAG_DELTA|
973 MTE_TRIGGER_FLAG_VALID);
974
975 DEBUGMSG(("disman:event:conf", "\n"));
976 }
977
978
979 /*
980 * Entries from the mteTriggerExistenceTable
981 */
982
983 char *
984 _parse_mteTExCols( char *line, struct mteTrigger *entry, int bcomp )
985 {
986 void *vp;
987 size_t tmp;
988 size_t len;
989
990 if (bcomp) {
991 len = 1;
992 vp = &entry->mteTExTest;
993 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
994 len = 1;
995 vp = &entry->mteTExStartup;
996 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
997 } else {
998 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
999 entry->mteTExStartup = ( tmp & 0xff ); tmp >>= 8;
1000 entry->mteTExTest = ( tmp & 0xff );
1001 }
1002
1003 len = MTE_STR1_LEN; vp = entry->mteTExObjOwner;
1004 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1005 len = MTE_STR1_LEN; vp = entry->mteTExObjects;
1006 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1007
1008 len = MTE_STR1_LEN; vp = entry->mteTExEvOwner;
1009 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1010 len = MTE_STR1_LEN; vp = entry->mteTExEvent;
1011 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1012
1013 return line;
1014 }
1015
1016 void
1017 parse_mteTExTable(const char *token, char *line)
1018 {
1019 char owner[MTE_STR1_LEN+1];
1020 char tname[MTE_STR1_LEN+1];
1021 void *vp;
1022 size_t len;
1023 struct mteTrigger *entry;
1024
1025 DEBUGMSGTL(("disman:event:conf", "Parsing mteTriggerExistenceTable config... "));
1026
1027 /*
1028 * Read in the index information for this entry
1029 * and create a (non-fixed) data structure for it.
1030 */
1031 memset( owner, 0, sizeof(owner));
1032 memset( tname, 0, sizeof(tname));
1033 len = MTE_STR1_LEN; vp = owner;
1034 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1035 len = MTE_STR1_LEN; vp = tname;
1036 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1037 entry = _find_mteTrigger_entry( owner, tname );
1038
1039 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
1040
1041 /*
1042 * Read in the accessible column values.
1043 * (Note that the first two are combined into a single field)
1044 */
1045 line = _parse_mteTExCols( line, entry, 0 );
1046
1047 entry->mteTriggerTest |= MTE_TRIGGER_EXISTENCE;
1048 entry->flags |= MTE_TRIGGER_FLAG_VALID;
1049
1050 DEBUGMSG(("disman:event:conf", "\n"));
1051 }
1052
1053
1054 /*
1055 * Entries from the mteTriggerBooleanTable
1056 */
1057
1058 char *
1059 _parse_mteTBlCols( char *line, struct mteTrigger *entry, int bcomp )
1060 {
1061 void *vp;
1062 size_t tmp;
1063 size_t len;
1064
1065 if (bcomp) {
1066 line = read_config_read_data(ASN_UNSIGNED, line,
1067 &entry->mteTBoolComparison, NULL);
1068 line = read_config_read_data(ASN_INTEGER, line,
1069 &entry->mteTBoolValue, NULL);
1070 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
1071 if (tmp == TV_TRUE)
1072 entry->flags |= MTE_TRIGGER_FLAG_BSTART;
1073 } else {
1074 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
1075 entry->mteTBoolComparison = ( tmp & 0x0f );
1076 entry->flags |= ( tmp & MTE_TRIGGER_FLAG_BSTART );
1077 line = read_config_read_data(ASN_INTEGER, line,
1078 &entry->mteTBoolValue, NULL);
1079 }
1080
1081
1082 len = MTE_STR1_LEN; vp = entry->mteTBoolObjOwner;
1083 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1084 len = MTE_STR1_LEN; vp = entry->mteTBoolObjects;
1085 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1086
1087 len = MTE_STR1_LEN; vp = entry->mteTBoolEvOwner;
1088 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1089 len = MTE_STR1_LEN; vp = entry->mteTBoolEvent;
1090 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1091
1092 return line;
1093 }
1094
1095 void
1096 parse_mteTBlTable(const char *token, char *line)
1097 {
1098 char owner[MTE_STR1_LEN+1];
1099 char tname[MTE_STR1_LEN+1];
1100 void *vp;
1101 size_t len;
1102 struct mteTrigger *entry;
1103
1104 DEBUGMSGTL(("disman:event:conf", "Parsing mteTriggerBooleanTable config... "));
1105
1106 /*
1107 * Read in the index information for this entry
1108 * and create a (non-fixed) data structure for it.
1109 */
1110 memset( owner, 0, sizeof(owner));
1111 memset( tname, 0, sizeof(tname));
1112 len = MTE_STR1_LEN; vp = owner;
1113 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1114 len = MTE_STR1_LEN; vp = tname;
1115 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1116 entry = _find_mteTrigger_entry( owner, tname );
1117
1118 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
1119
1120 /*
1121 * Read in the accessible column values.
1122 * (Note that the first & third are combined into a single field)
1123 */
1124 line = _parse_mteTBlCols( line, entry, 0 );
1125
1126 entry->mteTriggerTest |= MTE_TRIGGER_BOOLEAN;
1127 entry->flags |= MTE_TRIGGER_FLAG_VALID;
1128
1129 DEBUGMSG(("disman:event:conf", "\n"));
1130 }
1131
1132
1133 /*
1134 * Entries from the mteTriggerThresholdTable
1135 */
1136
1137 char *
1138 _parse_mteTThCols( char *line, struct mteTrigger *entry, int bcomp )
1139 {
1140 void *vp;
1141 size_t len;
1142
1143 line = read_config_read_data(ASN_UNSIGNED, line,
1144 &entry->mteTThStartup, NULL);
1145 line = read_config_read_data(ASN_INTEGER, line,
1146 &entry->mteTThRiseValue, NULL);
1147 line = read_config_read_data(ASN_INTEGER, line,
1148 &entry->mteTThFallValue, NULL);
1149 line = read_config_read_data(ASN_INTEGER, line,
1150 &entry->mteTThDRiseValue, NULL);
1151 line = read_config_read_data(ASN_INTEGER, line,
1152 &entry->mteTThDFallValue, NULL);
1153
1154 len = MTE_STR1_LEN; vp = entry->mteTThObjOwner;
1155 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1156 len = MTE_STR1_LEN; vp = entry->mteTThObjects;
1157 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1158
1159 len = MTE_STR1_LEN; vp = entry->mteTThRiseOwner;
1160 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1161 len = MTE_STR1_LEN; vp = entry->mteTThRiseEvent;
1162 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1163 len = MTE_STR1_LEN; vp = entry->mteTThFallOwner;
1164 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1165 len = MTE_STR1_LEN; vp = entry->mteTThFallEvent;
1166 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1167
1168 len = MTE_STR1_LEN; vp = entry->mteTThDRiseOwner;
1169 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1170 len = MTE_STR1_LEN; vp = entry->mteTThDRiseEvent;
1171 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1172 len = MTE_STR1_LEN; vp = entry->mteTThDFallOwner;
1173 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1174 len = MTE_STR1_LEN; vp = entry->mteTThDFallEvent;
1175 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1176
1177 return line;
1178 }
1179
1180 void
1181 parse_mteTThTable(const char *token, char *line)
1182 {
1183 char owner[MTE_STR1_LEN+1];
1184 char tname[MTE_STR1_LEN+1];
1185 void *vp;
1186 size_t len;
1187 struct mteTrigger *entry;
1188
1189 DEBUGMSGTL(("disman:event:conf", "Parsing mteTriggerThresholdTable config... "));
1190
1191 /*
1192 * Read in the index information for this entry
1193 * and create a (non-fixed) data structure for it.
1194 */
1195 memset( owner, 0, sizeof(owner));
1196 memset( tname, 0, sizeof(tname));
1197 len = MTE_STR1_LEN; vp = owner;
1198 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1199 len = MTE_STR1_LEN; vp = tname;
1200 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1201 entry = _find_mteTrigger_entry( owner, tname );
1202
1203 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
1204
1205 /*
1206 * Read in the accessible column values.
1207 */
1208 line = _parse_mteTThCols( line, entry, 0 );
1209
1210 entry->mteTriggerTest |= MTE_TRIGGER_THRESHOLD;
1211 entry->flags |= MTE_TRIGGER_FLAG_VALID;
1212
1213 DEBUGMSG(("disman:event:conf", "\n"));
1214 }
1215
1216
1217 /*
1218 * Backwards Compatability with the previous implementation
1219 */
1220
1221 void
1222 parse_mteTriggerTable(const char *token, char *line)
1223 {
1224 char owner[MTE_STR1_LEN+1];
1225 char tname[MTE_STR1_LEN+1];
1226 void *vp;
1227 size_t len;
1228 struct mteTrigger *entry;
1229
1230 DEBUGMSGTL(("disman:event:conf", "Parsing previous mteTriggerTable config... "));
1231
1232 /*
1233 * Read in the index information for this entry
1234 * and create a (non-fixed) data structure for it.
1235 */
1236 memset( owner, 0, sizeof(owner));
1237 memset( tname, 0, sizeof(tname));
1238 len = MTE_STR1_LEN; vp = owner;
1239 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1240 len = MTE_STR1_LEN; vp = tname;
1241 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
1242 entry = _find_mteTrigger_entry( owner, tname );
1243
1244 DEBUGMSG(("disman:event:conf", "(%s, %s) ", owner, tname));
1245
1246 /*
1247 * Read in the accessible column values for each table in turn...
1248 * (similar, though not identical to the newer style).
1249 */
1250 line = _parse_mteTCols( line, entry, 1 );
1251 line = _parse_mteTDCols( line, entry, 1 );
1252 line = _parse_mteTExCols( line, entry, 1 );
1253 line = _parse_mteTBlCols( line, entry, 1 );
1254 line = _parse_mteTThCols( line, entry, 1 );
1255
1256 /*
1257 * ... and then read in the "local internal variables"
1258 * XXX - TODO
1259 */
1260 entry->flags |= MTE_TRIGGER_FLAG_VALID;
1261
1262 /* XXX - mte_enable_trigger(); ??? */
1263 DEBUGMSG(("disman:event:conf", "\n"));
1264 }
1265
1266 /* ===============================================
1267 *
1268 * Handler for storing persistent trigger entries
1269 *
1270 * =============================================== */
1271
1272 int
1273 store_mteTTable(int majorID, int minorID, void *serverarg, void *clientarg)
1274 {
1275 char line[SNMP_MAXBUF];
1276 char *cptr, *cp;
1277 void *vp;
1278 size_t tint;
1279 netsnmp_tdata_row *row;
1280 struct mteTrigger *entry;
1281
1282
1283 DEBUGMSGTL(("disman:event:conf", "Storing mteTriggerTable config:\n"));
1284
1285 for (row = netsnmp_tdata_row_first( trigger_table_data );
1286 row;
1287 row = netsnmp_tdata_row_next( trigger_table_data, row )) {
1288
1289 /*
1290 * Skip entries that were set up via static config directives
1291 */
1292 entry = (struct mteTrigger *)netsnmp_tdata_row_entry( row );
1293 if ( entry->flags & MTE_TRIGGER_FLAG_FIXED )
1294 continue;
1295
1296 DEBUGMSGTL(("disman:event:conf", " Storing (%s %s)\n",
1297 entry->mteOwner, entry->mteTName));
1298
1299 /*
1300 * Save the basic mteTriggerTable entry...
1301 */
1302 memset(line, 0, sizeof(line));
1303 strcat(line, "_mteTTable ");
1304 cptr = line + strlen(line);
1305
1306 cp = entry->mteOwner; tint = strlen( cp );
1307 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1308 cp = entry->mteTName; tint = strlen( cp );
1309 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1310 cp = entry->mteTriggerComment; tint = strlen( cp );
1311 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1312 /*
1313 * ... (but skip the mteTriggerTest and
1314 * assorted boolean flag fields)...
1315 */
1316 vp = entry->mteTriggerValueID;
1317 tint = entry->mteTriggerValueID_len;
1318 cptr = read_config_store_data( ASN_OBJECT_ID, cptr, &vp, &tint );
1319 cp = entry->mteTriggerTarget; tint = strlen( cp );
1320 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1321 cp = entry->mteTriggerContext; tint = strlen( cp );
1322 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1323 tint = entry->mteTriggerFrequency;
1324 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1325 cp = entry->mteTriggerOOwner; tint = strlen( cp );
1326 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1327 cp = entry->mteTriggerObjects; tint = strlen( cp );
1328 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1329 tint = entry->flags &
1330 (MTE_TRIGGER_FLAG_VWILD |MTE_TRIGGER_FLAG_CWILD|
1331 MTE_TRIGGER_FLAG_ENABLED|MTE_TRIGGER_FLAG_ACTIVE);
1332 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1333 /* XXX - Need to store the 'iquery' access information */
1334 snmpd_store_config(line);
1335
1336 /*
1337 * ... then save the other (relevant) table entries separately,
1338 * starting with mteDeltaDiscontinuityTable...
1339 */
1340 if ( entry->flags & MTE_TRIGGER_FLAG_DELTA ) {
1341 memset(line, 0, sizeof(line));
1342 strcat(line, "_mteTDTable ");
1343 cptr = line + strlen(line);
1344
1345 cp = entry->mteOwner; tint = strlen( cp );
1346 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1347 cp = entry->mteTName; tint = strlen( cp );
1348 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1349
1350 vp = entry->mteDeltaDiscontID;
1351 tint = entry->mteDeltaDiscontID_len;
1352 cptr = read_config_store_data( ASN_OBJECT_ID, cptr, &vp, &tint );
1353
1354 tint = entry->flags & MTE_TRIGGER_FLAG_DWILD;
1355 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1356 tint = entry->mteDeltaDiscontIDType;
1357 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1358
1359 snmpd_store_config(line);
1360 }
1361
1362 /*
1363 * ... and the three type-specific trigger tables.
1364 */
1365 if ( entry->mteTriggerTest & MTE_TRIGGER_EXISTENCE ) {
1366 memset(line, 0, sizeof(line));
1367 strcat(line, "_mteTExTable ");
1368 cptr = line + strlen(line);
1369
1370 cp = entry->mteOwner; tint = strlen( cp );
1371 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1372 cp = entry->mteTName; tint = strlen( cp );
1373 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1374
1375 tint = (entry->mteTExTest & 0xff) << 8;
1376 tint|= (entry->mteTExStartup & 0xff);
1377 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1378
1379 cp = entry->mteTExObjOwner; tint = strlen( cp );
1380 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1381 cp = entry->mteTExObjects; tint = strlen( cp );
1382 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1383
1384 cp = entry->mteTExEvOwner; tint = strlen( cp );
1385 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1386 cp = entry->mteTExEvent; tint = strlen( cp );
1387 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1388
1389 snmpd_store_config(line);
1390 }
1391 if ( entry->mteTriggerTest & MTE_TRIGGER_BOOLEAN ) {
1392 memset(line, 0, sizeof(line));
1393 strcat(line, "_mteTBlTable ");
1394 cptr = line + strlen(line);
1395
1396 cp = entry->mteOwner; tint = strlen( cp );
1397 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1398 cp = entry->mteTName; tint = strlen( cp );
1399 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1400
1401 tint = entry->mteTBoolComparison;
1402 tint |= (entry->flags & MTE_TRIGGER_FLAG_BSTART);
1403 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
1404 tint = entry->mteTBoolValue;
1405 cptr = read_config_store_data( ASN_INTEGER, cptr, &tint, NULL );
1406
1407 cp = entry->mteTBoolObjOwner; tint = strlen( cp );
1408 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1409 cp = entry->mteTBoolObjects; tint = strlen( cp );
1410 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1411
1412 cp = entry->mteTBoolEvOwner; tint = strlen( cp );
1413 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1414 cp = entry->mteTBoolEvent; tint = strlen( cp );
1415 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1416
1417 snmpd_store_config(line);
1418 }
1419 if ( entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD ) {
1420 memset(line, 0, sizeof(line));
1421 strcat(line, "_mteTThTable ");
1422 cptr = line + strlen(line);
1423
1424 cp = entry->mteOwner; tint = strlen( cp );
1425 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1426 cp = entry->mteTName; tint = strlen( cp );
1427 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1428
1429 cptr = read_config_store_data(ASN_UNSIGNED, cptr,
1430 &entry->mteTThStartup, NULL );
1431 cptr = read_config_store_data(ASN_INTEGER, cptr,
1432 &entry->mteTThRiseValue, NULL );
1433 cptr = read_config_store_data(ASN_INTEGER, cptr,
1434 &entry->mteTThFallValue, NULL );
1435 cptr = read_config_store_data(ASN_INTEGER, cptr,
1436 &entry->mteTThDRiseValue, NULL );
1437 cptr = read_config_store_data(ASN_INTEGER, cptr,
1438 &entry->mteTThDFallValue, NULL );
1439
1440 cp = entry->mteTThObjOwner; tint = strlen( cp );
1441 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1442 cp = entry->mteTThObjects; tint = strlen( cp );
1443 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1444
1445 cp = entry->mteTThRiseOwner; tint = strlen( cp );
1446 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1447 cp = entry->mteTThRiseEvent; tint = strlen( cp );
1448 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1449 cp = entry->mteTThFallOwner; tint = strlen( cp );
1450 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1451 cp = entry->mteTThFallEvent; tint = strlen( cp );
1452 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1453
1454 cp = entry->mteTThDRiseOwner; tint = strlen( cp );
1455 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1456 cp = entry->mteTThDRiseEvent; tint = strlen( cp );
1457 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1458 cp = entry->mteTThDFallOwner; tint = strlen( cp );
1459 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1460 cp = entry->mteTThDFallEvent; tint = strlen( cp );
1461 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
1462
1463 snmpd_store_config(line);
1464 }
1465 }
1466
1467 DEBUGMSGTL(("disman:event:conf", " done.\n"));
1468 return SNMPERR_SUCCESS;
1469 }
1470
1471 int
1472 clear_mteTTable(int majorID, int minorID, void *serverarg, void *clientarg)
1473 {
1474 netsnmp_tdata_row *row;
1475
1476 while (( row = netsnmp_tdata_row_first( trigger_table_data ))) {
1477 struct mteTrigger *entry = (struct mteTrigger *)
1478 netsnmp_tdata_remove_and_delete_row(trigger_table_data, row);
1479 if (entry) {
1480 /* Remove from the callbacks list and disable triggers */
1481 snmp_unregister_callback( SNMP_CALLBACK_LIBRARY,
1482 SNMP_CALLBACK_POST_READ_CONFIG,
1483 _mteTrigger_callback_enable, entry, 0 );
1484 mteTrigger_disable( entry );
1485 SNMP_FREE(entry);
1486 }
1487 }
1488 return SNMPERR_SUCCESS;
1489 }