diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-08-25 15:28:04 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-08-25 15:28:04 +0200 |
commit | 7fe6ac8d08a2baf63db57fd33185224df7e18e27 (patch) | |
tree | 584921e865e31ef6499565fdca0dd37b8b7921ab /plugins/check_snmp.d | |
parent | 723e0d3466d85a6ed9811d0661db289e7d9406d9 (diff) | |
download | monitoring-plugins-7fe6ac8d08a2baf63db57fd33185224df7e18e27.tar.gz |
rebuild check_snmp
Diffstat (limited to 'plugins/check_snmp.d')
-rw-r--r-- | plugins/check_snmp.d/config.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/plugins/check_snmp.d/config.h b/plugins/check_snmp.d/config.h new file mode 100644 index 00000000..e2e1d6c2 --- /dev/null +++ b/plugins/check_snmp.d/config.h | |||
@@ -0,0 +1,107 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "states.h" | ||
4 | #include "thresholds.h" | ||
5 | #include "utils_base.h" | ||
6 | #include <stdlib.h> | ||
7 | #include <stdbool.h> | ||
8 | #include <regex.h> | ||
9 | |||
10 | // defines for snmp libs | ||
11 | #define u_char unsigned char | ||
12 | #define u_long unsigned long | ||
13 | #define u_short unsigned short | ||
14 | #define u_int unsigned int | ||
15 | |||
16 | #include <net-snmp/net-snmp-config.h> | ||
17 | #include <net-snmp/net-snmp-includes.h> | ||
18 | #include <net-snmp/library/snmp.h> | ||
19 | #include <net-snmp/session_api.h> | ||
20 | |||
21 | const int DEFAULT_PROTOCOL = SNMP_VERSION_1; | ||
22 | const char DEFAULT_PORT[] = "161"; | ||
23 | const char DEFAULT_OUTPUT_DELIMITER[] = " "; | ||
24 | const int DEFAULT_RETRIES = 5; | ||
25 | |||
26 | const int RANDOM_STATE_DATA_LENGTH_PREDICTION = 1024; | ||
27 | |||
28 | typedef struct eval_method { | ||
29 | bool crit_string; | ||
30 | bool crit_regex; | ||
31 | } eval_method; | ||
32 | |||
33 | typedef struct check_snmp_test_unit { | ||
34 | char *oid; | ||
35 | char *label; | ||
36 | char *unit_value; | ||
37 | eval_method eval_mthd; | ||
38 | } check_snmp_test_unit; | ||
39 | |||
40 | check_snmp_test_unit check_snmp_test_unit_init() { | ||
41 | check_snmp_test_unit tmp = {}; | ||
42 | return tmp; | ||
43 | } | ||
44 | |||
45 | typedef struct check_snmp_config { | ||
46 | // SNMP session to use | ||
47 | struct snmp_session snmp_session; | ||
48 | |||
49 | // use getnet instead of get | ||
50 | bool use_getnext; | ||
51 | |||
52 | // TODO actually make these useful | ||
53 | bool ignore_mib_parsing_errors; | ||
54 | bool need_mibs; | ||
55 | |||
56 | check_snmp_test_unit *test_units; | ||
57 | size_t num_of_test_units; | ||
58 | mp_thresholds thresholds; | ||
59 | |||
60 | // State if an empty value is encountered | ||
61 | mp_state_enum nulloid_result; | ||
62 | |||
63 | // String evaluation stuff | ||
64 | bool invert_search; | ||
65 | regex_t regex_cmp_value; // regex to match query results against | ||
66 | char string_cmp_value[MAX_INPUT_BUFFER]; | ||
67 | |||
68 | // Modify data | ||
69 | double multiplier; | ||
70 | double offset; | ||
71 | |||
72 | // Modify output | ||
73 | bool use_perf_data_labels_from_input; | ||
74 | } check_snmp_config; | ||
75 | |||
76 | check_snmp_config check_snmp_config_init() { | ||
77 | check_snmp_config tmp = { | ||
78 | .use_getnext = false, | ||
79 | |||
80 | .ignore_mib_parsing_errors = false, | ||
81 | .need_mibs = false, | ||
82 | |||
83 | .test_units = NULL, | ||
84 | .num_of_test_units = 0, | ||
85 | .thresholds = mp_thresholds_init(), | ||
86 | |||
87 | .nulloid_result = STATE_UNKNOWN, // state to return if no result for query | ||
88 | |||
89 | .invert_search = true, | ||
90 | .regex_cmp_value = {}, | ||
91 | .string_cmp_value = "", | ||
92 | |||
93 | .multiplier = 1.0, | ||
94 | .offset = 0, | ||
95 | |||
96 | .use_perf_data_labels_from_input = false, | ||
97 | }; | ||
98 | |||
99 | snmp_sess_init(&tmp.snmp_session); | ||
100 | |||
101 | tmp.snmp_session.retries = DEFAULT_RETRIES; | ||
102 | tmp.snmp_session.version = DEFAULT_SNMP_VERSION; | ||
103 | tmp.snmp_session.securityLevel = SNMP_SEC_LEVEL_NOAUTH; | ||
104 | tmp.snmp_session.community = (unsigned char *)"public"; | ||
105 | tmp.snmp_session.community_len = strlen("public"); | ||
106 | return tmp; | ||
107 | } | ||