Ignore:
Timestamp:
01/13/10 12:47:33 (15 years ago)
Author:
ogrimm
Message:
Various updates
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Alarm/Alarm.cc

    r127 r142  
    55  - Checks periodically if all required servers are up
    66    (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.
    911   
    10   Oliver Grimm, September 2009
     12  Oliver Grimm, January 2010
    1113
    1214\********************************************************************/
     
    1416#define SERVER_NAME "Alarm"
    1517#include "../Evidence.h"
     18
     19#define SUMMARYSIZE 10000       // Bytes for alarm summary text
     20
     21const char* StateString[] = {"OK", "WARN", "ERROR", "FATAL", "UNAVAILABLE"};
    1622
    1723//
     
    2127   
    2228    DimStampedInfo **StatusService;
     29
    2330    void infoHandler();
    2431
     
    2633    AlarmHandler();
    2734    ~AlarmHandler();
    28    
     35
     36        DimService *Summary, *Master;
     37       
     38        char *AlarmSummary;
     39        int MasterAlarm;
     40        int *State;   
    2941    char **Server;
    3042    unsigned int NumServers;
    31     char *StateString;
    32     char *ServerList; 
     43    char *ServerList;
     44       
     45        void UpdateAlarmSummary();
    3346};
    3447
     
    3649AlarmHandler::AlarmHandler(): EvidenceServer(SERVER_NAME) {
    3750
     51  AlarmSummary = new char [SUMMARYSIZE];
     52  MasterAlarm = 0;
     53 
    3854  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);
    3959
    4060  // Copy original list of servers to observe
     
    5373  // Subscribe with handler to 'Status' service of all servers
    5474  StatusService = new DimStampedInfo* [NumServers];
     75  State = new int [NumServers];
    5576 
    5677  for (int i=0; i<NumServers; i++) {
     
    5879    strcpy(Buffer, Server[i]);
    5980    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;
    6385  }
    64  
    65   StateString = new char [NumServers+1];
    66   for (int i=0; i<NumServers; i++) StateString[i] = '1';
    67   StateString[NumServers] = '\0';
    6886}
    6987
     
    7391  for (int i=0; i<NumServers; i++) delete StatusService[i];
    7492  delete[] StatusService;
     93  delete Master;
     94  delete Summary;
     95  delete[] State;
    7596  delete[] Server;
    7697  delete[] ServerList;
     98  delete[] AlarmSummary;
    7799}
    78100
    79 // Print messages of status changes to screen
     101// Print messages of status changes to screen and update status string
    80102void AlarmHandler::infoHandler() {
    81103
    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]) {
    90106
    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();
    96123  } 
    97124}
    98125
     126
     127// Update alarm status summary
     128void 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}
    99141
    100142//         
     
    113155  unsigned int Period = atoi(Alarm.GetConfig(SERVER_NAME " period"));
    114156
    115   // Create DIM services
    116   static DimService ServerState(SERVER_NAME"/State", Alarm.StateString);
    117   static DimService ServerList(SERVER_NAME"/Servers", Alarm.ServerList);
    118 
    119157  // Check periodically if servers are up
    120158  while(!EvidenceServer::ExitRequest) {
     
    125163        if (strcmp(ServerName, Alarm.Server[i]) == 0) Exists = true;
    126164      }
    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;
    132166    }
    133167   
    134     ServerState.updateService(Alarm.StateString);
     168    Alarm.UpdateAlarmSummary();
    135169    sleep(Period);
    136170  }
Note: See TracChangeset for help on using the changeset viewer.