summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-08-27 16:41:02 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-08-27 16:41:02 +0200
commitf976155863357e15961b280413244cc0badd89cb (patch)
tree9d65cdf1d13986ae9a558765ec4cdc3a51b243fe /plugins
parenta27862a9c774d3fc4a608f8593c83b11357cc6dc (diff)
downloadmonitoring-plugins-f976155863357e15961b280413244cc0badd89cb.tar.gz
check_snmp: Improve error handling
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index b71ee4fd..badf9260 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -161,18 +161,27 @@ int main(int argc, char **argv) {
161 161
162 struct snmp_session *active_session = snmp_open(&config.snmp_session); 162 struct snmp_session *active_session = snmp_open(&config.snmp_session);
163 if (active_session == NULL) { 163 if (active_session == NULL) {
164 snmp_sess_perror("Failed to open session", &config.snmp_session); 164 int pcliberr = 0;
165 die(STATE_UNKNOWN, "Failed to open SNMP session\n"); 165 int psnmperr = 0;
166 char *pperrstring = NULL;
167 snmp_error (&config.snmp_session, &pcliberr , &psnmperr, &pperrstring);
168 die(STATE_UNKNOWN, "Failed to open SNMP session: %s\n", pperrstring);
166 } 169 }
167 170
168 struct snmp_pdu *response = NULL; 171 struct snmp_pdu *response = NULL;
169 int snmp_query_status = snmp_synch_response(active_session, pdu, &response); 172 int snmp_query_status = snmp_synch_response(active_session, pdu, &response);
170 173
171 if (!(snmp_query_status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)) { 174 if (!(snmp_query_status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)) {
172 snmp_sess_perror("Failed to query", active_session); 175 int pcliberr = 0;
173 // FAILED somehow 176 int psnmperr = 0;
174 // TODO do some error analysis here 177 char *pperrstring = NULL;
175 die(STATE_UNKNOWN, "SNMP query failed\n"); 178 snmp_error (active_session, &pcliberr , &psnmperr, &pperrstring);
179
180 if (psnmperr == SNMPERR_TIMEOUT) {
181 // We exit with critical here for some historical reason
182 die(STATE_CRITICAL, "SNMP query ran into a timeout\n");
183 }
184 die(STATE_UNKNOWN, "SNMP query failed: %s\n", pperrstring);
176 } 185 }
177 186
178 snmp_close(active_session); 187 snmp_close(active_session);