summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c75
1 files changed, 58 insertions, 17 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 3822bcf..0f52126 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -24,7 +24,7 @@
24* 24*
25*****************************************************************************/ 25*****************************************************************************/
26 26
27#include "common.h" 27#include "../plugins/common.h"
28#include <stdarg.h> 28#include <stdarg.h>
29#include "utils_base.h" 29#include "utils_base.h"
30#include <ctype.h> 30#include <ctype.h>
@@ -37,6 +37,9 @@
37 37
38monitoring_plugin *this_monitoring_plugin=NULL; 38monitoring_plugin *this_monitoring_plugin=NULL;
39 39
40unsigned int timeout_state = STATE_CRITICAL;
41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42
40int _np_state_read_file(FILE *); 43int _np_state_read_file(FILE *);
41 44
42void np_init( char *plugin_name, int argc, char **argv ) { 45void np_init( char *plugin_name, int argc, char **argv ) {
@@ -87,10 +90,13 @@ void _get_monitoring_plugin( monitoring_plugin **pointer ){
87void 90void
88die (int result, const char *fmt, ...) 91die (int result, const char *fmt, ...)
89{ 92{
90 va_list ap; 93 if(fmt!=NULL) {
91 va_start (ap, fmt); 94 va_list ap;
92 vprintf (fmt, ap); 95 va_start (ap, fmt);
93 va_end (ap); 96 vprintf (fmt, ap);
97 va_end (ap);
98 }
99
94 if(this_monitoring_plugin!=NULL) { 100 if(this_monitoring_plugin!=NULL) {
95 np_cleanup(); 101 np_cleanup();
96 } 102 }
@@ -122,6 +128,7 @@ range
122 temp_range->end = 0; 128 temp_range->end = 0;
123 temp_range->end_infinity = TRUE; 129 temp_range->end_infinity = TRUE;
124 temp_range->alert_on = OUTSIDE; 130 temp_range->alert_on = OUTSIDE;
131 temp_range->text = strdup(str);
125 132
126 if (str[0] == '@') { 133 if (str[0] == '@') {
127 temp_range->alert_on = INSIDE; 134 temp_range->alert_on = INSIDE;
@@ -312,18 +319,18 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
312 319
313 while (1) { 320 while (1) {
314 /* Strip any leading space */ 321 /* Strip any leading space */
315 for (varlist; isspace(varlist[0]); varlist++); 322 for (; isspace(varlist[0]); varlist++);
316 323
317 if (strncmp(name, varlist, strlen(name)) == 0) { 324 if (strncmp(name, varlist, strlen(name)) == 0) {
318 varlist += strlen(name); 325 varlist += strlen(name);
319 /* strip trailing spaces */ 326 /* strip trailing spaces */
320 for (varlist; isspace(varlist[0]); varlist++); 327 for (; isspace(varlist[0]); varlist++);
321 328
322 if (varlist[0] == '=') { 329 if (varlist[0] == '=') {
323 /* We matched the key, go past the = sign */ 330 /* We matched the key, go past the = sign */
324 varlist++; 331 varlist++;
325 /* strip leading spaces */ 332 /* strip leading spaces */
326 for (varlist; isspace(varlist[0]); varlist++); 333 for (; isspace(varlist[0]); varlist++);
327 334
328 if (tmp = index(varlist, sep)) { 335 if (tmp = index(varlist, sep)) {
329 /* Value is delimited by a comma */ 336 /* Value is delimited by a comma */
@@ -356,6 +363,22 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
356 return value; 363 return value;
357} 364}
358 365
366const char *
367state_text (int result)
368{
369 switch (result) {
370 case STATE_OK:
371 return "OK";
372 case STATE_WARNING:
373 return "WARNING";
374 case STATE_CRITICAL:
375 return "CRITICAL";
376 case STATE_DEPENDENT:
377 return "DEPENDENT";
378 default:
379 return "UNKNOWN";
380 }
381}
359 382
360/* 383/*
361 * Read a string representing a state (ok, warning... or numeric: 0, 1) and 384 * Read a string representing a state (ok, warning... or numeric: 0, 1) and
@@ -379,26 +402,45 @@ int mp_translate_state (char *state_text) {
379 * parse of argv, so that uniqueness in parameters are reflected there. 402 * parse of argv, so that uniqueness in parameters are reflected there.
380 */ 403 */
381char *_np_state_generate_key() { 404char *_np_state_generate_key() {
382 struct sha1_ctx ctx;
383 int i; 405 int i;
384 char **argv = this_monitoring_plugin->argv; 406 char **argv = this_monitoring_plugin->argv;
385 unsigned char result[20];
386 char keyname[41]; 407 char keyname[41];
387 char *p=NULL; 408 char *p=NULL;
388 409
389 sha1_init_ctx(&ctx); 410 unsigned char result[256];
390 411
412#ifdef USE_OPENSSL
413 /*
414 * This code path is chosen if openssl is available (which should be the most common
415 * scenario). Alternatively, the gnulib implementation/
416 *
417 */
418 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
419
420 EVP_DigestInit(ctx, EVP_sha256());
421
391 for(i=0; i<this_monitoring_plugin->argc; i++) { 422 for(i=0; i<this_monitoring_plugin->argc; i++) {
392 sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); 423 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i]));
393 } 424 }
394 425
395 sha1_finish_ctx(&ctx, &result); 426 EVP_DigestFinal(ctx, result, NULL);
396 427#else
428
429 struct sha256_ctx ctx;
430
431 for(i=0; i<this_monitoring_plugin->argc; i++) {
432 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
433 }
434
435 sha256_finish_ctx(&ctx, result);
436#endif // FOUNDOPENSSL
437
397 for (i=0; i<20; ++i) { 438 for (i=0; i<20; ++i) {
398 sprintf(&keyname[2*i], "%02x", result[i]); 439 sprintf(&keyname[2*i], "%02x", result[i]);
399 } 440 }
441
400 keyname[40]='\0'; 442 keyname[40]='\0';
401 443
402 p = strdup(keyname); 444 p = strdup(keyname);
403 if(p==NULL) { 445 if(p==NULL) {
404 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 446 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
@@ -684,4 +726,3 @@ void np_state_write_string(time_t data_time, char *data_string) {
684 726
685 np_free(temp_file); 727 np_free(temp_file);
686} 728}
687