Skip to content

Commit

Permalink
new SNMP OID 1.3.6.1.4.1.27938.11.1.9 to query total bandwidth alloca…
Browse files Browse the repository at this point in the history
…ted to ongoing calls
  • Loading branch information
willamowius committed May 23, 2019
1 parent 6be5b5d commit 9b6dd93
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
11 changes: 11 additions & 0 deletions RasTbl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions RasTbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ class CallTable : public Singleton<CallTable>
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;
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/manual/misc.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ The following OIDs are available:
<item>1.3.6.1.4.1.27938.11.1.6 CatchAll destination (GET, SET)
<item>1.3.6.1.4.1.27938.11.1.7 Total calls since startup (GET)
<item>1.3.6.1.4.1.27938.11.1.8 Successful calls since startup (GET)
<item>1.3.6.1.4.1.27938.11.1.9 Total bandwidth allocated to ongoing calls in kbps (GET)
</itemize>
All of these OIDs are scalars, so please remember to append '.0' when querying them eg. with 'snmpget'.

Expand Down
15 changes: 11 additions & 4 deletions gnugk.mib
Original file line number Diff line number Diff line change
@@ -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.
-- *****************************************************************
--
Expand All @@ -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: [email protected]"
DESCRIPTION "SNMP MIB for the GNU Gatekeeper"
REVISION "201205070000Z"
REVISION "201905230000Z"
DESCRIPTION "Draft"
::= { enterprises 27938 }

Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions snmp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 };
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 9b6dd93

Please sign in to comment.