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

SNMP编程

开发平台:

Unix_Linux

  1. /**************************************************************
  2.  * Copyright (C) 2001 Alex Rozin, Optical Access
  3.  * 
  4.  *                     All Rights Reserved
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation. 
  11.  * 
  12.  * ALEX ROZIN DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  13.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  14.  * ALEX ROZIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  15.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  16.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  17.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  18.  * SOFTWARE. 
  19.  ******************************************************************/
  20. #include <net-snmp/net-snmp-config.h>
  21. #if HAVE_STDLIB_H
  22. #include <stdlib.h>
  23. #endif
  24. #if HAVE_UNISTD_H
  25. #include <unistd.h>
  26. #endif
  27. #if TIME_WITH_SYS_TIME
  28. # ifdef WIN32
  29. #  include <sys/timeb.h>
  30. # else
  31. #  include <sys/time.h>
  32. # endif
  33. # include <time.h>
  34. #else
  35. # if HAVE_SYS_TIME_H
  36. #  include <sys/time.h>
  37. # else
  38. #  include <time.h>
  39. # endif
  40. #endif
  41. #include <net-snmp/net-snmp-includes.h>
  42. #include <net-snmp/agent/net-snmp-agent-includes.h>
  43. #include "util_funcs.h"
  44. #include "alarm.h"
  45.     /*
  46.      * Implementation headers 
  47.      */
  48. #include "agutil_api.h"
  49. #include "row_api.h"
  50.     /*
  51.      * File scope definitions section 
  52.      */
  53.     /*
  54.      * from MIB compilation 
  55.      */
  56. #define alarmEntryFirstIndexBegin       11
  57. #define MMM_MAX 0xFFFFFFFFl
  58. #define IDalarmIndex                    1
  59. #define IDalarmInterval                 2
  60. #define IDalarmVariable                 3
  61. #define IDalarmSampleType               4
  62. #define IDalarmValue                    5
  63. #define IDalarmStartupAlarm             6
  64. #define IDalarmRisingThreshold          7
  65. #define IDalarmFallingThreshold         8
  66. #define IDalarmRisingEventIndex         9
  67. #define IDalarmFallingEventIndex        10
  68. #define IDalarmOwner                    11
  69. #define IDalarmStatus                   12
  70. #define MIN_alarmEventIndex             0
  71. #define MAX_alarmEventIndex             65535
  72.      typedef enum {
  73.          SAMPLE_TYPE_ABSOLUTE =
  74.              1,
  75.          SAMPLE_TYPE_DELTE
  76.      } SAMPLE_TYPE_T;
  77.      typedef enum {
  78.          ALARM_NOTHING =
  79.              0,
  80.          ALARM_RISING,
  81.          ALARM_FALLING,
  82.          ALARM_BOTH
  83.      } ALARM_TYPE_T;
  84.      typedef struct {
  85.          u_long
  86.              interval;
  87.          u_long
  88.              timer_id;
  89.          VAR_OID_T
  90.              var_name;
  91.          SAMPLE_TYPE_T
  92.              sample_type;
  93.          ALARM_TYPE_T
  94.              startup_type;      /* RISING | FALLING | BOTH */
  95.          u_long
  96.              rising_threshold;
  97.          u_long
  98.              falling_threshold;
  99.          u_long
  100.              rising_event_index;
  101.          u_long
  102.              falling_event_index;
  103.          u_long
  104.              last_abs_value;
  105.          u_long
  106.              value;
  107.          ALARM_TYPE_T
  108.              prev_alarm;        /* NOTHING | RISING | FALLING */
  109.      } CRTL_ENTRY_T;
  110. /*
  111.  * Main section 
  112.  */
  113.      static TABLE_DEFINTION_T
  114.          AlarmCtrlTable;
  115.      static TABLE_DEFINTION_T *
  116.          table_ptr = &
  117.          AlarmCtrlTable;
  118. #if 0                           /* KUKU */
  119.      static u_long
  120.          kuku_sum =
  121.          0,
  122.          kuku_cnt =
  123.          0;
  124. #endif
  125. /*
  126.  * find & enjoy it in event.c 
  127.  */
  128.      extern int
  129.      event_api_send_alarm(u_char is_rising,
  130.                           u_long alarm_index,
  131.                           u_long event_index,
  132.                           oid * alarmed_var,
  133.                           size_t alarmed_var_length,
  134.                           u_long sample_type,
  135.                           u_long value,
  136.                           u_long the_threshold, char *alarm_descr);
  137. static int
  138. fetch_var_val(oid * name, size_t namelen, u_long * new_value)
  139. {
  140.     netsnmp_subtree *tree_ptr;
  141.     size_t          var_len;
  142.     WriteMethod    *write_method;
  143.     struct variable called_var;
  144.     register struct variable *s_var_ptr = NULL;
  145.     register u_char *access;
  146.     tree_ptr = netsnmp_subtree_find(name, namelen, NULL, "");
  147.     if (!tree_ptr) {
  148.         ag_trace("tree_ptr is NULL");
  149.         return SNMP_ERR_NOSUCHNAME;
  150.     }
  151.     
  152.     memcpy(called_var.name, tree_ptr->name_a,
  153.            tree_ptr->namelen * sizeof(oid));
  154.  
  155.     if (tree_ptr->reginfo && 
  156.         tree_ptr->reginfo->handler && 
  157.         tree_ptr->reginfo->handler->next && 
  158.         tree_ptr->reginfo->handler->next->myvoid) {
  159.         s_var_ptr = (struct variable *)tree_ptr->reginfo->handler->next->myvoid;
  160.     }
  161.     if (s_var_ptr) {
  162.         if (s_var_ptr->namelen) {
  163.                 called_var.namelen = 
  164.                                    tree_ptr->namelen;
  165.                 called_var.type = s_var_ptr->type;
  166.                 called_var.magic = s_var_ptr->magic;
  167.                 called_var.acl = s_var_ptr->acl;
  168.                 called_var.findVar = s_var_ptr->findVar;
  169.                 access =    
  170.                     (*(s_var_ptr->findVar)) (&called_var, name, &namelen,
  171.                                              1, &var_len, &write_method);
  172.                 if (access
  173.                     && snmp_oid_compare(name, namelen, tree_ptr->end_a,
  174.                                         tree_ptr->end_len) > 0) {
  175.                     memcpy(name, tree_ptr->end_a, tree_ptr->end_len);
  176.                     access = 0;
  177.                     ag_trace("access := 0");
  178.                 }
  179.                 if (access) {
  180.                     /*
  181.                      * check 'var_len' ? 
  182.                      */
  183.                     /*
  184.                      * check type 
  185.                      */
  186.                     switch (called_var.type) {
  187.                     case ASN_INTEGER:
  188.                     case ASN_COUNTER:
  189.                     case ASN_TIMETICKS:
  190.                     case ASN_GAUGE:
  191.                     case ASN_COUNTER64:
  192.                         break;
  193.                     default:
  194.                         ag_trace("invalid type: %d",
  195.                                  (int) called_var.type);
  196.                         return SNMP_ERR_GENERR;
  197.                     }
  198.                     *new_value = *(u_long *) access;
  199.                     return SNMP_ERR_NOERROR;
  200.                 }
  201.             }
  202.         }
  203.     return SNMP_ERR_NOSUCHNAME;
  204. }
  205. static void
  206. alarm_check_var(unsigned int clientreg, void *clientarg)
  207. {
  208.     RMON_ENTRY_T   *hdr_ptr;
  209.     CRTL_ENTRY_T   *body;
  210.     u_long          new_value;
  211.     int             ierr;
  212.     hdr_ptr = (RMON_ENTRY_T *) clientarg;
  213.     if (!hdr_ptr) {
  214.         ag_trace
  215.             ("Err: history_get_backet: hdr_ptr=NULL ? (Inserted in shock)");
  216.         return;
  217.     }
  218.     body = (CRTL_ENTRY_T *) hdr_ptr->body;
  219.     if (!body) {
  220.         ag_trace
  221.             ("Err: history_get_backet: body=NULL ? (Inserted in shock)");
  222.         return;
  223.     }
  224.     if (RMON1_ENTRY_VALID != hdr_ptr->status) {
  225.         ag_trace("Err: history_get_backet when entry %d is not valid ?!!",
  226.                  (int) hdr_ptr->ctrl_index);
  227.         snmp_alarm_unregister(body->timer_id);
  228.         return;
  229.     }
  230.     ierr = fetch_var_val(body->var_name.objid,
  231.                          body->var_name.length, &new_value);
  232.     if (SNMP_ERR_NOERROR != ierr) {
  233.         ag_trace("Err: Can't fetch var_name");
  234.         return;
  235.     }
  236.     body->value = (SAMPLE_TYPE_ABSOLUTE == body->sample_type) ?
  237.         new_value : new_value - body->last_abs_value;
  238.     body->last_abs_value = new_value;
  239.     /*
  240.      * ag_trace ("fetched value=%ld check %ld", (long) new_value, (long) body->value); 
  241.      */
  242. #if 0                           /* KUKU */
  243.     kuku_sum += body->value;
  244.     kuku_cnt++;
  245. #endif
  246.     if (ALARM_RISING != body->prev_alarm &&
  247.         body->value >= body->rising_threshold &&
  248.         SNMP_ERR_NOERROR == event_api_send_alarm(1, hdr_ptr->ctrl_index,
  249.                                                  body->rising_event_index,
  250.                                                  body->var_name.objid,
  251.                                                  body->var_name.length,
  252.                                                  ALARM_RISING, body->value,
  253.                                                  body->rising_threshold,
  254.                                                  "Rising"))
  255.         body->prev_alarm = ALARM_RISING;
  256.     else if (ALARM_FALLING != body->prev_alarm &&
  257.              body->value <= body->falling_threshold &&
  258.              SNMP_ERR_NOERROR == event_api_send_alarm(0,
  259.                                                       hdr_ptr->ctrl_index,
  260.                                                       body->
  261.                                                       falling_event_index,
  262.                                                       body->var_name.objid,
  263.                                                       body->var_name.
  264.                                                       length, ALARM_RISING,
  265.                                                       body->value,
  266.                                                       body->
  267.                                                       falling_threshold,
  268.                                                       "Falling"))
  269.         body->prev_alarm = ALARM_FALLING;
  270. }
  271. /*
  272.  * Control Table RowApi Callbacks 
  273.  */
  274. int
  275. alarm_Create(RMON_ENTRY_T * eptr)
  276. {                               /* create the body: alloc it and set defaults */
  277.     CRTL_ENTRY_T   *body;
  278.     static VAR_OID_T DEFAULT_VAR = { 12,        /* etherStatsPkts.1 */
  279.         {1, 3, 6, 1, 2, 1, 16, 1, 1, 1, 5, 1}
  280.     };
  281.     eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));
  282.     if (!eptr->body)
  283.         return -3;
  284.     body = (CRTL_ENTRY_T *) eptr->body;
  285.     /*
  286.      * set defaults 
  287.      */
  288.     body->interval = 1;
  289.     memcpy(&body->var_name, &DEFAULT_VAR, sizeof(VAR_OID_T));
  290.     body->sample_type = SAMPLE_TYPE_ABSOLUTE;
  291.     body->startup_type = ALARM_BOTH;
  292.     body->rising_threshold = MMM_MAX;
  293.     body->falling_threshold = 0;
  294.     body->rising_event_index = body->falling_event_index = 0;
  295.     body->prev_alarm = ALARM_NOTHING;
  296.     return 0;
  297. }
  298. int
  299. alarm_Validate(RMON_ENTRY_T * eptr)
  300. {
  301.     CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
  302.     if (body->rising_threshold <= body->falling_threshold) {
  303.         ag_trace("alarm_Validate failed: %lu must be > %lu",
  304.                  body->rising_threshold, body->falling_threshold);
  305.         return SNMP_ERR_BADVALUE;
  306.     }
  307.     return 0;
  308. }
  309. int
  310. alarm_Activate(RMON_ENTRY_T * eptr)
  311. {
  312.     CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
  313.     int             ierr;
  314. #if 0                           /* KUKU */
  315.     kuku_sum = 0;
  316.     kuku_cnt = 0;
  317. #endif
  318.     ierr = fetch_var_val(body->var_name.objid,
  319.                          body->var_name.length, &body->last_abs_value);
  320.     if (SNMP_ERR_NOERROR != ierr) {
  321.         ag_trace("Can't fetch var_name");
  322.         return ierr;
  323.     }
  324.     if (SAMPLE_TYPE_ABSOLUTE != body->sample_type) {
  325.         /*
  326.          * check startup alarm 
  327.          */
  328.         if (ALARM_RISING == body->startup_type ||
  329.             ALARM_BOTH == body->startup_type) {
  330.             if (body->last_abs_value >= body->rising_threshold) {
  331.                 event_api_send_alarm(1, eptr->ctrl_index,
  332.                                      body->rising_event_index,
  333.                                      body->var_name.objid,
  334.                                      body->var_name.length,
  335.                                      ALARM_RISING, body->value,
  336.                                      body->rising_threshold,
  337.                                      "Startup Rising");
  338.             }
  339.         }
  340.         if (ALARM_FALLING == body->startup_type ||
  341.             ALARM_BOTH == body->startup_type) {
  342.             if (body->last_abs_value <= body->falling_threshold) {
  343.                 event_api_send_alarm(0, eptr->ctrl_index,
  344.                                      body->falling_event_index,
  345.                                      body->var_name.objid,
  346.                                      body->var_name.length,
  347.                                      ALARM_RISING, body->value,
  348.                                      body->falling_threshold,
  349.                                      "Startup Falling");
  350.             }
  351.         }
  352.     }
  353.     body->timer_id = snmp_alarm_register(body->interval, SA_REPEAT,
  354.                                          alarm_check_var, eptr);
  355.     return 0;
  356. }
  357. int
  358. alarm_Deactivate(RMON_ENTRY_T * eptr)
  359. {
  360.     CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
  361.     snmp_alarm_unregister(body->timer_id);
  362. #if 0                           /* KUKU */
  363.     ag_trace("kuku_sum=%ld kuku_cnt=%ld sp=%ld",
  364.              (long) kuku_sum, (long) kuku_cnt,
  365.              (long) (kuku_sum / kuku_cnt));
  366. #endif
  367.     return 0;
  368. }
  369. int
  370. alarm_Copy(RMON_ENTRY_T * eptr)
  371. {
  372.     CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
  373.     CRTL_ENTRY_T   *clone = (CRTL_ENTRY_T *) eptr->tmp;
  374.     if (RMON1_ENTRY_VALID == eptr->status &&
  375.         clone->rising_threshold <= clone->falling_threshold) {
  376.         ag_trace("alarm_Copy failed: invalid thresholds");
  377.         return SNMP_ERR_BADVALUE;
  378.     }
  379.     if (clone->interval != body->interval) {
  380.         if (RMON1_ENTRY_VALID == eptr->status) {
  381.             snmp_alarm_unregister(body->timer_id);
  382.             body->timer_id =
  383.                 snmp_alarm_register(clone->interval, SA_REPEAT,
  384.                                     alarm_check_var, eptr);
  385.         }
  386.         body->interval = clone->interval;
  387.     }
  388.     if (snmp_oid_compare(clone->var_name.objid, clone->var_name.length,
  389.                          body->var_name.objid, body->var_name.length)) {
  390.         memcpy(&body->var_name, &clone->var_name, sizeof(VAR_OID_T));
  391.     }
  392.     body->sample_type = clone->sample_type;
  393.     body->startup_type = clone->startup_type;
  394.     body->sample_type = clone->sample_type;
  395.     body->rising_threshold = clone->rising_threshold;
  396.     body->falling_threshold = clone->falling_threshold;
  397.     body->rising_event_index = clone->rising_event_index;
  398.     body->falling_event_index = clone->falling_event_index;
  399.     /*
  400.      * ag_trace ("alarm_Copy: rising_threshold=%lu falling_threshold=%lu",
  401.      * body->rising_threshold, body->falling_threshold); 
  402.      */
  403.     return 0;
  404. }
  405. static int
  406. write_alarmEntry(int action, u_char * var_val, u_char var_val_type,
  407.                  size_t var_val_len, u_char * statP,
  408.                  oid * name, size_t name_len)
  409. {
  410.     long            long_tmp;
  411.     int             leaf_id, snmp_status;
  412.     static int      prev_action = COMMIT;
  413.     RMON_ENTRY_T   *hdr;
  414.     CRTL_ENTRY_T   *cloned_body;
  415.     CRTL_ENTRY_T   *body;
  416.     switch (action) {
  417.     case RESERVE1:
  418.     case FREE:
  419.     case UNDO:
  420.     case ACTION:
  421.     case COMMIT:
  422.     default:
  423.         return ROWAPI_do_another_action(name, alarmEntryFirstIndexBegin,
  424.                                         action, &prev_action,
  425.                                         table_ptr, sizeof(CRTL_ENTRY_T));
  426.     case RESERVE2:
  427.         /*
  428.          * get values from PDU, check them and save them in the cloned entry 
  429.          */
  430.         long_tmp = name[alarmEntryFirstIndexBegin];
  431.         leaf_id = (int) name[alarmEntryFirstIndexBegin - 1];
  432.         hdr = ROWAPI_find(table_ptr, long_tmp); /* it MUST be OK */
  433.         cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
  434.         body = (CRTL_ENTRY_T *) hdr->body;
  435.         switch (leaf_id) {
  436.         case IDalarmInterval:
  437.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  438.                                                var_val_len,
  439.                                                0, MMM_MAX, &long_tmp);
  440.             if (SNMP_ERR_NOERROR != snmp_status) {
  441.                 return snmp_status;
  442.             }
  443.             cloned_body->interval = long_tmp;
  444.             break;
  445.         case IDalarmVariable:
  446.             snmp_status = AGUTIL_get_oid_value(var_val, var_val_type,
  447.                                                var_val_len,
  448.                                                &cloned_body->var_name);
  449.             if (SNMP_ERR_NOERROR != snmp_status) {
  450.                 return snmp_status;
  451.             }
  452.             if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
  453.                 snmp_oid_compare(cloned_body->var_name.objid,
  454.                                  cloned_body->var_name.length,
  455.                                  body->var_name.objid,
  456.                                  body->var_name.length))
  457.                 return SNMP_ERR_BADVALUE;
  458.             break;
  459.             break;
  460.         case IDalarmSampleType:
  461.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  462.                                                var_val_len,
  463.                                                SAMPLE_TYPE_ABSOLUTE,
  464.                                                SAMPLE_TYPE_DELTE,
  465.                                                &long_tmp);
  466.             if (SNMP_ERR_NOERROR != snmp_status) {
  467.                 return snmp_status;
  468.             }
  469.             cloned_body->sample_type = long_tmp;
  470.             break;
  471.         case IDalarmStartupAlarm:
  472.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  473.                                                var_val_len,
  474.                                                ALARM_RISING,
  475.                                                ALARM_BOTH, &long_tmp);
  476.             if (SNMP_ERR_NOERROR != snmp_status) {
  477.                 return snmp_status;
  478.             }
  479.             cloned_body->startup_type = long_tmp;
  480.             break;
  481.         case IDalarmRisingThreshold:
  482.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  483.                                                var_val_len,
  484.                                                0, MMM_MAX, &long_tmp);
  485.             if (SNMP_ERR_NOERROR != snmp_status) {
  486.                 return snmp_status;
  487.             }
  488.             cloned_body->rising_threshold = long_tmp;
  489.             break;
  490.         case IDalarmFallingThreshold:
  491.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  492.                                                var_val_len,
  493.                                                0, 0xFFFFFFFFl, &long_tmp);
  494.             if (SNMP_ERR_NOERROR != snmp_status) {
  495.                 return snmp_status;
  496.             }
  497.             cloned_body->falling_threshold = long_tmp;
  498.             break;
  499.         case IDalarmRisingEventIndex:
  500.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type, var_val_len, 0,   /* min. value */
  501.                                                0,       /* max. value */
  502.                                                &long_tmp);
  503.             if (SNMP_ERR_NOERROR != snmp_status) {
  504.                 return snmp_status;
  505.             }
  506.             cloned_body->rising_event_index = long_tmp;
  507.             break;
  508.         case IDalarmFallingEventIndex:
  509.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type, var_val_len, 0,   /* min. value */
  510.                                                0,       /* max. value */
  511.                                                &long_tmp);
  512.             if (SNMP_ERR_NOERROR != snmp_status) {
  513.                 return snmp_status;
  514.             }
  515.             cloned_body->falling_event_index = long_tmp;
  516.             break;
  517.         case IDalarmOwner:
  518.             if (hdr->new_owner)
  519.                 AGFREE(hdr->new_owner);
  520.             hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;
  521.             if (!hdr->new_owner)
  522.                 return SNMP_ERR_TOOBIG;
  523.             snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
  524.                                                   var_val_len,
  525.                                                   MAX_OWNERSTRING,
  526.                                                   1, NULL, hdr->new_owner);
  527.             if (SNMP_ERR_NOERROR != snmp_status) {
  528.                 return snmp_status;
  529.             }
  530.             break;
  531.         case IDalarmStatus:
  532.             snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
  533.                                                var_val_len,
  534.                                                RMON1_ENTRY_VALID,
  535.                                                RMON1_ENTRY_INVALID,
  536.                                                &long_tmp);
  537.             if (SNMP_ERR_NOERROR != snmp_status) {
  538.                 return snmp_status;
  539.             }
  540.             hdr->new_status = long_tmp;
  541.             break;
  542.         default:
  543.             ag_trace("%s:unknown leaf_id=%dn", table_ptr->name,
  544.                      (int) leaf_id);
  545.             return SNMP_ERR_NOSUCHNAME;
  546.         }                       /* of switch by 'leaf_id' */
  547.         break;
  548.     }                           /* of switch by actions */
  549.     prev_action = action;
  550.     return SNMP_ERR_NOERROR;
  551. }
  552. u_char         *
  553. var_alarmEntry(struct variable * vp, oid * name, size_t * length,
  554.                int exact, size_t * var_len, WriteMethod ** write_method)
  555. {
  556.     static long     long_return;
  557.     static CRTL_ENTRY_T theEntry;
  558.     RMON_ENTRY_T   *hdr;
  559.     *write_method = write_alarmEntry;
  560.     hdr = ROWAPI_header_ControlEntry(vp, name, length, exact, var_len,
  561.                                      table_ptr,
  562.                                      &theEntry, sizeof(CRTL_ENTRY_T));
  563.     if (!hdr)
  564.         return NULL;
  565.     *var_len = sizeof(long);    /* default */
  566.     switch (vp->magic) {
  567.     case IDalarmIndex:
  568.         long_return = hdr->ctrl_index;
  569.         return (u_char *) & long_return;
  570.     case IDalarmInterval:
  571.         long_return = theEntry.interval;
  572.         return (u_char *) & long_return;
  573.     case IDalarmVariable:
  574.         *var_len = sizeof(oid) * theEntry.var_name.length;
  575.         return (unsigned char *) theEntry.var_name.objid;
  576.         return (u_char *) & long_return;
  577.     case IDalarmSampleType:
  578.         long_return = theEntry.sample_type;
  579.         return (u_char *) & long_return;
  580.     case IDalarmValue:
  581.         long_return = theEntry.value;
  582.         return (u_char *) & long_return;
  583.     case IDalarmStartupAlarm:
  584.         long_return = theEntry.startup_type;
  585.         return (u_char *) & long_return;
  586.     case IDalarmRisingThreshold:
  587.         long_return = theEntry.rising_threshold;
  588.         return (u_char *) & long_return;
  589.     case IDalarmFallingThreshold:
  590.         long_return = theEntry.falling_threshold;
  591.         return (u_char *) & long_return;
  592.     case IDalarmRisingEventIndex:
  593.         long_return = theEntry.rising_event_index;
  594.         return (u_char *) & long_return;
  595.     case IDalarmFallingEventIndex:
  596.         long_return = theEntry.falling_event_index;
  597.         return (u_char *) & long_return;
  598.     case IDalarmOwner:
  599.         if (hdr->owner) {
  600.             *var_len = strlen(hdr->owner);
  601.             return (unsigned char *) hdr->owner;
  602.         } else {
  603.             *var_len = 0;
  604.             return (unsigned char *) "";
  605.         }
  606.     case IDalarmStatus:
  607.         long_return = hdr->status;
  608.         return (u_char *) & long_return;
  609.     default:
  610.         ag_trace("%s: unknown vp->magic=%d", table_ptr->name,
  611.                  (int) vp->magic);
  612.         ERROR_MSG("");
  613.     };                          /* of switch by 'vp->magic' */
  614.     return NULL;
  615. }
  616. /*
  617.  * Registration & Initializatio section 
  618.  */
  619. oid             oidalarmVariablesOid[] = { 1, 3, 6, 1, 2, 1, 16, 3 };
  620. struct variable7 oidalarmVariables[] = {
  621.     {IDalarmIndex, ASN_INTEGER, RONLY, var_alarmEntry, 3, {1, 1, 1}},
  622.     {IDalarmInterval, ASN_INTEGER, RWRITE, var_alarmEntry, 3, {1, 1, 2}},
  623.     {IDalarmVariable, ASN_OBJECT_ID, RWRITE, var_alarmEntry, 3, {1, 1, 3}},
  624.     {IDalarmSampleType, ASN_INTEGER, RWRITE, var_alarmEntry, 3, {1, 1, 4}},
  625.     {IDalarmValue, ASN_INTEGER, RONLY, var_alarmEntry, 3, {1, 1, 5}},
  626.     {IDalarmStartupAlarm, ASN_INTEGER, RWRITE, var_alarmEntry, 3,
  627.      {1, 1, 6}},
  628.     {IDalarmRisingThreshold, ASN_INTEGER, RWRITE, var_alarmEntry, 3,
  629.      {1, 1, 7}},
  630.     {IDalarmFallingThreshold, ASN_INTEGER, RWRITE, var_alarmEntry, 3,
  631.      {1, 1, 8}},
  632.     {IDalarmRisingEventIndex, ASN_INTEGER, RWRITE, var_alarmEntry, 3,
  633.      {1, 1, 9}},
  634.     {IDalarmFallingEventIndex, ASN_INTEGER, RWRITE, var_alarmEntry, 3,
  635.      {1, 1, 10}},
  636.     {IDalarmOwner, ASN_OCTET_STR, RWRITE, var_alarmEntry, 3, {1, 1, 11}},
  637.     {IDalarmStatus, ASN_INTEGER, RWRITE, var_alarmEntry, 3, {1, 1, 12}}
  638. };
  639. void
  640. init_alarm(void)
  641. {
  642.     REGISTER_MIB("alarmTable", oidalarmVariables, variable7,
  643.                  oidalarmVariablesOid);
  644.     ROWAPI_init_table(&AlarmCtrlTable, "Alarm", 0, &alarm_Create, NULL, /* &alarm_Clone, */
  645.                       NULL,     /* &alarm_Delete, */
  646.                       &alarm_Validate,
  647.                       &alarm_Activate, &alarm_Deactivate, &alarm_Copy);
  648. }
  649. /*
  650.  * end of file alarm.c 
  651.  */