aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-02-14 10:53:03 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-02-14 11:01:50 +0200
commit45c6086f8c0c0f6fe1a46b950682abfdbf104687 (patch)
tree61923d59ed3dbbe0365d88e574b7e4f1aec4fbcc
parentdffed71f70f7e7b6bf1cd32539a1a1131916a8b4 (diff)
downloadvarnish-mib-45c6086f8c0c0f6fe1a46b950682abfdbf104687.tar.gz
varnish-mib-45c6086f8c0c0f6fe1a46b950682abfdbf104687.tar.bz2
Rewrite as a stand-alone snmpd agent.
* NEWS: Document new features. * configure.ac: Raise version number. * src/.gitignore: Update. * src/Makefile.am: Build as an agent. * src/main.c: New file. * src/modconf.c: Remove "varnish" prefix from the configuration directives. (varnish_mib_config_init): Use program name as the base for the configuration file name. (varnish_mib_config_help): New function. * src/modconf.h (progname, pid_file, pid_file_immutable): New externs. * src/varnish-mib.8: Rewrite. * src/varnish_mib.mib2c (varnish_snmp_init) (varnish_snmp_deinit): Remove. (post_config): Extern. Called from main().
-rw-r--r--NEWS8
-rw-r--r--configure.ac10
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am20
-rw-r--r--src/main.c282
-rw-r--r--src/modconf.c54
-rw-r--r--src/modconf.h5
-rw-r--r--src/varnish-mib.8153
-rw-r--r--src/varnish_mib.mib2c30
9 files changed, 451 insertions, 112 deletions
diff --git a/NEWS b/NEWS
index 34ba295..8e0cbb4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,12 @@
1Varnish-mib NEWS -- history of user-visible changes. 2018-12-10 1Varnish-mib NEWS -- history of user-visible changes. 2019-02-14
2See the end of file for copying conditions. 2See the end of file for copying conditions.
3 3
4Please send Varnish-mib bug reports to <gray@gnu.org> 4Please send Varnish-mib bug reports to <gray@gnu.org>
5 5
6Version 3.99.90 (git)
7
8Rewrite as a stand-alone snmpd agent.
9
6Version 3.1, 2018-12-10 10Version 3.1, 2018-12-10
7 11
8Supports Varnish 6.0.2. 12Supports Varnish 6.0.2.
@@ -115,7 +119,7 @@ Initial release.
115 119
116* Copyright information: 120* Copyright information:
117 121
118Copyright (C) 2014-2018 Sergey Poznyakoff 122Copyright (C) 2014-2019 Sergey Poznyakoff
119 123
120 Permission is granted to anyone to make or distribute verbatim copies 124 Permission is granted to anyone to make or distribute verbatim copies
121 of this document as received, in any medium, provided that the 125 of this document as received, in any medium, provided that the
diff --git a/configure.ac b/configure.ac
index f2bca53..af72e65 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1# This file is part of Varnish-mib -*- autoconf -*- 1# This file is part of Varnish-mib -*- autoconf -*-
2# Copyright (C) 2014-2018 Sergey Poznyakoff 2# Copyright (C) 2014-2019 Sergey Poznyakoff
3# 3#
4# Varnish-mib is free software; you can redistribute it and/or modify 4# Varnish-mib is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
15# along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>. 15# along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>.
16 16
17AC_PREREQ(2.69) 17AC_PREREQ(2.69)
18AC_INIT([varnish-mib], 3.1, [gray@gnu.org]) 18AC_INIT([varnish-mib], 3.99.90, [gray@gnu.org])
19AC_CONFIG_SRCDIR(src/varnish_mib.mib2c) 19AC_CONFIG_SRCDIR(src/varnish_mib.mib2c)
20AM_CONFIG_HEADER(config.h) 20AM_CONFIG_HEADER(config.h)
21AC_CONFIG_AUX_DIR([build-aux]) 21AC_CONFIG_AUX_DIR([build-aux])
@@ -50,7 +50,11 @@ AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH)
50if test "$NET_SNMP_CONFIG" = "none"; then 50if test "$NET_SNMP_CONFIG" = "none"; then
51 AC_MSG_ERROR([cannot find Net-SNMP (net-snmp-config not found)]) 51 AC_MSG_ERROR([cannot find Net-SNMP (net-snmp-config not found)])
52fi 52fi
53AC_SUBST(NET_SNMP_CONFIG) 53
54AC_SUBST(NET_SNMP_LIBS, `$NET_SNMP_CONFIG --agent-libs`)
55AC_SUBST(NET_SNMP_EXLIBS, `$NET_SNMP_CONFIG --external-libs`)
56AC_SUBST(NET_SNMP_MIBDIRS, `$NET_SNMP_CONFIG --mibdirs`)
57AC_SUBST(NET_SNMP_MIBS, `$NET_SNMP_CONFIG --default-mibs`)
54 58
55# Checks for header files. 59# Checks for header files.
56AC_HEADER_STDC 60AC_HEADER_STDC
diff --git a/src/.gitignore b/src/.gitignore
index f40282a..e6ff459 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,3 +1,4 @@
1varnish-mib
1varnish_mib.c 2varnish_mib.c
2varnish_mib.h 3varnish_mib.h
3belex.c 4belex.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 5c79dfc..6019c39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
1# This file is part of varnish-mib -*- automake -*- 1# This file is part of varnish-mib -*- automake -*-
2# Copyright (C) 2014-2018 Sergey Poznyakoff 2# Copyright (C) 2014-2019 Sergey Poznyakoff
3# 3#
4# varnish-mib is free software; you can redistribute it and/or modify 4# varnish-mib is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -14,15 +14,14 @@
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with varnish-mib. If not, see <http://www.gnu.org/licenses/>. 15# along with varnish-mib. If not, see <http://www.gnu.org/licenses/>.
16 16
17dlmoddir=@DLMODDIR@ 17sbin_PROGRAMS = varnish-mib
18dlmod_LTLIBRARIES = varnish-mib.la 18varnish_mib_SOURCES = \
19
20varnish_mib_la_SOURCES = \
21 auth.c\ 19 auth.c\
22 ban.c\ 20 ban.c\
23 backend.h\ 21 backend.h\
24 belex.l\ 22 belex.l\
25 betab.c\ 23 betab.c\
24 main.c\
26 modconf.h\ 25 modconf.h\
27 modconf.c\ 26 modconf.c\
28 sha256.c\ 27 sha256.c\
@@ -44,18 +43,7 @@ varnish_mib.c varnish_mib.h: varnish_mib.mib2c VARNISH-MIB.txt
44 PERL5LIB=${top_srcdir}/lib \ 43 PERL5LIB=${top_srcdir}/lib \
45 mib2c -c $< -f $@ varnish 44 mib2c -c $< -f $@ varnish
46 45
47#NET_SNMP_INCLUDES = `$(NET_SNMP_CONFIG) --cflags`
48#NET_SNMP_INCLUDES =
49NET_SNMP_LIBS = `$(NET_SNMP_CONFIG) --libs`
50NET_SNMP_EXLIBS = `$(NET_SNMP_CONFIG) --external-libs`
51NET_SNMP_MIBDIRS = `net-snmp-config --mibdirs`
52NET_SNMP_MIBS = `net-snmp-config --default-mibs`
53
54AM_LDFLAGS = \ 46AM_LDFLAGS = \
55 -module \
56 -export-dynamic\
57 -avoid-version \
58 -rpath '$(dlmoddir)'\
59 ${VARNISHAPI_LIBS}\ 47 ${VARNISHAPI_LIBS}\
60 $(NET_SNMP_LIBS)\ 48 $(NET_SNMP_LIBS)\
61 $(NET_SNMP_EXLIBS) 49 $(NET_SNMP_EXLIBS)
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..a8d089f
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,282 @@
1#include "varnish_mib.h"
2#include <unistd.h>
3#include <sys/types.h>
4#include <signal.h>
5
6char *progname;
7
8static void pidfile_check(char const *pid_file);
9static void pidfile_create(char const *pid_file);
10static int pidfile_remove(char const *pid_file);
11
12void
13usage(FILE *fp)
14{
15 fprintf(fp, "usage: varnish-mib [OPTIONS]\n");
16 fprintf(fp, "SNMP agent for Varnish Cache monitoring\n");
17 fprintf(fp, "OPTIONS are:\n\n");
18
19 fprintf(fp,
20 " -A append to the log file rather than truncating it\n");
21 fprintf(fp,
22 " -C do not read any configuration files except the ones optionally\n"
23 " specified by the -c option\n");
24 fprintf(fp,
25 " -D TOKEN[,TOKEN...]\n"
26 " turn on debugging output for the given TOKENs\n");
27 fprintf(fp,
28 " -H display a list of configuration file directives understood\n"
29 " by the agent and then exit\n");
30 fprintf(fp,
31 " -L[efos] configure logging\n");
32 fprintf(fp,
33 " -c FILE ead FILE as a configuration file (or a comma-separated list of\n"
34 " configuration files\n");
35 fprintf(fp,
36 " -d dump (in hexadecimal) the sent and received SNMP packets\n");
37 fprintf(fp,
38 " -f remain in the foreground\n");
39 fprintf(fp,
40 " -h, -? print this help summary\n");
41 fprintf(fp,
42 " -n NAME assume this program name\n");
43 fprintf(fp,
44 " -p save the process ID of the daemon in FILE\n");
45 fprintf(fp, "\n");
46 fprintf(fp, "default configuration path is: %s\n",
47 get_configuration_directory());
48}
49
50static volatile int stop;
51
52static void
53stophandler(int sig)
54{
55 stop = 1;
56}
57
58int
59main(int argc, char **argv)
60{
61 int c, i;
62 int foreground = 0;
63 struct sigaction sa;
64 static int signo[] = {
65 SIGHUP,
66 SIGINT,
67 SIGQUIT,
68 SIGTERM,
69 0
70 };
71 int log_set = 0;
72 int snmp_dump_packet = 0;
73
74 progname = strrchr(argv[0], '/');
75 if (progname)
76 progname++;
77 else
78 progname = argv[0];
79 if (strncmp(progname, "lt-", 3) == 0)
80 progname += 3;
81
82 while ((c = getopt(argc, argv, "ACD:HL:c:dfhn:p:")) != EOF) {
83 switch (c) {
84 case 'A':
85 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
86 NETSNMP_DS_LIB_APPEND_LOGFILES,
87 1);
88 break;
89
90 case 'C':
91 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
92 NETSNMP_DS_LIB_DONT_READ_CONFIGS,
93 1);
94 break;
95
96 case 'D':