diff options
Diffstat (limited to 'lib/utils_base.c')
| -rw-r--r-- | lib/utils_base.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index b86ba737..cfff7cb9 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
| @@ -33,7 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | nagios_plugin *this_nagios_plugin=NULL; | 34 | nagios_plugin *this_nagios_plugin=NULL; |
| 35 | 35 | ||
| 36 | void np_init( char *plugin_name ) { | 36 | void np_init( char *plugin_name, int argc, char **argv ) { |
| 37 | if (this_nagios_plugin==NULL) { | 37 | if (this_nagios_plugin==NULL) { |
| 38 | this_nagios_plugin = malloc(sizeof(nagios_plugin)); | 38 | this_nagios_plugin = malloc(sizeof(nagios_plugin)); |
| 39 | if (this_nagios_plugin==NULL) { | 39 | if (this_nagios_plugin==NULL) { |
| @@ -41,6 +41,8 @@ void np_init( char *plugin_name ) { | |||
| 41 | strerror(errno)); | 41 | strerror(errno)); |
| 42 | } | 42 | } |
| 43 | this_nagios_plugin->plugin_name = strdup(plugin_name); | 43 | this_nagios_plugin->plugin_name = strdup(plugin_name); |
| 44 | this_nagios_plugin->argc = argc; | ||
| 45 | this_nagios_plugin->argv = argv; | ||
| 44 | } | 46 | } |
| 45 | } | 47 | } |
| 46 | 48 | ||
| @@ -354,7 +356,26 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
| 354 | * parse of argv, so that uniqueness in parameters are reflected there. | 356 | * parse of argv, so that uniqueness in parameters are reflected there. |
| 355 | */ | 357 | */ |
| 356 | char *_np_state_generate_key() { | 358 | char *_np_state_generate_key() { |
| 357 | return strdup("Ahash"); | 359 | struct sha1_ctx ctx; |
| 360 | int i; | ||
| 361 | char **argv = this_nagios_plugin->argv; | ||
| 362 | unsigned char result[20]; | ||
| 363 | char keyname[41]; | ||
| 364 | |||
| 365 | sha1_init_ctx(&ctx); | ||
| 366 | |||
| 367 | for(i=0; i<this_nagios_plugin->argc; i++) { | ||
| 368 | sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); | ||
| 369 | } | ||
| 370 | |||
| 371 | sha1_finish_ctx(&ctx, &result); | ||
| 372 | |||
| 373 | for (i=0; i<20; ++i) { | ||
| 374 | sprintf(&keyname[2*i], "%02x", result[i]); | ||
| 375 | } | ||
| 376 | keyname[40]='\0'; | ||
| 377 | |||
| 378 | return strdup(keyname); | ||
| 358 | } | 379 | } |
| 359 | 380 | ||
| 360 | void _cleanup_state_data() { | 381 | void _cleanup_state_data() { |
