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 lpoa->aAlerts[ iInsert ].aiTIMEOUT.stLastAttempt;
361 GetSystemTime (&lpoa->aAlerts[ iInsert ].aiTIMEOUT.stLastAttempt);
369 PostNotification (evtAlertsChanged, lpi);
375 size_t Alert_GetCount (LPIDENT lpi)
379 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
382 return lpoa->nAlerts;
386 ALERT Alert_GetAlert (LPIDENT lpi, size_t iAlert)
390 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
393 if (iAlert > lpoa->nAlerts)
396 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
398 return Alert_GetAlert (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
399 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary);
402 return lpoa->aAlerts[ iAlert ].alert;
406 LPIDENT Alert_GetIdent (LPIDENT lpi, size_t iAlert)
410 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
413 if (iAlert > lpoa->nAlerts)
416 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
418 return lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary;
425 LPTSTR Alert_GetQuickDescription (LPIDENT lpi)
427 LPTSTR pszStatus = NULL;
430 if ((cAlerts = Alert_GetCount (lpi)) <= 1)
431 pszStatus = Alert_GetDescription (lpi, 0, FALSE);
432 else if (lpi->fIsServer())
433 pszStatus = FormatString (IDS_SERVER_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
434 else if (lpi->fIsService())
435 pszStatus = FormatString (IDS_SERVICE_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
436 else if (lpi->fIsAggregate())
437 pszStatus = FormatString (IDS_AGGREGATE_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
438 else if (lpi->fIsFileset())
439 pszStatus = FormatString (IDS_FILESET_MULTIPLE_PROBLEMS, TEXT("%lu"), cAlerts);
445 LPTSTR Alert_GetDescription (LPIDENT lpi, size_t iAlert, BOOL fFull)
449 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
452 if (!lpoa->nAlerts && lpi->fIsServer())
455 if ((lpsp = (LPSERVER_PREF)lpi->GetUserParam()) != NULL)
457 if (!lpsp->fIsMonitored)
459 TCHAR szName[ cchNAME ];
460 lpi->GetServerName (szName);
461 return FormatString (IDS_ALERT_DESCSHORT_UNMONITORED, TEXT("%s"), szName);
466 if (iAlert >= lpoa->nAlerts)
469 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
471 return Alert_GetDescriptionFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
472 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
477 return Alert_GetDescriptionFunc (lpi, iAlert, NULL, fFull);
481 LPTSTR Alert_GetRemedy (LPIDENT lpi, size_t iAlert)
485 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
488 if (iAlert >= lpoa->nAlerts)
491 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
493 return Alert_GetRemedyFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
494 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
498 return Alert_GetRemedyFunc (lpi, iAlert, NULL);
502 LPTSTR Alert_GetButton (LPIDENT lpi, size_t iAlert)
506 if ((lpoa = Alert_GetObjectAlerts (lpi)) == NULL)
509 if (iAlert >= lpoa->nAlerts)
512 if (lpoa->aAlerts[ iAlert ].alert == alertSECONDARY)
514 return Alert_GetButtonFunc (lpoa->aAlerts[ iAlert ].aiSECONDARY.lpiSecondary,
515 lpoa->aAlerts[ iAlert ].aiSECONDARY.iSecondary,
519 return Alert_GetButtonFunc (lpi, iAlert, NULL);
523 LPTSTR Alert_GetDescriptionFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer, BOOL fFull)
526 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
529 TCHAR szServer[ cchRESOURCE ];
530 TCHAR szService[ cchRESOURCE ];
531 TCHAR szAggregate[ cchRESOURCE ];
532 TCHAR szFileset[ cchRESOURCE ];
534 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
537 ids = (fFull) ? IDS_ALERT_DESCFULL_TIMEOUT : IDS_ALERT_DESCSHORT_TIMEOUT;
538 lpiPrimary->GetServerName (szServer);
539 return FormatString (ids, TEXT("%s%t%e"), szServer, &lpoa->aAlerts[ iAlertPrimary ].aiTIMEOUT.stLastAttempt, lpoa->aAlerts[ iAlertPrimary ].aiTIMEOUT.status);
542 lpiPrimary->GetServerName (szServer);
543 lpiPrimary->GetAggregateName (szAggregate);
544 if (lpiPrimary->fIsAggregate())
546 ids = (fFull) ? IDS_ALERT_DESCFULL_AGG_FULL : IDS_ALERT_DESCSHORT_AGG_FULL;
547 return FormatString (ids, TEXT("%s%s%d%.1B"), szServer, szAggregate, lpoa->aAlerts[ iAlertPrimary ].aiFULL.perWarning, 1024.0 * (double)lpoa->aAlerts[ iAlertPrimary ].aiFULL.ckWarning);
549 else if (lpiPrimary->fIsFileset())
551 ids = (fFull) ? IDS_ALERT_DESCFULL_SET_FULL : IDS_ALERT_DESCSHORT_SET_FULL;
552 lpiPrimary->GetFilesetName (szFileset);
553 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);
557 case alertNO_VLDBENT:
558 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_VLDBENT : IDS_ALERT_DESCSHORT_NO_VLDBENT;
559 lpiPrimary->GetServerName (szServer);
560 lpiPrimary->GetAggregateName (szAggregate);
561 lpiPrimary->GetFilesetName (szFileset);
562 return FormatString (ids, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
565 if (lpiPrimary->fIsFileset())
567 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_SVRENT_SET : IDS_ALERT_DESCSHORT_NO_SVRENT_SET;
568 lpiPrimary->GetServerName (szServer);
569 lpiPrimary->GetAggregateName (szAggregate);
570 lpiPrimary->GetFilesetName (szFileset);
571 return FormatString (ids, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
575 ids = (fFull) ? IDS_ALERT_DESCFULL_NO_SVRENT_AGG : IDS_ALERT_DESCSHORT_NO_SVRENT_AGG;
576 lpiPrimary->GetServerName (szServer);
577 lpiPrimary->GetAggregateName (szAggregate);
578 return FormatString (ids, TEXT("%s%s"), szServer, szAggregate);
583 ids = (fFull) ? IDS_ALERT_DESCFULL_STOPPED : IDS_ALERT_DESCSHORT_STOPPED;
584 lpiPrimary->GetServerName (szServer);
585 lpiPrimary->GetServiceName (szService);
586 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);
589 ids = (fFull) ? IDS_ALERT_DESCFULL_BADCREDS : IDS_ALERT_DESCSHORT_BADCREDS;
590 lpiPrimary->GetServerName (szServer);
591 return FormatString (ids, TEXT("%s"), szServer);
594 lpiPrimary->GetServerName (szServer);
595 lpiPrimary->GetAggregateName (szAggregate);
596 ids = (fFull) ? IDS_ALERT_DESCFULL_AGG_ALLOC : IDS_ALERT_DESCSHORT_AGG_ALLOC;
597 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));
599 case alertSTATE_NO_VNODE:
600 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_NO_VNODE : IDS_ALERT_DESCSHORT_STATE_NO_VNODE;
601 lpiPrimary->GetServerName (szServer);
602 lpiPrimary->GetAggregateName (szAggregate);
603 lpiPrimary->GetFilesetName (szFileset);
604 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
606 case alertSTATE_NO_SERVICE:
607 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_NO_SERVICE : IDS_ALERT_DESCSHORT_STATE_NO_SERVICE;
608 lpiPrimary->GetServerName (szServer);
609 lpiPrimary->GetAggregateName (szAggregate);
610 lpiPrimary->GetFilesetName (szFileset);
611 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
613 case alertSTATE_OFFLINE:
614 ids = (fFull) ? IDS_ALERT_DESCFULL_STATE_OFFLINE : IDS_ALERT_DESCSHORT_STATE_OFFLINE;
615 lpiPrimary->GetServerName (szServer);
616 lpiPrimary->GetAggregateName (szAggregate);
617 lpiPrimary->GetFilesetName (szFileset);
618 return FormatString (ids, TEXT("%s%s%s%08lX"), szServer, szAggregate, szFileset, lpoa->aAlerts[ iAlertPrimary ].aiSTATE.State);
626 LPTSTR Alert_GetRemedyFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer)
629 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
631 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
634 return FormatString (IDS_ALERT_FIX_TIMEOUT);
636 if (lpiPrimary->fIsAggregate())
637 return FormatString (IDS_ALERT_FIX_AGG_FULL);
638 else if (lpiPrimary->fIsFileset())
639 return FormatString (IDS_ALERT_FIX_SET_FULL);
641 case alertNO_VLDBENT:
642 return FormatString (IDS_ALERT_FIX_NO_VLDBENT);
644 if (lpiPrimary->fIsFileset())
645 return FormatString (IDS_ALERT_FIX_NO_SVRENT_SET);
647 return FormatString (IDS_ALERT_FIX_NO_SVRENT_AGG);
650 return FormatString (IDS_ALERT_FIX_STOPPED);
652 return FormatString (IDS_ALERT_FIX_BADCREDS);
654 return FormatString (IDS_ALERT_FIX_AGG_ALLOC);
655 case alertSTATE_NO_VNODE:
656 return FormatString (IDS_ALERT_FIX_STATE_NO_VNODE);
657 case alertSTATE_NO_SERVICE:
658 return FormatString (IDS_ALERT_FIX_STATE_NO_SERVICE);
659 case alertSTATE_OFFLINE:
660 return FormatString (IDS_ALERT_FIX_STATE_OFFLINE);
668 LPTSTR Alert_GetButtonFunc (LPIDENT lpiPrimary, size_t iAlertPrimary, LPIDENT lpiServer)
671 if ((lpoa = Alert_GetObjectAlerts (lpiPrimary)) != NULL)
673 switch (lpoa->aAlerts[ iAlertPrimary ].alert)
676 return FormatString (IDS_ALERT_BUTTON_TRYAGAIN);
678 return FormatString (IDS_ALERT_BUTTON_WARNINGS);
679 case alertNO_VLDBENT:
684 return FormatString (IDS_ALERT_BUTTON_VIEWLOG);
686 return FormatString (IDS_ALERT_BUTTON_GETCREDS);
689 case alertSTATE_NO_VNODE:
691 case alertSTATE_NO_SERVICE:
693 case alertSTATE_OFFLINE:
703 * SCOUT ______________________________________________________________________
705 * (okay, well, our simulated Scout anyway)
709 static HANDLE hScout = 0; // scout's thread
710 static HANDLE heScoutWakeup = 0; // scout's wakeup event
712 BOOL Alert_StartScout (ULONG *pStatus)
714 if (hScout == 0) // create scout?
716 heScoutWakeup = CreateEvent (NULL, FALSE, FALSE, NULL);
719 if ((hScout = CreateThread (NULL, 0,
720 (LPTHREAD_START_ROUTINE)Alert_ScoutProc,
722 &dwThreadID)) == NULL)
725 *pStatus = GetLastError();
729 SetThreadPriority (hScout, THREAD_PRIORITY_BELOW_NORMAL);
731 else // or just wake up scout from its slumber?
733 PulseEvent (heScoutWakeup);
740 BOOL Alert_Scout_QueueCheckServer (LPIDENT lpiServer, ULONG *pStatus)
742 Alert_Scout_SetOutOfDate (lpiServer);
743 return Alert_StartScout (pStatus);
747 DWORD WINAPI Alert_ScoutProc (LPVOID lp)
749 // We'll keep working forever...
755 LPCELL lpCell = (g.lpiCell == NULL) ? NULL : g.lpiCell->OpenCell();
758 // See if our credentials have expired
760 CheckForExpiredCredentials();
762 // See if any new servers have arrived, or old servers disappeared.
764 lpCell->RefreshServerList();
766 // Check all the out-of-date servers we can find.
769 for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
771 LPIDENT lpiServer = lpServer->GetIdentifier();
774 if ( ((lpoa = Alert_GetObjectAlerts (lpiServer)) != NULL) &&
775 (lpoa->dwTickNextTest <= GetTickCount()) )
778 // Okay! We've found a server that needs to be tested for
779 // alert conditions. Do that now, and when we're done, set
780 // its next query-time to some distance in the future.
782 if (lpoa->dwTickNextRefresh == 0)
784 if (lpoa->cTickRefresh != 0)
785 lpoa->dwTickNextRefresh = lpoa->cTickRefresh + GetTickCount();
787 else if (lpoa->dwTickNextRefresh <= GetTickCount())
789 (void)lpServer->Invalidate();
790 (void)lpServer->RefreshAll();
791 lpoa->dwTickNextRefresh = lpoa->cTickRefresh + GetTickCount();
794 (void)Alert_Scout_CheckServer (lpServer);
805 // Now that we have completed a pass over the servers in this cell,
806 // and now that we're not holding any critical sections on which
807 // other threads would otherwise block, go to sleep for a while.
809 WaitForSingleObjectEx (heScoutWakeup, 45L * cmsec1SECOND, FALSE);
816 void Alert_Scout_SetOutOfDate (LPIDENT lpi)
819 if ((lpoa = Alert_GetObjectAlerts (lpi, TRUE)) != NULL)
821 lpoa->dwTickNextTest = GetTickCount() -1;
826 void Alert_Scout_SetUpToDate (LPOBJECTALERTS lpoa)
830 lpoa->dwTickNextTest = GetTickCount() + lpoa->cTickRefresh;
835 BOOL Alert_Scout_CheckServer (LPSERVER lpServer)
840 if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
843 if ((lpoa = Alert_GetObjectAlerts (lpServer->GetIdentifier())) != NULL)
845 PostNotification (evtScoutBegin, lpServer->GetIdentifier());
847 BOOL fChangedServerAlerts = FALSE;
849 DWORD dwTickNextTestWhenStarted = lpoa->dwTickNextTest;
851 // First look through the server's aggregates and filesets, to
852 // find any which have usages over their warning threshholds.
855 for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&heAggregate); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&heAggregate))
857 BOOL fChangedAggregateAlerts = FALSE;
858 LPIDENT lpiAggregate = lpAggregate->GetIdentifier();
860 LPOBJECTALERTS lpoaAggregate;
861 if ((lpoaAggregate = Alert_GetObjectAlerts (lpAggregate->GetIdentifier())) != NULL)
863 for (size_t iAlert = 0; iAlert < lpoaAggregate->nAlerts; )
865 if ( (lpoaAggregate->aAlerts[ iAlert ].alert == alertFULL) ||
866 (lpoaAggregate->aAlerts[ iAlert ].alert == alertOVERALLOC) ||
867 (lpoaAggregate->aAlerts[ iAlert ].alert == alertNO_SVRENT) )
869 fChangedAggregateAlerts = TRUE;
870 fChangedServerAlerts = TRUE;
871 Alert_Remove (lpAggregate->GetIdentifier(), iAlert);
877 LPAGGREGATE_PREF lpap;
878 if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
880 short wGhost = lpAggregate->GetGhostStatus();
881 if (lpsp->fWarnAggNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY))
884 ai.alert = alertNO_SVRENT;
885 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
886 fChangedAggregateAlerts = TRUE;
887 fChangedServerAlerts = TRUE;
890 if (lpsp->fWarnAggAlloc && lpap->fWarnAggAlloc)
893 if (lpAggregate->GetStatus (&as, TRUE))
895 if (as.ckStorageAllocated > as.ckStorageTotal)
898 ai.alert = alertOVERALLOC;
899 ai.aiOVERALLOC.ckAllocated = as.ckStorageAllocated;
900 ai.aiOVERALLOC.ckCapacity = as.ckStorageTotal;
901 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
902 fChangedAggregateAlerts = TRUE;
903 fChangedServerAlerts = TRUE;
908 short perWarnAggFull = lpap->perWarnAggFull;
909 if (perWarnAggFull == -1)
910 perWarnAggFull = lpsp->perWarnAggFull;
911 if (perWarnAggFull != 0)
914 if (lpAggregate->GetStatus (&as, TRUE))
916 if (as.ckStorageTotal != 0)
918 short perNow = (short)( (double)(as.ckStorageTotal - as.ckStorageFree) * 100.0 / (double)(as.ckStorageTotal) );
920 if (perNow > perWarnAggFull)
923 ai.alert = alertFULL;
924 ai.aiFULL.perWarning = perWarnAggFull;
925 ai.aiFULL.ckWarning = (ULONG)( (double)perWarnAggFull * (double)(as.ckStorageTotal) / 100.0 );
926 Alert_AddPrimary (lpAggregate->GetIdentifier(), &ai);
927 fChangedAggregateAlerts = TRUE;
928 fChangedServerAlerts = TRUE;
937 for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&heFileset); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&heFileset))
939 BOOL fChangedFilesetAlerts = FALSE;
940 LPIDENT lpiFileset = lpFileset->GetIdentifier();
942 LPOBJECTALERTS lpoaFileset;
943 if ((lpoaFileset = Alert_GetObjectAlerts (lpFileset->GetIdentifier())) != NULL)
945 for (size_t iAlert = 0; iAlert < lpoaFileset->nAlerts; )
947 if ( (lpoaFileset->aAlerts[ iAlert ].alert == alertFULL) ||
948 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_VNODE) ||
949 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_NO_SERVICE) ||
950 (lpoaFileset->aAlerts[ iAlert ].alert == alertSTATE_OFFLINE) ||
951 (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_VLDBENT) ||
952 (lpoaFileset->aAlerts[ iAlert ].alert == alertNO_SVRENT) )
954 fChangedFilesetAlerts = TRUE;
955 fChangedServerAlerts = TRUE;
956 Alert_Remove (lpFileset->GetIdentifier(), iAlert);
964 if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
967 if (lpFileset->GetStatus (&fs, TRUE))
969 if (fs.State & fsNO_VNODE)
972 ai.alert = alertSTATE_NO_VNODE;
973 ai.aiSTATE.State = fs.State;
974 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
975 fChangedFilesetAlerts = TRUE;
976 fChangedServerAlerts = TRUE;
978 else if (fs.State & fsNO_SERVICE)
981 ai.alert = alertSTATE_NO_SERVICE;
982 ai.aiSTATE.State = fs.State;
983 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
984 fChangedFilesetAlerts = TRUE;
985 fChangedServerAlerts = TRUE;
987 else if (fs.State & fsOFFLINE)
990 ai.alert = alertSTATE_OFFLINE;
991 ai.aiSTATE.State = fs.State;
992 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
993 fChangedFilesetAlerts = TRUE;
994 fChangedServerAlerts = TRUE;
997 short perWarnSetFull = lpfp->perWarnSetFull;
998 if (perWarnSetFull == -1)
999 perWarnSetFull = lpsp->perWarnSetFull;
1000 if (perWarnSetFull != 0)
1002 if (fs.Type == ftREADWRITE)
1004 if (fs.ckQuota != 0)
1006 short perNow = (short)( (double)(fs.ckUsed) * 100.0 / (double)(fs.ckQuota) );
1008 if (perNow > perWarnSetFull)
1011 ai.alert = alertFULL;
1012 ai.aiFULL.perWarning = perWarnSetFull;
1013 ai.aiFULL.ckWarning = (ULONG)( (double)perWarnSetFull * (double)(fs.ckQuota) / 100.0 );
1014 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1015 fChangedFilesetAlerts = TRUE;
1016 fChangedServerAlerts = TRUE;
1023 short wGhost = lpFileset->GetGhostStatus();
1024 if (lpsp->fWarnSetNoVLDB && !(wGhost & GHOST_HAS_VLDB_ENTRY))
1027 ai.alert = alertNO_VLDBENT;
1028 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1029 fChangedFilesetAlerts = TRUE;
1030 fChangedServerAlerts = TRUE;
1032 if (lpsp->fWarnSetNoServ && !(wGhost & GHOST_HAS_SERVER_ENTRY) && !(fs.Type == ftREPLICA))
1035 ai.alert = alertNO_SVRENT;
1036 Alert_AddPrimary (lpFileset->GetIdentifier(), &ai);
1037 fChangedFilesetAlerts = TRUE;
1038 fChangedServerAlerts = TRUE;
1043 if (fChangedFilesetAlerts)
1045 PostNotification (evtAlertsChanged, lpiFileset);
1049 lpAggregate->Close();
1050 if (fChangedAggregateAlerts)
1052 PostNotification (evtAlertsChanged, lpiAggregate);
1056 // Next look through the server's servces to find any
1057 // which have stopped.
1060 for (LPSERVICE lpService = lpServer->ServiceFindFirst (&heService); lpService; lpService = lpServer->ServiceFindNext (&heService))
1062 BOOL fChangedServiceAlerts = FALSE;
1063 LPIDENT lpiService = lpService->GetIdentifier();
1065 LPOBJECTALERTS lpoaService;
1066 if ((lpoaService = Alert_GetObjectAlerts (lpService->GetIdentifier())) != NULL)
1068 for (size_t iAlert = 0; iAlert < lpoaService->nAlerts; )
1070 if (lpoaService->aAlerts[ iAlert ].alert == alertSTOPPED)
1072 fChangedServiceAlerts = TRUE;
1073 fChangedServerAlerts = TRUE;
1074 Alert_Remove (lpService->GetIdentifier(), iAlert);
1080 LPSERVICE_PREF lpcp;
1081 if ((lpcp = (LPSERVICE_PREF)lpService->GetUserParam()) != NULL)
1083 if (lpcp->fWarnSvcStop && lpsp->fWarnSvcStop)
1086 if (lpService->GetStatus (&ss, TRUE))
1088 if (ss.state != SERVICESTATE_RUNNING)
1091 ai.alert = alertSTOPPED;
1092 memcpy (&ai.aiSTOPPED.stStopped, &ss.timeLastStop, sizeof(SYSTEMTIME));
1093 memcpy (&ai.aiSTOPPED.stLastError, &ss.timeLastFail, sizeof(SYSTEMTIME));
1094 ai.aiSTOPPED.errLastError = ss.dwErrLast;
1095 Alert_AddPrimary (lpService->GetIdentifier(), &ai);
1096 fChangedServiceAlerts = TRUE;
1097 fChangedServerAlerts = TRUE;
1105 if (fChangedServiceAlerts)
1107 PostNotification (evtAlertsChanged, lpiService);
1111 if (rc && (dwTickNextTestWhenStarted == lpoa->dwTickNextTest))
1113 Alert_Scout_SetUpToDate (lpoa);
1116 if (fChangedServerAlerts)
1118 PostNotification (evtAlertsChanged, lpServer->GetIdentifier());
1121 PostNotification (evtScoutEnd, lpServer->GetIdentifier());