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

Diff of /monit/alert.c

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

revision 1.17 by martinp, Mon Jun 9 20:51:01 2003 UTC revision 1.18 by hauk, Mon Jun 16 22:06:15 2003 UTC
# Line 31  Line 31 
31  #include "net.h"  #include "net.h"
32  #include "alert.h"  #include "alert.h"
33    
34    
35    /**
36     *  Alert routines, at the moment only mail alert is used. In the
37     *  future this could be a placeholder for other types of alert
38     *  notification.
39     *
40     *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>
41     *  @author Martin Pala <martin.pala@iol.cz>
42     *  @author Christian Hopp <chopp@iei.tu-clausthal.de>
43     *
44     *  @version \$Id$
45     *
46     *  @file
47     */
48    
49    
50    /* ------------------------------------------------------------- Definitions */
51    
52    
53  #define DO_TIMEOUT   0  #define DO_TIMEOUT   0
54  #define DO_RESTART   1  #define DO_RESTART   1
55  #define DO_CHECKSUM  2  #define DO_CHECKSUM  2
# Line 39  Line 58 
58  #define DO_FAILED    5  #define DO_FAILED    5
59  #define DO_TIMESTAMP 6  #define DO_TIMESTAMP 6
60    
   
 /* Private Prototypes */  
 static int count(char *, char *);  
 static void copy_mail(Mail_T, Mail_T);  
 static void replace(char **, char *, char *);  
 static void smtp_alert(Process_T, int, char *, va_list);  
 static void substitute(Mail_T*, char *name, char *event);  
   
61  /* Private Variables */  /* Private Variables */
62  static char desc[][STRLEN]= {"timed out", "restarted", "checksum error",  static char desc[][STRLEN]= {"timed out", "restarted", "checksum error",
63                               "matches resource limitation", "stopped",                               "matches resource limitation", "stopped",
# Line 57  static char desclog[][STRLEN]= {"Timeout Line 68  static char desclog[][STRLEN]= {"Timeout
68                                  "Failed", "Timestamp error"};                                  "Failed", "Timestamp error"};
69    
70    
71  /**  /* -------------------------------------------------------------- Prototypes */
72   *  Alert routines, at the moment only mail alert is used. In the  
73   *  future this could be a placeholder for other types of alert  
74   *  notification.  static int count(char *, char *);
75   *  static void copy_mail(Mail_T, Mail_T);
76   *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>  static void replace(char **, char *, char *);
77   *  @author Martin Pala <martin.pala@iol.cz>  static void smtp_alert(Service_T, int, char *, va_list);
78   *  @author Christian Hopp <chopp@iei.tu-clausthal.de>  static void substitute(Mail_T*, char *name, char *event);
  *  
  *  @version \$Id$  
  *  
  *  @file  
  */  
79    
80    
81  /* ------------------------------------------------------------------ Public */  /* ------------------------------------------------------------------ Public */
# Line 77  static char desclog[][STRLEN]= {"Timeout Line 83  static char desclog[][STRLEN]= {"Timeout
83    
84  /**  /**
85   * Send an alert timeout message to the email address for   * Send an alert timeout message to the email address for
86   * this process   * this service
87   * @param p A Process_T object   * @param s A Service_T object
88   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
89   */   */
90  void smtp_alert_timeout(Process_T p, char *m, ...) {  void smtp_alert_timeout(Service_T s, char *m, ...) {
91    
92    va_list ap;    va_list ap;
93    
94    ASSERT(p);    ASSERT(s);
95        
96    va_start(ap, m);    va_start(ap, m);
97    smtp_alert(p, DO_TIMEOUT, m, ap);    smtp_alert(s, DO_TIMEOUT, m, ap);
98    va_end(ap);    va_end(ap);
99        
100        
# Line 97  void smtp_alert_timeout(Process_T p, cha Line 103  void smtp_alert_timeout(Process_T p, cha
103    
104  /**  /**
105   * Send an alert checksum message to the email address for   * Send an alert checksum message to the email address for
106   * this process   * this service
107   * @param p A process_t object   * @param s A service_t object
108   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
109   */   */
110  void smtp_alert_checksum(Process_T p, char *m, ...) {  void smtp_alert_checksum(Service_T s, char *m, ...) {
111    
112    va_list ap;    va_list ap;
113        
114    ASSERT(p);    ASSERT(s);
115    
116    va_start(ap, m);    va_start(ap, m);
117    smtp_alert(p, DO_CHECKSUM, m, ap);    smtp_alert(s, DO_CHECKSUM, m, ap);
118    va_end(ap);    va_end(ap);
119        
120  }  }
121    
122    
123  /**  /**
124   * Send an alert restart message to the email address for this process   * Send an alert restart message to the email address for this service
125   * @param p A process_t object   * @param s A service_t object
126   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
127   */   */
128  void smtp_alert_restart(Process_T p, char *m, ...) {  void smtp_alert_restart(Service_T s, char *m, ...) {
129    
130    va_list ap;    va_list ap;
131        
132    ASSERT(p);    ASSERT(s);
133    
134    va_start(ap, m);    va_start(ap, m);
135    smtp_alert(p, DO_RESTART, m, ap);    smtp_alert(s, DO_RESTART, m, ap);
136    va_end(ap);    va_end(ap);
137        
138  }  }
139    
140    
141  /**  /**
142   * Send an alert resource message to the email address for this process   * Send an alert resource message to the email address for this service
143   * @param p A process_t object   * @param s A service_t object
144   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
145   */   */
146  void smtp_alert_resource(Process_T p, char *m, ...) {  void smtp_alert_resource(Service_T s, char *m, ...) {
147    
148    va_list ap;    va_list ap;
149        
150    ASSERT(p);    ASSERT(s);
151    
152    va_start(ap, m);    va_start(ap, m);
153    smtp_alert(p, DO_RESOURCE, m, ap);    smtp_alert(s, DO_RESOURCE, m, ap);
154    va_end(ap);    va_end(ap);
155        
156  }  }
157    
158    
159  /**  /**
160   * Send an alert stop message to the email address for this process   * Send an alert stop message to the email address for this service
161   * @param p A process_t object   * @param s A service_t object
162   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
163   */   */
164  void smtp_alert_stop(Process_T p, char *m, ...) {  void smtp_alert_stop(Service_T s, char *m, ...) {
165    
166    va_list ap;    va_list ap;
167        
168    ASSERT(p);    ASSERT(s);
169    
170    va_start(ap, m);    va_start(ap, m);
171    smtp_alert(p, DO_STOP, m, ap);    smtp_alert(s, DO_STOP, m, ap);
172    va_end(ap);    va_end(ap);
173        
174  }  }
175    
176    
177  /**  /**
178   * Send an alert failed message to the email address for this process   * Send an alert failed message to the email address for this service
179   * @param p A process_t object   * @param s A service_t object
180   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
181   */   */
182  void smtp_alert_failed(Process_T p, char *m, ...) {  void smtp_alert_failed(Service_T s, char *m, ...) {
183    
184    va_list ap;    va_list ap;
185    
186    ASSERT(p);    ASSERT(s);
187    
188    va_start(ap, m);    va_start(ap, m);
189    smtp_alert(p, DO_FAILED, m, ap);    smtp_alert(s, DO_FAILED, m, ap);
190    va_end(ap);    va_end(ap);
191    
192  }  }
193    
194    
195  /**  /**
196   * Send an alert timestamp message to the email address for this process   * Send an alert timestamp message to the email address for this service
197   * @param p A process_t object   * @param s A service_t object
198   * @param m An optional message string. May be NULL.   * @param m An optional message string. May be NULL.
199   */   */
200  void smtp_alert_timestamp(Process_T p, char *m, ...) {  void smtp_alert_timestamp(Service_T s, char *m, ...) {
201    
202    va_list ap;    va_list ap;
203    
204    ASSERT(p);    ASSERT(s);
205    
206    va_start(ap, m);    va_start(ap, m);
207    smtp_alert(p, DO_TIMESTAMP, m, ap);    smtp_alert(s, DO_TIMESTAMP, m, ap);
208    va_end(ap);    va_end(ap);
209    
210  }  }
# Line 210  void smtp_alert_timestamp(Process_T p, c Line 216  void smtp_alert_timestamp(Process_T p, c
216  /*  /*
217   * Send a smtp notification   * Send a smtp notification
218   */   */
219  static void smtp_alert(Process_T p, int event, char *optmsg, va_list ap) {  static void smtp_alert(Service_T s, int event, char *optmsg, va_list ap) {
220    
221    ASSERT(p);    ASSERT(s);
222    
223    if(p->maillist) {    if(s->maillist) {
224    
225      Mail_T m;      Mail_T m;
226      sigset_t ns, os;      sigset_t ns, os;
# Line 229  static void smtp_alert(Process_T p, int Line 235  static void smtp_alert(Process_T p, int
235       * Build a mail-list with recipients that has registered interest       * Build a mail-list with recipients that has registered interest
236       * for this event.       * for this event.
237       */       */
238      for(m= p->maillist; m; m= m->next) {      for(m= s->maillist; m; m= m->next) {
239                
240        int notify[]= { m->alert_on_timeout,        int notify[]= { m->alert_on_timeout,
241                        m->alert_on_restart,                        m->alert_on_restart,
# Line 248  static void smtp_alert(Process_T p, int Line 254  static void smtp_alert(Process_T p, int
254          if(optmsg)          if(optmsg)
255              tmp->opt_message= format(optmsg, ap);              tmp->opt_message= format(optmsg, ap);
256                    
257          substitute(&tmp, p->name, desc[event]);          substitute(&tmp, s->name, desc[event]);
258                    
259          tmp->next= list;          tmp->next= list;
260          list= tmp;          list= tmp;

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

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