monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PLAN: implement a "new" Event model


From: Jan-Henrik Haukeland
Subject: PLAN: implement a "new" Event model
Date: Mon, 30 Jun 2003 19:46:41 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Civil Service, linux)


Okay to summarize the latest event discussion here is the PLAN. I will
start on this today and hopefully have it ready later this
evening/night.  This work is necessary to prepare monit for Martin's
method language changes.

The plan is to replace the current alert_xxx with a true event system
but do this as gentle as possible and avoid changing to much of the
code. Most notably the change will simply replace alert_xxx with a
post_event() method in validate.c. After I have done this I hope that
Christian and Martin can refactor all code in validate.c contained in
the

   case TASK_PROCESS
   case TASK_DEVICE
   case TASK_FILE
   case TASK_DIRECTORY

into the following functions:

  check_processes(); // Including mem/cpu/children/ and if process is running
  check_device()
  check_file();
  check_directory();

with the new event system this should be not to much work.

THE GOAL is that do_validate will look like this when we are finnished:

static void do_validate(..) {

  // initialization
  ...
  check_processes(); // Including mem/cpu/children/ and if process is running
  check_device()
  check_file();
  check_directory();
  
}



What I will do:

1) Create an Event_T object looking like this
    typedef struct myevent {
            int id; // The event type [DO_STOP, DO_TIMEOUT ...]
            Service_T source; // The Service the event occured on
            char message[STRLEN]; // Optional descripton of the event
    } Event_T;

2) Remove Alert_T and replace Alert_T with: long events; where events
   is a bit-mapped flag containing events. This means that Mail_T will
   look like this:
   
   /** Defines a mailinglist object */
   typedef struct mymail {
           char *to;           /**< Mail address for alert notification */
           char *from;                       /**< The mail from address */
           char *subject;                         /**< The mail subject */
           char *message;                         /**< The mail message */
           char *opt_message;   /**< An optional message used in alerts */
   NEW-->  long events;     /**< Events triggering this mail to be sent */
          /** For internal use */
          struct mymail *next;              /**< next recipient in chain */
   } *Mail_T;

3) Create the following events and removing DO_XXX:

   #define START_EVENT     1
   #define STOP_EVENT      2
   #define RESTART_EVENT   4
   #define CHECKSUM_EVENT  8
   #define RESOURCE_EVENT  16
   #define TIMEOUT_EVENT   32
   #define FAILED_EVENT    64
   #define TIMESTAMP_EVENT 128


   Setting an event in e.g. Mail_T will look like this

    Mail_T m; ..
  
    m->events |= START_EVENT;
    m->events |= STOP_EVENT;

    If no events is set, m->events has the value 0

    Checking for events will look like this:

    if(m->events & START_EVENT) { do start stuff }
    if(m->events & STOP_EVENT)  { do stop stuff }


4)  Create a new module called event.c containing at least two functions.

    /**
     * Post an event to the event handler
     * @param source The Service the event occured on
     * @param id The event type
     * @param  s Optional message describing the event
     */
    void post_event(Service_T source, long id, char s, ...);

    The post_event function will call handle_event

    /**
     * Handle the posted event
     * @param event The event to handle
     * @return TRUE if the event was handled otherwise FALSE
    static int handle_event(Event_T event);


5) Please do not check-in anything into CVS until this is ready.

-- 
Jan-Henrik Haukeland




reply via email to

[Prev in Thread] Current Thread [Next in Thread]