diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-01 11:22:58 +0200 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-01 11:22:58 +0200 |
| commit | 41d309d438800102fc8aed736642e22da9f599fc (patch) | |
| tree | 59b239a45ce37ae0406d2ebbfc7bedda0859ec9c | |
| parent | a7c6760cfe46fce4010056b8cdc36a1c9bd1d366 (diff) | |
| download | monitoring-plugins-41d309d438800102fc8aed736642e22da9f599fc.tar.gz | |
check_snmp: improve string quoting in result
| -rw-r--r-- | plugins/check_snmp.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d5abd8c2..3c054259 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -235,8 +235,23 @@ int main(int argc, char **argv) { | |||
| 235 | if (verbose) { | 235 | if (verbose) { |
| 236 | printf("Debug: Got a string\n"); | 236 | printf("Debug: Got a string\n"); |
| 237 | } | 237 | } |
| 238 | |||
| 238 | char *tmp = (char *)vars->val.string; | 239 | char *tmp = (char *)vars->val.string; |
| 239 | xasprintf(&sc_oid_test.output, "%s - Value: %s", sc_oid_test.output, tmp); | 240 | |
| 241 | if (strchr(tmp, '"') != NULL) { | ||
| 242 | // got double quote in the string | ||
| 243 | if (strchr(tmp, '\'') != NULL) { | ||
| 244 | // got single quote in the string too | ||
| 245 | // dont quote that at all to avoid even more confusion | ||
| 246 | xasprintf(&sc_oid_test.output, "%s - Value: %s", sc_oid_test.output, tmp); | ||
| 247 | } else { | ||
| 248 | // quote with single quotes | ||
| 249 | xasprintf(&sc_oid_test.output, "%s - Value: '%s'", sc_oid_test.output, tmp); | ||
| 250 | } | ||
| 251 | } else { | ||
| 252 | // quote with double quotes | ||
| 253 | xasprintf(&sc_oid_test.output, "%s - Value: \"%s\"", sc_oid_test.output, tmp); | ||
| 254 | } | ||
| 240 | 255 | ||
| 241 | if (strlen(tmp) == 0) { | 256 | if (strlen(tmp) == 0) { |
| 242 | sc_oid_test = mp_set_subcheck_state(sc_oid_test, config.nulloid_result); | 257 | sc_oid_test = mp_set_subcheck_state(sc_oid_test, config.nulloid_result); |
