remove a lot of dead code
This commit is contained in:
parent
e779ac7394
commit
75dfc1e0e3
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
PROG= snmpd_ntpd
|
||||
SRCS= mib.c log.c util.c
|
||||
SRCS= mib.c log.c
|
||||
MAN=
|
||||
|
||||
CFLAGS+= -Wall -I${.CURDIR}
|
||||
|
96
mib.c
96
mib.c
@ -39,45 +39,43 @@
|
||||
#include "mib.h"
|
||||
|
||||
struct event connev;
|
||||
const char *agentxsocket = NULL;
|
||||
int agentxfd = -1;
|
||||
|
||||
void snmp_connect(struct agentx *, void *, int);
|
||||
void snmp_tryconnect(int, short, void *);
|
||||
void snmp_read(int, short, void *);
|
||||
|
||||
struct agentx_context *sac;
|
||||
struct snmpd *snmpd_env;
|
||||
|
||||
|
||||
void mib_hottisntpdcounter(struct agentx_varbind *);
|
||||
|
||||
|
||||
void
|
||||
mib_hottisntpdcounter(struct agentx_varbind *vb)
|
||||
{
|
||||
static void mib_hottisntpdcounter(struct agentx_varbind *vb) {
|
||||
long long ticks = 200169;
|
||||
|
||||
agentx_varbind_counter64(vb, ticks);
|
||||
}
|
||||
|
||||
static void mib_register(struct agentx_context *sac) {
|
||||
struct agentx_region *hottis;
|
||||
struct agentx_object *hottisNtpdCounter;
|
||||
|
||||
if ((hottis = agentx_region(sac, AGENTX_OID(HOTTIS_MIB), 0)) == NULL)
|
||||
fatal("agentx_region");
|
||||
|
||||
if ((hottisNtpdCounter = agentx_object(hottis, AGENTX_OID(HOTTIS_NTPD_COUNTER),
|
||||
NULL, 0, 0, mib_hottisntpdcounter)) == NULL)
|
||||
fatal("agentx_object");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
static struct snmpd conf;
|
||||
struct agentx *sa;
|
||||
struct agentx_context *sac;
|
||||
struct agentx_session *sas;
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
char agentxsocketdir[PATH_MAX];
|
||||
int ch;
|
||||
int verbose = 0, daemonize = 1, debug = 0;
|
||||
char *context = NULL;
|
||||
const char *errstr;
|
||||
|
||||
struct agentx_region *hottis;
|
||||
struct agentx_object *hottisNtpdCounter;
|
||||
int verbose = 0, daemonize = 1;
|
||||
|
||||
snmpd_env = &conf;
|
||||
log_init(2, LOG_DAEMON);
|
||||
@ -87,70 +85,34 @@ main(int argc, char *argv[])
|
||||
agentx_log_info = log_info;
|
||||
agentx_log_debug = log_debug;
|
||||
|
||||
while ((ch = getopt(argc, argv, "c:ds:vx:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "dv")) != -1) {
|
||||
switch (ch) {
|
||||
case 'c':
|
||||
context = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
daemonize = 0;
|
||||
debug = 1;
|
||||
break;
|
||||
case 's':
|
||||
if (optarg[0] != '/')
|
||||
fatalx("agentx socket path must be absolute");
|
||||
agentxsocket = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
case 'x':
|
||||
/* Undocumented flag for snmpd(8) spawning */
|
||||
agentxfd = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
fatalx("invalid agentx fd: %s", errstr);
|
||||
daemonize = 0;
|
||||
break;
|
||||
default:
|
||||
fatalx("usage: snmpd_ntpd [-dv] "
|
||||
"[-c context] [-s master]\n");
|
||||
fatalx("usage: snmpd_ntpd [-dv]\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (agentxfd != -1 && !debug)
|
||||
/* Initialize syslog logging asap for snmpd */
|
||||
log_init(0, LOG_DAEMON);
|
||||
|
||||
if ((pw = getpwnam("_snmpd")) == NULL)
|
||||
fatal("can't find _snmpd user");
|
||||
if ((gr = getgrnam("_agentx")) == NULL)
|
||||
fatal("can't find _agentx group");
|
||||
|
||||
if (agentxfd != -1 && agentxsocket != NULL)
|
||||
fatalx("-s and -x are mutually exclusive");
|
||||
if (agentxfd == -1 && agentxsocket == NULL)
|
||||
agentxsocket = AGENTX_MASTER_PATH;
|
||||
|
||||
event_init();
|
||||
|
||||
if ((sa = agentx(snmp_connect, NULL)) == NULL)
|
||||
fatal("agentx");
|
||||
if ((sas = agentx_session(sa, NULL, 0, "OpenSNMPd metrics", 0)) == NULL)
|
||||
if ((sas = agentx_session(sa, NULL, 0, "Hottis NTP Metrics for OpenNTPD", 0)) == NULL)
|
||||
fatal("agentx_session");
|
||||
if ((sac = agentx_context(sas, context)) == NULL)
|
||||
if ((sac = agentx_context(sas, NULL)) == NULL)
|
||||
fatal("agentx_context");
|
||||
|
||||
|
||||
if (agentxsocket != NULL) {
|
||||
if (strlcpy(agentxsocketdir, agentxsocket,
|
||||
sizeof(agentxsocketdir)) >= sizeof(agentxsocketdir)) {
|
||||
errno = ENAMETOOLONG;
|
||||
fatal("-s");
|
||||
}
|
||||
if (unveil(dirname(agentxsocketdir), "r") == -1)
|
||||
fatal("unveil");
|
||||
}
|
||||
|
||||
/* Can't pledge: kvm_getfiles */
|
||||
if (unveil(NULL, NULL) == -1)
|
||||
fatal("unveil");
|
||||
@ -160,13 +122,7 @@ main(int argc, char *argv[])
|
||||
if (setuid(pw->pw_uid) == -1)
|
||||
fatal("setuid");
|
||||
|
||||
if ((hottis = agentx_region(sac, AGENTX_OID(HOTTIS_MIB), 0)) == NULL)
|
||||
fatal("agentx_region");
|
||||
|
||||
if ((hottisNtpdCounter = agentx_object(hottis, AGENTX_OID(HOTTIS_NTPD_COUNTER),
|
||||
NULL, 0, 0, mib_hottisntpdcounter)) == NULL)
|
||||
fatal("agentx_object");
|
||||
|
||||
mib_register(sac);
|
||||
|
||||
if (daemonize) {
|
||||
log_init(0, LOG_DAEMON);
|
||||
@ -180,24 +136,12 @@ main(int argc, char *argv[])
|
||||
void
|
||||
snmp_connect(struct agentx *sa, void *cookie, int close)
|
||||
{
|
||||
static int init = 0;
|
||||
|
||||
if (close) {
|
||||
event_del(&connev);
|
||||
return;
|
||||
}
|
||||
|
||||
if (agentxfd != -1) {
|
||||
/* Exit if snmpd(8) leaves */
|
||||
if (init)
|
||||
exit(0);
|
||||
agentx_connect(sa, agentxfd);
|
||||
event_set(&connev, agentxfd, EV_READ | EV_PERSIST,
|
||||
snmp_read, sa);
|
||||
event_add(&connev, NULL);
|
||||
init = 1;
|
||||
} else
|
||||
snmp_tryconnect(-1, 0, sa);
|
||||
snmp_tryconnect(-1, 0, sa);
|
||||
}
|
||||
|
||||
void
|
||||
|
4
mib.h
4
mib.h
@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: mib.h,v 1.1.1.1 2022/09/01 14:20:34 martijn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 Wolfgang Hottgenroth <woho@hottis.de>
|
||||
* Copyright (c) 2022 Martijn van Duren <martijn@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@ -18,6 +19,7 @@
|
||||
|
||||
#include <agentx.h>
|
||||
|
||||
#define HOTTIS_MIB 1,3,6,1,4,1,9676
|
||||
#define ENTERPRISE_MIB 1,3,6,1,4,1
|
||||
#define HOTTIS_MIB ENTERPRISE_MIB, 9676
|
||||
#define HOTTIS_NTPD HOTTIS_MIB, 1
|
||||
#define HOTTIS_NTPD_COUNTER HOTTIS_NTPD, 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user