Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

RMMonitors.c

Go to the documentation of this file.
00001 /* This file was generated by mib2c and is intended for use as a mib module
00002    for the ucd-snmp snmpd agent. */
00003 
00004 #include <netinet/in.h>
00005 
00006 
00007 #ifdef IN_UCD_SNMP_SOURCE
00008 /* If we're compiling this file inside the ucd-snmp source tree */
00009 
00010 
00011 /* This should always be included first before anything else */
00012 #include <config.h>
00013 
00014 
00015 /* minimal include directives */
00016 #include "mibincl.h"
00017 #include "util_funcs.h"
00018 
00019 
00020 #else /* !IN_UCD_SNMP_SOURCE */
00021 
00022 
00023 #include <ucd-snmp/ucd-snmp-config.h>
00024 #include <ucd-snmp/ucd-snmp-includes.h>
00025 #include <ucd-snmp/ucd-snmp-agent-includes.h>
00026 
00027 
00028 #endif /* !IN_UCD_SNMP_SOURCE */
00029 
00030 
00031 #include "RMMonitors.h"
00032 
00033 #include <string.h>
00034 #include <ucd-snmp/util_funcs.h>
00035 #include "utility.h"
00036 #include "rmClient.h"
00037 
00038 
00039 /* 
00040  * RMMonitors_variables_oid:
00041  *   this is the top level oid that we want to register under.  This
00042  *   is essentially a prefix, with the suffix appearing in the
00043  *   variable below.
00044  */
00045 
00046 
00047 oid RMMonitors_variables_oid[] = { 1,3,6,1,4,1,343,2,15,1,2,4 };
00048 
00049 
00050 /* 
00051  * variable4 RMMonitors_variables:
00052  *   this variable defines function callbacks and type return information 
00053  *   for the RMMonitors mib section 
00054  */
00055 
00056 
00057 struct variable4 RMMonitors_variables[] = {
00058 /*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
00059 #define   MONITORNEXTINDEX      1
00060   { MONITORNEXTINDEX    , ASN_UNSIGNED  , RONLY , var_RMMonitors, 1, { 1 } },
00061 #define   MONITORUUID           5
00062   { MONITORUUID         , ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,2 } },
00063 #define   MONITORCONTROLINDEX   6
00064   { MONITORCONTROLINDEX , ASN_UNSIGNED  , RWRITE, var_MonitorTable, 3, { 2,1,3 } },
00065 #define   MONITORCONFIGINDEX    7
00066   { MONITORCONFIGINDEX  , ASN_UNSIGNED  , RWRITE, var_MonitorTable, 3, { 2,1,4 } },
00067 #define   MONITORLOCATION       8
00068   { MONITORLOCATION     , ASN_INTEGER   , RONLY , var_MonitorTable, 3, { 2,1,5 } },
00069 #define   MONITORTYPE           9
00070   { MONITORTYPE         , ASN_INTEGER   , RONLY , var_MonitorTable, 3, { 2,1,6 } },
00071 #define   MONITORSUBSYSTEMID    10
00072   { MONITORSUBSYSTEMID  , ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,7 } },
00073 #define   MONITORRESOUCEID      11
00074   { MONITORRESOUCEID    , ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,8 } },
00075 #define   MONITORSTATISTICID    12
00076   { MONITORSTATISTICID  , ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,9 } },
00077 #define   MONITORLASTVALUELOW   13
00078   { MONITORLASTVALUELOW , ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,10 } },
00079 #define   MONITORLASTVALUEHIGH  14
00080   { MONITORLASTVALUEHIGH, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,11 } },
00081 #define   MONITORSTARTTIME      15
00082   { MONITORSTARTTIME    , ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,12 } },
00083 #define   MONITORSTOPTIME       16
00084   { MONITORSTOPTIME     , ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,13 } },
00085 #define   MONITORTHRESHOLDLASTEVENTTIME  17
00086   { MONITORTHRESHOLDLASTEVENTTIME, ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,14 } },
00087 #define   MONITORHIGHWATERMARKVALUELOW  18
00088   { MONITORHIGHWATERMARKVALUELOW, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,15 } },
00089 #define   MONITORHIGHWATERMARKVALUEHIGH  19
00090   { MONITORHIGHWATERMARKVALUEHIGH, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,16 } },
00091 #define   MONITORLOWWATERMARKVALUELOW  20
00092   { MONITORLOWWATERMARKVALUELOW, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,17 } },
00093 #define   MONITORLOWWATERMARKVALUEHIGH  21
00094   { MONITORLOWWATERMARKVALUEHIGH, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,18 } },
00095 #define   MONITORHIGHWATERMARKTIME  22
00096   { MONITORHIGHWATERMARKTIME, ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,19 } },
00097 #define   MONITORLOWWATERMARKTIME  23
00098   { MONITORLOWWATERMARKTIME, ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,20 } },
00099 #define   MONITORLEAKYBUCKETLASTEVENTTIME  24
00100   { MONITORLEAKYBUCKETLASTEVENTTIME, ASN_OCTET_STR , RONLY , var_MonitorTable, 3, { 2,1,21 } },
00101 #define   MONITORLEAKYBUCKETVALUELOW  25
00102   { MONITORLEAKYBUCKETVALUELOW, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,22 } },
00103 #define   MONITORLEAKYBUCKETVALUEHIGH  26
00104   { MONITORLEAKYBUCKETVALUEHIGH, ASN_UNSIGNED  , RONLY , var_MonitorTable, 3, { 2,1,23 } },
00105 #define   MONITORNOTIFICATIONSTATUS  27
00106   { MONITORNOTIFICATIONSTATUS, ASN_INTEGER   , RONLY , var_MonitorTable, 3, { 2,1,24 } },
00107 #define   MONITORSTATUS         28
00108   { MONITORSTATUS       , ASN_INTEGER   , RONLY , var_MonitorTable, 3, { 2,1,25 } },
00109 #define   MONITORSNMPTRAP       29
00110   { MONITORSNMPTRAP     , ASN_INTEGER   , RWRITE, var_MonitorTable, 3, { 2,1,26 } },
00111 #define   MONITORCOMMAND        30
00112   { MONITORCOMMAND      , ASN_INTEGER   , RWRITE, var_MonitorTable, 3, { 2,1,27 } },
00113 
00114 };
00115 /*    (L = length of the oidsuffix) */
00116 
00117 
00118 /*
00119  * init_RMMonitors():
00120  *   Initialization routine.  This is called when the agent starts up.
00121  *   At a minimum, registration of your variables should take place here.
00122  */
00123 void init_RMMonitors(void) {
00124 
00125 
00126   /* register ourselves with the agent to handle our mib tree */
00127   REGISTER_MIB("RMMonitors", RMMonitors_variables, variable4,
00128                RMMonitors_variables_oid);
00129 
00130 
00131   /* place any other initialization junk you need here */
00132 }
00133 
00134 
00135 /*
00136  * var_RMMonitors():
00137  *   This function is called every time the agent gets a request for
00138  *   a scalar variable that might be found within your mib section
00139  *   registered above.  It is up to you to do the right thing and
00140  *   return the correct value.
00141  *     You should also correct the value of "var_len" if necessary.
00142  *
00143  *   Please see the documentation for more information about writing
00144  *   module extensions, and check out the examples in the examples
00145  *   and mibII directories.
00146  */
00147 unsigned char *
00148 var_RMMonitors(struct variable *vp, 
00149                 oid     *name, 
00150                 size_t  *length, 
00151                 int     exact, 
00152                 size_t  *var_len, 
00153                 WriteMethod **write_method)
00154 {
00155 
00156 
00157   /* variables we may use later */
00158   static u_long ulong_ret;
00159   /*
00160   static long long_ret;
00161   static unsigned char string[SPRINT_MAX_LEN];
00162   static oid objid[MAX_OID_LEN];
00163   static struct counter64 c64;
00164   */
00165 
00166 
00167   if (header_generic(vp,name,length,exact,var_len,write_method)
00168                                   == MATCH_FAILED )
00169     return NULL;
00170 
00171 
00172   /* 
00173    * this is where we do the value assignments for the mib results.
00174    */
00175   switch(vp->magic) {
00176 
00177 
00178     case MONITORNEXTINDEX:
00179         
00180         ulong_ret = getNewId(MONITOR);
00181         return (unsigned char *) &ulong_ret;
00182 
00183 
00184     default:
00185       ERROR_MSG("");
00186   }
00187   return NULL;
00188 }
00189 
00190 
00191 /*
00192  * var_MonitorTable():
00193  *   Handle this table separately from the scalar value case.
00194  *   The workings of this are basically the same as for var_RMMonitors above.
00195  */
00196 unsigned char *
00197 var_MonitorTable(struct variable *vp,
00198             oid     *name,
00199             size_t  *length,
00200             int     exact,
00201             size_t  *var_len,
00202             WriteMethod **write_method)
00203 {
00204 
00205 
00206   /* variables we may use later */
00207   static long long_ret;
00208   static u_long ulong_ret;
00209   static unsigned char string[SPRINT_MAX_LEN];
00210   /*
00211   static oid objid[MAX_OID_LEN];
00212   static struct counter64 c64;
00213   */
00214 
00215   static u_int64_t v64;
00216   unsigned long id;
00217 
00218   id = header_MyGeneric(vp,name,length,exact,var_len,write_method, MONITOR);
00219   if(id == 0) {
00220     switch(vp->magic) {
00221 
00222     case MONITORCONTROLINDEX:
00223         *write_method = write_monitorControlIndex;
00224         break;
00225 
00226     case MONITORCONFIGINDEX:
00227         *write_method = write_monitorConfigIndex;
00228         break;
00229 
00230     case MONITORSNMPTRAP:
00231         *write_method = write_monitorSNMPTrap;
00232         break;
00233 
00234     case MONITORCOMMAND:
00235         *write_method = write_monitorCommand;
00236         break;
00237 
00238     default:
00239         ERROR_MSG("");
00240 
00241     }
00242     return NULL;
00243   }
00244 
00245 
00246   /* 
00247    * this is where we do the value assignments for the mib results.
00248    */
00249   switch(vp->magic) {
00250 
00251 
00252     case MONITORUUID:
00253         
00254         *string = 0;
00255         getUUIDString(MONITOR, MONITOR_UUID, id, string);
00256         *var_len = strlen(string);
00257         return (unsigned char *) string;
00258 
00259     case MONITORCONTROLINDEX:
00260         *write_method = write_monitorControlIndex;
00261         ulong_ret = 0;
00262         getUnsigned(MONITOR, MONITOR_CONTROLID, id, &ulong_ret);
00263         return (unsigned char *) &ulong_ret;
00264 
00265     case MONITORCONFIGINDEX:
00266         *write_method = write_monitorConfigIndex;
00267         ulong_ret = 0;
00268         getUnsigned(MONITOR, MONITOR_CONFIGID, id, &ulong_ret);
00269         return (unsigned char *) &ulong_ret;
00270 
00271     case MONITORLOCATION:
00272         
00273         long_ret = 0;
00274         getInteger32(MONITOR, MONITOR_LOCATION, id, &long_ret);
00275         return (unsigned char *) &long_ret;
00276 
00277     case MONITORTYPE:
00278         
00279         long_ret = 0;
00280         getInteger32(MONITOR, MONITOR_TYPE, id, &long_ret);
00281         return (unsigned char *) &long_ret;
00282 
00283     case MONITORSUBSYSTEMID:
00284         
00285         ulong_ret = 0;
00286         getUnsigned(MONITOR, MONITOR_SUBSYSTEMID, id, &ulong_ret);
00287         return (unsigned char *) &ulong_ret;
00288 
00289     case MONITORRESOUCEID:
00290         
00291         ulong_ret = 0;
00292         getUnsigned(MONITOR, MONITOR_RESORUCEID, id, &ulong_ret);
00293         return (unsigned char *) &ulong_ret;
00294 
00295     case MONITORSTATISTICID:
00296         
00297         ulong_ret = 0;
00298         getUnsigned(MONITOR, MONITOR_STATISTICID, id, &ulong_ret);
00299         return (unsigned char *) &ulong_ret;
00300 
00301     case MONITORLASTVALUELOW:
00302         
00303         ulong_ret = 0;
00304         getUnsigned(MONITOR, MONITOR_LASTVALUE32, id, &ulong_ret);
00305         return (unsigned char *) &ulong_ret;
00306 
00307     case MONITORLASTVALUEHIGH:
00308         
00309         v64 = 0;
00310         getUnsigned64(MONITOR, MONITOR_LASTVALUE64, id, &v64);
00311         ulong_ret = getHigh32(v64);
00312         return (unsigned char *) &ulong_ret;
00313 
00314     case MONITORSTARTTIME:
00315         
00316         *string = 0;
00317         ulong_ret = 0;
00318         getUnsigned(MONITOR, MONITOR_STARTTIME, id, &ulong_ret);
00319         if(ulong_ret) 
00320           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00321 
00322         *var_len = strlen(string);
00323         return (unsigned char *) string;
00324 
00325     case MONITORSTOPTIME:
00326         
00327         *string = 0;
00328         ulong_ret = 0;
00329         getUnsigned(MONITOR, MONITOR_STOPTIME, id, &ulong_ret);
00330         if(ulong_ret)
00331           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00332 
00333         *var_len = strlen(string);
00334         return (unsigned char *) string;
00335 
00336     case MONITORTHRESHOLDLASTEVENTTIME:
00337         
00338         *string = 0;
00339         ulong_ret = 0;
00340         getUnsigned(MONITOR, MONITOR_THRESHOLDLASTEVENTTIME, id, &ulong_ret);
00341         if(ulong_ret)
00342           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00343 
00344         *var_len = strlen(string);
00345         return (unsigned char *) string;
00346 
00347     case MONITORHIGHWATERMARKVALUELOW:
00348         
00349         ulong_ret = 0;
00350         getUnsigned(MONITOR, MONITOR_WATERMARKHIGH32, id, &ulong_ret);
00351         return (unsigned char *) &ulong_ret;
00352 
00353     case MONITORHIGHWATERMARKVALUEHIGH:
00354         
00355         v64 = 0;
00356         getUnsigned64(MONITOR, MONITOR_WATERMARKHIGH64, id, &v64);
00357         ulong_ret = getHigh32(v64);
00358         return (unsigned char *) &ulong_ret;
00359 
00360     case MONITORLOWWATERMARKVALUELOW:
00361         
00362         ulong_ret = 0;
00363         getUnsigned(MONITOR, MONITOR_WATERMARKLOW32, id, &ulong_ret);
00364         return (unsigned char *) &ulong_ret;
00365 
00366     case MONITORLOWWATERMARKVALUEHIGH:
00367         
00368         v64 = 0;
00369         getUnsigned64(MONITOR, MONITOR_WATERMARKLOW64, id, &v64);
00370         ulong_ret = getHigh32(v64);
00371         return (unsigned char *) &ulong_ret;
00372 
00373     case MONITORHIGHWATERMARKTIME:
00374         
00375         *string = 0;
00376         ulong_ret = 0;
00377         getUnsigned(MONITOR, MONITOR_WATERMARKHIGHTIME, id, &ulong_ret);
00378         if(ulong_ret)
00379           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00380 
00381         *var_len = strlen(string);
00382         return (unsigned char *) string;
00383 
00384     case MONITORLOWWATERMARKTIME:
00385         
00386         *string = 0;
00387         ulong_ret = 0;
00388         getUnsigned(MONITOR, MONITOR_WATERMARKLOWTIME, id, &ulong_ret);
00389         if(ulong_ret)
00390           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00391 
00392         *var_len = strlen(string);
00393         return (unsigned char *) string;
00394 
00395     case MONITORLEAKYBUCKETLASTEVENTTIME:
00396         
00397         *string = 0;
00398         ulong_ret = 0;
00399         getUnsigned(MONITOR, MONITOR_LEAKYBUCKETLASTEVENTTIME, id, &ulong_ret);
00400         if(ulong_ret)
00401           strncpy(string, ctime((const time_t *) &ulong_ret), SPRINT_MAX_LEN);
00402 
00403         *var_len = strlen(string);
00404         return (unsigned char *) string;
00405 
00406     case MONITORLEAKYBUCKETVALUELOW:
00407         
00408         ulong_ret = 0;
00409         getUnsigned(MONITOR, MONITOR_LEAKYBUCKETLEVEL32, id, &ulong_ret);
00410         return (unsigned char *) &ulong_ret;
00411 
00412     case MONITORLEAKYBUCKETVALUEHIGH:
00413         
00414         v64 = 0;
00415         getUnsigned64(MONITOR, MONITOR_LEAKYBUCKETLEVEL64, id, &v64);
00416         ulong_ret = getHigh32(v64);
00417         return (unsigned char *) &ulong_ret;
00418 
00419     case MONITORNOTIFICATIONSTATUS:
00420         
00421         long_ret = 0;
00422         getInteger32(MONITOR, MONITOR_NOTIFICATIONPAUSED, id, &long_ret);
00423         return (unsigned char *) &long_ret;
00424 
00425     case MONITORSTATUS:
00426         
00427         long_ret = 0;
00428         getInteger32(MONITOR, MONITOR_STATUS, id, &long_ret);
00429         return (unsigned char *) &long_ret;
00430 
00431     case MONITORSNMPTRAP:
00432         *write_method = write_monitorSNMPTrap;
00433         long_ret = 0;
00434         getInteger32(MONITOR, MONITOR_SNMPTRAP, id, &long_ret);
00435         if(long_ret ==0)
00436           long_ret = 2;
00437         return (unsigned char *) &long_ret;
00438 
00439     case MONITORCOMMAND:
00440         *write_method = write_monitorCommand;
00441         long_ret = 0;
00442         getInteger32(MONITOR, MONITOR_COMMAND, id, &long_ret);
00443         return (unsigned char *) &long_ret;
00444 
00445 
00446     default:
00447       ERROR_MSG("");
00448   }
00449   return NULL;
00450 }
00451 
00452 
00453 
00454 
00455 int
00456 write_monitorControlIndex(int      action,
00457             u_char   *var_val,
00458             u_char   var_val_type,
00459             size_t   var_val_len,
00460             u_char   *statP,
00461             oid      *name,
00462             size_t   name_len)
00463 {
00464   static unsigned long *ulong_ret;
00465   int size;
00466 
00467   int createNew, ret;
00468   unsigned long id;
00469   size_t prefix_len;
00470 
00471   static unsigned long oldVal;
00472 
00473   oid suffix[] = { 2, 1, 3 };
00474   createNew = 0;
00475   prefix_len = sizeof(RMMonitors_variables_oid)/sizeof(oid);
00476 
00477   id = header_writeGeneric(name, name_len, RMMonitors_variables_oid, prefix_len, suffix, 3, MONITOR, &createNew);
00478 
00479   if(id == 0 || (createNew && action == ACTION))
00480     return SNMP_ERR_NOSUCHNAME;
00481 
00482 
00483   switch ( action ) {
00484         case RESERVE1:
00485           if (var_val_type != ASN_UNSIGNED){
00486               fprintf(stderr, "write to monitorControlIndex not ASN_UNSIGNED\n");
00487               return SNMP_ERR_WRONGTYPE;
00488           }
00489           if (var_val_len > sizeof(ulong_ret)){
00490               fprintf(stderr,"write to monitorControlIndex: bad length\n");
00491               return SNMP_ERR_WRONGLENGTH;
00492           }
00493           break;
00494 
00495 
00496         case RESERVE2:
00497           size = var_val_len;
00498           ulong_ret = (unsigned long *) var_val;
00499 
00500           if(!createNew) {
00501             ret = getUnsigned(MONITOR, MONITOR_CONTROLID, id, &oldVal);
00502             if(ret)
00503               return SNMP_ERR_INCONSISTENTVALUE;
00504           }
00505 
00506 
00507           break;
00508 
00509 
00510         case FREE:
00511              /* Release any resources that have been allocated */
00512           break;
00513 
00514 
00515         case ACTION:
00516              /* The variable has been stored in ulong_ret for
00517              you to use, and you have just been asked to do something with
00518              it.  Note that anything done here must be reversable in the UNDO case */
00519           ret = setUnsigned(MONITOR, MONITOR_CONTROLID, id, *ulong_ret);
00520           if(ret)
00521             return SNMP_ERR_INCONSISTENTVALUE;
00522 
00523           break;
00524 
00525 
00526         case UNDO:
00527              /* Back out any changes made in the ACTION case */
00528           setUnsigned(MONITOR, MONITOR_CONTROLID, id, oldVal);
00529           break;
00530 
00531 
00532         case COMMIT:
00533              /* Things are working well, so it's now safe to make the change
00534              permanently.  Make sure that anything done here can't fail! */
00535           break;
00536   }
00537   return SNMP_ERR_NOERROR;
00538 }
00539 
00540 
00541 
00542 
00543 int
00544 write_monitorConfigIndex(int      action,
00545             u_char   *var_val,
00546             u_char   var_val_type,
00547             size_t   var_val_len,
00548             u_char   *statP,
00549             oid      *name,
00550             size_t   name_len)
00551 {
00552   static unsigned long *ulong_ret;
00553   int size;
00554 
00555   int createNew, ret;
00556   unsigned long id;
00557   size_t prefix_len;
00558 
00559   static unsigned long oldVal;
00560 
00561   oid suffix[] = { 2, 1, 4 };
00562   createNew = 0;
00563   prefix_len = sizeof(RMMonitors_variables_oid)/sizeof(oid);
00564 
00565   id = header_writeGeneric(name, name_len, RMMonitors_variables_oid, prefix_len, suffix, 3, MONITOR, &createNew);
00566 
00567   if(id == 0 || (createNew && action == ACTION))
00568     return SNMP_ERR_NOSUCHNAME;
00569 
00570 
00571   switch ( action ) {
00572         case RESERVE1:
00573           if (var_val_type != ASN_UNSIGNED){
00574               fprintf(stderr, "write to monitorConfigIndex not ASN_UNSIGNED\n");
00575               return SNMP_ERR_WRONGTYPE;
00576           }
00577           if (var_val_len > sizeof(ulong_ret)){
00578               fprintf(stderr,"write to monitorConfigIndex: bad length\n");
00579               return SNMP_ERR_WRONGLENGTH;
00580           }
00581           break;
00582 
00583 
00584         case RESERVE2:
00585           size = var_val_len;
00586           ulong_ret = (unsigned long *) var_val;
00587 
00588           if(!createNew) {
00589             ret = getUnsigned(MONITOR, MONITOR_CONFIGID, id, &oldVal);
00590             if(ret)
00591               return SNMP_ERR_INCONSISTENTVALUE;
00592           }
00593 
00594 
00595           break;
00596 
00597 
00598         case FREE:
00599              /* Release any resources that have been allocated */
00600           break;
00601 
00602 
00603         case ACTION:
00604              /* The variable has been stored in ulong_ret for
00605              you to use, and you have just been asked to do something with
00606              it.  Note that anything done here must be reversable in the UNDO case */
00607           ret = setUnsigned(MONITOR, MONITOR_CONFIGID, id, *ulong_ret);
00608           if(ret)
00609             return SNMP_ERR_INCONSISTENTVALUE;
00610 
00611           break;
00612 
00613 
00614         case UNDO:
00615              /* Back out any changes made in the ACTION case */
00616           setUnsigned(MONITOR, MONITOR_CONFIGID, id, oldVal);
00617           break;
00618 
00619 
00620         case COMMIT:
00621              /* Things are working well, so it's now safe to make the change
00622              permanently.  Make sure that anything done here can't fail! */
00623           break;
00624   }
00625   return SNMP_ERR_NOERROR;
00626 }
00627 
00628 
00629 
00630 
00631 int
00632 write_monitorSNMPTrap(int      action,
00633             u_char   *var_val,
00634             u_char   var_val_type,
00635             size_t   var_val_len,
00636             u_char   *statP,
00637             oid      *name,
00638             size_t   name_len)
00639 {
00640   static long *long_ret;
00641   int size;
00642 
00643   int createNew, ret;
00644   unsigned long id;
00645   size_t prefix_len;
00646 
00647   static long oldVal;
00648 
00649   oid suffix[] = { 2, 1, 26 };
00650   createNew = 0;
00651   prefix_len = sizeof(RMMonitors_variables_oid)/sizeof(oid);
00652 
00653   id = header_writeGeneric(name, name_len, RMMonitors_variables_oid, prefix_len, suffix, 3, MONITOR, &createNew);
00654 
00655   if(id == 0 || (createNew && action == ACTION))
00656     return SNMP_ERR_NOSUCHNAME;
00657 
00658 
00659   switch ( action ) {
00660         case RESERVE1:
00661           if (var_val_type != ASN_INTEGER){
00662               fprintf(stderr, "write to monitorSNMPTrap not ASN_INTEGER\n");
00663               return SNMP_ERR_WRONGTYPE;
00664           }
00665           if (var_val_len > sizeof(long_ret)){
00666               fprintf(stderr,"write to monitorSNMPTrap: bad length\n");
00667               return SNMP_ERR_WRONGLENGTH;
00668           }
00669           break;
00670 
00671 
00672         case RESERVE2:
00673           size = var_val_len;
00674           long_ret = (long *) var_val;
00675 
00676           if(!createNew) {
00677             ret = getInteger32(MONITOR, MONITOR_SNMPTRAP, id, &oldVal);
00678             if(ret)
00679               return SNMP_ERR_INCONSISTENTVALUE;
00680           }
00681 
00682 
00683           break;
00684 
00685 
00686         case FREE:
00687              /* Release any resources that have been allocated */
00688           break;
00689 
00690 
00691         case ACTION:
00692              /* The variable has been stored in long_ret for
00693              you to use, and you have just been asked to do something with
00694              it.  Note that anything done here must be reversable in the UNDO case */
00695           ret = setInteger32(MONITOR, MONITOR_SNMPTRAP, id, *long_ret);
00696           if(ret)
00697             return SNMP_ERR_INCONSISTENTVALUE;
00698 
00699           break;
00700 
00701 
00702         case UNDO:
00703              /* Back out any changes made in the ACTION case */
00704           setInteger32(MONITOR, MONITOR_SNMPTRAP, id, oldVal);
00705 
00706           break;
00707 
00708 
00709         case COMMIT:
00710              /* Things are working well, so it's now safe to make the change
00711              permanently.  Make sure that anything done here can't fail! */
00712           break;
00713   }
00714   return SNMP_ERR_NOERROR;
00715 }
00716 
00717 
00718 
00719 
00720 int
00721 write_monitorCommand(int      action,
00722             u_char   *var_val,
00723             u_char   var_val_type,
00724             size_t   var_val_len,
00725             u_char   *statP,
00726             oid      *name,
00727             size_t   name_len)
00728 {
00729   static long *long_ret;
00730   int size;
00731 
00732   int createNew, ret;
00733   unsigned long id;
00734   size_t prefix_len;
00735 
00736   static int rowCreated;
00737 
00738   oid suffix[] = { 2, 1, 27 };
00739   createNew = 0;
00740   prefix_len = sizeof(RMMonitors_variables_oid)/sizeof(oid);
00741 
00742   id = header_writeGeneric(name, name_len, RMMonitors_variables_oid, prefix_len, suffix, 3, MONITOR, &createNew);
00743 
00744   if(action == COMMIT && *long_ret == DELETE_MONITOR && id ==0)
00745     return SNMP_ERR_NOERROR;
00746 
00747   if(id == 0)
00748     return SNMP_ERR_NOSUCHNAME;
00749 
00750 
00751   switch ( action ) {
00752         case RESERVE1:
00753           if (var_val_type != ASN_INTEGER){
00754               fprintf(stderr, "write to monitorCommand not ASN_INTEGER\n");
00755               return SNMP_ERR_WRONGTYPE;
00756           }
00757           if (var_val_len > sizeof(long_ret)){
00758               fprintf(stderr,"write to monitorCommand: bad length\n");
00759               return SNMP_ERR_WRONGLENGTH;
00760           }
00761           break;
00762 
00763 
00764         case RESERVE2:
00765           size = var_val_len;
00766           long_ret = (long *) var_val;
00767 
00768           rowCreated = 0;
00769           if (*long_ret < NEW_MONITORENTRY || *long_ret > RESET_NOTIFICATION) 
00770             return SNMP_ERR_INCONSISTENTVALUE;
00771 
00772           if(createNew &&
00773               (*long_ret != NEW_MONITORENTRY && *long_ret != CREATE_MONITOR))
00774             return SNMP_ERR_INCONSISTENTVALUE;
00775 
00776 
00777           break;
00778 
00779 
00780         case FREE:
00781              /* Release any resources that have been allocated */
00782           break;
00783 
00784 
00785         case ACTION:
00786              /* The variable has been stored in long_ret for
00787              you to use, and you have just been asked to do something with
00788              it.  Note that anything done here must be reversable in the UNDO case */
00789           if(*long_ret == NEW_MONITORENTRY || *long_ret == CREATE_MONITOR) {
00790 
00791             if(createNew) {
00792               ret =  newEntry(MONITOR, id);
00793               if(ret)
00794                 return SNMP_ERR_INCONSISTENTVALUE;
00795 
00796               rowCreated = 1;
00797             }
00798           }
00799           else {
00800             ret = setInteger32(MONITOR, MONITOR_COMMAND, id, *long_ret);
00801             if(ret)
00802               return SNMP_ERR_INCONSISTENTVALUE;
00803           }
00804           break;
00805 
00806 
00807         case UNDO:
00808              /* Back out any changes made in the ACTION case */
00809           if(rowCreated) {
00810             deleteEntry(MONITOR, id);
00811           }
00812           else {
00813 
00814             // note: don't know how to back up commands either. 
00815             
00816           }
00817           break;
00818 
00819 
00820         case COMMIT:
00821              /* Things are working well, so it's now safe to make the change
00822              permanently.  Make sure that anything done here can't fail! */
00823           if(*long_ret == CREATE_MONITOR) {
00824             ret = setInteger32(MONITOR, MONITOR_COMMAND, id, CREATE_MONITOR);
00825             if(ret)
00826               return SNMP_ERR_COMMITFAILED;
00827           }
00828 
00829           break;
00830   }
00831   return SNMP_ERR_NOERROR;
00832 }
00833 
00834 
00835 
00836 
00837 
00838 

Generated on Tue Sep 10 16:46:33 2002 for ResourceMonitorSNMPSubagent by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002