BOOL Services_fRunning (LPSERVICE lpService) { SERVICESTATUS ss; ULONG status; if (!lpService->GetStatus (&ss, FALSE, &status)) return FALSE; return (ss.state == SERVICESTATE_RUNNING) ? TRUE : FALSE; }
BOOL Alert_Scout_CheckServer (LPSERVER lpServer) { BOOL rc = TRUE; LPSERVER_PREF lpsp; if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL) { LPOBJECTALERTS lpoa; if ((lpoa = Alert_GetObjectAlerts (lpServer->GetIdentifier())) != NULL) { PostNotification (evtScoutBegin, lpServer->GetIdentifier()); BOOL fChangedServerAlerts = FALSE; DWORD dwTickNextTestWhenStarted = lpoa->dwTickNextTest; // First look through the server's aggregates and filesets, to // find any which have usages over their warning threshholds. // HENUM heAggregate; for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&heAggregate); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&heAggregate)) { BOOL fChangedAggregateAlerts = FALSE; LPIDENT lpiAggregate = lpAggregate->GetIdentifier(); LPOBJECTALERTS lpoaAggregate; if ((lpoaAggregate = Alert_GetObjectAlerts (lpAggregate->GetIdentifier())) != NULL) { for (size_t iAlert = 0; iAlert < lpoaAggregate->nAlerts; ) { if ( (lpoaAggregate->aAlerts[ iAlert ].alert == alertFULL) || (lpoaAggregate->aAlerts[ iAlert ].alert == alertOVERALLOC) || (lpoaAggregate->aAlerts[ iAlert ].alert == alertNO_SVRENT) ) { fChangedAggregateAlerts = TRUE; fChangedServerAlerts = TRUE; Alert_Remove (lpAggregate->GetIdentifier(), iAlert); } else ++iAlert; } LPAGGREGATE_PREF lpap; if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL) { short wGhost = lpAggregate->GetGhostStatus(); if (lpsp->fWarnAggNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY)) { ALERTINFO ai; ai.alert = alertNO_SVRENT; Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai); fChangedAggregateAlerts = TRUE; fChangedServerAlerts = TRUE; } if (lpsp->fWarnAggAlloc && lpap->fWarnAggAlloc) { AGGREGATESTATUS as; if (lpAggregate->GetStatus (&as, TRUE)) { if (as.ckStorageAllocated > as.ckStorageTotal) { ALERTINFO ai; ai.alert = alertOVERALLOC; ai.aiOVERALLOC.ckAllocated = as.ckStorageAllocated; ai.aiOVERALLOC.ckCapacity = as.ckStorageTotal; Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai); fChangedAggregateAlerts = TRUE; fChangedServerAlerts = TRUE; } } } short perWarnAggFull = lpap->perWarnAggFull; if (perWarnAggFull == -1) perWarnAggFull = lpsp->perWarnAggFull; if (perWarnAggFull != 0) { AGGREGATESTATUS as; if (lpAggregate->GetStatus (&as, TRUE)) { if (as.ckStorageTotal != 0) { short perNow = (short)( (double)(as.ckStorageTotal - as.ckStorageFree) * 100.0 / (double)(as.ckStorageTotal) ); if (perNow > perWarnAggFull) { ALERTINFO ai; ai.alert = alertFULL; ai.aiFULL.perWarning = perWarnAggFull; ai.aiFULL.ckWarning = (ULONG)( (double)perWarnAggFull * (double)(as.ckStorageTotal) / 100.0 ); Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai); fChangedAggregateAlerts = TRUE; fChangedServerAlerts = TRUE; } } } } } } HENUM heFileset; for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&heFileset); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&heFileset)) { BOOL fChangedFilesetAlerts = FALSE; LPIDENT lpiFileset = lpFileset->GetIdentifier(); LPOBJECTALERTS lpoaFileset; if ((lpoaFileset = Alert_GetObjectAlerts (lpFileset->GetIdentifier())) != NULL) { for (size_t iAlert = 0; iAlert < lpoaFileset->nAlerts; ) { if ( (lpoaFileset->aAlerts[ iAlert ].alert == alertFULL) || (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_VNODE) || (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_SERVICE) || (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_OFFLINE) || (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_VLDBENT) || (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_SVRENT) ) { fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; Alert_Remove (lpFileset->GetIdentifier(), iAlert); } else ++iAlert; } } LPFILESET_PREF lpfp; if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL) { FILESETSTATUS fs; if (lpFileset->GetStatus (&fs, TRUE)) { if (fs.State & fsNO_VNODE) { ALERTINFO ai; ai.alert = alertSTATE_NO_VNODE; ai.aiSTATE.State = fs.State; Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } else if (fs.State & fsNO_SERVICE) { ALERTINFO ai; ai.alert = alertSTATE_NO_SERVICE; ai.aiSTATE.State = fs.State; Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } else if (fs.State & fsOFFLINE) { ALERTINFO ai; ai.alert = alertSTATE_OFFLINE; ai.aiSTATE.State = fs.State; Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } short perWarnSetFull = lpfp->perWarnSetFull; if (perWarnSetFull == -1) perWarnSetFull = lpsp->perWarnSetFull; if (perWarnSetFull != 0) { if (fs.Type == ftREADWRITE) { if (fs.ckQuota != 0) { short perNow = (short)( (double)(fs.ckUsed) * 100.0 / (double)(fs.ckQuota) ); if (perNow > perWarnSetFull) { ALERTINFO ai; ai.alert = alertFULL; ai.aiFULL.perWarning = perWarnSetFull; ai.aiFULL.ckWarning = (ULONG)( (double)perWarnSetFull * (double)(fs.ckQuota) / 100.0 ); Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } } } } } short wGhost = lpFileset->GetGhostStatus(); if (lpsp->fWarnSetNoVLDB && !(wGhost & GHOST_HAS_VLDB_ENTRY)) { ALERTINFO ai; ai.alert = alertNO_VLDBENT; Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } if (lpsp->fWarnSetNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY) && !(fs.Type == ftREPLICA)) { ALERTINFO ai; ai.alert = alertNO_SVRENT; Alert_AddPrimary (lpFileset->GetIdentifier(), &ai); fChangedFilesetAlerts = TRUE; fChangedServerAlerts = TRUE; } } lpFileset->Close(); if (fChangedFilesetAlerts) { PostNotification (evtAlertsChanged, lpiFileset); } } lpAggregate->Close(); if (fChangedAggregateAlerts) { PostNotification (evtAlertsChanged, lpiAggregate); } } // Next look through the server's servces to find any // which have stopped. // HENUM heService; for (LPSERVICE lpService = lpServer->ServiceFindFirst (&heService); lpService; lpService = lpServer->ServiceFindNext (&heService)) { BOOL fChangedServiceAlerts = FALSE; LPIDENT lpiService = lpService->GetIdentifier(); LPOBJECTALERTS lpoaService; if ((lpoaService = Alert_GetObjectAlerts (lpService->GetIdentifier())) != NULL) { for (size_t iAlert = 0; iAlert < lpoaService->nAlerts; ) { if (lpoaService->aAlerts[ iAlert ].alert == alertSTOPPED) { fChangedServiceAlerts = TRUE; fChangedServerAlerts = TRUE; Alert_Remove (lpService->GetIdentifier(), iAlert); } else ++iAlert; } LPSERVICE_PREF lpcp; if ((lpcp = (LPSERVICE_PREF)lpService->GetUserParam()) != NULL) { if (lpcp->fWarnSvcStop && lpsp->fWarnSvcStop) { SERVICESTATUS ss; if (lpService->GetStatus (&ss, TRUE)) { if (ss.state != SERVICESTATE_RUNNING) { ALERTINFO ai; ai.alert = alertSTOPPED; memcpy (&ai.aiSTOPPED.stStopped, &ss.timeLastStop, sizeof(SYSTEMTIME)); memcpy (&ai.aiSTOPPED.stLastError, &ss.timeLastFail, sizeof(SYSTEMTIME)); ai.aiSTOPPED.errLastError = ss.dwErrLast; Alert_AddPrimary (lpService->GetIdentifier(), &ai); fChangedServiceAlerts = TRUE; fChangedServerAlerts = TRUE; } } } } } lpService->Close(); if (fChangedServiceAlerts) { PostNotification (evtAlertsChanged, lpiService); } } if (rc && (dwTickNextTestWhenStarted == lpoa->dwTickNextTest)) { Alert_Scout_SetUpToDate (lpoa); } if (fChangedServerAlerts) { PostNotification (evtAlertsChanged, lpServer->GetIdentifier()); } PostNotification (evtScoutEnd, lpServer->GetIdentifier()); } } return rc; }