-
/*
- * $Id: snmp_agent.cc,v 1.94 2006/11/09 16:35:32 hno Exp $
+ * $Id$
*
- * DEBUG: section 49 SNMP Interface
+ * DEBUG: section 49 SNMP Interface
* AUTHOR: Kostas Anagnostakis
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
*/
-
#include "squid.h"
#include "cache_snmp.h"
-#include "Store.h"
+#include "globals.h"
#include "mem_node.h"
+#include "protos.h"
+#include "StatCounters.h"
+#include "StatHist.h"
+#include "SquidMath.h"
+#include "SquidTime.h"
+#include "Store.h"
/************************************************************************
-
+
SQUID MIB Implementation
-
+
************************************************************************/
+/*
+ * cacheSystem group
+ */
+
variable_list *
snmp_sysFn(variable_list * Var, snint * ErrP)
{
variable_list *Answer = NULL;
- debug(49, 5) ("snmp_sysFn: Processing request:\n");
- snmpDebugOid(5, Var->name, Var->name_length);
+ MemBuf tmp;
+ debugs(49, 5, "snmp_sysFn: Processing request:" << snmpDebugOid(Var->name, Var->name_length, tmp));
*ErrP = SNMP_ERR_NOERROR;
switch (Var->name[LEN_SQ_SYS]) {
case SYSVMSIZ:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- mem_node::store_mem_size >> 10,
+ mem_node::StoreMemSize() >> 10,
ASN_INTEGER);
break;
case SYSSTOR:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- store_swap_size,
+ Store::Root().currentSize() >> 10,
ASN_INTEGER);
break;
return Answer;
}
+/*
+ * cacheConfig group
+ */
variable_list *
snmp_confFn(variable_list * Var, snint * ErrP)
{
variable_list *Answer = NULL;
const char *cp = NULL;
- debug(49, 5) ("snmp_confFn: Processing request with magic %d!\n", Var->name[8]);
+ debugs(49, 5, "snmp_confFn: Processing request with magic " << Var->name[8] << "!");
*ErrP = SNMP_ERR_NOERROR;
switch (Var->name[LEN_SQ_CONF]) {
case CONF_VERSION:
Answer = snmp_var_new(Var->name, Var->name_length);
Answer->type = ASN_OCTET_STR;
- Answer->val_len = strlen(appname);
- Answer->val.string = (u_char *) xstrdup(appname);
+ Answer->val_len = strlen(APP_SHORTNAME);
+ Answer->val.string = (u_char *) xstrdup(APP_SHORTNAME);
break;
case CONF_VERSION_ID:
case CONF_ST_MMAXSZ:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) Config.memMaxSize >> 20,
+ (snint) (Config.memMaxSize >> 20),
ASN_INTEGER);
break;
case CONF_ST_SWMAXSZ:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) Store::Root().maxSize() >> 10,
+ (snint) (Store::Root().maxSize() >> 20),
ASN_INTEGER);
break;
case CONF_LOG_FAC:
Answer = snmp_var_new(Var->name, Var->name_length);
- if (!(cp = Config.debugOptions))
+ if (!(cp = Debug::debugOptions))
cp = "None";
Answer->type = ASN_OCTET_STR;
return Answer;
}
+/*
+ * cacheMesh group
+ * - cachePeerTable
+ */
variable_list *
snmp_meshPtblFn(variable_list * Var, snint * ErrP)
{
variable_list *Answer = NULL;
- struct IN_ADDR *laddr;
+ Ip::Address laddr;
char *cp = NULL;
peer *p = NULL;
int cnt = 0;
- debug(49, 5) ("snmp_meshPtblFn: peer %d requested!\n", Var->name[LEN_SQ_MESH + 3]);
+ debugs(49, 5, "snmp_meshPtblFn: peer " << Var->name[LEN_SQ_MESH + 3] << " requested!");
*ErrP = SNMP_ERR_NOERROR;
- laddr = oid2addr(&Var->name[LEN_SQ_MESH + 3]);
- for (p = Config.peers; p != NULL; p = p->next, cnt++)
- if (p->in_addr.sin_addr.s_addr == laddr->s_addr)
+ u_int index = Var->name[LEN_SQ_MESH + 3] ;
+ for (p = Config.peers; p != NULL; p = p->next, ++cnt) {
+ if (p->index == index) {
+ laddr = p->in_addr ;
break;
+ }
+ }
if (p == NULL) {
*ErrP = SNMP_ERR_NOSUCHNAME;
}
switch (Var->name[LEN_SQ_MESH + 2]) {
+ case MESH_PTBL_INDEX: { // FIXME INET6: Should be visible?
+ Answer = snmp_var_new_integer(Var->name, Var->name_length,
+ (snint)p->index, SMI_INTEGER);
+ }
+ break;
case MESH_PTBL_NAME:
cp = p->host;
Answer->type = ASN_OCTET_STR;
Answer->val_len = strlen(cp);
Answer->val.string = (u_char *) xstrdup(cp);
+
break;
- case MESH_PTBL_IP:
+ case MESH_PTBL_ADDR_TYPE: {
+ int ival;
+ ival = laddr.IsIPv4() ? INETADDRESSTYPE_IPV4 : INETADDRESSTYPE_IPV6 ;
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) p->in_addr.sin_addr.s_addr,
- SMI_IPADDRESS);
- break;
+ ival, SMI_INTEGER);
+ }
+ break;
+ case MESH_PTBL_ADDR: {
+ Answer = snmp_var_new(Var->name, Var->name_length);
+ // InetAddress doesn't have its own ASN.1 type,
+ // like IpAddr does (SMI_IPADDRESS)
+ // See: rfc4001.txt
+ Answer->type = ASN_OCTET_STR;
+ char host[MAX_IPSTRLEN];
+ laddr.NtoA(host,MAX_IPSTRLEN);
+ Answer->val_len = strlen(host);
+ Answer->val.string = (u_char *) xstrdup(host);
+ }
+ break;
case MESH_PTBL_HTTP:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
variable_list *Answer = NULL;
static struct rusage rusage;
- debug(49, 5) ("snmp_prfSysFn: Processing request with magic %d!\n", Var->name[LEN_SQ_PRF + 1]);
+ debugs(49, 5, "snmp_prfSysFn: Processing request with magic " << Var->name[LEN_SQ_PRF + 1] << "!");
*ErrP = SNMP_ERR_NOERROR;
switch (Var->name[LEN_SQ_PRF + 1]) {
case PERF_SYS_CPUUSAGE:
squid_getrusage(&rusage);
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) dpercent(rusage_cputime(&rusage), tvSubDsec(squid_start, current_time)),
+ (snint) Math::doublePercent(rusage_cputime(&rusage), tvSubDsec(squid_start, current_time)),
ASN_INTEGER);
break;
break;
case PERF_SYS_CURUSED_FD:
- Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) Number_FD,
- SMI_GAUGE32);
- break;
+ Answer = snmp_var_new_integer(Var->name, Var->name_length,
+ (snint) Number_FD,
+ SMI_GAUGE32);
+ break;
case PERF_SYS_CURMAX_FD:
- Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) Biggest_FD,
- SMI_GAUGE32);
- break;
+ Answer = snmp_var_new_integer(Var->name, Var->name_length,
+ (snint) Biggest_FD,
+ SMI_GAUGE32);
+ break;
case PERF_SYS_NUMOBJCNT:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
static StatCounters *l = NULL;
double x;
int minutes;
- debug(49, 5) ("snmp_prfProtoFn: Processing request with magic %d!\n", Var->name[LEN_SQ_PRF]);
+ debugs(49, 5, "snmp_prfProtoFn: Processing request with magic " << Var->name[LEN_SQ_PRF] << "!");
*ErrP = SNMP_ERR_NOERROR;
switch (Var->name[LEN_SQ_PRF + 1]) {
case PERF_PROTOSTAT_AGGR_CURSWAP:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) store_swap_size,
+ (snint) Store::Root().currentSize() >> 10,
SMI_GAUGE32);
break;
l = snmpStatGet(minutes);
- debug(49, 8) ("median: min= %d, %d l= %p , f = %p\n", minutes,
- Var->name[LEN_SQ_PRF + 3], l, f);
-
- debug(49, 8) ("median: l= %p , f = %p\n", l, f);
+ debugs(49, 8, "median: min= " << minutes << ", " << Var->name[LEN_SQ_PRF + 3] << " l= " << l << " , f = " << f);
+ debugs(49, 8, "median: l= " << l << " , f = " << f);
switch (Var->name[LEN_SQ_PRF + 3]) {
break;
case PERF_MEDIAN_HTTP_ALL:
- x = statHistDeltaMedian(&l->client_http.all_svc_time,
- &f->client_http.all_svc_time);
+ x = statHistDeltaMedian(l->client_http.allSvcTime,
+ f->client_http.allSvcTime);
break;
case PERF_MEDIAN_HTTP_MISS:
- x = statHistDeltaMedian(&l->client_http.miss_svc_time,
- &f->client_http.miss_svc_time);
+ x = statHistDeltaMedian(l->client_http.missSvcTime,
+ f->client_http.missSvcTime);
break;
case PERF_MEDIAN_HTTP_NM:
- x = statHistDeltaMedian(&l->client_http.nm_svc_time,
- &f->client_http.nm_svc_time);
+ x = statHistDeltaMedian(l->client_http.nearMissSvcTime,
+ f->client_http.nearMissSvcTime);
break;
case PERF_MEDIAN_HTTP_HIT:
- x = statHistDeltaMedian(&l->client_http.hit_svc_time,
- &f->client_http.hit_svc_time);
+ x = statHistDeltaMedian(l->client_http.hitSvcTime,
+ f->client_http.hitSvcTime);
break;
case PERF_MEDIAN_ICP_QUERY:
- x = statHistDeltaMedian(&l->icp.query_svc_time, &f->icp.query_svc_time);
+ x = statHistDeltaMedian(l->icp.querySvcTime, f->icp.querySvcTime);
break;
case PERF_MEDIAN_ICP_REPLY:
- x = statHistDeltaMedian(&l->icp.reply_svc_time, &f->icp.reply_svc_time);
+ x = statHistDeltaMedian(l->icp.replySvcTime, f->icp.replySvcTime);
break;
case PERF_MEDIAN_DNS:
- x = statHistDeltaMedian(&l->dns.svc_time, &f->dns.svc_time);
+ x = statHistDeltaMedian(l->dns.svcTime, f->dns.svcTime);
break;
case PERF_MEDIAN_RHR:
x = statByteHitRatio(minutes);
break;
- case PERF_MEDIAN_HTTP_NH:
- x = statHistDeltaMedian(&l->client_http.nh_svc_time,
- &f->client_http.nh_svc_time);
- break;
+ case PERF_MEDIAN_HTTP_NH:
+ x = statHistDeltaMedian(l->client_http.nearHitSvcTime,
+ f->client_http.nearHitSvcTime);
+ break;
default:
*ErrP = SNMP_ERR_NOSUCHNAME;