[monitoring-plugins] check_snmp: detect missing OIDs (#2331)
GitHub
git at monitoring-plugins.org
Sat Aug 29 17:00:14 CEST 2026
Module: monitoring-plugins
Branch: master
Commit: dcbc20668614309161f49f1afe5d3a0174900720
Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
Committer: GitHub <noreply at github.com>
Date: Sat Aug 29 16:56:33 2026 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=dcbc2066
check_snmp: detect missing OIDs (#2331)
* check_snmp: detect missing OIDs
When an OID is missing in the query result that particular sub check will have a specific status.
This status can be configured with the new parameter `missing-oid`.
---
plugins/check_snmp.c | 21 ++++++++++++++++++++-
plugins/check_snmp.d/check_snmp_helpers.c | 16 +++++++++++++++-
plugins/check_snmp.d/config.h | 3 +++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 8e9830cd..4b5714c0 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -399,7 +399,8 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
connection_prefix_index,
output_format_index,
calculate_rate,
- rate_multiplier
+ rate_multiplier,
+ missing_oid,
};
static struct option longopts[] = {
@@ -409,6 +410,7 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
{"object", required_argument, 0, 'o'},
{"delimiter", required_argument, 0, 'd'},
{"nulloid", required_argument, 0, 'z'},
+ {"missing-oid", required_argument, 0, missing_oid},
{"output-delimiter", required_argument, 0, 'D'},
{"string", required_argument, 0, 's'},
{"timeout", required_argument, 0, 't'},
@@ -717,9 +719,18 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
if (!is_integer(optarg)) {
usage2(_("Exit status must be a positive integer"), optarg);
} else {
+ // TODO: do real parsing here
config.evaluation_params.nulloid_result = atoi(optarg);
}
break;
+ case missing_oid: // What to do when an OID is missing in response
+ if (!is_integer(optarg)) {
+ usage2(_("Exit status must be a positive integer"), optarg);
+ } else {
+ // TODO: do real parsing here
+ config.evaluation_params.missing_oid_result = atoi(optarg);
+ }
+ break;
case 's': /* string or substring */
strncpy(config.evaluation_params.string_cmp_value, optarg,
sizeof(config.evaluation_params.string_cmp_value) - 1);
@@ -1096,6 +1107,14 @@ void print_help(void) {
printf(" %s\n", _("1 = WARNING"));
printf(" %s\n", _("2 = CRITICAL"));
printf(" %s\n", _("3 = UNKNOWN"));
+ printf(" %s\n", "--missing-oid=#");
+ printf(" %s\n", _("If a query for an OID returns nothing (OID missing on the target)"));
+ printf(" %s\n", _("this option allows you to choose what status you want for this specific OID"));
+ printf(" %s\n", _("Excluding this option renders the default exit of 2 (CRITICAL)"));
+ printf(" %s\n", _("0 = OK"));
+ printf(" %s\n", _("1 = WARNING"));
+ printf(" %s\n", _("2 = CRITICAL"));
+ printf(" %s\n", _("3 = UNKNOWN"));
/* Tests Against Integers */
printf(" %s\n", "-w, --warning=THRESHOLD(s)");
diff --git a/plugins/check_snmp.d/check_snmp_helpers.c b/plugins/check_snmp.d/check_snmp_helpers.c
index 5a02d9b7..5190a07b 100644
--- a/plugins/check_snmp.d/check_snmp_helpers.c
+++ b/plugins/check_snmp.d/check_snmp_helpers.c
@@ -107,6 +107,7 @@ check_snmp_config check_snmp_config_init() {
.evaluation_params =
{
.nulloid_result = STATE_UNKNOWN, // state to return if no result for query
+ .missing_oid_result = STATE_CRITICAL,
.invert_search = true,
.regex_cmp_value = {},
@@ -290,7 +291,7 @@ snmp_responces do_snmp_query(check_snmp_config_snmp_parameters parameters) {
if (verbose) {
printf("Debug: Got a unmatched result type: %hhu\n", vars->type);
}
- // TODO: Error here?
+ result.response_values[result.number_of_results].type = vars->type;
break;
}
}
@@ -540,6 +541,19 @@ check_snmp_evaluation evaluate_single_unit(response_value response,
case ASN_IPADDRESS:
// TODO
break;
+ default: {
+ // no known type
+ xasprintf(&sc_oid_test.output, "%s: no valid response", oid_string);
+ sc_oid_test = mp_set_subcheck_default_state(sc_oid_test, eval_params.missing_oid_result);
+ check_snmp_evaluation result = {
+ .sc = sc_oid_test,
+ .state = result_state,
+ };
+
+ return result;
+
+ break;
+ }
}
if (got_a_numerical_value) {
diff --git a/plugins/check_snmp.d/config.h b/plugins/check_snmp.d/config.h
index e7b6d1b3..17742eda 100644
--- a/plugins/check_snmp.d/config.h
+++ b/plugins/check_snmp.d/config.h
@@ -51,6 +51,9 @@ typedef struct {
// State if an empty value is encountered
mp_state_enum nulloid_result;
+ // State if an OID is not available
+ mp_state_enum missing_oid_result;
+
// String evaluation stuff
bool invert_search;
regex_t regex_cmp_value; // regex to match query results against
More information about the Commits
mailing list