/[monit]/monit/event.c
ViewVC logotype

Diff of /monit/event.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.48 by martinp, Sun Aug 14 08:51:55 2005 UTC revision 1.49 by martinp, Mon Sep 5 09:51:37 2005 UTC
# Line 82  static int  handle_action(Event_T, Actio Line 82  static int  handle_action(Event_T, Actio
82   * Post a new Event   * Post a new Event
83   * @param service The Service the event belongs to   * @param service The Service the event belongs to
84   * @param id The event identification   * @param id The event identification
85   * @param state TRUE for failed, FALSE for passed event state   * @param state The event state
86   * @param action Description of the event action   * @param action Description of the event action
87   * @param s Optional message describing the event   * @param s Optional message describing the event
88   */   */
# Line 93  void Event_post(Service_T service, long Line 93  void Event_post(Service_T service, long
93    
94    ASSERT(service);    ASSERT(service);
95    ASSERT(action);    ASSERT(action);
96      ASSERT(state == STATE_FAILED || state == STATE_PASSED);
97    
98    if(e == NULL)    if(e == NULL)
99    {    {
# Line 109  void Event_post(Service_T service, long Line 110  void Event_post(Service_T service, long
110      e->id = id;      e->id = id;
111      e->collected = time(NULL);      e->collected = time(NULL);
112      e->source = service;      e->source = service;
113      e->state = state;      e->state = STATE_INIT;
114      e->state_changed = TRUE;      e->state_map = state;
     e->count = 1;  
115      e->action = action;      e->action = action;
116      if(s)      if(s)
117      {      {
# Line 137  void Event_post(Service_T service, long Line 137  void Event_post(Service_T service, long
137          LOCK(e->mutex)          LOCK(e->mutex)
138            e->collected = time(NULL);            e->collected = time(NULL);
139    
140            /* update the message */            /* Shift the existing event flags to the left
141               * and set the first bit based on actual state */
142              e->state_map <<= 1;
143              e->state_map |= state;
144    
145              /* Update the message */
146            if(s)            if(s)
147            {            {
148              long l;              long l;
# Line 149  void Event_post(Service_T service, long Line 154  void Event_post(Service_T service, long
154              va_end(ap);              va_end(ap);
155            }            }
156    
           if(e->state != state)  
           {  
             e->state = state;  
             e->state_changed = TRUE;  
             e->count = 1;  
           }  
           else  
           {  
             e->count++;  
           }  
157          END_LOCK;          END_LOCK;
158          break;          break;
159        }        }
# Line 178  void Event_post(Service_T service, long Line 173  void Event_post(Service_T service, long
173        e->id = id;        e->id = id;
174        e->collected = time(NULL);        e->collected = time(NULL);
175        e->source = service;        e->source = service;
176        e->state = state;        e->state = STATE_INIT;
177        e->state_changed = TRUE;        e->state_map = state;
       e->count = 1;  
178        e->action = action;        e->action = action;
179        if(s)        if(s)
180        {        {
# Line 197  void Event_post(Service_T service, long Line 191  void Event_post(Service_T service, long
191      }      }
192    }    }
193    
194      e->state_changed = Event_check_state(e, state);
195    
196      /* In the case that the state changed, update it and reset the counter */
197      if(e->state_changed)
198      {
199        e->state = state;
200        e->count = 1;
201      }
202      else
203      {
204        e->count++;
205      }
206    
207    LOCK(e->mutex)    LOCK(e->mutex)
208      handle_event(e);      handle_event(e);
209    END_LOCK;    END_LOCK;
# Line 250  short Event_get_state(Event_T E) { Line 257  short Event_get_state(Event_T E) {
257    
258    
259  /**  /**
260     * Return the actual event state based on event state bitmap
261     * and event ratio needed to trigger the state change
262     * @param E An event object
263     * @param S Actual posted state
264     * @return The Event raw state
265     */
266    short Event_check_state(Event_T E, short S) {
267    
268      int       i;
269      int       count = 0;
270      Action_T  action;
271      long long flag;
272    
273      ASSERT(E);
274    
275      action = (S == STATE_PASSED)?E->action->passed:E->action->failed;
276    
277      /* Compare as many bits as cycles able to trigger the action */
278      for(i = 0; i < action->cycles; i++)
279      {
280        /* Check the state of the particular cycle given by the bit position */
281        flag = (E->state_map >> i) & 0x1;
282    
283        /* Count occurences of the posted state */
284        if(flag == S)
285        {
286          count++;
287        }
288      }
289    
290      if(count >= action->count && S != E->state)
291      {
292        return TRUE;
293      }
294      
295      return FALSE;
296    
297    }
298    
299    
300    /**
301   * Get the Event type   * Get the Event type
302   * @param E An event object   * @param E An event object
303   * @return The Event type   * @return The Event type
# Line 368  static void handle_event(Event_T E) { Line 416  static void handle_event(Event_T E) {
416    ASSERT(E->action->failed);    ASSERT(E->action->failed);
417    ASSERT(E->action->passed);    ASSERT(E->action->passed);
418    
419    /* We will handle only first passed event, recurrent passed events are    /* We will handle only first passed event, recurrent passed events
420       * or insufficient passed events during failed service state are
421     * ignored. Failed events are handled each time. */     * ignored. Failed events are handled each time. */
422    if(!E->state_changed && !E->state)    if(!E->state_changed && E->state == STATE_PASSED)
423    {    {
424      return;      return;
425    }    }
# Line 380  static void handle_event(Event_T E) { Line 429  static void handle_event(Event_T E) {
429      log("%s\n", E->message);      log("%s\n", E->message);
430    }    }
431    
432    if(E->state)    if(E->state == STATE_FAILED)
433    {    {
434      E->source->error |= E->id;      E->source->error |= E->id;
435      handle_action(E, E->action->failed);      handle_action(E, E->action->failed);

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26