mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
Import from release candidate 2.13.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
commit
74aef1c34e
38 changed files with 15998 additions and 0 deletions
2
contrib/Makefile.am
Normal file
2
contrib/Makefile.am
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
contribdir = $(datadir)/dhcpd-pools/
|
||||
dist_contrib_SCRIPTS = dhcpd-pools.cgi snmptest.pl
|
||||
379
contrib/Makefile.in
Normal file
379
contrib/Makefile.in
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
# Makefile.in generated by automake 1.11.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
|
||||
# Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
subdir = contrib
|
||||
DIST_COMMON = $(dist_contrib_SCRIPTS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
|
||||
am__install_max = 40
|
||||
am__nobase_strip_setup = \
|
||||
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
|
||||
am__nobase_strip = \
|
||||
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
|
||||
am__nobase_list = $(am__nobase_strip_setup); \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
|
||||
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
|
||||
if (++n[$$2] == $(am__install_max)) \
|
||||
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
|
||||
END { for (dir in files) print dir, files[dir] }'
|
||||
am__base_list = \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
|
||||
am__installdirs = "$(DESTDIR)$(contribdir)"
|
||||
SCRIPTS = $(dist_contrib_SCRIPTS)
|
||||
SOURCES =
|
||||
DIST_SOURCES =
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build_alias = @build_alias@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host_alias = @host_alias@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
contribdir = $(datadir)/dhcpd-pools/
|
||||
dist_contrib_SCRIPTS = dhcpd-pools.cgi snmptest.pl
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu contrib/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu contrib/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
install-dist_contribSCRIPTS: $(dist_contrib_SCRIPTS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(contribdir)" || $(MKDIR_P) "$(DESTDIR)$(contribdir)"
|
||||
@list='$(dist_contrib_SCRIPTS)'; test -n "$(contribdir)" || list=; \
|
||||
for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \
|
||||
done | \
|
||||
sed -e 'p;s,.*/,,;n' \
|
||||
-e 'h;s|.*|.|' \
|
||||
-e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \
|
||||
$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \
|
||||
{ d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
|
||||
if ($$2 == $$4) { files[d] = files[d] " " $$1; \
|
||||
if (++n[d] == $(am__install_max)) { \
|
||||
print "f", d, files[d]; n[d] = 0; files[d] = "" } } \
|
||||
else { print "f", d "/" $$4, $$1 } } \
|
||||
END { for (d in files) print "f", d, files[d] }' | \
|
||||
while read type dir files; do \
|
||||
if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
|
||||
test -z "$$files" || { \
|
||||
echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(contribdir)$$dir'"; \
|
||||
$(INSTALL_SCRIPT) $$files "$(DESTDIR)$(contribdir)$$dir" || exit $$?; \
|
||||
} \
|
||||
; done
|
||||
|
||||
uninstall-dist_contribSCRIPTS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(dist_contrib_SCRIPTS)'; test -n "$(contribdir)" || exit 0; \
|
||||
files=`for p in $$list; do echo "$$p"; done | \
|
||||
sed -e 's,.*/,,;$(transform)'`; \
|
||||
test -n "$$list" || exit 0; \
|
||||
echo " ( cd '$(DESTDIR)$(contribdir)' && rm -f" $$files ")"; \
|
||||
cd "$(DESTDIR)$(contribdir)" && rm -f $$files
|
||||
tags: TAGS
|
||||
TAGS:
|
||||
|
||||
ctags: CTAGS
|
||||
CTAGS:
|
||||
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
|
||||
else \
|
||||
test -f "$(distdir)/$$file" \
|
||||
|| cp -p $$d/$$file "$(distdir)/$$file" \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(SCRIPTS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(contribdir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-generic
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-dist_contribSCRIPTS
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-generic
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-dist_contribSCRIPTS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: all all-am check check-am clean clean-generic distclean \
|
||||
distclean-generic distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am \
|
||||
install-dist_contribSCRIPTS install-dvi install-dvi-am \
|
||||
install-exec install-exec-am install-html install-html-am \
|
||||
install-info install-info-am install-man install-pdf \
|
||||
install-pdf-am install-ps install-ps-am install-strip \
|
||||
installcheck installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
|
||||
pdf-am ps ps-am uninstall uninstall-am \
|
||||
uninstall-dist_contribSCRIPTS
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
34
contrib/dhcpd-pools.cgi
Executable file
34
contrib/dhcpd-pools.cgi
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Simple CGI for dhcpd-pools.
|
||||
|
||||
echo Content-type: text/html
|
||||
echo
|
||||
|
||||
# To make lease table more fancy use CSS definition something
|
||||
# like this in your style.css file.
|
||||
#
|
||||
# TABLE.dhcpd-pools {
|
||||
# border-style : groove;
|
||||
# margin-left : 2px;
|
||||
# foo : bar;
|
||||
# }
|
||||
#
|
||||
# http://www.w3.org/TR/REC-CSS2/tables.html
|
||||
#
|
||||
# And uncomment this line.
|
||||
#
|
||||
#echo <link type="text/css" rel="stylesheet" href="/style.css" />
|
||||
|
||||
echo "<html>"
|
||||
echo "<body>"
|
||||
echo "<p>This was situation at "
|
||||
date
|
||||
echo "</p>"
|
||||
|
||||
/usr/local/bin/dhcpd-pools --format html
|
||||
|
||||
echo "</body>"
|
||||
echo "</html>"
|
||||
|
||||
# EOF
|
||||
472
contrib/snmptest.pl
Normal file
472
contrib/snmptest.pl
Normal file
|
|
@ -0,0 +1,472 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# <Note from="Sami Kerola">
|
||||
# This script is anonymous user contribution (due legal
|
||||
# department did not let the person the get credit because
|
||||
# they are afraid open source contributions). You know who you
|
||||
# are, and I am graceful to get this to be part of the
|
||||
# package.
|
||||
# </Note>
|
||||
|
||||
# 1) modify snmpd.conf and add the following line. Note that the
|
||||
# last field must match the path/name of the script:
|
||||
#
|
||||
# pass_persist .1.3.6.1.4.1.2021.250.255 /root/snmptest.pl
|
||||
#
|
||||
# This assumes you've already configured snmpd, i.e. community
|
||||
# strings, etc.
|
||||
#
|
||||
# 2) Install the following script. Note that if you changed the
|
||||
# OID string above, then you'll need to change the value for
|
||||
# $root in this file, too. Be sure that $datafile is set to
|
||||
# the location of the .CSV output from dhcpd-pools. NOTE: if
|
||||
# you set $dbg to 1 then output will be generated in /tmp.
|
||||
|
||||
use strict;
|
||||
|
||||
# Version info:
|
||||
my $SNMPver = "snmp1.0";
|
||||
my $DHCPver = "dhcp1.0";
|
||||
my $VERSION = "$SNMPver/$DHCPver";
|
||||
#
|
||||
# set $dbg to a non-zero value to get debug output in /tmp
|
||||
#
|
||||
my $dbg=0;
|
||||
|
||||
#
|
||||
# Here's an example entry for snmpd.conf:
|
||||
# pass_persist .1.3.6.1.4.1.2021.250.255 /path/to/this/script.pl
|
||||
# so in this case $root should be '.1.3.6.1.4.1.2021.250.255'
|
||||
#
|
||||
# $root.1.x : shared network name for index x
|
||||
# $root.2.x : IP range name for index x
|
||||
# $root.3.x : Range Contained-In for index x
|
||||
# $root.4.x : Shared Net Stats for index x
|
||||
# $root.5.x : IP range stats for index x
|
||||
#
|
||||
# $root.4.1.x : 'max' value for shared network at index=x
|
||||
# $root.4.2.x : 'cur' value for shared network at index=x
|
||||
# $root.4.3.x : 'tou' value for shared network at index=x
|
||||
#
|
||||
# $root.5.1.x : 'max' value for IP range at index=x
|
||||
# $root.5.2.x : 'cur' value for IP range at index=x
|
||||
# $root.5.3.x : 'tou' value for IP range at index=x
|
||||
|
||||
#
|
||||
# $root must match pass_persis entry in snmpd.conf
|
||||
#
|
||||
my $root='.1.3.6.1.4.1.2021.250.255';
|
||||
|
||||
#
|
||||
# $datafile is the location of the .CSV file created by dhcpd-pools.
|
||||
# NOTE: It is assumed that this file is routinely updated, i.e. at least
|
||||
# every 5 minutes, by some other process, i.e. cron.
|
||||
#
|
||||
my $datafile='/var/lib/dhcp/dhcpstats.csv';
|
||||
|
||||
#
|
||||
# $cachetime determines how long we can cache parse data from $datafile. If
|
||||
# more than $cachetime has elapsed we'll re-read $datafile, otherwise we'll
|
||||
# just send back the last-parsed data
|
||||
#
|
||||
# Generally 60 seconds seems pretty reasonable, but any positive value is
|
||||
# permitted.
|
||||
#
|
||||
my $cachetime = 60;
|
||||
|
||||
#
|
||||
# global variables for DHCP
|
||||
#
|
||||
my %SharedNetwork;
|
||||
my %RangeName;
|
||||
my %RangeContained;
|
||||
my @SNNindex;
|
||||
my @IPRNindex;
|
||||
|
||||
#
|
||||
# global variables for SNMP
|
||||
#
|
||||
my @validoidlist;
|
||||
|
||||
########## BEGIN UNIQUE-CODE FOR YOUR SNMP-QUERY NEEDS
|
||||
#
|
||||
# ParseDataFile does just that, and stores info in %SharedNetwork for later
|
||||
# processing.
|
||||
#
|
||||
# The routine ParseDataFile is calls at invocation to initialize all
|
||||
# datasets and also periodically (based on $cachetime).
|
||||
#
|
||||
my @where = qw( unknown Ranges SharedNets SumData );
|
||||
sub ParseDataFile () {
|
||||
print DBG "ParseDataFile\n" if $dbg;
|
||||
my $where = 0; # location in file unknown
|
||||
# used to generate ifIndex-like values for each Shared network
|
||||
my $shareindex = 1;
|
||||
# used to generate ifIndex-like values for each Shared network
|
||||
my $rangeindex = 1;
|
||||
|
||||
undef %SharedNetwork;
|
||||
undef %RangeName;
|
||||
undef %RangeContained;
|
||||
undef @SNNindex;
|
||||
undef @IPRNindex;
|
||||
@validoidlist = ();
|
||||
|
||||
open(IN, $datafile) || return undef;
|
||||
while (<IN>) {
|
||||
chomp;
|
||||
print DBG "...Read: $_\n" if $dbg;
|
||||
next if /^\s*$/; # skip blank lines
|
||||
next if /^"shared net name"/; # skip titles
|
||||
next if /^"name","max","cur"/; # skip titles
|
||||
if (/^"Ranges/) { $where = 1; next; }
|
||||
if (/^"Shared/) { $where = 2; next; }
|
||||
if (/^"Sum of/) { $where = 3; next; }
|
||||
print DBG "...Found data for @where[$where]: $_\n" if $dbg;
|
||||
#
|
||||
# "Ranges:"
|
||||
# 0 1 2 3 4 5 6 7 8
|
||||
# "shared net name","1stIP","lastIP","max","cur","%","touch","t+c","t+c %"
|
||||
#
|
||||
# "Shared networks:" and "Sum of all ranges:"
|
||||
# 0 1 2 3 4 5 6
|
||||
# "name","max","cur","%","touch","t+c","t+c %"
|
||||
#
|
||||
my @data = split /,/;
|
||||
my ($nam, $max, $cur, $tou, $fir);
|
||||
($nam = @data[0]) =~ s/"//g; # shared net name
|
||||
|
||||
($fir = @data[1]) =~ s/"//g if ($where == 1); # Range ID (1st IP)
|
||||
|
||||
($max = @data[3]) =~ s/"//g if ($where == 1); # max # of IPs
|
||||
($max = @data[1]) =~ s/"//g if ($where > 1); # max # of IPs
|
||||
|
||||
($cur = @data[4]) =~ s/"//g if ($where == 1); # cur # of IPs
|
||||
($cur = @data[2]) =~ s/"//g if ($where > 1); # cur # of IPs
|
||||
|
||||
($tou = @data[6]) =~ s/"//g if ($where == 1); # touched IP's
|
||||
($tou = @data[4]) =~ s/"//g if ($where > 1); # touched IP's
|
||||
|
||||
|
||||
print DBG "...idx sh/rg=$shareindex/$rangeindex : nam=$nam : max=$max : cur=$cur : tou=$tou\n" if $dbg;
|
||||
|
||||
#
|
||||
# Summary data for each IP range
|
||||
#
|
||||
if ($where == 1) { # Store IP range data
|
||||
if (defined($RangeName{$fir})) {
|
||||
print DBG "...WARNING: duplicate name '$fir'\n" if $dbg
|
||||
}
|
||||
$IPRNindex[$rangeindex] = $fir;
|
||||
$RangeName{$fir} = pack("LLLL", $rangeindex, $max, $cur, $tou);
|
||||
$RangeContained{$fir} = $nam;
|
||||
push @validoidlist, "$root.2.$rangeindex"; # IP range name
|
||||
push @validoidlist, "$root.3.$rangeindex"; # Contained In
|
||||
push @validoidlist, "$root.5.1.$rangeindex"; # range stats
|
||||
push @validoidlist, "$root.5.2.$rangeindex"; # range stats
|
||||
push @validoidlist, "$root.5.3.$rangeindex"; # range stats
|
||||
$rangeindex++;
|
||||
}
|
||||
|
||||
#
|
||||
# Summary data for each Shared network
|
||||
#
|
||||
if ($where == 2) { # Store Shared network summary data
|
||||
if (defined($SharedNetwork{$nam})) {
|
||||
print DBG "...WARNING: duplicate name '$nam'\n" if $dbg
|
||||
}
|
||||
$SNNindex[$shareindex] = $nam;
|
||||
$SharedNetwork{$nam} = pack("LLLL", $shareindex, $max, $cur, $tou);
|
||||
push @validoidlist, "$root.1.$shareindex"; # shared name
|
||||
push @validoidlist, "$root.4.1.$shareindex"; # shared stats
|
||||
push @validoidlist, "$root.4.2.$shareindex"; # shared stats
|
||||
push @validoidlist, "$root.4.3.$shareindex"; # shared stats
|
||||
$shareindex++;
|
||||
}
|
||||
|
||||
#
|
||||
# Summary data for everything
|
||||
#
|
||||
if ($where == 3) { # Store "All" network summary data
|
||||
print DBG "...We don't store 'All' info yet!\n" if $dbg;
|
||||
}
|
||||
}
|
||||
close IN;
|
||||
if ($dbg) {
|
||||
foreach (sort @validoidlist) { print DBG "ValidOID: $_\n"; }
|
||||
}
|
||||
|
||||
if ($dbg) {
|
||||
foreach (@IPRNindex) {
|
||||
print DBG "IP range $_\n";
|
||||
}
|
||||
foreach (@SNNindex) {
|
||||
print DBG "Shared Net $_\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#############################################################################
|
||||
#############################################################################
|
||||
#############################################################################
|
||||
# Forward Declarations
|
||||
#
|
||||
sub SendReturnNone ();
|
||||
sub SendReturn($$$);
|
||||
|
||||
#
|
||||
# GetData gets data, but will leverage caching of data if last parse was
|
||||
# over 60 seconds ago
|
||||
#
|
||||
my $lasttime = 0;
|
||||
sub GetData ($) {
|
||||
my $oid = shift;
|
||||
|
||||
(my $suboid = $oid) =~ s/$root//;
|
||||
|
||||
#
|
||||
# If enough time has elapsed, go fetch fresh data, otherwise use cached
|
||||
# data
|
||||
#
|
||||
print DBG "GetData: Time is: ", time, " : oid $oid->$suboid\n" if $dbg;
|
||||
if ((time - $lasttime) > $cachetime) {
|
||||
ParseDataFile();
|
||||
$lasttime = time;
|
||||
}
|
||||
|
||||
#
|
||||
# Quick sanity check of OID string:
|
||||
#
|
||||
if ( (!($oid =~ /^$root/)) ||
|
||||
($suboid eq '') ) {
|
||||
SendReturnNone();
|
||||
return;
|
||||
}
|
||||
|
||||
#
|
||||
# split the remaining OID pieces to analyse
|
||||
#
|
||||
my @oidlist = split(/\./, $suboid);
|
||||
|
||||
###################### EDIT THIS FOR YOUR APPLICATION ######################
|
||||
#
|
||||
# If we only get a single value, then barf (we need 2)
|
||||
#
|
||||
my $good = 0;
|
||||
$good = 1 if (($oidlist[1] eq '1') && ($#oidlist == 2)); # shared name
|
||||
$good = 1 if (($oidlist[1] eq '2') && ($#oidlist == 2)); # ip range name
|
||||
$good = 1 if (($oidlist[1] eq '3') && ($#oidlist == 2)); # contained in
|
||||
$good = 1 if (($oidlist[1] eq '4') && ($#oidlist == 3)); # shared-range stats
|
||||
$good = 1 if (($oidlist[1] eq '5') && ($#oidlist == 3)); # ip-range stats
|
||||
|
||||
if (!$good) {
|
||||
print DBG "oidlistcount = $#oidlist and oidlist1 is ", $oidlist[1], "\n" if $dbg;
|
||||
SendReturnNone();
|
||||
return;
|
||||
}
|
||||
|
||||
# $oidlist[1] = 1-5
|
||||
# $oidlist[2] = index for shared-name or range-name
|
||||
# or datatype to return
|
||||
# $oidlist[3] = index for datatype
|
||||
#
|
||||
if ($oidlist[1] eq '1') { # looking for name associated with shared net
|
||||
SendReturn($oid, 'string', $SNNindex[$oidlist[2]]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($oidlist[1] eq '2') { # looking for name associated with ip range
|
||||
print DBG "Responding with IPRNindex[$oidlist[2]]\n" if $dbg;
|
||||
SendReturn($oid, 'string', $IPRNindex[$oidlist[2]]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($oidlist[1] eq '3') { # looking for contained-in info
|
||||
if (defined($IPRNindex[$oidlist[2]])) { # valid subnet!
|
||||
my $fir = $IPRNindex[$oidlist[2]];
|
||||
my $con = $RangeContained{$fir};
|
||||
my @vals= unpack("LLLL", $SharedNetwork{$con});
|
||||
print DBG "fir=$fir : con=$con : vals=@vals : vals0=$vals[0]\n" if $dbg;
|
||||
SendReturn($oid, 'integer', @vals[0]);
|
||||
return;
|
||||
} else {
|
||||
SendReturnNone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($oidlist[1] eq '4') {
|
||||
if (defined($SNNindex[$oidlist[3]])) { # valid subnet!
|
||||
my $nam = $SNNindex[$oidlist[3]];
|
||||
my @vals= unpack("LLLL", $SharedNetwork{$nam});
|
||||
print DBG "nam=$nam, vals=@vals, oidlist[2]=$oidlist[2]\n" if $dbg;
|
||||
SendReturn($oid, 'integer', @vals[$oidlist[2]]);
|
||||
return;
|
||||
} else {
|
||||
print DBG "invalid subnet SNN $oidlist[3]\n" if $dbg;
|
||||
SendReturnNone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($oidlist[1] eq '5') {
|
||||
if (defined($IPRNindex[$oidlist[3]])) { # valid subnet!
|
||||
my $fir = $IPRNindex[$oidlist[3]];
|
||||
my @vals= unpack("LLLL", $RangeName{$fir});
|
||||
print DBG "fir=$fir, vals=@vals, oidlist[2]=", $oidlist[2], "\n" if $dbg;
|
||||
SendReturn($oid, 'integer', @vals[$oidlist[2]]);
|
||||
return;
|
||||
} else {
|
||||
print DBG "invalid subnet IPRN $oidlist[3]\n" if $dbg;
|
||||
SendReturnNone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
################## END EDIT THIS FOR YOUR APPLICATION ######################
|
||||
}
|
||||
|
||||
#############################################################################
|
||||
#############################################################################
|
||||
#############################################################################
|
||||
#
|
||||
# From here down the routines should NEVER change
|
||||
#
|
||||
#
|
||||
# SNMP-specific routines
|
||||
#
|
||||
|
||||
{ ######## limit scope for some variable
|
||||
#
|
||||
# Compare looks at the OID validoid and userquery
|
||||
# and returns +1 if userquery > validoid
|
||||
# and returns -1 if userquery < validoid
|
||||
# and returns 0 if userquery = validoid
|
||||
#
|
||||
my @validoid;
|
||||
my @userquery;
|
||||
sub Compare () {
|
||||
my $i=1;
|
||||
while (($i <= $#validoid) && ($i <= $#userquery)) {
|
||||
# print DBG "Comparing $validoid[$i] vs $userquery[$i]\n" if $dbg;
|
||||
if ($userquery[$i] > $validoid[$i]) { return +1; }
|
||||
if ($userquery[$i] < $validoid[$i]) { return -1; }
|
||||
$i++;
|
||||
}
|
||||
$i--;
|
||||
my $returnval = 0;
|
||||
$returnval = +1 if (($i < $#userquery) && ($i == $#validoid));
|
||||
$returnval = -1 if (($i == $#userquery) && ($i < $#validoid));
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
#
|
||||
# FindNext looks through the list of validoid's trying to find the Next
|
||||
# oid after $oid (aka @userquery)
|
||||
#
|
||||
sub FindNext ($) {
|
||||
my $userqueryoid = shift;
|
||||
print DBG "FindNext($userqueryoid)\n" if $dbg;
|
||||
my $next = $validoidlist[0];
|
||||
|
||||
@userquery = split (/\./, $userqueryoid);
|
||||
my $found = 0;
|
||||
foreach (sort @validoidlist) {
|
||||
$next = $_;
|
||||
print DBG "Comparing $userqueryoid vs. $_\n" if $dbg;
|
||||
@validoid = split (/\./, $_);
|
||||
my $x = Compare();
|
||||
if ($x < 0) {
|
||||
$found = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (!$found) { return undef; }
|
||||
|
||||
print DBG "Returning $next as next valid OID\n" if $dbg;
|
||||
return $next;
|
||||
}
|
||||
|
||||
} ######### end scope limit
|
||||
|
||||
sub SendReturnNone () {
|
||||
print "NONE\n";
|
||||
print DBG "Sent NONE\n" if $dbg;
|
||||
}
|
||||
|
||||
sub SendReturn($$$) {
|
||||
printf "%s\n%s\n%s\n", shift, shift, shift;
|
||||
}
|
||||
|
||||
my $line=0;
|
||||
sub Get ($$) {
|
||||
my $cmd = shift;
|
||||
my $oid = shift;
|
||||
GetData($oid);
|
||||
$line = 0;
|
||||
}
|
||||
|
||||
sub GetNext ($$) {
|
||||
my $cmd = shift;
|
||||
my $oid = shift;
|
||||
$oid = FindNext($oid);
|
||||
if (defined($oid)) {
|
||||
GetData($oid);
|
||||
} else {
|
||||
SendReturnNone();
|
||||
}
|
||||
$line = 0;
|
||||
}
|
||||
|
||||
sub Set ($$$) {
|
||||
my $cmd = shift;
|
||||
my $oid = shift;
|
||||
my $tv = shift;
|
||||
print "not-writable\n"; # we don't support snmpset
|
||||
print DBG "Sent not-writable\n" if $dbg;
|
||||
$line = 0;
|
||||
}
|
||||
|
||||
sub Pong {
|
||||
print "PONG\n";
|
||||
print DBG "PONG Sent\n" if $dbg;
|
||||
$line = 0;
|
||||
}
|
||||
|
||||
################################## START ##################################
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
||||
select((select(STDOUT), $| = 1)[0]);
|
||||
|
||||
if ($dbg) {
|
||||
open(DBG, ">/tmp/snmp.dbg") || die ("Can't open debug!");
|
||||
select((select(DBG), $| = 1)[0]);
|
||||
print DBG "Version $VERSION\n";
|
||||
}
|
||||
|
||||
# Initialize Data
|
||||
ParseDataFile();
|
||||
|
||||
my $cmd;
|
||||
my $oid;
|
||||
my $tv;
|
||||
while (<STDIN>) {
|
||||
$line++;
|
||||
chomp;
|
||||
s/ //g;
|
||||
tr/A-Z/a-z/;
|
||||
printf DBG "%3d '%s'\n", $line, $_ if $dbg;
|
||||
last if ($_ eq '');
|
||||
$cmd = $_ if ($line == 1);
|
||||
$oid = $_ if ($line == 2);
|
||||
$tv = $_ if ($line == 3);
|
||||
Pong() if ($cmd eq 'ping');
|
||||
Get($cmd, $oid) if (($cmd eq 'get') && ($line == 2));
|
||||
GetNext($cmd, $oid) if (($cmd eq 'getnext') && ($line == 2));
|
||||
Set($cmd, $oid, $tv) if (($cmd eq 'set') && ($line == 3));
|
||||
}
|
||||
|
||||
print DBG "Clean Exit\n" if $dbg;
|
||||
close DBG if $dbg;
|
||||
exit 0;
|
||||
Loading…
Add table
Add a link
Reference in a new issue