2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
21 * DEFINITIONS ________________________________________________________________
27 * VARIABLES __________________________________________________________________
33 * PROTOTYPES _________________________________________________________________
37 BOOL Alert_Scout_CheckServer (LPSERVER lpServer);
39 void Alert_BeginUpdate (LPIDENT lpi, LPSERVER *ppServer);
40 void Alert_EndUpdate (LPIDENT lpi, LPSERVER lpServer);
42 void Alert_RemoveFunc (LPOBJECTALERTS lpoa, size_t iAlert);
43 LPTSTR Alert_GetDescriptionFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer, BOOL fFull);
44 LPTSTR Alert_GetRemedyFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer);
45 LPTSTR Alert_GetButtonFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer);
47 DWORD WINAPI Alert_ScoutProc (LPVOID lp);
48 void Alert_Scout_SetUpToDate (LPOBJECTALERTS lpoa);
52 * ROUTINES ___________________________________________________________________
56 LPOBJECTALERTS Alert_GetObjectAlerts (LPIDENT lpi, BOOL fAlwaysServer, ULONG *pStatus)
58 LPOBJECTALERTS lpoa = NULL;
60 if (fAlwaysServer || lpi->fIsServer())
63 if ((lpsp = (LPSERVER_PREF)lpi->GetServer()->GetUserParam()) != NULL)
68 else if (lpi->fIsService())
71 if ((lpsp = (LPSERVICE_PREF)lpi->GetUserParam()) != NULL)
76 else if (lpi->fIsAggregate())
78 LPAGGREGATE_PREF lpap;
79 if ((lpap = (LPAGGREGATE_PREF)lpi->GetUserParam()) != NULL)
84 else if (lpi->fIsFileset())
87 if ((lpfp = (LPFILESET_PREF)lpi->GetUserParam()) != NULL)
97 void Alert_BeginUpdate (LPIDENT lpi, LPSERVER *ppServer)
105 *ppServer = lpi->OpenServer();
110 void Alert_EndUpdate (LPIDENT lpi, LPSERVER lpServer)
112 // If we just updated some aggregate, fileset or service, then the
113 // associated server's secondary alerts are probably out-of-date.
116 if (lpServer != NULL)
118 LPOBJECTALERTS lpoaServer = Alert_GetObjectAlerts (lpServer->GetIdentifier());
119 LPOBJECTALERTS lpoaChild = Alert_GetObjectAlerts (lpi);
123 for (size_t iAlert = 0; iAlert < lpoaServer->nAlerts; )
125 if ( (lpoaServer->aAlerts[ iAlert ].alert == alertSECONDARY) &&
126 (lpoaServer->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary == lpi) )
128 Alert_RemoveFunc (lpoaServer, iAlert);
137 if (lpoaServer && lpoaChild)
139 BOOL fNeedBadCredsWarning = FALSE;
140 BOOL fHaveBadCredsWarning = FALSE;
142 for (size_t iAlert = 0; iAlert < lpoaServer->nAlerts; ++iAlert)
144 if (lpoaServer->aAlerts[ iAlert ].alert == alertSECONDARY)
146 ALERT alert = Alert_GetAlert (lpoaServer->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
147 lpoaServer->aAlerts[ iAlert ].aiSECONDARY.iSecondary);
148 if (alert == alertNO_SVRENT)
149 fNeedBadCredsWarning = TRUE;
152 for (iAlert = 0; iAlert < lpoaChild->nAlerts; ++iAlert)
154 if (lpoaChild->aAlerts[ iAlert ].alert == alertNO_SVRENT)
155 fNeedBadCredsWarning = TRUE;
157 if (lpoaServer->nAlerts &&
158 lpoaServer->aAlerts[ 0 ].alert == alertBADCREDS)
160 fHaveBadCredsWarning = TRUE;
163 if (fNeedBadCredsWarning)
165 fNeedBadCredsWarning = !CheckCredentials (FALSE);
168 if (fHaveBadCredsWarning && !fNeedBadCredsWarning)
170 Alert_RemoveFunc (lpoaServer, 0);
172 else if (fNeedBadCredsWarning && !fHaveBadCredsWarning)
174 for (iAlert = min( lpoaServer->nAlerts, nAlertsMAX-1 );
178 memcpy (&lpoaServer->aAlerts[ iAlert ], &lpoaServer->aAlerts[ iAlert-1 ], sizeof(ALERTINFO));
180 lpoaServer->aAlerts[0].alert = alertBADCREDS;
181 lpoaServer->nAlerts = min( nAlertsMAX, lpoaServer->nAlerts+1 );
184 for (iAlert = 0; iAlert < lpoaChild->nAlerts; ++iAlert)
186 if (lpoaServer->nAlerts < nAlertsMAX)
188 lpoaServer->aAlerts[ lpoaServer->nAlerts ].alert = alertSECONDARY;
189 lpoaServer->aAlerts[ lpoaServer->nAlerts ].aiSECONDARY.lpiSecondary = lpi;
190 lpoaServer->aAlerts[ lpoaServer->nAlerts ].aiSECONDARY.iSecondary = iAlert;
191 lpoaServer->nAlerts ++;
201 void Alert_SetDefaults (LPOBJECTALERTS lpoa)
205 memset (lpoa, 0x00, sizeof(OBJECTALERTS));
206 lpoa->cTickRefresh = DEFAULT_SCOUT_REFRESH_RATE;
211 void Alert_Initialize (LPOBJECTALERTS lpoa)
215 lpoa->dwTickNextTest = 0;
216 lpoa->dwTickNextRefresh = 0;
222 void Alert_RemoveSecondary (LPIDENT lpiChild)
224 BOOL fChangedAlerts = FALSE;
227 if ((lpoa = Alert_GetObjectAlerts (lpiChild, TRUE)) != NULL)
229 for (size_t iAlert = 0; iAlert < lpoa->nAlerts; )
231 if ( (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY) &&
232 (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary == lpiChild) )
234 Alert_RemoveFunc (lpoa, iAlert);
235 fChangedAlerts = TRUE;
244 BOOL fNeedBadCredsWarning = FALSE;
246 for (iAlert = 0; iAlert < lpoa->nAlerts; ++iAlert)
248 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
250 ALERT alert = Alert_GetAlert (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
251 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary);
252 if (alert == alertNO_SVRENT)
253 fNeedBadCredsWarning = TRUE;
257 if ( (!fNeedBadCredsWarning) &&
258 (lpoa->nAlerts && (lpoa->aAlerts[ 0 ].alert == alertBADCREDS)) )
260 Alert_RemoveFunc (lpoa, 0);
261 fChangedAlerts = TRUE;
267 PostNotification (evtAlertsChanged, lpiChild->GetServer());
268 PostNotification (evtAlertsChanged, lpiChild);
273 void Alert_Remove (LPIDENT lpi, size_t iAlert)
277 if ((lpoa = Alert_GetObjectAlerts (lpi)) != NULL)
279 if (iAlert < lpoa->nAlerts)
282 Alert_BeginUpdate (lpi, &lpServer);
284 Alert_RemoveFunc (lpoa, iAlert);
286 Alert_EndUpdate (lpi, lpServer);
292 void Alert_RemoveFunc (LPOBJECTALERTS lpoa, size_t iAlert)
294 if (iAlert < lpoa->nAlerts-1)
296 memcpy (&lpoa->aAlerts[ iAlert ], &lpoa->aAlerts[ lpoa->nAlerts-1 ], sizeof(ALERTINFO));
302 void Alert_AddPrimary (LPIDENT lpi, LPALERTINFO lpai)
306 if ((lpoa = Alert_GetObjectAlerts (lpi)) != NULL)
308 if (lpoa->nAlerts < nAlertsMAX)
311 Alert_BeginUpdate (lpi, &lpServer);
313 memcpy (&lpoa->aAlerts[ lpoa->nAlerts ], lpai, sizeof(ALERTINFO));
316 Alert_EndUpdate (lpi, lpServer);
322 void Alert_Scout_ServerStatus (LPIDENT lpi, ULONG status)
325 if ((lpoa = Alert_GetObjectAlerts (lpi)) != NULL)
327 BOOL fChanged = FALSE;
329 for (size_t iAlert = 0; iAlert < lpoa->nAlerts; ++iAlert)
331 if (lpoa->aAlerts[ iAlert ].alert == alertTIMEOUT)
334 Alert_RemoveFunc (lpoa, iAlert);
342 if (lpoa->nAlerts && (lpoa->aAlerts[0].alert == alertBADCREDS))
345 for (size_t iHole = iInsert; iHole < lpoa->nAlerts; ++iHole)
347 if (lpoa->aAlerts[ iHole ].alert == alertINVALID)
350 if (iHole < nAlertsMAX)
352 for (size_t iTarget = iHole; iTarget > iInsert; --iTarget)
354 memcpy (&lpoa->aAlerts[ iTarget ], &lpoa->aAlerts[ iTarget-1 ], sizeof(ALERTINFO));
358 lpoa->aAlerts[ iInsert ].alert = alertTIMEOUT;
359 lpoa->aAlerts[ iInsert ].aiTIMEOUT.status = status;
360 GetSystemTime (&lpoa->aAlerts[ iInsert ].aiTIMEOUT.stLastAttempt);
368 PostNotification (evtAlertsChanged, lpi);
374 size_t Alert_GetCount (LPIDENT lpi)
378 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
381 return lpoa->nAlerts;
385 ALERT Alert_GetAlert (LPIDENT lpi, size_t iAlert)
389 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
392 if (iAlert > lpoa->nAlerts)
395 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
397 return Alert_GetAlert (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
398 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary);
401 return lpoa->aAlerts[ iAlert ].alert;
405 LPIDENT Alert_GetIdent (LPIDENT lpi, size_t iAlert)
409 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
412 if (iAlert > lpoa->nAlerts)
415 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
417 return lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary;
424 LPTSTR Alert_GetQuickDescription (LPIDENT lpi)
426 LPTSTR pszStatus = NULL;
429 if ((cAlerts = Alert_GetCount (lpi)) <= 1)
430 pszStatus = Alert_GetDescription (lpi, 0, FALSE);
431 else if (lpi->fIsServer())
432 pszStatus = FormatString (IDS_SERVER_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
433 else if (lpi->fIsService())
434 pszStatus = FormatString (IDS_SERVICE_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
435 else if (lpi->fIsAggregate())
436 pszStatus = FormatString (IDS_AGGREGATE_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
437 else if (lpi->fIsFileset())
438 pszStatus = FormatString (IDS_FILESET_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
444 LPTSTR Alert_GetDescription (LPIDENT lpi, size_t iAlert, BOOL fFull)
448 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
451 if (!lpoa->nAlerts && lpi->fIsServer())
454 if ((lpsp = (LPSERVER_PREF)lpi->GetUserParam()) != NULL)
456 if (!lpsp->fIsMonitored)
458 TCHAR szName[ cchNAME ];
459 lpi->GetServerName (szName);
460 return FormatString (IDS_ALERT_DESCSHORT_UNMONITORED, TEXT("%s"), szName);
465 if (iAlert >= lpoa->nAlerts)
468 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
470 return Alert_GetDescriptionFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
471 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
476 return Alert_GetDescriptionFunc (lpi, iAlert, NULL, fFull);
480 LPTSTR Alert_GetRemedy (LPIDENT lpi, size_t iAlert)
484 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
487 if (iAlert >= lpoa->nAlerts)
490 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
492 return Alert_GetRemedyFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
493 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
497 return Alert_GetRemedyFunc (lpi, iAlert, NULL);
501 LPTSTR Alert_GetButton (LPIDENT lpi, size_t iAlert)
505 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
508 if (iAlert >= lpoa->nAlerts)
511 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
513 return Alert_GetButtonFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
514 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
518 return Alert_GetButtonFunc (lpi, iAlert, NULL);
522 LPTSTR Alert_GetDescriptionFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer, BOOL fFull)
525 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
528 TCHAR szServer[ cchRESOURCE ];
529 TCHAR szService[ cchRESOURCE ];
530 TCHAR szAggregate[ cchRESOURCE ];
531 TCHAR szFileset[ cchRESOURCE ];
533 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
536 ids = (fFull) ? IDS_ALERT_DESCFULL_TIMEOUT : IDS_ALERT_DESCSHORT_TIMEOUT;
537 lpiPrimary->GetServerName (szServer);
538 return FormatString (ids, TEXT("%s%t%e"), szServer, &lpoa->aAlerts[ iAlertPrimary ].aiTIMEOUT.stLastAttempt, lpoa->aAlerts[ iAlertPrimary ].aiTIMEOUT.status);
541 lpiPrimary->GetServerName (szServer);
542 lpiPrimary->GetAggregateName (szAggregate);
543 if (lpiPrimary->fIsAggregate())
545 ids = (fFull) ? IDS_ALERT_DESCFULL_AGG_FULL : IDS_ALERT_DESCSHORT_AGG_FULL;
546 return FormatString (ids, TEXT("%s%s%d%.1B"), szServer, szAggregate, lpoa->aAlerts[ iAlertPrimary ].aiFULL.perWarning, 1024.0 * (double)lpoa->aAlerts[ iAlertPrimary ].aiFULL.ckWarning);
548 else if (lpiPrimary->fIsFileset())
550 ids = (fFull) ? IDS_ALERT_DESCFULL_SET_FULL : IDS_ALERT_DESCSHORT_SET_FULL;
551 lpiPrimary->GetFilesetName (szFileset);
552 return FormatString (ids, TEXT("%s%s%s%d%.1B"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiFULL.perWarning, 1024.0 * (double)lpoa->aAlerts[ iAlertPrimary ].aiFULL.ckWarning);
556 case alertNO_VLDBENT:
557 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_VLDBENT : IDS_ALERT_DESCSHORT_NO_VLDBENT;
558 lpiPrimary->GetServerName (szServer);
559 lpiPrimary->GetAggregateName (szAggregate);
560 lpiPrimary->GetFilesetName (szFileset);
561 return FormatString (ids, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
564 if (lpiPrimary->fIsFileset())
566 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_SVRENT_SET : IDS_ALERT_DESCSHORT_NO_SVRENT_SET;
567 lpiPrimary->GetServerName (szServer);
568 lpiPrimary->GetAggregateName (szAggregate);
569 lpiPrimary->GetFilesetName (szFileset);
570 return FormatString (ids, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
574 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_SVRENT_AGG : IDS_ALERT_DESCSHORT_NO_SVRENT_AGG;
575 lpiPrimary->GetServerName (szServer);
576 lpiPrimary->GetAggregateName (szAggregate);
577 return FormatString (ids, TEXT("%s%s"), szServer, szAggregate);
582 ids = (fFull) ? IDS_ALERT_DESCFULL_STOPPED : IDS_ALERT_DESCSHORT_STOPPED;
583 lpiPrimary->GetServerName (szServer);
584 lpiPrimary->GetServiceName (szService);
585 return FormatString (ids, TEXT("%s%s%t%t%lu"), szServer, szService, &lpoa->aAlerts[ iAlertPrimary ].aiSTOPPED.stStopped, &lpoa->aAlerts[ iAlertPrimary ].aiSTOPPED.stLastError, lpoa->aAlerts[ iAlertPrimary ].aiSTOPPED.errLastError);
588 ids = (fFull) ? IDS_ALERT_DESCFULL_BADCREDS : IDS_ALERT_DESCSHORT_BADCREDS;
589 lpiPrimary->GetServerName (szServer);
590 return FormatString (ids, TEXT("%s"), szServer);
593 lpiPrimary->GetServerName (szServer);
594 lpiPrimary->GetAggregateName (szAggregate);
595 ids = (fFull) ? IDS_ALERT_DESCFULL_AGG_ALLOC : IDS_ALERT_DESCSHORT_AGG_ALLOC;
596 return FormatString (ids, TEXT("%s%s%.1B%.1B"), szServer, szAggregate, 1024.0 * (double)(lpoa->aAlerts[ iAlertPrimary ].aiOVERALLOC.ckCapacity), 1024.0 * (double)(lpoa->aAlerts[ iAlertPrimary ].aiOVERALLOC.ckAllocated));
598 case alertSTATE_NO_VNODE:
599 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_NO_VNODE : IDS_ALERT_DESCSHORT_STATE_NO_VNODE;
600 lpiPrimary->GetServerName (szServer);
601 lpiPrimary->GetAggregateName (szAggregate);
602 lpiPrimary->GetFilesetName (szFileset);
603 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
605 case alertSTATE_NO_SERVICE:
606 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_NO_SERVICE : IDS_ALERT_DESCSHORT_STATE_NO_SERVICE;
607 lpiPrimary->GetServerName (szServer);
608 lpiPrimary->GetAggregateName (szAggregate);
609 lpiPrimary->GetFilesetName (szFileset);
610 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
612 case alertSTATE_OFFLINE:
613 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_OFFLINE : IDS_ALERT_DESCSHORT_STATE_OFFLINE;
614 lpiPrimary->GetServerName (szServer);
615 lpiPrimary->GetAggregateName (szAggregate);
616 lpiPrimary->GetFilesetName (szFileset);
617 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
625 LPTSTR Alert_GetRemedyFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer)
628 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
630 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
633 return FormatString (IDS_ALERT_FIX_TIMEOUT);
635 if (lpiPrimary->fIsAggregate())
636 return FormatString (IDS_ALERT_FIX_AGG_FULL);
637 else if (lpiPrimary->fIsFileset())
638 return FormatString (IDS_ALERT_FIX_SET_FULL);
640 case alertNO_VLDBENT:
641 return FormatString (IDS_ALERT_FIX_NO_VLDBENT);
643 if (lpiPrimary->fIsFileset())
644 return FormatString (IDS_ALERT_FIX_NO_SVRENT_SET);
646 return FormatString (IDS_ALERT_FIX_NO_SVRENT_AGG);
649 return FormatString (IDS_ALERT_FIX_STOPPED);
651 return FormatString (IDS_ALERT_FIX_BADCREDS);
653 return FormatString (IDS_ALERT_FIX_AGG_ALLOC);
654 case alertSTATE_NO_VNODE:
655 return FormatString (IDS_ALERT_FIX_STATE_NO_VNODE);
656 case alertSTATE_NO_SERVICE:
657 return FormatString (IDS_ALERT_FIX_STATE_NO_SERVICE);
658 case alertSTATE_OFFLINE:
659 return FormatString (IDS_ALERT_FIX_STATE_OFFLINE);
667 LPTSTR Alert_GetButtonFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer)
670 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
672 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
675 return FormatString (IDS_ALERT_BUTTON_TRYAGAIN);
677 return FormatString (IDS_ALERT_BUTTON_WARNINGS);
678 case alertNO_VLDBENT:
683 return FormatString (IDS_ALERT_BUTTON_VIEWLOG);
685 return FormatString (IDS_ALERT_BUTTON_GETCREDS);
688 case alertSTATE_NO_VNODE:
690 case alertSTATE_NO_SERVICE:
692 case alertSTATE_OFFLINE:
702 * SCOUT ______________________________________________________________________
704 * (okay, well, our simulated Scout anyway)
708 static HANDLE hScout = 0; // scout's thread
709 static HANDLE heScoutWakeup = 0; // scout's wakeup event
711 BOOL Alert_StartScout (ULONG *pStatus)
713 if (hScout == 0) // create scout?
715 heScoutWakeup = CreateEvent (NULL, FALSE, FALSE, TEXT("AfsSvrMgr Alert Scout Wakeup"));
718 if ((hScout = CreateThread (NULL, 0,
719 (LPTHREAD_START_ROUTINE)Alert_ScoutProc,
721 &dwThreadID)) == NULL)
724 *pStatus = GetLastError();
728 SetThreadPriority (hScout, THREAD_PRIORITY_BELOW_NORMAL);
730 else // or just wake up scout from its slumber?
732 PulseEvent (heScoutWakeup);
739 BOOL Alert_Scout_QueueCheckServer (LPIDENT lpiServer, ULONG *pStatus)
741 Alert_Scout_SetOutOfDate (lpiServer);
742 return Alert_StartScout (pStatus);
746 DWORD WINAPI Alert_ScoutProc (LPVOID lp)
748 // We'll keep working forever...
754 LPCELL lpCell = (g.lpiCell == NULL) ? NULL : g.lpiCell->OpenCell();
757 // See if our credentials have expired
759 CheckForExpiredCredentials();
761 // See if any new servers have arrived, or old servers disappeared.
763 lpCell->RefreshServerList();
765 // Check all the out-of-date servers we can find.
768 for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
770 LPIDENT lpiServer = lpServer->GetIdentifier();
773 if ( ((lpoa = Alert_GetObjectAlerts (lpiServer)) != NULL) &&
774 (lpoa->dwTickNextTest <= GetTickCount()) )
777 // Okay! We've found a server that needs to be tested for
778 // alert conditions. Do that now, and when we're done, set
779 // its next query-time to some distance in the future.
781 if (lpoa->dwTickNextRefresh == 0)
783 if (lpoa->cTickRefresh != 0)
784 lpoa->dwTickNextRefresh = lpoa->cTickRefresh + GetTickCount();
786 else if (lpoa->dwTickNextRefresh <= GetTickCount())
788 (void)lpServer->Invalidate();
789 (void)lpServer->RefreshAll();
790 lpoa->dwTickNextRefresh = lpoa->cTickRefresh + GetTickCount();
793 (void)Alert_Scout_CheckServer (lpServer);
804 // Now that we have completed a pass over the servers in this cell,
805 // and now that we're not holding any critical sections on which
806 // other threads would otherwise block, go to sleep for a while.
808 WaitForSingleObjectEx (heScoutWakeup, 45L * cmsec1SECOND, FALSE);
815 void Alert_Scout_SetOutOfDate (LPIDENT lpi)
818 if ((lpoa = Alert_GetObjectAlerts (lpi, TRUE)) != NULL)
820 lpoa->dwTickNextTest = GetTickCount() -1;
825 void Alert_Scout_SetUpToDate (LPOBJECTALERTS lpoa)
829 lpoa->dwTickNextTest = GetTickCount() + lpoa->cTickRefresh;
834 BOOL Alert_Scout_CheckServer (LPSERVER lpServer)
839 if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
842 if ((lpoa = Alert_GetObjectAlerts (lpServer->GetIdentifier())) != NULL)
844 PostNotification (evtScoutBegin, lpServer->GetIdentifier());
846 BOOL fChangedServerAlerts = FALSE;
848 DWORD dwTickNextTestWhenStarted = lpoa->dwTickNextTest;
850 // First look through the server's aggregates and filesets, to
851 // find any which have usages over their warning threshholds.
854 for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&heAggregate); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&heAggregate))
856 BOOL fChangedAggregateAlerts = FALSE;
857 LPIDENT lpiAggregate = lpAggregate->GetIdentifier();
859 LPOBJECTALERTS lpoaAggregate;
860 if ((lpoaAggregate = Alert_GetObjectAlerts (lpAggregate->GetIdentifier())) != NULL)
862 for (size_t iAlert = 0; iAlert < lpoaAggregate->nAlerts; )
864 if ( (lpoaAggregate->aAlerts[ iAlert ].alert == alertFULL) ||
865 (lpoaAggregate->aAlerts[ iAlert ].alert == alertOVERALLOC) ||
866 (lpoaAggregate->aAlerts[ iAlert ].alert == alertNO_SVRENT) )
868 fChangedAggregateAlerts = TRUE;
869 fChangedServerAlerts = TRUE;
870 Alert_Remove (lpAggregate->GetIdentifier(), iAlert);
876 LPAGGREGATE_PREF lpap;
877 if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
879 short wGhost = lpAggregate->GetGhostStatus();
880 if (lpsp->fWarnAggNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY))
883 ai.alert = alertNO_SVRENT;
884 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
885 fChangedAggregateAlerts = TRUE;
886 fChangedServerAlerts = TRUE;
889 if (lpsp->fWarnAggAlloc && lpap->fWarnAggAlloc)
892 if (lpAggregate->GetStatus (&as, TRUE))
894 if (as.ckStorageAllocated > as.ckStorageTotal)
897 ai.alert = alertOVERALLOC;
898 ai.aiOVERALLOC.ckAllocated = as.ckStorageAllocated;
899 ai.aiOVERALLOC.ckCapacity = as.ckStorageTotal;
900 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
901 fChangedAggregateAlerts = TRUE;
902 fChangedServerAlerts = TRUE;
907 short perWarnAggFull = lpap->perWarnAggFull;
908 if (perWarnAggFull == -1)
909 perWarnAggFull = lpsp->perWarnAggFull;
910 if (perWarnAggFull != 0)
913 if (lpAggregate->GetStatus (&as, TRUE))
915 if (as.ckStorageTotal != 0)
917 short perNow = (short)( (double)(as.ckStorageTotal - as.ckStorageFree) * 100.0 / (double)(as.ckStorageTotal) );
919 if (perNow > perWarnAggFull)
922 ai.alert = alertFULL;
923 ai.aiFULL.perWarning = perWarnAggFull;
924 ai.aiFULL.ckWarning = (ULONG)( (double)perWarnAggFull * (double)(as.ckStorageTotal) / 100.0 );
925 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
926 fChangedAggregateAlerts = TRUE;
927 fChangedServerAlerts = TRUE;
936 for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&heFileset); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&heFileset))
938 BOOL fChangedFilesetAlerts = FALSE;
939 LPIDENT lpiFileset = lpFileset->GetIdentifier();
941 LPOBJECTALERTS lpoaFileset;
942 if ((lpoaFileset = Alert_GetObjectAlerts (lpFileset->GetIdentifier())) != NULL)
944 for (size_t iAlert = 0; iAlert < lpoaFileset->nAlerts; )
946 if ( (lpoaFileset->aAlerts[ iAlert ].alert == alertFULL) ||
947 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_VNODE) ||
948 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_SERVICE) ||
949 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_OFFLINE) ||
950 (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_VLDBENT) ||
951 (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_SVRENT) )
953 fChangedFilesetAlerts = TRUE;
954 fChangedServerAlerts = TRUE;
955 Alert_Remove (lpFileset->GetIdentifier(), iAlert);
963 if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
966 if (lpFileset->GetStatus (&fs, TRUE))
968 if (fs.State & fsNO_VNODE)
971 ai.alert = alertSTATE_NO_VNODE;
972 ai.aiSTATE.State = fs.State;
973 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
974 fChangedFilesetAlerts = TRUE;
975 fChangedServerAlerts = TRUE;
977 else if (fs.State & fsNO_SERVICE)
980 ai.alert = alertSTATE_NO_SERVICE;
981 ai.aiSTATE.State = fs.State;
982 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
983 fChangedFilesetAlerts = TRUE;
984 fChangedServerAlerts = TRUE;
986 else if (fs.State & fsOFFLINE)
989 ai.alert = alertSTATE_OFFLINE;
990 ai.aiSTATE.State = fs.State;
991 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
992 fChangedFilesetAlerts = TRUE;
993 fChangedServerAlerts = TRUE;
996 short perWarnSetFull = lpfp->perWarnSetFull;
997 if (perWarnSetFull == -1)
998 perWarnSetFull = lpsp->perWarnSetFull;
999 if (perWarnSetFull != 0)
1001 if (fs.Type == ftREADWRITE)
1003 if (fs.ckQuota != 0)
1005 short perNow = (short)( (double)(fs.ckUsed) * 100.0 / (double)(fs.ckQuota) );
1007 if (perNow > perWarnSetFull)
1010 ai.alert = alertFULL;
1011 ai.aiFULL.perWarning = perWarnSetFull;
1012 ai.aiFULL.ckWarning = (ULONG)( (double)perWarnSetFull * (double)(fs.ckQuota) / 100.0 );
1013 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1014 fChangedFilesetAlerts = TRUE;
1015 fChangedServerAlerts = TRUE;
1022 short wGhost = lpFileset->GetGhostStatus();
1023 if (lpsp->fWarnSetNoVLDB && !(wGhost & GHOST_HAS_VLDB_ENTRY))
1026 ai.alert = alertNO_VLDBENT;
1027 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1028 fChangedFilesetAlerts = TRUE;
1029 fChangedServerAlerts = TRUE;
1031 if (lpsp->fWarnSetNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY) && !(fs.Type == ftREPLICA))
1034 ai.alert = alertNO_SVRENT;
1035 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1036 fChangedFilesetAlerts = TRUE;
1037 fChangedServerAlerts = TRUE;
1042 if (fChangedFilesetAlerts)
1044 PostNotification (evtAlertsChanged, lpiFileset);
1048 lpAggregate->Close();
1049 if (fChangedAggregateAlerts)
1051 PostNotification (evtAlertsChanged, lpiAggregate);
1055 // Next look through the server's servces to find any
1056 // which have stopped.
1059 for (LPSERVICE lpService = lpServer->ServiceFindFirst (&heService); lpService; lpService = lpServer->ServiceFindNext (&heService))
1061 BOOL fChangedServiceAlerts = FALSE;
1062 LPIDENT lpiService = lpService->GetIdentifier();
1064 LPOBJECTALERTS lpoaService;
1065 if ((lpoaService = Alert_GetObjectAlerts (lpService->GetIdentifier())) != NULL)
1067 for (size_t iAlert = 0; iAlert < lpoaService->nAlerts; )
1069 if (lpoaService->aAlerts[ iAlert ].alert == alertSTOPPED)
1071 fChangedServiceAlerts = TRUE;
1072 fChangedServerAlerts = TRUE;
1073 Alert_Remove (lpService->GetIdentifier(), iAlert);
1079 LPSERVICE_PREF lpcp;
1080 if ((lpcp = (LPSERVICE_PREF)lpService->GetUserParam()) != NULL)
1082 if (lpcp->fWarnSvcStop && lpsp->fWarnSvcStop)
1085 if (lpService->GetStatus (&ss, TRUE))
1087 if (ss.state != SERVICESTATE_RUNNING)
1090 ai.alert = alertSTOPPED;
1091 memcpy (&ai.aiSTOPPED.stStopped, &ss.timeLastStop, sizeof(SYSTEMTIME));
1092 memcpy (&ai.aiSTOPPED.stLastError, &ss.timeLastFail, sizeof(SYSTEMTIME));
1093 ai.aiSTOPPED.errLastError = ss.dwErrLast;
1094 Alert_AddPrimary (lpService->GetIdentifier(), &ai);
1095 fChangedServiceAlerts = TRUE;
1096 fChangedServerAlerts = TRUE;
1104 if (fChangedServiceAlerts)
1106 PostNotification (evtAlertsChanged, lpiService);
1110 if (rc && (dwTickNextTestWhenStarted == lpoa->dwTickNextTest))
1112 Alert_Scout_SetUpToDate (lpoa);
1115 if (fChangedServerAlerts)
1117 PostNotification (evtAlertsChanged, lpServer->GetIdentifier());
1120 PostNotification (evtScoutEnd, lpServer->GetIdentifier());