summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c9
-rw-r--r--plugins/check_snmp.d/check_snmp_helpers.c19
2 files changed, 18 insertions, 10 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 0f62ce8b..2b3099c9 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -256,7 +256,10 @@ int main(int argc, char **argv) {
256 256
257 timeout_interval = DEFAULT_SOCKET_TIMEOUT; 257 timeout_interval = DEFAULT_SOCKET_TIMEOUT;
258 258
259 np_init((char *)progname, argc, argv); 259 char progname_copy[256];
260 strncpy(progname_copy, progname, sizeof(progname_copy)-1);
261 progname_copy[255] = '\0';
262 np_init(progname_copy, argc, argv);
260 263
261 state_key stateKey = np_enable_state(NULL, 1, progname, argc, argv); 264 state_key stateKey = np_enable_state(NULL, 1, progname, argc, argv);
262 265
@@ -508,8 +511,8 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
508 unsigned char *privpasswd = NULL; 511 unsigned char *privpasswd = NULL;
509 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; 512 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
510 char *port = NULL; 513 char *port = NULL;
511 char *miblist = NULL; 514 const char *miblist = NULL;
512 char *connection_prefix = NULL; 515 const char *connection_prefix = NULL;
513 bool snmp_version_set_explicitely = false; 516 bool snmp_version_set_explicitely = false;
514 // TODO error checking 517 // TODO error checking
515 while (true) { 518 while (true) {
diff --git a/plugins/check_snmp.d/check_snmp_helpers.c b/plugins/check_snmp.d/check_snmp_helpers.c
index 2dfc88b5..d680678a 100644
--- a/plugins/check_snmp.d/check_snmp_helpers.c
+++ b/plugins/check_snmp.d/check_snmp_helpers.c
@@ -91,6 +91,8 @@ const char DEFAULT_OUTPUT_DELIMITER[] = " ";
91 91
92const int RANDOM_STATE_DATA_LENGTH_PREDICTION = 8192; 92const int RANDOM_STATE_DATA_LENGTH_PREDICTION = 8192;
93 93
94char community[100];
95
94check_snmp_config check_snmp_config_init() { 96check_snmp_config check_snmp_config_init() {
95 check_snmp_config tmp = { 97 check_snmp_config tmp = {
96 .snmp_params = 98 .snmp_params =
@@ -129,14 +131,17 @@ check_snmp_config check_snmp_config_init() {
129 tmp.snmp_params.snmp_session.retries = DEFAULT_RETRIES; 131 tmp.snmp_params.snmp_session.retries = DEFAULT_RETRIES;
130 tmp.snmp_params.snmp_session.version = DEFAULT_SNMP_VERSION; 132 tmp.snmp_params.snmp_session.version = DEFAULT_SNMP_VERSION;
131 tmp.snmp_params.snmp_session.securityLevel = SNMP_SEC_LEVEL_NOAUTH; 133 tmp.snmp_params.snmp_session.securityLevel = SNMP_SEC_LEVEL_NOAUTH;
132 tmp.snmp_params.snmp_session.community = (unsigned char *)"public"; 134 strcpy(community, "public");
133 tmp.snmp_params.snmp_session.community_len = strlen("public"); 135 tmp.snmp_params.snmp_session.community = (unsigned char *)community;
136 tmp.snmp_params.snmp_session.community_len = strlen(community);
134 return tmp; 137 return tmp;
135} 138}
136 139
137snmp_responces do_snmp_query(check_snmp_config_snmp_parameters parameters) { 140snmp_responces do_snmp_query(check_snmp_config_snmp_parameters parameters) {
138 if (parameters.ignore_mib_parsing_errors) { 141 if (parameters.ignore_mib_parsing_errors) {
139 char *opt_toggle_res = snmp_mib_toggle_options("e"); 142 char option_e[2];
143 option_e[0] = 'e'; option_e[1] = '\0';
144 char *opt_toggle_res = snmp_mib_toggle_options(option_e);
140 if (opt_toggle_res != NULL) { 145 if (opt_toggle_res != NULL) {
141 die(STATE_UNKNOWN, "Unable to disable MIB parsing errors"); 146 die(STATE_UNKNOWN, "Unable to disable MIB parsing errors");
142 } 147 }
@@ -436,7 +441,7 @@ check_snmp_evaluation evaluate_single_unit(response_value response,
436 } 441 }
437 } else { 442 } else {
438 // It's only a counter if we cont compute rate 443 // It's only a counter if we cont compute rate
439 pd_num_val.uom = "c"; 444 pd_num_val.uom = strdup("c");
440 pd_result_val = mp_create_pd_value(response.value.uIntVal); 445 pd_result_val = mp_create_pd_value(response.value.uIntVal);
441 } 446 }
442 break; 447 break;
@@ -476,7 +481,7 @@ check_snmp_evaluation evaluate_single_unit(response_value response,
476 pd_result_val = mp_create_pd_value(treated_value); 481 pd_result_val = mp_create_pd_value(treated_value);
477 482
478 if (response.type == ASN_COUNTER) { 483 if (response.type == ASN_COUNTER) {
479 pd_num_val.uom = "c"; 484 pd_num_val.uom = strdup("c");
480 } 485 }
481 } 486 }
482 487
@@ -820,7 +825,7 @@ state_data *np_state_read(state_key stateKey) {
820 * envvar NAGIOS_PLUGIN_STATE_DIRECTORY 825 * envvar NAGIOS_PLUGIN_STATE_DIRECTORY
821 * statically compiled shared state directory 826 * statically compiled shared state directory
822 */ 827 */
823char *_np_state_calculate_location_prefix(void) { 828static const char *_np_state_calculate_location_prefix(void) {
824 char *env_dir; 829 char *env_dir;
825 830
826 /* Do not allow passing MP_STATE_PATH in setuid plugins 831 /* Do not allow passing MP_STATE_PATH in setuid plugins
@@ -871,7 +876,7 @@ state_key np_enable_state(char *keyname, int expected_data_version, const char *
871 tmp_char++; 876 tmp_char++;
872 } 877 }
873 this_state->name = temp_keyname; 878 this_state->name = temp_keyname;
874 this_state->plugin_name = (char *)plugin_name; 879 this_state->plugin_name = strdup(plugin_name);
875 this_state->data_version = expected_data_version; 880 this_state->data_version = expected_data_version;
876 this_state->state_data = NULL; 881 this_state->state_data = NULL;
877 882