![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /************************************************************************ 00002 * 00003 * MACROS.H - Common macro functions 00004 * 00005 * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors 00007 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00008 * 00009 * License: 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License version 2 as 00013 * published by the Free Software Foundation. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 ************************************************************************/ 00024 00025 #ifndef _MACROS_H 00026 #define _MACROS_H 00027 00028 #include "config.h" 00029 #include "common.h" 00030 #include "objects.h" 00031 00032 00033 00034 /****************** LENGTH LIMITATIONS ****************/ 00035 00036 #define MAX_COMMAND_ARGUMENTS 32 /* maximum number of $ARGx$ macros */ 00037 00038 00039 /****************** MACRO DEFINITIONS *****************/ 00040 00041 #define MACRO_ENV_VAR_PREFIX "ICINGA_" 00042 00043 #define MAX_USER_MACROS 256 /* maximum number of $USERx$ macros */ 00044 00045 #define MACRO_X_COUNT 154 /* size of macro_x[] array */ 00046 00047 struct icinga_macros { 00048 char *x[MACRO_X_COUNT]; 00049 char *argv[MAX_COMMAND_ARGUMENTS]; 00050 char *contactaddress[MAX_CONTACT_ADDRESSES]; 00051 char *ondemand; 00052 host *host_ptr; 00053 hostgroup *hostgroup_ptr; 00054 service *service_ptr; 00055 servicegroup *servicegroup_ptr; 00056 contact *contact_ptr; 00057 contactgroup *contactgroup_ptr; 00058 customvariablesmember *custom_host_vars; 00059 customvariablesmember *custom_service_vars; 00060 customvariablesmember *custom_contact_vars; 00061 }; 00062 typedef struct icinga_macros icinga_macros; 00063 00064 /* stay compatible */ 00065 struct nagios_macros { 00066 char *x[MACRO_X_COUNT]; 00067 char *argv[MAX_COMMAND_ARGUMENTS]; 00068 char *contactaddress[MAX_CONTACT_ADDRESSES]; 00069 char *ondemand; 00070 host *host_ptr; 00071 hostgroup *hostgroup_ptr; 00072 service *service_ptr; 00073 servicegroup *servicegroup_ptr; 00074 contact *contact_ptr; 00075 contactgroup *contactgroup_ptr; 00076 customvariablesmember *custom_host_vars; 00077 customvariablesmember *custom_service_vars; 00078 customvariablesmember *custom_contact_vars; 00079 }; 00080 typedef struct nagios_macros nagios_macros; 00081 00082 #define MACRO_HOSTNAME 0 00083 #define MACRO_HOSTALIAS 1 00084 #define MACRO_HOSTADDRESS 2 00085 #define MACRO_SERVICEDESC 3 00086 #define MACRO_SERVICESTATE 4 00087 #define MACRO_SERVICESTATEID 5 00088 #define MACRO_SERVICEATTEMPT 6 00089 #define MACRO_LONGDATETIME 7 00090 #define MACRO_SHORTDATETIME 8 00091 #define MACRO_DATE 9 00092 #define MACRO_TIME 10 00093 #define MACRO_TIMET 11 00094 #define MACRO_LASTHOSTCHECK 12 00095 #define MACRO_LASTSERVICECHECK 13 00096 #define MACRO_LASTHOSTSTATECHANGE 14 00097 #define MACRO_LASTSERVICESTATECHANGE 15 00098 #define MACRO_HOSTOUTPUT 16 00099 #define MACRO_SERVICEOUTPUT 17 00100 #define MACRO_HOSTPERFDATA 18 00101 #define MACRO_SERVICEPERFDATA 19 00102 #define MACRO_CONTACTNAME 20 00103 #define MACRO_CONTACTALIAS 21 00104 #define MACRO_CONTACTEMAIL 22 00105 #define MACRO_CONTACTPAGER 23 00106 #define MACRO_ADMINEMAIL 24 00107 #define MACRO_ADMINPAGER 25 00108 #define MACRO_HOSTSTATE 26 00109 #define MACRO_HOSTSTATEID 27 00110 #define MACRO_HOSTATTEMPT 28 00111 #define MACRO_NOTIFICATIONTYPE 29 00112 #define MACRO_NOTIFICATIONNUMBER 30 /* deprecated - see HOSTNOTIFICATIONNUMBER and SERVICENOTIFICATIONNUMBER macros */ 00113 #define MACRO_HOSTEXECUTIONTIME 31 00114 #define MACRO_SERVICEEXECUTIONTIME 32 00115 #define MACRO_HOSTLATENCY 33 00116 #define MACRO_SERVICELATENCY 34 00117 #define MACRO_HOSTDURATION 35 00118 #define MACRO_SERVICEDURATION 36 00119 #define MACRO_HOSTDURATIONSEC 37 00120 #define MACRO_SERVICEDURATIONSEC 38 00121 #define MACRO_HOSTDOWNTIME 39 00122 #define MACRO_SERVICEDOWNTIME 40 00123 #define MACRO_HOSTSTATETYPE 41 00124 #define MACRO_SERVICESTATETYPE 42 00125 #define MACRO_HOSTPERCENTCHANGE 43 00126 #define MACRO_SERVICEPERCENTCHANGE 44 00127 #define MACRO_HOSTGROUPNAME 45 00128 #define MACRO_HOSTGROUPALIAS 46 00129 #define MACRO_SERVICEGROUPNAME 47 00130 #define MACRO_SERVICEGROUPALIAS 48 00131 #define MACRO_HOSTACKAUTHOR 49 00132 #define MACRO_HOSTACKCOMMENT 50 00133 #define MACRO_SERVICEACKAUTHOR 51 00134 #define MACRO_SERVICEACKCOMMENT 52 00135 #define MACRO_LASTSERVICEOK 53 00136 #define MACRO_LASTSERVICEWARNING 54 00137 #define MACRO_LASTSERVICEUNKNOWN 55 00138 #define MACRO_LASTSERVICECRITICAL 56 00139 #define MACRO_LASTHOSTUP 57 00140 #define MACRO_LASTHOSTDOWN 58 00141 #define MACRO_LASTHOSTUNREACHABLE 59 00142 #define MACRO_SERVICECHECKCOMMAND 60 00143 #define MACRO_HOSTCHECKCOMMAND 61 00144 #define MACRO_MAINCONFIGFILE 62 00145 #define MACRO_STATUSDATAFILE 63 00146 #define MACRO_HOSTDISPLAYNAME 64 00147 #define MACRO_SERVICEDISPLAYNAME 65 00148 #define MACRO_RETENTIONDATAFILE 66 00149 #define MACRO_OBJECTCACHEFILE 67 00150 #define MACRO_TEMPFILE 68 00151 #define MACRO_LOGFILE 69 00152 #define MACRO_RESOURCEFILE 70 00153 #define MACRO_COMMANDFILE 71 00154 #define MACRO_HOSTPERFDATAFILE 72 00155 #define MACRO_SERVICEPERFDATAFILE 73 00156 #define MACRO_HOSTACTIONURL 74 00157 #define MACRO_HOSTNOTESURL 75 00158 #define MACRO_HOSTNOTES 76 00159 #define MACRO_SERVICEACTIONURL 77 00160 #define MACRO_SERVICENOTESURL 78 00161 #define MACRO_SERVICENOTES 79 00162 #define MACRO_TOTALHOSTSUP 80 00163 #define MACRO_TOTALHOSTSDOWN 81 00164 #define MACRO_TOTALHOSTSUNREACHABLE 82 00165 #define MACRO_TOTALHOSTSDOWNUNHANDLED 83 00166 #define MACRO_TOTALHOSTSUNREACHABLEUNHANDLED 84 00167 #define MACRO_TOTALHOSTPROBLEMS 85 00168 #define MACRO_TOTALHOSTPROBLEMSUNHANDLED 86 00169 #define MACRO_TOTALSERVICESOK 87 00170 #define MACRO_TOTALSERVICESWARNING 88 00171 #define MACRO_TOTALSERVICESCRITICAL 89 00172 #define MACRO_TOTALSERVICESUNKNOWN 90 00173 #define MACRO_TOTALSERVICESWARNINGUNHANDLED 91 00174 #define MACRO_TOTALSERVICESCRITICALUNHANDLED 92 00175 #define MACRO_TOTALSERVICESUNKNOWNUNHANDLED 93 00176 #define MACRO_TOTALSERVICEPROBLEMS 94 00177 #define MACRO_TOTALSERVICEPROBLEMSUNHANDLED 95 00178 #define MACRO_PROCESSSTARTTIME 96 00179 #define MACRO_HOSTCHECKTYPE 97 00180 #define MACRO_SERVICECHECKTYPE 98 00181 #define MACRO_LONGHOSTOUTPUT 99 00182 #define MACRO_LONGSERVICEOUTPUT 100 00183 #define MACRO_TEMPPATH 101 00184 #define MACRO_HOSTNOTIFICATIONNUMBER 102 00185 #define MACRO_SERVICENOTIFICATIONNUMBER 103 00186 #define MACRO_HOSTNOTIFICATIONID 104 00187 #define MACRO_SERVICENOTIFICATIONID 105 00188 #define MACRO_HOSTEVENTID 106 00189 #define MACRO_LASTHOSTEVENTID 107 00190 #define MACRO_SERVICEEVENTID 108 00191 #define MACRO_LASTSERVICEEVENTID 109 00192 #define MACRO_HOSTGROUPNAMES 110 00193 #define MACRO_SERVICEGROUPNAMES 111 00194 #define MACRO_HOSTACKAUTHORNAME 112 00195 #define MACRO_HOSTACKAUTHORALIAS 113 00196 #define MACRO_SERVICEACKAUTHORNAME 114 00197 #define MACRO_SERVICEACKAUTHORALIAS 115 00198 #define MACRO_MAXHOSTATTEMPTS 116 00199 #define MACRO_MAXSERVICEATTEMPTS 117 00200 #define MACRO_SERVICEISVOLATILE 118 00201 #define MACRO_TOTALHOSTSERVICES 119 00202 #define MACRO_TOTALHOSTSERVICESOK 120 00203 #define MACRO_TOTALHOSTSERVICESWARNING 121 00204 #define MACRO_TOTALHOSTSERVICESUNKNOWN 122 00205 #define MACRO_TOTALHOSTSERVICESCRITICAL 123 00206 #define MACRO_HOSTGROUPNOTES 124 00207 #define MACRO_HOSTGROUPNOTESURL 125 00208 #define MACRO_HOSTGROUPACTIONURL 126 00209 #define MACRO_SERVICEGROUPNOTES 127 00210 #define MACRO_SERVICEGROUPNOTESURL 128 00211 #define MACRO_SERVICEGROUPACTIONURL 129 00212 #define MACRO_HOSTGROUPMEMBERS 130 00213 #define MACRO_SERVICEGROUPMEMBERS 131 00214 #define MACRO_CONTACTGROUPNAME 132 00215 #define MACRO_CONTACTGROUPALIAS 133 00216 #define MACRO_CONTACTGROUPMEMBERS 134 00217 #define MACRO_CONTACTGROUPNAMES 135 00218 #define MACRO_NOTIFICATIONRECIPIENTS 136 00219 #define MACRO_NOTIFICATIONISESCALATED 137 00220 #define MACRO_NOTIFICATIONAUTHOR 138 00221 #define MACRO_NOTIFICATIONAUTHORNAME 139 00222 #define MACRO_NOTIFICATIONAUTHORALIAS 140 00223 #define MACRO_NOTIFICATIONCOMMENT 141 00224 #define MACRO_EVENTSTARTTIME 142 00225 #define MACRO_HOSTPROBLEMID 143 00226 #define MACRO_LASTHOSTPROBLEMID 144 00227 #define MACRO_SERVICEPROBLEMID 145 00228 #define MACRO_LASTSERVICEPROBLEMID 146 00229 #define MACRO_ISVALIDTIME 147 00230 #define MACRO_NEXTVALIDTIME 148 00231 #define MACRO_LASTHOSTSTATE 149 00232 #define MACRO_LASTHOSTSTATEID 150 00233 #define MACRO_LASTSERVICESTATE 151 00234 #define MACRO_LASTSERVICESTATEID 152 00235 #define MACRO_HOSTADDRESS6 153 00236 00237 00238 /************* MACRO CLEANING OPTIONS *****************/ 00239 00240 #define STRIP_ILLEGAL_MACRO_CHARS 1 00241 #define ESCAPE_MACRO_CHARS 2 00242 #define URL_ENCODE_MACRO_CHARS 4 00243 00244 00245 00246 /****************** MACRO FUNCTIONS ******************/ 00247 00248 icinga_macros *get_global_macros(void); 00249 00250 /* 00251 * Replace macros with their actual values 00252 * This function modifies the global_macros struct and is thus 00253 * not thread-safe. 00254 */ 00255 int process_macros(char *, char **, int); 00256 00257 /* thread-safe version of the above */ 00258 int process_macros_r(icinga_macros *mac, char *,char **,int); 00259 00260 /* cleans macros characters before insertion into output string */ 00261 char *clean_macro_chars(char *,int); 00262 00263 /* 00264 * These functions updates **macros with the values from 00265 * their respective object type. 00266 */ 00267 00268 int grab_service_macros(service *); 00269 int grab_host_macros(host *); 00270 int grab_servicegroup_macros(servicegroup *); 00271 int grab_hostgroup_macros(hostgroup *); 00272 int grab_contact_macros(contact *); 00273 int grab_contactgroup_macros(contactgroup *); 00274 00275 int grab_macro_value(char *,char **,int *,int *); 00276 int grab_macrox_value(int,char *,char *,char **,int *); 00277 int grab_custom_macro_value(char *,char *,char *,char **); 00278 int grab_datetime_macro(int,char *,char *,char **); 00279 int grab_standard_host_macro(int,host *,char **,int *); 00280 int grab_standard_hostgroup_macro(int,hostgroup *,char **); 00281 int grab_standard_service_macro(int,service *,char **,int *); 00282 int grab_standard_servicegroup_macro(int,servicegroup *,char **); 00283 int grab_standard_contact_macro(int,contact *,char **); 00284 int grab_contact_address_macro(int,contact *,char **); 00285 int grab_standard_contactgroup_macro(int,contactgroup *,char **); 00286 int grab_custom_object_macro(char *,customvariablesmember *,char **); 00287 00288 00289 /* thread-safe version of the above */ 00290 int grab_service_macros_r(icinga_macros *mac, service *); 00291 int grab_host_macros_r(icinga_macros *mac, host *); 00292 int grab_servicegroup_macros_r(icinga_macros *mac, servicegroup *); 00293 int grab_hostgroup_macros_r(icinga_macros *mac, hostgroup *); 00294 int grab_contact_macros_r(icinga_macros *mac, contact *); 00295 int grab_contactgroup_macros_r(icinga_macros *mac, contactgroup *); 00296 00297 int grab_macro_value_r(icinga_macros *mac, char *,char **,int *,int *); 00298 int grab_macrox_value_r(icinga_macros *mac, int,char *,char *,char **,int *); 00299 int grab_custom_macro_value_r(icinga_macros *mac, char *,char *,char *,char **); 00300 int grab_datetime_macro_r(icinga_macros *mac, int,char *,char *,char **); 00301 int grab_standard_host_macro_r(icinga_macros *mac, int,host *,char **,int *); 00302 int grab_standard_hostgroup_macro_r(icinga_macros *mac, int,hostgroup *,char **); 00303 int grab_standard_service_macro_r(icinga_macros *mac, int,service *,char **,int *); 00304 int grab_standard_servicegroup_macro_r(icinga_macros *mac, int,servicegroup *,char **); 00305 int grab_standard_contact_macro_r(icinga_macros *mac, int,contact *,char **); 00306 int grab_contact_address_macro_r(icinga_macros *mac, int,contact *,char **); 00307 int grab_standard_contactgroup_macro_r(icinga_macros *mac, int,contactgroup *,char **); 00308 int grab_custom_object_macro_r(icinga_macros *mac, char *,customvariablesmember *,char **); 00309 00310 00311 char *get_url_encoded_string(char *); /* URL encode a string */ 00312 00313 int init_macros(void); 00314 int init_macrox_names(void); 00315 int free_macrox_names(void); 00316 00317 00318 extern void copy_constant_macros(char **dest); 00319 00320 /* clear macros */ 00321 int clear_argv_macros(void); 00322 int clear_volatile_macros(void); 00323 int clear_host_macros(void); 00324 int clear_service_macros(void); 00325 int clear_hostgroup_macros(void); 00326 int clear_servicegroup_macros(void); 00327 int clear_contact_macros(void); 00328 int clear_contactgroup_macros(void); 00329 int clear_summary_macros(void); 00330 00331 /* thread-safe version of the above */ 00332 int clear_argv_macros_r(icinga_macros *mac); 00333 int clear_volatile_macros_r(icinga_macros *mac); 00334 int clear_host_macros_r(icinga_macros *mac); 00335 int clear_service_macros_r(icinga_macros *mac); 00336 int clear_hostgroup_macros_r(icinga_macros *mac); 00337 int clear_servicegroup_macros_r(icinga_macros *mac); 00338 int clear_contact_macros_r(icinga_macros *mac); 00339 int clear_contactgroup_macros_r(icinga_macros *mac); 00340 int clear_summary_macros_r(icinga_macros *mac); 00341 00342 #ifdef NSCORE 00343 int set_all_macro_environment_vars(int); 00344 int set_macrox_environment_vars(int); 00345 int set_argv_macro_environment_vars(int); 00346 int set_custom_macro_environment_vars(int); 00347 int set_contact_address_environment_vars(int); 00348 00349 int set_all_macro_environment_vars_r(icinga_macros *mac, int); 00350 int set_macrox_environment_vars_r(icinga_macros *mac, int); 00351 int set_argv_macro_environment_vars_r(icinga_macros *mac, int); 00352 int set_custom_macro_environment_vars_r(icinga_macros *mac, int); 00353 int set_contact_address_environment_vars_r(icinga_macros *mac, int); 00354 00355 int set_macro_environment_var(char *,char *,int); 00356 #endif 00357 00358 #endif