Changeset 142 for Evidence/Alarm/Alarm.cc
- Timestamp:
- 01/13/10 12:47:33 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Alarm/Alarm.cc
r127 r142 5 5 - Checks periodically if all required servers are up 6 6 (later it should try to start them if not) 7 - Listens to the 'Status' service of each server. The server state 8 is published as a DIM service. 7 - Listens to the 'Status' service of each server. 8 - A text describing the state of all servers is published as DIM service. 9 The states are described in StateString[]. 10 - A master alarm (indicating most severe of individual alarms) is published. 9 11 10 Oliver Grimm, September 200912 Oliver Grimm, January 2010 11 13 12 14 \********************************************************************/ … … 14 16 #define SERVER_NAME "Alarm" 15 17 #include "../Evidence.h" 18 19 #define SUMMARYSIZE 10000 // Bytes for alarm summary text 20 21 const char* StateString[] = {"OK", "WARN", "ERROR", "FATAL", "UNAVAILABLE"}; 16 22 17 23 // … … 21 27 22 28 DimStampedInfo **StatusService; 29 23 30 void infoHandler(); 24 31 … … 26 33 AlarmHandler(); 27 34 ~AlarmHandler(); 28 35 36 DimService *Summary, *Master; 37 38 char *AlarmSummary; 39 int MasterAlarm; 40 int *State; 29 41 char **Server; 30 42 unsigned int NumServers; 31 char *StateString; 32 char *ServerList; 43 char *ServerList; 44 45 void UpdateAlarmSummary(); 33 46 }; 34 47 … … 36 49 AlarmHandler::AlarmHandler(): EvidenceServer(SERVER_NAME) { 37 50 51 AlarmSummary = new char [SUMMARYSIZE]; 52 MasterAlarm = 0; 53 38 54 char *ServerNames = GetConfig(SERVER_NAME " servers"); 55 56 // Create DIM services 57 Summary = new DimService(SERVER_NAME"/Summary", AlarmSummary); 58 Master = new DimService(SERVER_NAME"/MasterAlarm", MasterAlarm); 39 59 40 60 // Copy original list of servers to observe … … 53 73 // Subscribe with handler to 'Status' service of all servers 54 74 StatusService = new DimStampedInfo* [NumServers]; 75 State = new int [NumServers]; 55 76 56 77 for (int i=0; i<NumServers; i++) { … … 58 79 strcpy(Buffer, Server[i]); 59 80 strcat(Buffer, "/Status"); 60 StatusService[i] = new DimStampedInfo(Buffer, 0, this); 61 printf("Subscribed to %s\n", Buffer); 62 delete[] Buffer; 81 StatusService[i] = new DimStampedInfo(Buffer, NO_LINK, this); 82 delete[] Buffer; 83 84 State[i] = 0; 63 85 } 64 65 StateString = new char [NumServers+1];66 for (int i=0; i<NumServers; i++) StateString[i] = '1';67 StateString[NumServers] = '\0';68 86 } 69 87 … … 73 91 for (int i=0; i<NumServers; i++) delete StatusService[i]; 74 92 delete[] StatusService; 93 delete Master; 94 delete Summary; 95 delete[] State; 75 96 delete[] Server; 76 97 delete[] ServerList; 98 delete[] AlarmSummary; 77 99 } 78 100 79 // Print messages of status changes to screen 101 // Print messages of status changes to screen and update status string 80 102 void AlarmHandler::infoHandler() { 81 103 82 // Ignore empty messages 83 if (strlen(getInfo()->getString()) == 0) return; 84 85 // Print message 86 time_t RawTime = getInfo()->getTimestamp(); 87 struct tm *TM = localtime(&RawTime); 88 printf("%s (%02d:%02d:%02d): %s\n", getInfo()->getName(), TM->tm_hour, 89 TM->tm_min, TM->tm_sec, getInfo()->getString()); 104 // Identify status service 105 for (int i=0; i<NumServers; i++) if (getInfo() == StatusService[i]) { 90 106 91 // Update status string 92 for (int i=0; i<NumServers; i++) { 93 if (strcmp(getInfo()->getName(),Server[i]) == 0) { 94 StateString[i] = '2'; 95 } 107 // Ignore DIS_DNS (has no status service) 108 if (strcmp(getInfo()->getName(),"DIS_DNS/Status") == 0) return; 109 110 // Update State if server is unavailable or with current severity of status 111 if (getInfo()->getSize()==strlen(NO_LINK)+1 && 112 strcmp(getInfo()->getString(), NO_LINK)==0) State[i] = 4; 113 else { 114 State[i] = *(getInfo()->getString()+strlen(getInfo()->getString())+2); 115 116 // Print message 117 time_t RawTime = getInfo()->getTimestamp(); 118 struct tm *TM = localtime(&RawTime); 119 printf("%s (%02d:%02d:%02d): %s\n", getInfo()->getName(), TM->tm_hour, 120 TM->tm_min, TM->tm_sec, getInfo()->getString()); 121 } 122 UpdateAlarmSummary(); 96 123 } 97 124 } 98 125 126 127 // Update alarm status summary 128 void AlarmHandler::UpdateAlarmSummary() { 129 130 int Offset = 0; 131 MasterAlarm = 0; 132 133 for (int i=0; i<NumServers; i++) { 134 snprintf(AlarmSummary+Offset, SUMMARYSIZE-Offset, "%s: %s\n", Server[i], StateString[State[i]]); 135 Offset += strlen(AlarmSummary+Offset); 136 if (State[i] > MasterAlarm) MasterAlarm = State[i]; 137 } 138 Summary->updateService(); 139 Master->updateService(); 140 } 99 141 100 142 // … … 113 155 unsigned int Period = atoi(Alarm.GetConfig(SERVER_NAME " period")); 114 156 115 // Create DIM services116 static DimService ServerState(SERVER_NAME"/State", Alarm.StateString);117 static DimService ServerList(SERVER_NAME"/Servers", Alarm.ServerList);118 119 157 // Check periodically if servers are up 120 158 while(!EvidenceServer::ExitRequest) { … … 125 163 if (strcmp(ServerName, Alarm.Server[i]) == 0) Exists = true; 126 164 } 127 if (!Exists) { 128 Alarm.Msg(Alarm.WARN, "Server %s unavailable", Alarm.Server[i]); 129 Alarm.StateString[i] = '0'; 130 } 131 else if (Alarm.StateString[i] == '0') Alarm.StateString[i] = '1'; 165 if (!Exists) Alarm.State[i] = 4; 132 166 } 133 167 134 ServerState.updateService(Alarm.StateString);168 Alarm.UpdateAlarmSummary(); 135 169 sleep(Period); 136 170 }
Note:
See TracChangeset
for help on using the changeset viewer.