00001 #include <stdio.h>
00002 #include <wchar.h>
00003 #include <string.h>
00004
00005 #include <exception>
00006
00007
00008
00009 #include <ResourceMonitor/ResourceMonitor.h>
00010
00011 #include "rmClient.h"
00012
00013 #include "rmClientError.h"
00014 #include "rmSysInfo.h"
00015 #include "rmConfig.h"
00016 #include "rmControl.h"
00017 #include "rmMonitor.h"
00018 #include "rmEvent.h"
00019
00020 #include "eventLog.h"
00021
00022 #include "uuid/uuid.h"
00023
00024 #include <tcpd.h>
00025
00026 int allow_severity = LOG_INFO;
00027 int deny_severity = LOG_WARNING;
00028
00040 class subagentBase
00041 {
00042 public:
00043 subagentBase(){}
00044 virtual ~subagentBase(){}
00045
00047 virtual int init() = 0;
00048
00050 virtual void shutdown() = 0;
00051
00052 virtual int getInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long & aValue);
00053 virtual int setInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long aValue);
00054
00055 virtual int getUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long & aValue);
00056 virtual int setUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long aValue);
00057
00058 virtual int getUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t & aValue);
00059 virtual int setUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t aValue);
00060
00061 virtual int getUUID(RMEntity aEntity, RMAttribute aName, unsigned long aID, uuid_t aUUID);
00062
00063 virtual int getUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf);
00064 virtual int setUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aUUID);
00065
00066 virtual int getString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * & aBuf);
00067 virtual int setString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf);
00068
00069 virtual int getBinary(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * & aBuf, unsigned long & aLength);
00070
00071 virtual int newEntry(RMEntity aEntity, unsigned long aID);
00072
00073 virtual int deleteEntry(RMEntity aEntity, unsigned long aID);
00074
00076 virtual unsigned long getNewId(RMEntity aEntity);
00077
00079 virtual int findId(RMEntity aEntity, unsigned long aID);
00080
00082 virtual int getNextId(RMEntity aEntity, unsigned long aID, unsigned long & aNextID);
00083
00085 virtual size_t getCount(RMEntity aEntity);
00086
00088 virtual void addEvent(posix_log_recid_t aRecid, unsigned long aId) = 0;
00089
00091 virtual void processEvents() = 0;
00092
00093 protected:
00095 virtual IBaseAccessor * getEntity(RMEntity aEntity) = 0;
00096 };
00097
00104 class rmClient : public subagentBase
00105 {
00106 public:
00107 rmClient(){}
00108 virtual ~rmClient();
00109
00110 virtual int init();
00111 virtual void shutdown();
00112
00113 virtual void addEvent(posix_log_recid_t aRecid, unsigned long aMonid)
00114 {
00115 return mEvent->addEvent(aRecid, aMonid);
00116 }
00117
00118 virtual void processEvents()
00119 {
00120 return mEvent->processEvents();
00121 }
00122
00123 protected:
00124 virtual IBaseAccessor * getEntity(RMEntity aEntity);
00125
00126 private:
00127 subsystemInfo * mSubsystemInfo;
00128 resourceInfo * mResourceInfo;
00129 statisticInfo * mStatisticInfo;
00130 dataCaptureInfo * mDataCaptureInfo;
00131 rmThresholdMonitorConfig * mThresholdConfig;
00132 rmWatermarkMonitorConfig * mWatermarkConfig;
00133 rmLeakyBucketMonitorConfig * mLeakyBucketConfig;
00134 rmGenericMonitorConfig * mGenericConfig;
00135 rmThresholdMonitorControl * mThresholdControl;
00136 rmLeakyBucketMonitorControl * mLeakyBucketControl;
00137 rmGenericMonitorControl * mGenericControl;
00138 rmMonitor * mMonitor;
00139 rmEvent * mEvent;
00140 eventLog * mEventLog;
00141 };
00142
00158 int
00159 subagentBase::getInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long & aValue)
00160 {
00161 IBaseAccessor * pBase = getEntity(aEntity);
00162 if(!pBase)
00163 return RMCLIENT_ERROR_NOSUCHENTITY;
00164
00165 return pBase->getInteger32(aName, aID, aValue);
00166 }
00167
00182 int
00183 subagentBase::setInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long aValue)
00184 {
00185 IBaseAccessor * pBase = getEntity(aEntity);
00186 if(!pBase)
00187 return RMCLIENT_ERROR_NOSUCHENTITY;
00188
00189 return pBase->setInteger32(aName, aID, aValue);
00190 }
00191
00207 int
00208 subagentBase::getUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long & aValue)
00209 {
00210 IBaseAccessor * pBase = getEntity(aEntity);
00211 if(!pBase)
00212 return RMCLIENT_ERROR_NOSUCHENTITY;
00213
00214 return pBase->getUnsigned(aName, aID, aValue);
00215 }
00216
00232 int
00233 subagentBase::setUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long aValue)
00234 {
00235 IBaseAccessor * pBase = getEntity(aEntity);
00236 if(!pBase)
00237 return RMCLIENT_ERROR_NOSUCHENTITY;
00238
00239 return pBase->setUnsigned(aName, aID, aValue);
00240 }
00241
00257 int
00258 subagentBase::getUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t & aValue)
00259 {
00260 IBaseAccessor * pBase = getEntity(aEntity);
00261 if(!pBase)
00262 return RMCLIENT_ERROR_NOSUCHENTITY;
00263
00264 return pBase->getUnsigned64(aName, aID, aValue);
00265 }
00266
00282 int
00283 subagentBase::setUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t aValue)
00284 {
00285 IBaseAccessor * pBase = getEntity(aEntity);
00286 if(!pBase)
00287 return RMCLIENT_ERROR_NOSUCHENTITY;
00288
00289 return pBase->setUnsigned64(aName, aID, aValue);
00290 }
00291
00307 int
00308 subagentBase::getUUID(RMEntity aEntity, RMAttribute aName, unsigned long aID, uuid_t aUUID)
00309 {
00310 IBaseAccessor * pBase = getEntity(aEntity);
00311 if(!pBase)
00312 return RMCLIENT_ERROR_NOSUCHENTITY;
00313
00314 return pBase->getUUID(aName, aID, aUUID);
00315 }
00316
00333 int
00334 subagentBase::getUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf)
00335 {
00336 IBaseAccessor * pBase = getEntity(aEntity);
00337 if(!pBase)
00338 return RMCLIENT_ERROR_NOSUCHENTITY;
00339
00340 return pBase->getUUIDString(aName, aID, aBuf);
00341 }
00342
00358 int
00359 subagentBase::setUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aUUID)
00360 {
00361 IBaseAccessor * pBase = getEntity(aEntity);
00362 if(!pBase)
00363 return RMCLIENT_ERROR_NOSUCHENTITY;
00364
00365 return pBase->setUUIDString(aName, aID, aUUID);
00366 }
00367
00384 int
00385 subagentBase::getString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * & aBuf)
00386 {
00387 IBaseAccessor * pBase = getEntity(aEntity);
00388 if(!pBase)
00389 return RMCLIENT_ERROR_NOSUCHENTITY;
00390
00391 return pBase->getString(aName, aID, aBuf);
00392 }
00393
00409 int
00410 subagentBase::setString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf)
00411 {
00412 IBaseAccessor * pBase = getEntity(aEntity);
00413 if(!pBase)
00414 return RMCLIENT_ERROR_NOSUCHENTITY;
00415
00416 return pBase->setString(aName, aID, aBuf);
00417 }
00418
00435 int
00436 subagentBase::getBinary(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * & aBuf, unsigned long & aLength)
00437 {
00438 IBaseAccessor * pBase = getEntity(aEntity);
00439 if(!pBase)
00440 return RMCLIENT_ERROR_NOSUCHENTITY;
00441
00442 return pBase->getBinary(aName, aID, aBuf, aLength);
00443 }
00444
00457 int
00458 subagentBase::newEntry(RMEntity aEntity, unsigned long aID)
00459 {
00460 IBaseAccessor * pBase = getEntity(aEntity);
00461 if(!pBase)
00462 return RMCLIENT_ERROR_NOSUCHENTITY;
00463
00464 return pBase->addDefaultElement(aID);
00465 }
00466
00479 int
00480 subagentBase::deleteEntry(RMEntity aEntity, unsigned long aID)
00481 {
00482 IBaseAccessor * pBase = getEntity(aEntity);
00483
00484 if(!pBase)
00485 return RMCLIENT_ERROR_NOSUCHENTITY;
00486
00487 return pBase->removeElement(aID);
00488 }
00489
00501 unsigned long
00502 subagentBase::getNewId(RMEntity aEntity)
00503 {
00504 IBaseAccessor * pBase = getEntity(aEntity);
00505 if(!pBase)
00506 return RMCLIENT_ERROR_NOSUCHENTITY;
00507
00508 return pBase->getNewId();
00509 }
00510
00523 int
00524 subagentBase::findId(RMEntity aEntity, unsigned long aID)
00525 {
00526 IBaseAccessor * pBase = getEntity(aEntity);
00527 if(!pBase)
00528 return RMCLIENT_ERROR_NOSUCHENTITY;
00529
00530 return pBase->findExactId(aID);
00531 }
00532
00548 int
00549 subagentBase::getNextId(RMEntity aEntity, unsigned long aID, unsigned long & aNextID)
00550 {
00551 IBaseAccessor * pBase = getEntity(aEntity);
00552 if(!pBase)
00553 return RMCLIENT_ERROR_NOSUCHENTITY;
00554
00555 return pBase->getNextId(aID, aNextID);
00556 }
00557
00569 size_t
00570 subagentBase::getCount(RMEntity aEntity)
00571 {
00572 IBaseAccessor * pBase = getEntity(aEntity);
00573 if(!pBase)
00574 return RMCLIENT_ERROR_NOSUCHENTITY;
00575
00576 return pBase->getCount();
00577 }
00578
00579 rmClient::~rmClient()
00580 {
00581 shutdown();
00582 }
00583
00593 int
00594 rmClient::init()
00595 {
00596
00597 int ret;
00598
00599 long startupTime;
00600 struct timezone tz;
00601 struct timeval tv;
00602
00603 gettimeofday(&tv, &tz);
00604 startupTime = tv.tv_sec;
00605
00606 int i = 0;
00607
00608 try{
00609
00610 mSubsystemInfo = new subsystemInfo(startupTime);
00611 mResourceInfo = new resourceInfo();
00612 mStatisticInfo = new statisticInfo();
00613
00614
00615
00616 ret = mSubsystemInfo->init(mResourceInfo, mStatisticInfo);
00617 if(ret)
00618 return ret;
00619
00620 ret = mResourceInfo->init(mSubsystemInfo, mStatisticInfo);
00621 if(ret)
00622 return ret;
00623
00624 ret = mStatisticInfo->init(mSubsystemInfo, mResourceInfo);
00625 if(ret)
00626 return ret;
00627
00628 mDataCaptureInfo = new dataCaptureInfo(mSubsystemInfo);
00629 ret = mDataCaptureInfo->init();
00630 if(ret)
00631 return ret;
00632
00633 mThresholdConfig = new rmThresholdMonitorConfig;
00634 ret = mThresholdConfig->init();
00635 if(ret) {
00636 return ret;
00637 }
00638
00639 mWatermarkConfig = new rmWatermarkMonitorConfig;
00640 ret = mWatermarkConfig->init();
00641 if(ret)
00642 return ret;
00643
00644 mLeakyBucketConfig = new rmLeakyBucketMonitorConfig;
00645 ret = mLeakyBucketConfig->init();
00646 if(ret)
00647 return ret;
00648
00649
00650
00651
00652 mGenericConfig = new rmGenericMonitorConfig(mSubsystemInfo, mThresholdConfig, mWatermarkConfig, mLeakyBucketConfig);
00653 ret = mGenericConfig->init();
00654 if(ret) {
00655 return ret;
00656 }
00657
00658 mThresholdControl = new rmThresholdMonitorControl;
00659 ret = mThresholdControl->init();
00660 if(ret)
00661 return ret;
00662
00663 mLeakyBucketControl = new rmLeakyBucketMonitorControl;
00664 ret = mLeakyBucketControl->init();
00665 if(ret)
00666 return ret;
00667
00668 mGenericControl = new rmGenericMonitorControl(mThresholdControl, mLeakyBucketControl);
00669 ret = mGenericControl->init();
00670 if(ret)
00671 return ret;
00672
00673 mMonitor = new rmMonitor(startupTime, mSubsystemInfo, mGenericConfig, mThresholdConfig, mWatermarkConfig, mLeakyBucketConfig, mGenericControl, mThresholdControl, mLeakyBucketControl);
00674 ret = mMonitor->init();
00675 if(ret)
00676 return ret;
00677
00678 mEvent = new rmEvent(mSubsystemInfo, mResourceInfo, mDataCaptureInfo);
00679 ret = mEvent->init();
00680 if(ret)
00681 return ret;
00682
00683
00684 mEventLog = new eventLog(NULL);
00685 ret = mEventLog->init();
00686 if(ret)
00687 return ret;
00688
00689 return RMCLIENT_SUCCESS;
00690
00691 }
00692 catch(...) {
00693 shutdown();
00694
00695 return RMCLIENT_ERROR_MEMORY;
00696 }
00697 }
00698
00707 void
00708 rmClient::shutdown()
00709 {
00710 delete mGenericConfig;
00711 delete mThresholdConfig;
00712 delete mWatermarkConfig;
00713 delete mLeakyBucketConfig;
00714 delete mGenericControl;
00715 delete mThresholdControl;
00716 delete mLeakyBucketControl;
00717 delete mMonitor;
00718 delete mSubsystemInfo;
00719 delete mResourceInfo;
00720 delete mStatisticInfo;
00721 delete mDataCaptureInfo;
00722 delete mEvent;
00723 delete mEventLog;
00724 }
00725
00736 IBaseAccessor *
00737 rmClient::getEntity(RMEntity aEntity)
00738 {
00739 IBaseAccessor * pBase = NULL;
00740
00741 switch(aEntity) {
00742
00743 case SUBSYSTEMINFO:
00744 pBase = mSubsystemInfo;
00745 break;
00746
00747 case RESORUCEINFO:
00748 pBase = mResourceInfo;
00749 break;
00750
00751 case STATISTICINFO:
00752 pBase = mStatisticInfo;
00753 break;
00754
00755 case DATACAPTUREPLUGININFO:
00756 pBase = mDataCaptureInfo;
00757 break;
00758
00759 case GENERICCONFIG:
00760 pBase = mGenericConfig;
00761 break;
00762
00763 case THRESHOLDCONFIG:
00764 pBase = mThresholdConfig;
00765 break;
00766
00767 case WATERMARKCONFIG:
00768 pBase = mWatermarkConfig;
00769 break;
00770
00771 case LEAKYBUCKETCONFIG:
00772 pBase = mLeakyBucketConfig;
00773 break;
00774
00775 case GENERICCONTROL:
00776 pBase = mGenericControl;
00777 break;
00778
00779 case THRESHOLDCONTROL:
00780 pBase = mThresholdControl;
00781 break;
00782
00783 case LEAKYBUCKETCONTROL:
00784 pBase = mLeakyBucketControl;
00785 break;
00786
00787 case MONITOR:
00788 pBase = mMonitor;
00789 break;
00790
00791 case EVENTLOG:
00792 pBase = mEventLog;
00793 break;
00794
00795 default:
00796 return NULL;
00797 }
00798
00799 return pBase;
00800 }
00801
00802
00803
00804
00805
00806
00807
00823 subagentBase * gSubagent(NULL);
00824
00825 int
00826 initRMClient()
00827 {
00828 int ret;
00829 gSubagent = new rmClient();
00830 return gSubagent->init();
00831 }
00832
00841 void
00842 shutdownRMClient()
00843 {
00844 gSubagent->shutdown();
00845 }
00846
00852 int
00853 getRMVersion()
00854 {
00855 return ResourceMonitor::rmGetResourceMonitorVersion();
00856 }
00857
00858
00859
00860
00861
00862
00863
00864
00887 int
00888 getInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long * aValue)
00889 {
00890 return gSubagent->getInteger32(aEntity, aName, aID, *aValue);
00891 }
00892
00915 int
00916 setInteger32(RMEntity aEntity, RMAttribute aName, unsigned long aID, long aValue)
00917 {
00918 return gSubagent->setInteger32(aEntity, aName, aID, aValue);
00919 }
00920
00944 int
00945 getUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long * aValue)
00946 {
00947 return gSubagent->getUnsigned(aEntity, aName, aID, *aValue);
00948 }
00949
00973 int
00974 setUnsigned(RMEntity aEntity, RMAttribute aName, unsigned long aID, unsigned long aValue)
00975 {
00976 return gSubagent->setUnsigned(aEntity, aName, aID, aValue);
00977 }
00978
01002 int
01003 getUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t * aValue)
01004 {
01005 return gSubagent->getUnsigned64(aEntity, aName, aID, *aValue);
01006 }
01007
01031 int
01032 setUnsigned64(RMEntity aEntity, RMAttribute aName, unsigned long aID, u_int64_t aValue)
01033 {
01034 return gSubagent->setUnsigned64(aEntity, aName, aID, aValue);
01035 }
01036
01073 int
01074 getUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf)
01075 {
01076 return gSubagent->getUUIDString(aEntity, aName, aID, aBuf);
01077 }
01078
01113 int
01114 getUUID(RMEntity aEntity, RMAttribute aName, unsigned long aID, uuid_t aUUID)
01115 {
01116 return gSubagent->getUUID(aEntity, aName, aID, aUUID);
01117 }
01118
01144 int
01145 setUUIDString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aUUID)
01146 {
01147 return gSubagent->setUUIDString(aEntity, aName, aID, aUUID);
01148 }
01149
01171 int
01172 getString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * * aBuf)
01173 {
01174 return gSubagent->getString(aEntity, aName, aID, *aBuf);
01175 }
01176
01177
01196 int
01197 setString(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * aBuf)
01198 {
01199 return gSubagent->setString(aEntity, aName, aID, aBuf);
01200 }
01201
01202
01220 int
01221 newEntry(RMEntity aEntity, unsigned long aID)
01222 {
01223 return gSubagent->newEntry(aEntity, aID);
01224 }
01225
01238 int
01239 deleteEntry(RMEntity aEntity, unsigned long aID)
01240 {
01241 return gSubagent->deleteEntry(aEntity, aID);
01242 }
01243
01253 unsigned long
01254 getNewId(RMEntity aEntity)
01255 {
01256 return gSubagent->getNewId(aEntity);
01257 }
01258
01259
01272 int
01273 findId(RMEntity aEntity, unsigned long aID)
01274 {
01275 return gSubagent->findId(aEntity, aID);
01276 }
01277
01292 int
01293 getNextId(RMEntity aEntity, unsigned long aID, unsigned long * aNextID)
01294 {
01295 return gSubagent->getNextId(aEntity, aID, *aNextID);
01296 }
01297
01298
01308 size_t
01309 getCount(RMEntity aEntity)
01310 {
01311 return gSubagent->getCount(aEntity);
01312 }
01313
01333 int
01334 getBinary(RMEntity aEntity, RMAttribute aName, unsigned long aID, char * * aBuf, unsigned long * aLength)
01335 {
01336 return gSubagent->getBinary(aEntity, aName, aID, *aBuf, *aLength);
01337 }
01338
01339
01357 void
01358 addEvent(posix_log_recid_t aRecid, unsigned long aId)
01359 {
01360 return gSubagent->addEvent(aRecid, aId);
01361 }
01362
01363
01371 void
01372 processEvents()
01373 {
01374 return gSubagent->processEvents();
01375 }
01376
01377
01378
01379