#include <config.h>
#if defined(HAVE_UCDSNMP) || defined(HAVE_NETSNMP)
#ifdef HAVE_NETSNMP
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/utilities.h>
extern int header_generic(struct variable *, oid *, size_t *, int,
size_t *, WriteMethod **);
extern int header_simple_table(struct variable *, oid *, size_t *,
int, size_t *, WriteMethod **, int);
#else
#ifdef IN_UCD_SNMP_SOURCE
#include <config.h>
#include "mibincl.h"
#include "util_funcs.h"
#else
#include <ucd-snmp/ucd-snmp-config.h>
#include <ucd-snmp/ucd-snmp-includes.h>
#include <ucd-snmp/ucd-snmp-agent-includes.h>
#include <ucd-snmp/util_funcs.h>
#endif
#endif
#include <time.h>
#include <string.h>
#include "cyrusMasterMIB.h"
#include "master.h"
#include "../imap/version.h"
oid cyrusMasterMIB_variables_oid[] = { 1,3,6,1,4,1,3,6,1 };
struct variable4 cyrusMasterMIB_variables[] = {
#define CYRUSMASTERINFODESCR 1
{ CYRUSMASTERINFODESCR, ASN_OCTET_STR , RONLY , var_cyrusMasterMIB, 2, { 1,1 } },
#define CYRUSMASTERINFOVERS 2
{ CYRUSMASTERINFOVERS , ASN_OCTET_STR , RONLY , var_cyrusMasterMIB, 2, { 1,2 } },
#define CYRUSMASTERINFOUPTIME 3
{ CYRUSMASTERINFOUPTIME , ASN_TIMETICKS , RONLY , var_cyrusMasterMIB, 2, { 1,3 } },
#define SERVICEFORKS 5
{ SERVICEFORKS , ASN_COUNTER , RONLY , var_serviceTable, 3, { 2,1,1 } },
#define SERVICEACTIVE 6
{ SERVICEACTIVE , ASN_GAUGE , RONLY , var_serviceTable, 3, { 2,1,2 } },
#define SERVICENAME 7
{ SERVICENAME , ASN_OCTET_STR , RONLY , var_serviceTable, 3, { 2,1,3 } },
#define SERVICEID 8
{ SERVICEID , ASN_INTEGER , NOACCESS , var_serviceTable, 3, { 2,1,4 } },
#define SERVICECONNS 9
{ SERVICECONNS , ASN_COUNTER , NOACCESS , var_serviceTable, 3, { 2,1,5 } },
};
static time_t startTime = 0;
void init_cyrusMasterMIB(void)
{
REGISTER_MIB("cyrusMasterMIB", cyrusMasterMIB_variables, variable4,
cyrusMasterMIB_variables_oid);
if (!startTime) {
startTime = time(NULL);
}
}
unsigned char *
var_cyrusMasterMIB(struct variable *vp,
oid *name,
size_t *length,
int exact,
size_t *var_len,
WriteMethod **write_method)
{
static long long_ret;
static char string[SPRINT_MAX_LEN];
if (header_generic(vp,name,length,exact,var_len,write_method)
== MATCH_FAILED )
return NULL;
switch(vp->magic) {
case CYRUSMASTERINFODESCR:
strlcpy(string, "Cyrus IMAP server master process", sizeof(string));
*var_len = strlen(string);
return (unsigned char *) string;
case CYRUSMASTERINFOVERS:
strlcpy(string, CYRUS_VERSION, sizeof(string));
*var_len = strlen(string);
return (unsigned char *) string;
case CYRUSMASTERINFOUPTIME:
long_ret = 100 * (time(NULL) - startTime);
return (unsigned char *) &long_ret;
default:
ERROR_MSG("");
}
return NULL;
}
unsigned char *
var_serviceTable(struct variable *vp,
oid *name,
size_t *length,
int exact,
size_t *var_len,
WriteMethod **write_method)
{
static long long_ret;
static char string[SPRINT_MAX_LEN];
int index;
if (header_simple_table(vp,name,length,exact,var_len,write_method, nservices)
== MATCH_FAILED )
return NULL;
index = name[*length - 1];
switch(vp->magic) {
case SERVICEFORKS:
long_ret = Services[index - 1].nforks;
return (unsigned char *) &long_ret;
case SERVICEACTIVE:
long_ret = Services[index - 1].nactive;
return (unsigned char *) &long_ret;
case SERVICENAME:
if (Services[index - 1].name != NULL) {
strlcpy(string, Services[index - 1].name, sizeof(string));
if(Services[index - 1].family == AF_INET6) {
strlcat(string, "[v6]", sizeof(string));
}
} else {
strlcpy(string, "", sizeof(string));
}
*var_len = strlen(string);
return (unsigned char *) string;
case SERVICEID:
long_ret = index;
return (unsigned char *) &long_ret;
case SERVICECONNS:
long_ret = Services[index - 1].nconnections;
return (unsigned char *) &long_ret;
default:
ERROR_MSG("");
}
return NULL;
}
#endif