From d1aa00176eb05f500f11afacc76f7c3fa0122b89 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Mon, 14 Oct 2024 14:29:46 +0200 Subject: [PATCH] SNMP fixes --- server.h | 12 ++++++------ snmp.cpp | 26 +++++++++++++------------- snmp/snmp.cpp | 28 ++++++++++++++-------------- snmp/snmp_data.cpp | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/server.h b/server.h index 747f4fc..bcb768d 100644 --- a/server.h +++ b/server.h @@ -8,14 +8,14 @@ typedef struct { - uint32_t iscsiSsnCmdPDUs; // 1.3.6.1.2.1.142.1.10.2.1.1 - uint32_t iscsiInstSsnFailures; // 1.3.6.1.2.1.142.1.1.1.1.10 - uint32_t iscsiInstSsnFormatErrors; // 1.3.6.1.2.1.142.1.1.2.1.3 - uint32_t iscsiInstSsnDigestErrors; // 1.3.6.1.2.1.142.1.1.2.1.1 + uint64_t iscsiSsnCmdPDUs; // 1.3.6.1.2.1.142.1.10.2.1.1 + uint64_t iscsiInstSsnFailures; // 1.3.6.1.2.1.142.1.1.1.1.10 + uint64_t iscsiInstSsnFormatErrors; // 1.3.6.1.2.1.142.1.1.2.1.3 + uint64_t iscsiInstSsnDigestErrors; // 1.3.6.1.2.1.142.1.1.2.1.1 uint64_t iscsiSsnTxDataOctets; // 1.3.6.1.2.1.142.1.10.2.1.3 uint64_t iscsiSsnRxDataOctets; // 1.3.6.1.2.1.142.1.10.2.1.4 - uint32_t iscsiTgtLoginAccepts; // 1.3.6.1.2.1.142.1.6.2.1.1 - uint32_t iscsiTgtLogoutNormals; // 1.3.6.1.2.1.142.1.6.3.1.1 + uint64_t iscsiTgtLoginAccepts; // 1.3.6.1.2.1.142.1.6.2.1.1 + uint64_t iscsiTgtLogoutNormals; // 1.3.6.1.2.1.142.1.6.3.1.1 } iscsi_stats_t; class server diff --git a/snmp.cpp b/snmp.cpp index 24f05de..37574ca 100644 --- a/snmp.cpp +++ b/snmp.cpp @@ -10,7 +10,6 @@ void init_snmp(snmp **const snmp_, snmp_data **const snmp_data_, io_stats_t *const ios, iscsi_stats_t *const is, std::function get_percentage_diskspace, void *const gpd_context, int *const cpu_usage, int *const ram_free_kb, std::atomic_bool *const stop, const int port) { *snmp_data_ = new snmp_data(); - (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.2", "iESP" ); (*snmp_data_)->register_oid("1.3.6.1.2.1.1.1.0", "iESP" ); //(*snmp_data_)->register_oid("1.3.6.1.2.1.1.2.0", new snmp_data_type_oid("1.3.6.1.4.1.57850.1")); (*snmp_data_)->register_oid("1.3.6.1.2.1.1.3.0", new snmp_data_type_running_since()); @@ -18,29 +17,30 @@ void init_snmp(snmp **const snmp_, snmp_data **const snmp_data_, io_stats_t *con (*snmp_data_)->register_oid("1.3.6.1.2.1.1.5.0", "iESP"); (*snmp_data_)->register_oid("1.3.6.1.2.1.1.6.0", "The Netherlands, Europe, Earth"); (*snmp_data_)->register_oid("1.3.6.1.2.1.1.7.0", snmp_integer::si_integer, 254); - (*snmp_data_)->register_oid("1.3.6.1.2.1.1.8.0", snmp_integer::si_integer, 0); + (*snmp_data_)->register_oid("1.3.6.1.2.1.1.8.0", snmp_integer::si_ticks, 0); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.1.1.10", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnFailures)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnDigestErrors)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnFormatErrors)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiTgtLoginAccepts)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.3.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiTgtLogoutNormals)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiSsnCmdPDUs)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnTxDataOctets)); + (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnRxDataOctets)); + (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.54", new snmp_data_type_stats_uint32_t(&ios->io_wait)); + (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.2", "iESP" ); + (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.1", snmp_integer::snmp_integer_type::si_integer, 1); #if defined(ARDUINO) (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.2", version_str); #endif (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.3", __DATE__); - (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.1", snmp_integer::snmp_integer_type::si_integer, 1); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->bytes_read )); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->bytes_written)); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.5", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->n_reads )); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.6", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->n_writes )); - (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.54", new snmp_data_type_stats_uint32_t(&ios->io_wait)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.1.1.10", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnFailures)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiSsnCmdPDUs)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiTgtLoginAccepts)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.3.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiTgtLogoutNormals)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnDigestErrors)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnTxDataOctets)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnRxDataOctets)); - (*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.3", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnFormatErrors)); + (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.4.11.0", new snmp_data_type_stats_int(ram_free_kb)); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.9.1.9.1", new snmp_data_type_stats_int_callback(get_percentage_diskspace, gpd_context)); (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.9.0", new snmp_data_type_stats_int(cpu_usage)); - (*snmp_data_)->register_oid("1.3.6.1.4.1.2021.4.11.0", new snmp_data_type_stats_int(ram_free_kb)); *snmp_ = new snmp(*snmp_data_, stop, port); } diff --git a/snmp/snmp.cpp b/snmp/snmp.cpp index f669168..f71d7b3 100644 --- a/snmp/snmp.cpp +++ b/snmp/snmp.cpp @@ -72,7 +72,7 @@ uint64_t snmp::get_INTEGER(const uint8_t *p, const size_t length) uint64_t v = 0; if (length > 8) - DOLOG(logging::ll_error, "SNMP::get_INTEGER", "-", "truncated (%zu bytes)\n", length); + DOLOG(logging::ll_error, "SNMP::get_INTEGER", "-", "truncated (%zu bytes)", length); for(size_t i=0; i &p[len_vb_list]) { - DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "length field out of bounds (PDU)\n"); + DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "length field out of bounds (PDU)"); return false; } @@ -200,7 +200,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids pnt += seq_length; } else { - DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "unexpected/invalid type %02x\n", seq_type); + DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "unexpected/invalid type %02x", seq_type); return false; } } @@ -211,7 +211,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids_req, const bool is_getnext, const int is_top) { if (len < 2) { - DOLOG(logging::ll_error, "SNMP::process_BER", "-", "BER too small\n"); + DOLOG(logging::ll_error, "SNMP::process_BER", "-", "BER too small"); return false; } @@ -224,7 +224,7 @@ bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids uint8_t length = *pnt++; if (&pnt[length] > &p[len]) { - DOLOG(logging::ll_error, "SNMP::process_BER", "-", "length field out of bounds (BER)\n"); + DOLOG(logging::ll_error, "SNMP::process_BER", "-", "length field out of bounds (BER)"); return false; } @@ -293,7 +293,7 @@ bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids pnt += length; } else { - DOLOG(logging::ll_error, "SNMP::process_BER", "-", "invalid type %02x\n", type); + DOLOG(logging::ll_error, "SNMP::process_BER", "-", "invalid type %02x", type); return false; } } @@ -332,7 +332,7 @@ void snmp::gen_reply(oid_req_t & oids_req, uint8_t **const packet_out, size_t *c varbind->add(new snmp_oid(e)); - DOLOG(logging::ll_error, "SNMP:process_BER", "-", "requested: %s\n", e.c_str()); + DOLOG(logging::ll_debug, "SNMP:process_BER", "-", "requested: %s", e.c_str()); std::optional rc = sd->find_by_oid(e); @@ -351,7 +351,7 @@ void snmp::gen_reply(oid_req_t & oids_req, uint8_t **const packet_out, size_t *c varbind->add(new snmp_null()); } else { - DOLOG(logging::ll_error, "SNMP::process_BER", "-", "requested %s not found, returning null\n", e.c_str()); + DOLOG(logging::ll_info, "SNMP::process_BER", "-", "requested %s not found, returning null", e.c_str()); // FIXME snmp_null? varbind->add(new snmp_null()); diff --git a/snmp/snmp_data.cpp b/snmp/snmp_data.cpp index 7fd98f0..4d1595b 100644 --- a/snmp/snmp_data.cpp +++ b/snmp/snmp_data.cpp @@ -78,7 +78,7 @@ snmp_elem * snmp_data_type_static::get_data() if (is_string) return new snmp_octet_string(reinterpret_cast(data.c_str()), data.size()); - return new snmp_integer(snmp_integer::si_integer, data_int); + return new snmp_integer(type, data_int); } snmp_data_type_stats::snmp_data_type_stats(const snmp_integer::snmp_integer_type type, uint64_t *const counter) :