1 /*----------------------------------------------------------------------------*/ 2 /* Xymon monitor library. */ 3 /* */ 4 /* Copyright (C) 2004-2011 Henrik Storner <henrik@hswn.dk> */ 5 /* */ 6 /* This program is released under the GNU General Public License (GPL), */ 7 /* version 2. See the file "COPYING" for details. */ 8 /* */ 9 /*----------------------------------------------------------------------------*/ 10 11 #ifndef __LOADALERTS_H__ 12 #define __LOADALERTS_H__ 13 14 #include <time.h> 15 #include <stdio.h> 16 17 /* The clients probably don't have the pcre headers */ 18 #if defined(LOCALCLIENT) || !defined(CLIENTONLY) 19 #include <pcre.h> 20 21 typedef enum { A_PAGING, A_NORECIP, A_ACKED, A_RECOVERED, A_DISABLED, A_NOTIFY, A_DEAD } astate_t; 22 23 typedef struct activealerts_t { 24 /* Identification of the alert */ 25 char *hostname; 26 char *testname; 27 char *location; 28 char *osname; 29 char *classname; 30 char *groups; 31 char ip[IP_ADDR_STRLEN]; 32 33 /* Alert status */ 34 int color, maxcolor; 35 unsigned char *pagemessage; 36 unsigned char *ackmessage; 37 time_t eventstart; 38 time_t nextalerttime; 39 astate_t state; 40 int cookie; 41 42 struct activealerts_t *next; 43 } activealerts_t; 44 45 /* These are the criteria we use when matching an alert. Used both generally for a rule, and for recipients */ 46 enum method_t { M_MAIL, M_SCRIPT, M_IGNORE }; 47 enum msgformat_t { ALERTFORM_TEXT, ALERTFORM_PLAIN, ALERTFORM_SMS, ALERTFORM_PAGER, ALERTFORM_SCRIPT, ALERTFORM_NONE }; 48 enum recovermsg_t { SR_UNKNOWN, SR_NOTWANTED, SR_WANTED }; 49 typedef struct criteria_t { 50 int cfid; 51 char *cfline; 52 char *pagespec; /* Pages to include */ 53 pcre *pagespecre; 54 char *expagespec; /* Pages to exclude */ 55 pcre *expagespecre; 56 char *dgspec; /* Display groups to include */ 57 pcre *dgspecre; 58 char *exdgspec; /* Display groups to exclude */ 59 pcre *exdgspecre; 60 char *hostspec; /* Hosts to include */ 61 pcre *hostspecre; 62 char *exhostspec; /* Hosts to exclude */ 63 pcre *exhostspecre; 64 char *svcspec; /* Services to include */ 65 pcre *svcspecre; 66 char *exsvcspec; /* Services to exclude */ 67 pcre *exsvcspecre; 68 char *classspec; 69 pcre *classspecre; 70 char *exclassspec; 71 pcre *exclassspecre; 72 char *groupspec; 73 pcre *groupspecre; 74 char *exgroupspec; 75 pcre *exgroupspecre; 76 int colors; 77 char *timespec; 78 char *extimespec; 79 int minduration, maxduration; /* In seconds */ 80 enum recovermsg_t sendrecovered, sendnotice; 81 } criteria_t; 82 83 /* This defines a recipient. There may be some criteria, and then how we send alerts to him */ 84 typedef struct recip_t { 85 int cfid; 86 criteria_t *criteria; 87 enum method_t method; 88 char *recipient; 89 char *scriptname; 90 enum msgformat_t format; 91 time_t interval; /* In seconds */ 92 int stoprule, unmatchedonly, noalerts; 93 struct recip_t *next; 94 } recip_t; 95 96 extern int load_alertconfig(char *configfn, int alertcolors, int alertinterval); 97 extern void dump_alertconfig(int showlinenumbers); 98 extern void set_localalertmode(int localmode); 99 100 extern int stoprulefound; 101 extern recip_t *next_recipient(activealerts_t *alert, int *first, int *anymatch, time_t *nexttime); 102 extern int have_recipient(activealerts_t *alert, int *anymatch); 103 104 extern void alert_printmode(int on); 105 extern void print_alert_recipients(activealerts_t *alert, strbuffer_t *buf); 106 #endif 107 108 #endif 109 110