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

rmMonitor.cpp

Go to the documentation of this file.
00001 #include "rmMonitor.h"
00002 #include "rmClientError.h"
00003 #include <ResourceMonitor/ResourceMonitor.h>
00004 
00005 rmString RM_MONITOR_NAME = "RMSubagent, ID=cfa60dcc-cf41-4253-a60a-f1946552938e";
00006 
00007 
00019 int
00020 rmMonitor::removeElement(unsigned long aID)
00021 {
00022   int ret;
00023 
00024   if (aID > mMaxId)
00025     return RMCLIENT_ERROR_BASE_ID;
00026 
00027   map<unsigned long, Monitor>::iterator pos;
00028 
00029   pos = mElementArray.find(aID);
00030   if(pos == mElementArray.end())
00031     return RMCLIENT_ERROR_BASE_ID;
00032   else {
00033     pos->second.command = DELETE_MONITOR;
00034 
00035     // uuid_t uuid = pos->second.uuid;
00036 
00037     // remove the monitor from the deamon if necessary
00038     rmHandle handle = NULL;
00039     handle = ResourceMonitor::rmAccessMonitor(pos->second.uuid);
00040     if(handle) {
00041       ret = ResourceMonitor::rmDeleteMonitor(handle);
00042       if(ret)
00043         return RMCLIENT_ERROR_MONITOR_COMMAND;
00044     }
00045 
00046     unsigned long ctid = pos->second.controlId;
00047     unsigned long cfid = pos->second.configId; 
00048 
00049     if(ctid > 0) {
00050       mGenericControl->release(ctid);
00051     }
00052 
00053     if(cfid > 0) {
00054       mGenericConfig->release(cfid);
00055     }
00056     mElementArray.erase(pos);
00057   }
00058 
00059   return RMCLIENT_SUCCESS;
00060 }
00061 
00062 /*
00063  * watermarkconfig and watermarkcontrol has not been implemented yet.
00064  */
00065 
00076 int
00077 rmMonitor::init()
00078 {
00079   size_t count = ResourceMonitor::rmGetMonitorCount();
00080 
00081   if(count) {
00082     rmMonitorInfo * minfo;
00083     minfo = new rmMonitorInfo[count];
00084     if(!minfo)
00085       return RMCLIENT_ERROR_MEMORY;
00086 
00087     int ret = ResourceMonitor::rmGetMonitors(minfo, &count);
00088     if(ret)
00089       return RMCLIENT_ERROR_PERSISTENT_MONITOR;
00090 
00091     rmHandle mhandle;
00092     rmMonitorState mstate;
00093     rmMonitorControl mcontrol;
00094     rmMonitorConfiguration mconfig;
00095 
00096     GenericControl gcontrol;
00097     GenericConfig gconfig;
00098     // size_t gControlIndex, gConfigIndex, tindex;
00099     unsigned long gconfigid, gcontrolid, tconfid, tctrlid, mid, wconfid, lconfid, lctrlid;
00100 
00101     rmString mname;
00102 
00103     for (int i=0; i<count; i++){
00104       mhandle = ResourceMonitor::rmAccessMonitor(minfo[i].uid);
00105       if(!mhandle)
00106         return RMCLIENT_ERROR_ACCESS_MONITOR;
00107 
00108       // if it is not a monitor created by us, then skip it.
00109       mname = ResourceMonitor::rmGetMonitorDescription(mhandle, rmShortDescription);
00110       if(strcmp(mname, RM_MONITOR_NAME)) {
00111         free(mname);
00112         continue;
00113       }
00114       free(mname);
00115 
00116       ret = ResourceMonitor::rmGetMonitorState(mhandle, &mstate);
00117       if(ret)
00118         return RMCLIENT_ERROR_MONITOR_STATE;
00119 
00120       ret = ResourceMonitor::rmGetMonitorControl(mhandle, &mcontrol);
00121       if(ret)
00122         return RMCLIENT_ERROR_MONITOR_CONTROL;
00123 
00124       ret = ResourceMonitor::rmGetMonitorConfiguration(mhandle, &mconfig);
00125       if(ret)
00126         return RMCLIENT_ERROR_MONITOR_CONFIG;
00127 
00128       ThresholdControl tcontrol;
00129       LeakyBucketControl lcontrol;
00130       ThresholdConfig tconfig;
00131       WatermarkConfig wconfig;
00132       LeakyBucketConfig lconfig;
00133 
00134       switch(mcontrol.monitorType) {
00135         case rmThresholding:
00136           tcontrol.control = mcontrol.typeControl.threshold;
00137           tcontrol.status = ACTIVE;
00138           mThresholdControl->newElement(tcontrol, tctrlid);
00139 
00140           // need to addref it
00141           mThresholdControl->addRef(tctrlid);
00142 
00143           gcontrol.thresholdControlId = tctrlid;
00144           gcontrol.leakyBucketControlId = 0;
00145           gcontrol.control = mcontrol;
00146           gcontrol.status = ACTIVE;
00147           mGenericControl->newElement(gcontrol, gcontrolid);
00148 
00149           // need to addref it
00150           mGenericControl->addRef(gcontrolid);
00151 
00152           tconfig.config = mconfig.typeConfiguration.threshold;
00153           tconfig.status = ACTIVE;
00154           mThresholdConfig->newElement(tconfig, tconfid);
00155 
00156           // need to addref this
00157           mThresholdConfig->addRef(tconfid);
00158 
00159           gconfig.thresholdConfigId = tconfid;
00160           gconfig.watermarkConfigId = 0;
00161           gconfig.leakyBucketConfigId = 0;
00162           gconfig.subsystemId = mSubsystemInfo->getSubsystemIDByUUID(mconfig.statisticKey.SubsystemId);
00163           // gconfig.subsystemId = gSysInfo->getSubsystemId(&mconfig.statId.SubsystemId);
00164           gconfig.config = mconfig;
00165           gconfig.status = ACTIVE;
00166           mGenericConfig->newElement(gconfig, gconfigid);
00167 
00168           // need to addref this
00169           mGenericConfig->addRef(gconfigid);
00170 
00171           break;
00172 
00173         case rmWatermarking:
00174 
00175           gcontrol.thresholdControlId = 0;
00176           gcontrol.leakyBucketControlId = 0;
00177           gcontrol.control = mcontrol;
00178           gcontrol.status = ACTIVE;
00179           mGenericControl->newElement(gcontrol, gcontrolid);
00180 
00181           // need to addref it
00182           mGenericControl->addRef(gcontrolid);
00183 
00184           wconfig.config = mconfig.typeConfiguration.watermark;
00185           wconfig.status = ACTIVE;
00186           mWatermarkConfig->newElement(wconfig, wconfid);
00187 
00188           // addref
00189           mWatermarkConfig->addRef(wconfid);
00190 
00191           gconfig.thresholdConfigId = 0;
00192           gconfig.watermarkConfigId = wconfid;
00193           gconfig.leakyBucketConfigId = 0;
00194           gconfig.subsystemId = mSubsystemInfo->getSubsystemIDByUUID(mconfig.statisticKey.SubsystemId);
00195           // gconfig.subsystemId = gSysInfo->getSubsystemId(&mconfig.statId.SubsystemId);
00196           gconfig.config = mconfig;
00197           gconfig.status = ACTIVE;
00198           mGenericConfig->newElement(gconfig, gconfigid);
00199 
00200           // need to addref this
00201           mGenericConfig->addRef(gconfigid);
00202 
00203           break;
00204 
00205         case rmLeakyBucket:
00206 
00207           lcontrol.control = mcontrol.typeControl.leakyBucket;
00208           lcontrol.status = ACTIVE;
00209           mLeakyBucketControl->newElement(lcontrol, lctrlid);
00210 
00211           // need to addref it
00212           mLeakyBucketControl->addRef(lctrlid);
00213 
00214           gcontrol.thresholdControlId = 0;
00215           gcontrol.leakyBucketControlId = lctrlid;
00216           gcontrol.control = mcontrol;
00217           gcontrol.status = ACTIVE;
00218           mGenericControl->newElement(gcontrol, gcontrolid);
00219 
00220           // need to addref it
00221           mGenericControl->addRef(gcontrolid);
00222 
00223           lconfig.config = mconfig.typeConfiguration.leakyBucket;
00224           lconfig.status = ACTIVE;
00225           mLeakyBucketConfig->newElement(lconfig, lconfid);
00226 
00227           // addref
00228           mLeakyBucketConfig->addRef(lconfid);
00229 
00230           gconfig.thresholdConfigId = 0;
00231           gconfig.watermarkConfigId = 0;
00232           gconfig.leakyBucketConfigId = lconfid;
00233           gconfig.subsystemId = mSubsystemInfo->getSubsystemIDByUUID(mconfig.statisticKey.SubsystemId);
00234           // gconfig.subsystemId = gSysInfo->getSubsystemId(&mconfig.statId.SubsystemId);
00235           gconfig.config = mconfig;
00236           gconfig.status = ACTIVE;
00237           mGenericConfig->newElement(gconfig, gconfigid);
00238 
00239           // need to addref this
00240           mGenericConfig->addRef(gconfigid);
00241 
00242           break;
00243       }
00244 
00245       Monitor mon;
00246 
00247       mon.controlId = gcontrolid;
00248       mon.configId = gconfigid;
00249       mon.uuid = minfo[i].uid;
00250       mon.command = 0;
00251       mon.nfHandle = 0;
00252 
00253       unsigned long monid ;
00254       newElement(mon, monid);
00255     }
00256   }
00257   return RMCLIENT_SUCCESS;
00258 }
00259 
00260 bool
00261 rmMonitor::elementIsReady(const Monitor & aElement) const
00262 {
00263   if(aElement.controlId < 0)
00264     return false;
00265 
00266   if(aElement.configId < 0)
00267     return false;
00268 
00269   return true;
00270 }
00271 
00272 int
00273 rmMonitor::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00274 {
00275   int ret;
00276   rmHandle handle = NULL;
00277   rmMonitorState state;
00278   const GenericControl * gcontrol;
00279 
00280   aValue = -1;
00281   const Monitor * monitor = getConstElement(aID);
00282   if(!monitor)
00283     return RMCLIENT_ERROR_MONITOR;
00284 
00285   if(aName == MONITOR_COMMAND) {
00286     aValue = monitor->command;
00287     return RMCLIENT_SUCCESS;
00288   }
00289 
00290   else if (aName == MONITOR_SNMPTRAP) {
00291     if(monitor->nfHandle) 
00292       aValue = 1;
00293     else 
00294       aValue = 0;
00295 
00296     return RMCLIENT_SUCCESS;
00297   }
00298 
00299   else if(aName == MONITOR_LOCATION) {
00300     if(monitor->controlId > 0) {
00301       gcontrol = mGenericControl->getConstElement(monitor->controlId);
00302       if(!gcontrol)
00303         return RMCLIENT_ERROR_GENERIC_CONTROL;
00304 
00305       aValue = gcontrol->control.location;
00306     }
00307     return RMCLIENT_SUCCESS;
00308   }
00309 
00310   // if monitor is not created yet, then return.
00311   if(uuid_is_null((unsigned char*)monitor->uuid))
00312     return RMCLIENT_SUCCESS;
00313 
00314   handle = ResourceMonitor::rmAccessMonitor(monitor->uuid);
00315   if(handle) {
00316     ret = ResourceMonitor::rmGetMonitorState(handle, &state);
00317     if(ret) {
00318       // something is wrong with the monitor.
00319       // assume we don't have the handle.
00320       return RMCLIENT_ERROR_MONITOR_STATE;
00321     }
00322   }
00323 
00324   switch(aName) {
00325 
00326     case MONITOR_TYPE:
00327       aValue = state.monitorType;
00328       break;
00329 
00330     case MONITOR_STATUS:
00331       // this is the case that monitor does not exist yet.
00332       if(!handle)
00333         aValue = NOTEXIST;
00334 
00335       aValue = state.currentStatus;
00336       break;
00337 
00338     case MONITOR_NOTIFICATIONPAUSED:
00339       aValue = state.notificationPaused;
00340       break;
00341 
00342     default:
00343       return RMCLIENT_ERROR_NOSUCHNAME;
00344   }
00345   return RMCLIENT_SUCCESS;
00346 }
00347 
00348 int
00349 rmMonitor::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00350 {
00351   int ret;
00352 
00353   Monitor * monitor = getElement(aID);
00354   if(!monitor)
00355     return RMCLIENT_ERROR_MONITOR;
00356 
00357   long oldControl, oldConfig;
00358   GenericControl * control = NULL;
00359   const GenericConfig * config = NULL;
00360   GenericControl ctrl;
00361   rmHandle handle = NULL;
00362 
00363   char uuid_str[UUID_STRING_LENGTH];
00364   size_t buf(256);
00365   char query_str[buf];
00366   char error_str[buf];
00367   int flag = POSIX_LOG_SEND_RECID & POSIX_LOG_SEND_SIGVAL;
00368 
00369   posix_log_query_t query;
00370   posix_log_notify_t nfhandle;
00371   struct sigevent notification;
00372 
00373   handle = ResourceMonitor::rmAccessMonitor(monitor->uuid);
00374 
00375   switch(aName) {
00376     case MONITOR_SNMPTRAP:
00377       // "1" is "true" as truthValue defined in SNMPv2-TC.
00378       if(aValue == 1) {
00379 
00380         // if we already have notification set up, just return.
00381         if(monitor->nfHandle)
00382           return RMCLIENT_SUCCESS;
00383 
00384         // create notification
00385         if(!handle) 
00386           return RMCLIENT_ERROR_ACCESS_MONITOR;
00387 
00388         // creating query string
00389         uuid_unparse(monitor->uuid, uuid_str);
00390         snprintf(query_str, buf, "data contains \"Monitor_ID=%s\"", uuid_str);
00391         ret =  posix_log_query_create(query_str, POSIX_LOG_PRPS_NOTIFY,
00392             &query, error_str, buf);
00393 
00394         if(ret)
00395           return RMCLIENT_ERROR_QUERY;
00396 
00397         // creating notification.
00398         notification.sigev_notify = SIGEV_SIGNAL;
00399         notification.sigev_signo = SIGRTMIN + 1;
00400         notification.sigev_value.sival_int = aID;
00401 
00402         ret = posix_log_notify_add(&query, &notification,
00403             flag, &nfhandle);
00404 
00405         if(ret)
00406           return RMCLIENT_ERROR_NOTIFY_CREATE;
00407 
00408         monitor->nfHandle = nfhandle;
00409       }
00410       // "2" is false as truthValue defined in SNMPv2-TC
00411       else if(aValue == 2) {
00412         if(!handle || monitor->nfHandle == 0)
00413           return RMCLIENT_SUCCESS;
00414 
00415         ret = posix_log_notify_remove(monitor->nfHandle);
00416         if(ret)
00417           return RMCLIENT_ERROR_NOTIFY_DESTROY;
00418 
00419         monitor->nfHandle = 0;
00420       }
00421       else 
00422         return RMCLIENT_ERROR_NOSUCHVALUE;
00423 
00424       break;
00425 
00426     case MONITOR_COMMAND:
00427 
00428       if(!handle && (aValue != CREATE_MONITOR && aValue != DELETE_MONITOR)) {
00429 
00430         return RMCLIENT_ERROR_ACCESS_MONITOR;
00431       }
00432 
00433       if(aValue == START_MONITOR) {
00434         ret = ResourceMonitor::rmStartMonitor(handle);
00435         if(ret)
00436           return RMCLIENT_ERROR_MONITOR_COMMAND;
00437       }
00438       else if(aValue == STOP_MONITOR) {
00439         ret = ResourceMonitor::rmStopMonitor(handle);
00440         if(ret)
00441           return RMCLIENT_ERROR_MONITOR_COMMAND;
00442       }
00443       else if(aValue == RESET_MONITOR) {
00444         ret = ResourceMonitor::rmResetMonitor(handle);
00445         if(ret)
00446           return RMCLIENT_ERROR_MONITOR_COMMAND;
00447       }
00448       else if(aValue == DELETE_MONITOR) {
00449 
00450         // return directly. 
00451         // no modifyElement necessary since it's been removed
00452 
00453         return removeElement(aID);
00454       }
00455       else if(aValue == PAUSE_NOTIFICATION) {
00456         ret = ResourceMonitor::rmPauseNotification(handle);
00457         if(ret)
00458           return RMCLIENT_ERROR_MONITOR_COMMAND;
00459       }
00460       else if(aValue == RESET_NOTIFICATION) {
00461         ret = ResourceMonitor::rmResetNotification(handle);
00462         if(ret)
00463           return RMCLIENT_ERROR_MONITOR_COMMAND;
00464       }
00465       else if(aValue == CREATE_MONITOR) {
00466 
00467         config = mGenericConfig->getConstElement(monitor->configId);
00468         control = mGenericControl->getElement(monitor->controlId);
00469         if(!config || !control)
00470           return RMCLIENT_ERROR_MONITOR_COMMAND;
00471 
00472         handle = ResourceMonitor::rmCreateMonitor(&(config->config), &(control->control));
00473         if(!handle)
00474           return RMCLIENT_ERROR_MONITOR_COMMAND;
00475 
00476         monitor->uuid = control->control.uid;
00477 
00478         ret = ResourceMonitor::rmSetMonitorDescription(handle, rmShortDescription, RM_MONITOR_NAME);
00479         if(ret)
00480           return RMCLIENT_ERROR_MONITOR_COMMAND;
00481 
00482         // this special command is needed here because 
00483         // we can not just modify the control directly because it's been
00484         // addrefed.
00485         // updateMonitorControlByID(monitor->controlId, control);
00486       }
00487       else
00488         return RMCLIENT_ERROR_NOSUCHVALUE;
00489 
00490       monitor->command = aValue;
00491       break;
00492 
00493     default:
00494       return RMCLIENT_ERROR_NOSUCHNAME;
00495   }
00496 
00497   return RMCLIENT_SUCCESS;
00498 }
00499 
00500 int
00501 rmMonitor::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00502 {
00503   int ret;
00504   const GenericConfig * gconfig = NULL;
00505   rmHandle handle = NULL;
00506   rmMonitorState state;
00507 
00508   aValue = 0;
00509   const Monitor * monitor = getConstElement(aID);
00510   if(!monitor)
00511     return RMCLIENT_ERROR_MONITOR;
00512 
00513   if(aName == MONITOR_CONTROLID) {
00514     aValue = monitor->controlId;
00515     return RMCLIENT_SUCCESS;
00516   }
00517 
00518   if(aName == MONITOR_CONFIGID) {
00519     aValue = monitor->configId;
00520     return RMCLIENT_SUCCESS;
00521   }
00522 
00523   if(aName == MONITOR_RESORUCEID || aName == MONITOR_STATISTICID || 
00524      aName == MONITOR_SUBSYSTEMID) {
00525 
00526     if(monitor->configId > 0) {
00527       gconfig = mGenericConfig->getConstElement(monitor->configId);
00528       if(!gconfig)
00529         return RMCLIENT_ERROR_GENERIC_CONFIG;
00530 
00531       if(aName == MONITOR_RESORUCEID) 
00532         aValue = gconfig->config.statisticKey.ResourceId;
00533       else if(aName == MONITOR_STATISTICID) 
00534         aValue = gconfig->config.statisticKey.StatisticId;
00535       else if(aName == MONITOR_SUBSYSTEMID) 
00536         aValue = gconfig->subsystemId;
00537     }
00538     return RMCLIENT_SUCCESS;
00539   }
00540 
00541   // if monitor is not created yet, then return.
00542   if(uuid_is_null((unsigned char*)monitor->uuid))
00543     return RMCLIENT_SUCCESS;
00544 
00545   handle = ResourceMonitor::rmAccessMonitor(monitor->uuid);
00546   if(handle) {
00547     ret = ResourceMonitor::rmGetMonitorState(handle, &state);
00548     if(ret) {
00549       // something is wrong with the monitor.
00550       // assume we don't have the handle.
00551       return RMCLIENT_ERROR_MONITOR_STATE;
00552     }
00553   }
00554 
00555   switch(aName) {
00556 
00557     case MONITOR_LASTVALUE32:
00558       aValue = state.lastMonitoredValue.Value.rmValueU32;
00559       break;
00560 
00561     case MONITOR_STARTTIME:
00562       aValue = state.startTime;
00563       break;
00564 
00565     case MONITOR_STOPTIME:
00566       aValue = state.stopTime;
00567       break;
00568 
00569     case MONITOR_THRESHOLDLASTEVENTTIME:
00570       if(state.monitorType == rmThresholding) 
00571         aValue = state.typeState.threshold.LastEventTime;
00572       else 
00573         return RMCLIENT_ERROR_NOSUCHNAME;
00574       break;
00575 
00576     case MONITOR_WATERMARKHIGHTIME:
00577       if(state.monitorType == rmWatermarking) 
00578         aValue = state.typeState.watermark.highTime;
00579       else 
00580         return RMCLIENT_ERROR_NOSUCHNAME;
00581       break;
00582 
00583     case MONITOR_WATERMARKLOWTIME:
00584       if(state.monitorType == rmWatermarking) 
00585         aValue = state.typeState.watermark.lowTime;
00586       else 
00587         return RMCLIENT_ERROR_NOSUCHNAME;
00588       break;
00589 
00590     case MONITOR_WATERMARKHIGH32:
00591       if(state.monitorType == rmWatermarking) 
00592         aValue = state.typeState.watermark.highWatermark.rmValueU32;
00593       else 
00594         return RMCLIENT_ERROR_NOSUCHNAME;
00595       break;
00596 
00597     case MONITOR_WATERMARKLOW32:
00598       if(state.monitorType == rmWatermarking) 
00599         aValue = state.typeState.watermark.lowWatermark.rmValueU32;
00600       else 
00601         return RMCLIENT_ERROR_NOSUCHNAME;
00602       break;
00603 
00604     case MONITOR_LEAKYBUCKETLEVEL32:
00605       if(state.monitorType == rmLeakyBucket)
00606         aValue = state.typeState.leakyBucket.bucketLevel.rmValueU32;
00607       else 
00608         return RMCLIENT_ERROR_NOSUCHNAME;
00609       break;
00610 
00611     case MONITOR_LEAKYBUCKETLASTEVENTTIME:
00612       if(state.monitorType == rmLeakyBucket)
00613         aValue = state.typeState.leakyBucket.LastEventTime;
00614       else 
00615         return RMCLIENT_ERROR_NOSUCHNAME;
00616       break;
00617 
00618     default:
00619       return RMCLIENT_ERROR_NOSUCHNAME;
00620   }
00621   return RMCLIENT_SUCCESS;
00622 }
00623 
00624 int
00625 rmMonitor::setUnsigned(RMAttribute aName, unsigned long aID, unsigned long aValue)
00626 {
00627   int ret;
00628 
00629   Monitor * monitor = getElement(aID);
00630   if(!monitor)
00631     return RMCLIENT_ERROR_MONITOR;
00632 
00633   long oldControl, oldConfig;
00634   const GenericControl * control = NULL;
00635   const GenericConfig * config = NULL;
00636   GenericControl ctrl;
00637   rmHandle handle = NULL;
00638 
00639   handle = ResourceMonitor::rmAccessMonitor(monitor->uuid);
00640 
00641   switch(aName) {
00642     case MONITOR_CONTROLID:
00643 
00644       // release the old control if needed
00645       oldControl = monitor->controlId;
00646       if(oldControl > 0) {
00647         mGenericControl->release(oldControl);
00648       }
00649 
00650       // addref the new one 
00651       // control can only be addrefed once. 
00652       control = mGenericControl->getElement(aValue);
00653       // we can only refcnt control once.
00654       if(!control || control->status != ACTIVE || control->refCnt > 0)
00655         return RMCLIENT_ERROR_CC_REFCNT;
00656 
00657       ret = mGenericControl->addRef(aValue);
00658       if(ret < 0)
00659         return RMCLIENT_ERROR_CC_REFCNT;
00660 
00661       // if monitor exists, try to change the control
00662       if(handle) {
00663         ret = ResourceMonitor::rmSetMonitorControl(handle, &(control->control));        if(ret)
00664           return RMCLIENT_ERROR_MONITOR_CONTROL;
00665       }
00666 
00667       monitor->controlId = aValue;
00668       break;
00669 
00670     case MONITOR_CONFIGID:
00671 
00672       // release the old control if needed
00673       oldConfig = monitor->configId;
00674       if(oldConfig > 0) {
00675         mGenericConfig->release(oldConfig);
00676       }
00677 
00678       // addref the new
00679       config = mGenericConfig->getElement(aValue);
00680       if(!config || config->status != ACTIVE)
00681         return RMCLIENT_ERROR_MONITOR_CONFIG;
00682 
00683       mGenericConfig->addRef(aValue);
00684 
00685       // if monitor exists, try to change the config
00686       if(handle) {
00687         ret = ResourceMonitor::rmSetMonitorConfiguration(handle, &(config->config));
00688         if(ret)
00689           return RMCLIENT_ERROR_MONITOR_CONFIG;
00690       }
00691 
00692       monitor->configId = aValue;
00693       break;
00694 
00695     default:
00696       return RMCLIENT_ERROR_NOSUCHNAME;
00697   }
00698 
00699   // updateStatus(*monitor);
00700   return RMCLIENT_SUCCESS;
00701 }
00702 
00703 int
00704 rmMonitor::getUnsigned64(RMAttribute aName, unsigned long aID, u_int64_t & aValue)
00705 {
00706   int ret;
00707   rmMonitorState state;
00708   rmHandle handle;
00709 
00710   aValue = 0;
00711   const Monitor * monitor = getConstElement(aID);
00712   if(!monitor)
00713     return RMCLIENT_ERROR_MONITOR;
00714   
00715   // if monitor is not created yet, then return.
00716   if(uuid_is_null((unsigned char*)monitor->uuid))
00717     return RMCLIENT_SUCCESS;
00718 
00719   handle = ResourceMonitor::rmAccessMonitor(monitor->uuid);
00720   if(!handle)
00721     return RMCLIENT_ERROR_ACCESS_MONITOR;
00722 
00723   ret = ResourceMonitor::rmGetMonitorState(handle, &state);
00724   if(ret)
00725     return RMCLIENT_ERROR_MONITOR_STATE;
00726 
00727   switch(aName) {
00728 
00729     case MONITOR_LASTVALUE64:
00730 
00731       aValue = state.lastMonitoredValue.Value.rmValueU64;
00732       break;
00733 
00734     case MONITOR_WATERMARKHIGH64:
00735 
00736       if(state.monitorType != rmWatermarking)
00737         return RMCLIENT_ERROR_NOSUCHNAME;
00738 
00739       aValue = state.typeState.watermark.highWatermark.rmValueU64;
00740       break;
00741 
00742     case MONITOR_WATERMARKLOW64:
00743 
00744       if(state.monitorType != rmWatermarking)
00745         return RMCLIENT_ERROR_NOSUCHNAME;
00746 
00747       aValue = state.typeState.watermark.lowWatermark.rmValueU64;
00748       break;
00749 
00750     case MONITOR_LEAKYBUCKETLEVEL64:
00751 
00752       if(state.monitorType != rmLeakyBucket)
00753         return RMCLIENT_ERROR_NOSUCHNAME;
00754 
00755       aValue = state.typeState.leakyBucket.bucketLevel.rmValueU64;
00756       break;
00757 
00758     default:
00759       return RMCLIENT_ERROR_NOSUCHNAME;
00760   }
00761   return RMCLIENT_SUCCESS;
00762 }
00763 
00764 int
00765 rmMonitor::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00766 {
00767   if(aUUIDStr == NULL)
00768     return RMCLIENT_ERROR_BAD_POINTER;
00769 
00770   aUUIDStr[0] = '\0';
00771 
00772   uuid_t uuid;
00773   const GenericConfig * gconfig = NULL;
00774 
00775   const Monitor * monitor = getConstElement(aID);
00776   if(!monitor)
00777     return RMCLIENT_ERROR_MONITOR;
00778 
00779   switch(aName) {
00780     case MONITOR_UUID:
00781       uuid_unparse((unsigned char*)monitor->uuid, aUUIDStr);
00782       aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00783 
00784       break;
00785 
00786     case MONITOR_SUBSYSTEMUUID:
00787 
00788       if(monitor->configId > 0) {
00789         gconfig = mGenericConfig->getConstElement(monitor->configId);
00790         if(gconfig) {
00791           uuid_copy(uuid, (unsigned char *)gconfig->config.statisticKey.SubsystemId);
00792           uuid_unparse(uuid, aUUIDStr);
00793         } else 
00794           return RMCLIENT_ERROR_MONITOR_CONFIG;
00795       } else 
00796         return RMCLIENT_ERROR_NOSUCHVALUE;
00797 
00798       break;
00799 
00800     default:
00801       return RMCLIENT_ERROR_NOSUCHNAME;
00802   }
00803   return RMCLIENT_SUCCESS;
00804 
00805 }
00806 
00807 int
00808 rmMonitor::getUUID(RMAttribute aName, unsigned long aID, uuid_t aUUID)
00809 {
00810   if(aUUID == NULL)
00811     return RMCLIENT_ERROR_BAD_POINTER;
00812 
00813   uuid_clear(aUUID);
00814 
00815   const GenericConfig * gconfig = NULL;
00816 
00817   const Monitor * monitor = getConstElement(aID);
00818   if(!monitor)
00819     return RMCLIENT_ERROR_MONITOR;
00820 
00821   switch(aName) {
00822     case MONITOR_UUID:
00823       uuid_copy(aUUID, (unsigned char*)monitor->uuid);
00824       break;
00825 
00826     case MONITOR_SUBSYSTEMUUID:
00827 
00828       if(monitor->configId > 0) {
00829         gconfig = mGenericConfig->getConstElement(monitor->configId);
00830         if(gconfig) {
00831           uuid_copy(aUUID, (unsigned char *)gconfig->config.statisticKey.SubsystemId);        } else
00832           return RMCLIENT_ERROR_MONITOR_CONFIG;
00833       } else
00834         return RMCLIENT_ERROR_NOSUCHVALUE;
00835 
00836       break;
00837 
00838     default:
00839       return RMCLIENT_ERROR_NOSUCHNAME;
00840   }
00841   return RMCLIENT_SUCCESS;
00842 
00843 }
00844 
00845 

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