- fix in uptime related processing
authorAlex Kalimulin <alex@netxms.org>
Sat, 24 Sep 2011 21:34:04 +0000 (21:34 +0000)
committerAlex Kalimulin <alex@netxms.org>
Sat, 24 Sep 2011 21:34:04 +0000 (21:34 +0000)
src/server/core/bizsvcroot.cpp
src/server/core/svccontainer.cpp
src/server/core/uptimecalc.cpp
src/server/include/nms_objects.h

index 1f72b25..6d95227 100644 (file)
@@ -122,22 +122,3 @@ void BusinessServiceRoot::LinkChildObjects()
    }
 }
 
-//
-// Recalculate uptime for each service in the tree 
-//
-
-void BusinessServiceRoot::recalculateAllUptimes( time_t currentTime )
-{
-       updateUptimeStats(currentTime);
-
-       LockChildList(TRUE);
-
-       for (int i = 0; i < int(m_dwChildCount); i++)
-       {
-               NetObj *child = m_pChildList[i];
-               if (child->Type() == OBJECT_BUSINESSSERVICE || child->Type() == OBJECT_NODELINK)
-                       ((ServiceContainer*)child)->updateUptimeStats(currentTime);
-       }
-
-       UnlockChildList();
-}
\ No newline at end of file
index 0b00f3f..d1838c5 100644 (file)
@@ -144,17 +144,6 @@ void ServiceContainer::calculateCompoundStatus(BOOL bForcedRecalc)
        setStatus((iCount > 0) ? iMostCriticalStatus : STATUS_UNKNOWN);
        UnlockChildList();
 
-       // A hack to make service root to recalculate uptime properly
-       /*
-       for(i = 0; iOldStatus == m_iStatus && i < int(m_dwParentCount); i++)
-       {
-               if (m_pParentList[i]->Type() == OBJECT_BUSINESSSERVICEROOT)
-               {
-                       ((BusinessServiceRoot*)m_pParentList[i])->updateUptimeStats();
-                       break;
-               }
-       }*/
-
        // Cause parent object(s) to recalculate it's status
        if ((iOldStatus != m_iStatus) || bForcedRecalc)
        {
@@ -179,7 +168,6 @@ void ServiceContainer::calculateCompoundStatus(BOOL bForcedRecalc)
 void ServiceContainer::setStatus(int newStatus)
 {
        m_iStatus = newStatus;
-       // updateUptimeStats(); 
 }
 
 
@@ -295,12 +283,11 @@ double ServiceContainer::getUptimeFromDBFor(Period period, LONG *downtime)
        return percentage;
 }
 
-
 //
 // Update uptime counters 
 //
 
-void ServiceContainer::updateUptimeStats(time_t currentTime /* = 0*/)
+void ServiceContainer::updateUptimeStats(time_t currentTime /* = 0*/, BOOL updateChilds /* = FALSE */)
 {
        LONG timediffTillNow;
        LONG downtimeBetweenPolls = 0;
@@ -353,6 +340,18 @@ void ServiceContainer::updateUptimeStats(time_t currentTime /* = 0*/)
        m_prevUptimeUpdateTime = currentTime;
 
        DbgPrintf(7, _T("++++ ServiceContainer::updateUptimeStats() [%d] %lf %lf %lf"), int(m_dwId), m_uptimeDay, m_uptimeWeek, m_uptimeMonth);
+
+       if (updateChilds)
+       {
+               LockChildList(TRUE);
+               for (int i = 0; i < int(m_dwChildCount); i++)
+               {
+                       NetObj *child = m_pChildList[i];
+                       if (child->Type() == OBJECT_BUSINESSSERVICE || child->Type() == OBJECT_NODELINK)
+                               ((ServiceContainer*)child)->updateUptimeStats(currentTime, TRUE);
+               }
+               UnlockChildList();
+       }
 }
 
 
index cb61f95..5716049 100644 (file)
@@ -34,7 +34,7 @@ THREAD_RESULT THREAD_CALL UptimeCalculator(void *arg)
 
        while (TRUE)
        {
-               g_pBusinessServiceRoot->recalculateAllUptimes(time(NULL));
+               g_pBusinessServiceRoot->updateUptimeStats(time(NULL), TRUE);
                if (SleepAndCheckForShutdown(calcInterval))
                        break;
        }
index 5932c1a..2b3946c 100644 (file)
@@ -1656,7 +1656,7 @@ public:
 
        virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
        virtual void setStatus(int newStatus);
-       void updateUptimeStats(time_t currentTime = 0);
+       void updateUptimeStats(time_t currentTime = 0, BOOL updateChilds = FALSE);
 };
 
 
@@ -1677,8 +1677,6 @@ public:
 
    void LinkChildObjects();
    void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
-
-   void recalculateAllUptimes(time_t currentTime);
 };