rebuild check_snmp

This commit is contained in:
Lorenz Kästle 2025-08-25 15:28:04 +02:00
parent 723e0d3466
commit 7fe6ac8d08
3 changed files with 864 additions and 952 deletions

View file

@ -78,6 +78,7 @@ EXTRA_DIST = t \
check_ping.d \
check_by_ssh.d \
check_smtp.d \
check_snmp.d \
check_mysql.d \
check_ntp_time.d \
check_dig.d \
@ -152,6 +153,8 @@ check_procs_LDADD = $(BASEOBJS)
check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS)
check_real_LDADD = $(NETLIBS)
check_snmp_LDADD = $(BASEOBJS)
check_snmp_LDFLAGS = $(AM_LDFLAGS) `net-snmp-config --libs`
check_snmp_CFLAGS = $(AM_CFLAGS) `net-snmp-config --cflags`
check_smtp_LDADD = $(SSLOBJS)
check_ssh_LDADD = $(NETLIBS)
check_swap_SOURCES = check_swap.c check_swap.d/swap.c

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,107 @@
#pragma once
#include "states.h"
#include "thresholds.h"
#include "utils_base.h"
#include <stdlib.h>
#include <stdbool.h>
#include <regex.h>
// defines for snmp libs
#define u_char unsigned char
#define u_long unsigned long
#define u_short unsigned short
#define u_int unsigned int
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/library/snmp.h>
#include <net-snmp/session_api.h>
const int DEFAULT_PROTOCOL = SNMP_VERSION_1;
const char DEFAULT_PORT[] = "161";
const char DEFAULT_OUTPUT_DELIMITER[] = " ";
const int DEFAULT_RETRIES = 5;
const int RANDOM_STATE_DATA_LENGTH_PREDICTION = 1024;
typedef struct eval_method {
bool crit_string;
bool crit_regex;
} eval_method;
typedef struct check_snmp_test_unit {
char *oid;
char *label;
char *unit_value;
eval_method eval_mthd;
} check_snmp_test_unit;
check_snmp_test_unit check_snmp_test_unit_init() {
check_snmp_test_unit tmp = {};
return tmp;
}
typedef struct check_snmp_config {
// SNMP session to use
struct snmp_session snmp_session;
// use getnet instead of get
bool use_getnext;
// TODO actually make these useful
bool ignore_mib_parsing_errors;
bool need_mibs;
check_snmp_test_unit *test_units;
size_t num_of_test_units;
mp_thresholds thresholds;
// State if an empty value is encountered
mp_state_enum nulloid_result;
// String evaluation stuff
bool invert_search;
regex_t regex_cmp_value; // regex to match query results against
char string_cmp_value[MAX_INPUT_BUFFER];
// Modify data
double multiplier;
double offset;
// Modify output
bool use_perf_data_labels_from_input;
} check_snmp_config;
check_snmp_config check_snmp_config_init() {
check_snmp_config tmp = {
.use_getnext = false,
.ignore_mib_parsing_errors = false,
.need_mibs = false,
.test_units = NULL,
.num_of_test_units = 0,
.thresholds = mp_thresholds_init(),
.nulloid_result = STATE_UNKNOWN, // state to return if no result for query
.invert_search = true,
.regex_cmp_value = {},
.string_cmp_value = "",
.multiplier = 1.0,
.offset = 0,
.use_perf_data_labels_from_input = false,
};
snmp_sess_init(&tmp.snmp_session);
tmp.snmp_session.retries = DEFAULT_RETRIES;
tmp.snmp_session.version = DEFAULT_SNMP_VERSION;
tmp.snmp_session.securityLevel = SNMP_SEC_LEVEL_NOAUTH;
tmp.snmp_session.community = (unsigned char *)"public";
tmp.snmp_session.community_len = strlen("public");
return tmp;
}