From 9b6dd9361792f6dd947c2fbedbffeb467f624de9 Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Thu, 23 May 2019 13:21:08 +0200 Subject: [PATCH] new SNMP OID 1.3.6.1.4.1.27938.11.1.9 to query total bandwidth allocated to ongoing calls --- RasTbl.cxx | 11 +++++++++++ RasTbl.h | 2 ++ changes.txt | 1 + docs/manual/misc.sgml | 1 + gnugk.mib | 15 +++++++++++---- snmp.cxx | 26 ++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/RasTbl.cxx b/RasTbl.cxx index eba36392..d2dc0fb7 100644 --- a/RasTbl.cxx +++ b/RasTbl.cxx @@ -5359,6 +5359,17 @@ void CallTable::UpdateEPBandwidth(const endptr & ep, long bw) } } +unsigned CallTable::GetTotalAllocatedBandwidth() const // in kbps +{ + long used = 0; + WriteLock lock(listLock); + const_iterator Iter = CallList.begin(), eIter = CallList.end(); + while (Iter != eIter) + used += (*Iter++)->GetBandwidth(); + + return ::round(used / 10); +} + callptr CallTable::FindCallRec(const H225_CallIdentifier & CallId) const { return InternalFind(bind2nd(mem_fun(&CallRec::CompareCallId), &CallId)); diff --git a/RasTbl.h b/RasTbl.h index bbfbaa1b..19717ba6 100644 --- a/RasTbl.h +++ b/RasTbl.h @@ -1753,6 +1753,8 @@ class CallTable : public Singleton long CheckEPBandwidth(const endptr & ep, long bw) const; void UpdateEPBandwidth(const endptr & ep, long bw); + unsigned GetTotalAllocatedBandwidth() const; // in kbps + callptr FindCallRec(const H225_CallIdentifier & CallId) const; callptr FindCallRec(const H225_CallReferenceValue & CallRef) const; callptr FindCallRec(PINDEX CallNumber) const; diff --git a/changes.txt b/changes.txt index b1908046..549f3828 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,6 @@ Changes from 5.2 to 5.3 ======================= +- new SNMP OID 1.3.6.1.4.1.27938.11.1.9 to query total bandwidth allocated to ongoing calls - BUGFIX(ProxyChannel.cxx) fix hangup when making many TLS calls quickly one after another - BUGFIX(RasSrv.cxx) don't require H.460.22 parameters in ARQs - BUGFIX(ProxyChannel.cxx) fix TLS without LARGE_FDSET diff --git a/docs/manual/misc.sgml b/docs/manual/misc.sgml index 321e18cf..d05fcca3 100644 --- a/docs/manual/misc.sgml +++ b/docs/manual/misc.sgml @@ -903,6 +903,7 @@ The following OIDs are available: 1.3.6.1.4.1.27938.11.1.6 CatchAll destination (GET, SET) 1.3.6.1.4.1.27938.11.1.7 Total calls since startup (GET) 1.3.6.1.4.1.27938.11.1.8 Successful calls since startup (GET) +1.3.6.1.4.1.27938.11.1.9 Total bandwidth allocated to ongoing calls in kbps (GET) All of these OIDs are scalars, so please remember to append '.0' when querying them eg. with 'snmpget'. diff --git a/gnugk.mib b/gnugk.mib index 03a32f91..ed19e848 100644 --- a/gnugk.mib +++ b/gnugk.mib @@ -1,9 +1,9 @@ -- ***************************************************************** -- A MIB for the GNU Gatekeeper (GnuGk) -- --- May 2012, Jan Willamowius +-- May 2019, Jan Willamowius -- --- Copyright (c) 2008-2012 by Jan Willamowius, https://www.willamowius.com +-- Copyright (c) 2008-2019 by Jan Willamowius, https://www.willamowius.com -- All rights reserved. -- ***************************************************************** -- @@ -22,14 +22,14 @@ IMPORTS FROM SNMPv2-CONF; gnugkMIB MODULE-IDENTITY - LAST-UPDATED "201205070000Z" + LAST-UPDATED "201905230000Z" ORGANIZATION "GNU Gatekeeper Project" CONTACT-INFO " Jan Willamowius Web: https://www.gnugk.org Email: jan@willamowius.de" DESCRIPTION "SNMP MIB for the GNU Gatekeeper" - REVISION "201205070000Z" + REVISION "201905230000Z" DESCRIPTION "Draft" ::= { enterprises 27938 } @@ -109,6 +109,13 @@ gnugkSuccessfulCalls OBJECT-TYPE DESCRIPTION "Successful calls since startup" ::= { gnugkStatusObjects 8 } +gnugkBandwidthAllocated OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION "Total bandwidth allocated for all ongoing calls in kbps" + ::= { gnugkStatusObjects 9 } + -- data objects for traps / notifications gnugkTrapSeverity OBJECT-TYPE diff --git a/snmp.cxx b/snmp.cxx index c4e4f00a..1541b073 100644 --- a/snmp.cxx +++ b/snmp.cxx @@ -35,6 +35,7 @@ const char * const TraceLevelOIDStr = "1.3.6.1.4.1.27938.11.1.5"; const char * const CatchAllOIDStr = "1.3.6.1.4.1.27938.11.1.6"; const char * const TotalCallsOIDStr = "1.3.6.1.4.1.27938.11.1.7"; const char * const SuccessfulCallsOIDStr = "1.3.6.1.4.1.27938.11.1.8"; +const char * const TotalBandwidthOIDStr = "1.3.6.1.4.1.27938.11.1.9"; const char * const severityOIDStr = "1.3.6.1.4.1.27938.11.2.1"; const char * const groupOIDStr = "1.3.6.1.4.1.27938.11.2.2"; const char * const displayMsgOIDStr = "1.3.6.1.4.1.27938.11.2.3"; @@ -59,6 +60,7 @@ static oid TraceLevelOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 1, 5 }; static oid CatchAllOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 1, 6 }; static oid TotalCallsOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 1, 7 }; static oid SuccessfulCallsOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 1, 8 }; +static oid TotalBandwidthOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 1, 9 }; static oid severityOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 2, 1 }; static oid groupOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 2, 2 }; static oid displayMsgOID[] = { 1, 3, 6, 1, 4, 1, 27938, 11, 2, 3 }; @@ -163,6 +165,22 @@ int calls_handler(netsnmp_mib_handler * /* handler */, return SNMPERR_SUCCESS; } +int bandwidth_handler(netsnmp_mib_handler * /* handler */, + netsnmp_handler_registration * /* reg */, + netsnmp_agent_request_info * reqinfo, + netsnmp_request_info * requests) +{ + PWaitAndSignal lock(g_NetSNMPMutex); + + if (reqinfo->mode != MODE_GET) + return SNMPERR_SUCCESS; + for (netsnmp_request_info *request = requests; request; request = request->next) { + unsigned total_bandwidth = CallTable::Instance()->GetTotalAllocatedBandwidth(); + snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, total_bandwidth); + } + return SNMPERR_SUCCESS; +} + int totalcalls_handler(netsnmp_mib_handler * /* handler */, netsnmp_handler_registration * /* reg */, netsnmp_agent_request_info * reqinfo, @@ -331,6 +349,8 @@ void NetSNMPAgent::Run() netsnmp_create_handler_registration("catchall", tracelevel_handler, TraceLevelOID, OID_LENGTH(TraceLevelOID), HANDLER_CAN_RWRITE)); netsnmp_register_scalar( netsnmp_create_handler_registration("catchall", catchall_handler, CatchAllOID, OID_LENGTH(CatchAllOID), HANDLER_CAN_RWRITE)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("bandwidth", bandwidth_handler, CallsOID, OID_LENGTH(CallsOID), HANDLER_CAN_RONLY)); init_snmp(agent_name); // reads $HOME/.snmp/gnugk-agent.conf + $HOME/.snmp/agentx.conf @@ -505,6 +525,9 @@ PBoolean PTLibSNMPAgent::MIB_LocalMatch(PSNMP_PDU & answerPDU) } else if (vars[i].m_name == CallsOIDStr + PString(".0")) { SetRFC1155Object(vars[i].m_value, CallTable::Instance()->Size()); found = true; + } else if (vars[i].m_name == TotalBandwidthOIDStr + PString(".0")) { + SetRFC1155Object(vars[i].m_value, CallTable::Instance()->GetTotalAllocatedBandwidth()); + found = true; } else if (vars[i].m_name == TotalCallsOIDStr + PString(".0")) { SetRFC1155CounterObject(vars[i].m_value, CallTable::Instance()->TotalCallCount()); found = true; @@ -615,6 +638,9 @@ PString WindowsSNMPAgent::HandleRequest(const PString & request) if (token[1] == CallsOIDStr + PString(".0")) { return "GET_RESPONSE u " + PString(PString::Unsigned, CallTable::Instance()->Size()); } + if (token[1] == TotalBandwidthOIDStr + PString(".0")) { + return "GET_RESPONSE u " + PString(PString::Unsigned, CallTable::Instance()->GetTotalAllocatedBandwidth()); + } if (token[1] == TotalCallsOIDStr + PString(".0")) { return "GET_RESPONSE c " + PString(PString::Unsigned, CallTable::Instance()->TotalCallCount()); }