summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.d/check_snmp_helpers.h
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-08 15:57:06 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-08 15:57:06 +0200
commit87195f5511bf18db2a64f71ea9783ebbfb33c3a5 (patch)
tree491157b89647d73ed6acb0e4e2ae7cdf7fffb01c /plugins/check_snmp.d/check_snmp_helpers.h
parent1aefb1f9df5268ccbcd3ce38f5527ebca3896db6 (diff)
downloadmonitoring-plugins-87195f5511bf18db2a64f71ea9783ebbfb33c3a5.tar.gz
check_snmp: refactoring + fixes
This commit moves the state retention logic to check_snmp as it is only used there and I do not want it to be used at all, so it doesn't get a place in the lib. Otherwise this adapts tests and fixes the rate computing in the refactored version of check_snmp. Also fixes some bugs detected with the tests
Diffstat (limited to 'plugins/check_snmp.d/check_snmp_helpers.h')
-rw-r--r--plugins/check_snmp.d/check_snmp_helpers.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/check_snmp.d/check_snmp_helpers.h b/plugins/check_snmp.d/check_snmp_helpers.h
index 28e3c4e3..0f7780b1 100644
--- a/plugins/check_snmp.d/check_snmp_helpers.h
+++ b/plugins/check_snmp.d/check_snmp_helpers.h
@@ -1,7 +1,71 @@
1#pragma once 1#pragma once
2 2
3#include "./config.h" 3#include "./config.h"
4#include <net-snmp/library/asn1.h>
4 5
5check_snmp_test_unit check_snmp_test_unit_init(); 6check_snmp_test_unit check_snmp_test_unit_init();
6int check_snmp_set_thresholds(const char *, check_snmp_test_unit[], size_t, bool); 7int check_snmp_set_thresholds(const char *, check_snmp_test_unit[], size_t, bool);
7check_snmp_config check_snmp_config_init(); 8check_snmp_config check_snmp_config_init();
9
10typedef struct {
11 oid oid[MAX_OID_LEN];
12 size_t oid_length;
13 unsigned char type;
14 union {
15 uint64_t uIntVal;
16 int64_t intVal;
17 double doubleVal;
18 } value;
19 char *string_response;
20} response_value;
21
22typedef struct {
23 int errorcode;
24 response_value *response_values;
25} snmp_responces;
26snmp_responces do_snmp_query(check_snmp_config_snmp_parameters parameters);
27
28// state is similar to response, but only numerics and a timestamp
29typedef struct {
30 time_t timestamp;
31 oid oid[MAX_OID_LEN];
32 size_t oid_length;
33 unsigned char type;
34 union {
35 unsigned long long uIntVal;
36 long long intVal;
37 double doubleVal;
38 } value;
39} check_snmp_state_entry;
40
41typedef struct {
42 check_snmp_state_entry state;
43 mp_subcheck sc;
44} check_snmp_evaluation;
45check_snmp_evaluation evaluate_single_unit(response_value response,
46 check_snmp_evaluation_parameters eval_params,
47 check_snmp_test_unit test_unit, time_t query_timestamp,
48 check_snmp_state_entry prev_state,
49 bool have_previous_state);
50
51#define NP_STATE_FORMAT_VERSION 1
52
53typedef struct state_data_struct {
54 time_t time;
55 void *data;
56 size_t length; /* Of binary data */
57 int errorcode;
58} state_data;
59
60typedef struct state_key_struct {
61 char *name;
62 char *plugin_name;
63 int data_version;
64 char *_filename;
65 state_data *state_data;
66} state_key;
67
68state_data *np_state_read(state_key stateKey);
69state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc,
70 char **argv);
71void np_state_write_string(state_key stateKey, time_t timestamp, char *stringToStore);