1 /* 2 * File: globals.h 3 * Copyright: (c) 2006 by Peter Gritsch 4 * Email: s4nag@no-where.at 5 * 6 * This file is part of SNMP4Nagios. 7 * 8 * SNMP4Nagios is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or (at 11 * your option) any later version. 12 * 13 * SNMP4Nagios is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with SNMP4Nagios; if not, write to the 20 * 21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 * MA 02110-1301, USA 23 */ 24 25 #ifndef GLOBALS_H 26 #define GLOBALS_H 27 28 29 #ifndef NETSNMP_NO_INLINE 30 #define NETSNMP_NO_INLINE /* Turn off inlining */ 31 #endif 32 33 34 #include <net-snmp/net-snmp-config.h> 35 #include <net-snmp/net-snmp-includes.h> 36 37 38 /**********************/ 39 /* Exported constants */ 40 41 #if(WITH_RRD) 42 /* 43 * Directory where the host directories are created which in turn contain the 44 * rrd files. 45 */ 46 #ifndef RRDDIR 47 #define RRDDIR "/usr/local/nagios/perflog/rrd" 48 #endif 49 50 /* 51 * Directory where the host directories are created which in turn contain the 52 * rrd files. 53 */ 54 #ifndef PNGDIR 55 #define PNGDIR "/usr/local/nagios/perflog/img" 56 #endif 57 #endif /* WITH_RRD */ 58 59 /* 60 * Facility where messages are logged. 61 */ 62 #ifndef LOGFACILITY 63 #define LOGFACILITY LOG_DAEMON 64 #endif 65 66 67 /*********************/ 68 /* Just to make sure */ 69 70 #ifndef FALSE 71 #define FALSE 0 72 #endif 73 74 #ifndef TRUE 75 #define TRUE !FALSE 76 #endif 77 78 #ifndef ulong 79 #define ulong unsigned long int 80 #endif 81 82 83 /***********************/ 84 /* Little helper macro */ 85 86 #define MAXIMUM(a,b) ( (a) > (b) ) ? (a) : (b) 87 88 /********************/ 89 /* Global variables */ 90 91 /* 92 * basename of the program when running. (Default: NULL) 93 */ 94 extern char* progName; 95 96 /* 97 * service name, often the same as progName; used to build the file names 98 * of the rrd archives and plots. (Default: NULL) 99 */ 100 extern char* srvName; 101 102 /* 103 * version of the program. (Default: NULL) 104 */ 105 extern char* progVersion; 106 107 /* 108 * logging level. (Default: LOG_ERR) 109 */ 110 extern int loggingLevel; 111 112 /* 113 * TRUE if the host should be scanned for services of this type. 114 * (Default: FALSE) 115 */ 116 extern int scanServices; 117 118 /* 119 * TRUE if the actual service check should be made. (Default: FALSE) 120 */ 121 extern int checkData; 122 123 #if(WITH_RRD) 124 /* 125 * TRUE if the performance data should be checked. (Default: FALSE) 126 */ 127 extern int logPerfData; 128 129 /* 130 * TRUE if the performance data should be plotted. (Default: FALSE) 131 */ 132 extern int plotPerfData; 133 #endif /* WITH_RRD */ 134 135 /* 136 * TRUE if the Nagios Plugins compatible performance data format should be 137 * used. (Default: FALSE) 138 */ 139 extern int npPerfData; 140 141 /* 142 * String containing the synopsis of the program specific index parameters 143 * e.g. "-s SYSTEM -i INDEX". (Default: NULL) 144 */ 145 extern char* helpIndexP; 146 147 /* 148 * String containing the synopsis of the program specific threshold parameters 149 * e.g. "-w WARN -c CRIT". (Default: NULL) 150 */ 151 extern char* helpThresP; 152 153 /* 154 * String containing a short description of the program. 155 */ 156 extern char* helpPurpose; 157 158 /* 159 * The variable where the host name will be stored. (Default: NULL) 160 */ 161 extern char* hostName; 162 163 /* 164 * Set to TRUE if host name has been set. (Default: FALSE) 165 */ 166 extern int isHostNameSet; 167 168 /* 169 * The variable where the host address will be stored. (Default: NULL) 170 */ 171 extern char* hostAddr; 172 173 /* 174 * Set to TRUE if host address has been set. (Default: FALSE) 175 */ 176 extern int isHostAddrSet; 177 178 /* 179 * Does the plugin have a '--index' parameter? This is special because it is 180 * common enough to handle that globally. (Default: FALSE) 181 */ 182 extern int hasIndexParam; 183 184 /* 185 * The variable where the index passed by an command line argument will be 186 * stored. (Default: -1) 187 */ 188 extern int idx; 189 190 /* 191 * Set to TRUE if idx has been set by the command line. (Default: FALSE) 192 */ 193 extern int isIdxSet; 194 195 /* 196 * Does the plugin have a '--additional-info' parameter? This is special 197 * because it is common enough to handle that globally. (Default: FALSE) 198 */ 199 extern int hasAddInfParam; 200 201 /* 202 * The variable where the additional info passed by an command line argument 203 * will be stored. This is only used (usable) if supportsPerfLog is TRUE. 204 * (Default: NULL) 205 */ 206 extern char* addInf; 207 208 /* 209 * Set to TRUE if addInf has been set by the command line. (Default: FALSE) 210 */ 211 extern int isAddInfSet; 212 213 /* 214 * The community string if provided on the command line, else NULL. 215 * (Default: NULL) 216 */ 217 extern char* community; 218 219 /* 220 * The community string file name if provided on the command line, 221 * else NULL. (Default: NULL) 222 */ 223 extern char* commFile; 224 225 /* 226 * Defaults to SNMP_VERSION_2c, can be set to SNMP_VERSION_1 by a command 227 * line switch. 228 */ 229 extern long snmpVersion; 230 231 /* 232 * Number of times to retry a SNMP request. This can be set by the --retries 233 * command line option. Defaults to 5. 234 */ 235 extern int snmpRetries; 236 237 /* 238 * Timeout for the first SNMP request in microseconds. This is just a global 239 * variable in case I want to make it configurable some day. Defaults to 240 * 1000000 (1 Second). 241 */ 242 extern int snmpTimeOut; 243 244 /* 245 * Does the plugin support performance logging and plotting? (Default: FALSE) 246 */ 247 extern int supportsPerfLog; 248 249 #if(WITH_RRD) 250 /* 251 * Base(!) directory for the rrd archives. (Default: RRDDIR) 252 */ 253 extern char* rrdDir; 254 255 /* 256 * RRD Step (c.f. man rrdcreate). (Default: -1) 257 */ 258 extern int rrdStep; 259 260 /* 261 * RRD Heartbeat (c.f. man rrdcreate). (Default: -1) 262 */ 263 extern int rrdHBeat; 264 265 /* 266 * Base(!) directory for the png files. (Default: PNGDIR) 267 */ 268 extern char* pngDir; 269 #endif /* WITH_RRD */ 270 271 272 /***********************************************************/ 273 /* Function which have to be provided by the using program */ 274 275 /* 276 * Writes the plugin specific parameters to stdout. An example 277 * would be: 278 * 279 * void HelpSpecificParams () 280 * { 281 * printf ( 282 * "-w, --warning INTEGER\n" 283 * " Level at which a warning is generated.\n" 284 * "\n" 285 * "-c, --critical INTEGER\n" 286 * " Level at which a critical is generated.\n" 287 * "\n" 288 * ); 289 * } 290 */ 291 extern void HelpSpecificParams (); 292 293 /* 294 * This function writes a help text about the function of this program to 295 * stdout. Example: 296 * 297 * void HelpExplain () 298 * { 299 * printf ( 300 * "This plugin monitors the function of the foobar device. If the\n" 301 * "device reports a failing foo entity, then a warning is generated.\n" 302 * "If two or more entities fail, then a critical is generated.\n" 303 * "\n" 304 * ); 305 * } 306 */ 307 extern void HelpExplain (); 308 309 /* 310 * This function writes a help text about the performance data provided by 311 * this program to stdout. Example: 312 * 313 * void HelpPerformanceData () 314 * { 315 * printf ( 316 * "Native performance data is provided in the format:\n" 317 * "<foo>;<bar>\n" 318 * "where\n" 319 * " foo ... foo counter\n" 320 * " bar ... current bar value\n" 321 * "\n" 322 * ); 323 * printf ( 324 * "Nagios Plugins compatible performance data is provided in the format:\n" 325 * "'foo counter'=<foo>c " 326 * "'current bar value'=<bar>\n" 327 * "\n" 328 * ); 329 * } 330 */ 331 extern void HelpPerformanceData (); 332 333 /* 334 * This function should try to interpret the argument argv[(*i)] 335 * as a program specific option. If that is a known argument, appropriate 336 * measures should be taken, *i should be incremented and TRUE should be 337 * returned. If the function can not handle this parameter, then FALSE 338 * should be returned. 339 * 340 * The function can also interpret additional parameters, each time 341 * incrementing *i. 342 * 343 * Example: 344 * 345 * int ChkOptSpecificParams ( int argc, char** argv, int* i ) 346 * { 347 * int ret = TRUE; 348 * if ( !strcmp ( argv [(*i)], "-w" ) 349 * || !strcmp ( argv [(*i)], "--warning" ) ) 350 * { 351 * isWarnSet = TRUE; 352 * (*i)++; 353 * if ( (*i) < argc ) 354 * { 355 * char *tail = argv [(*i)]; 356 * errno = 0; 357 * warn = strtod ( argv [(*i)++], &tail ); 358 * if ( errno || *tail ) Usage ( "Invalid 'warn' parameter" ); 359 * } else 360 * { 361 * Usage ( "Missing 'warn' parameter(s)" ); 362 * } 363 * } else ret = FALSE; 364 * return ( ret ); 365 * } 366 */ 367 int ChkOptSpecificParams ( int argc, char** argv, int* i ); 368 369 #if(WITH_RRD) 370 /* 371 * Creates a rrd file suitable for the data which is to be handled. 372 */ 373 extern void CreateDataFile ( const char* dataFile ); 374 375 /* 376 * Parses performance data as given by aData into the global data set. 377 */ 378 void ParseData ( const char* aData ); 379 380 /* 381 * Writes the performance data from the global data set to the RRD archive. 382 */ 383 void WriteData ( const char* aRRDFPath ); 384 #endif /* WITH_RRD */ 385 386 /* 387 * This function is called for each valid variable which is found during 388 * a SnmpWalk(). 389 * 390 * It could/should be used to figure out if this object has some meaning 391 * while scanning for a service. 392 */ 393 extern void SnmpWalkHandleVariable ( netsnmp_variable_list* aVar ); 394 395 #endif /* GLOBALS_H */ 396