mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-18 00:22:44 -04:00
check_curl: pre compile regex for string matching
This commit is contained in:
parent
01f3532284
commit
c06ea4e44c
2 changed files with 12 additions and 3 deletions
|
|
@ -1261,9 +1261,8 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat
|
|||
}
|
||||
|
||||
if (strlen(config.regexp)) {
|
||||
regex_t preg;
|
||||
regmatch_t pmatch[REGS];
|
||||
int errcode = regexec(&preg, global_state.body_buf.buf, REGS, pmatch, 0);
|
||||
int errcode = regexec(&config.compiled_regex, global_state.body_buf.buf, REGS, pmatch, 0);
|
||||
if ((errcode == 0 && !config.invert_regex) ||
|
||||
(errcode == REG_NOMATCH && config.invert_regex)) {
|
||||
/* OK - No-op to avoid changing the logic around it */
|
||||
|
|
@ -1284,7 +1283,7 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat
|
|||
}
|
||||
result = config.state_regex;
|
||||
} else {
|
||||
regerror(errcode, &preg, errbuf, MAX_INPUT_BUFFER);
|
||||
regerror(errcode, &config.compiled_regex, errbuf, MAX_INPUT_BUFFER);
|
||||
|
||||
char tmp[DEFAULT_BUFFER_SIZE];
|
||||
|
||||
|
|
@ -1969,6 +1968,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
result.config.compiled_regex = preg;
|
||||
break;
|
||||
case INVERT_REGEX:
|
||||
result.config.invert_regex = true;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include "curl/curl.h"
|
||||
#include "regex.h"
|
||||
|
||||
enum {
|
||||
MAX_RE_SIZE = 1024,
|
||||
|
|
@ -87,7 +88,13 @@ typedef struct {
|
|||
char *cookie_jar_file;
|
||||
|
||||
int maximum_age;
|
||||
|
||||
// the original regex string from the command line
|
||||
char regexp[MAX_RE_SIZE];
|
||||
|
||||
// the compiled regex for usage later
|
||||
regex_t compiled_regex;
|
||||
|
||||
mp_state_enum state_regex;
|
||||
bool invert_regex;
|
||||
bool verify_peer_and_host;
|
||||
|
|
@ -136,6 +143,7 @@ check_curl_config check_curl_config_init() {
|
|||
|
||||
.maximum_age = -1,
|
||||
.regexp = {},
|
||||
.compiled_regex = {},
|
||||
.state_regex = STATE_CRITICAL,
|
||||
.invert_regex = false,
|
||||
.verify_peer_and_host = false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue