Imported Upstream version 2.6.3

This commit is contained in:
Arnaud Quette 2012-01-24 11:22:33 +01:00
parent 45043b58d0
commit fad6ced6f6
255 changed files with 11081 additions and 4629 deletions

View file

@ -1,3 +1,4 @@
# TODO: remove redundancies!
# Force build in ./ before nut-scanner, to have nutscan-{usb,snmp}.h
# built before going into the nut-scanner sub-directory
@ -29,12 +30,13 @@ nut-scanner-deps:
fi
website:
@if python -c pass; then \
@if python -c "import json,simplejson,lxml"; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
$(top_srcdir)/tools/nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Python is not available."; \
echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \
echo "is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
@ -42,6 +44,7 @@ website:
# call the USB info script upon "make dist", and if Perl is present
# call the SNMP info script upon "make dist", and if Python is present
# and call both for building nut-scanner
# also generate HCL data files
dist-hook:
@if python -c 1; then \
echo "Regenerating the SNMP helper files."; \
@ -63,4 +66,15 @@ dist-hook:
echo "----------------------------------------------------------------------"; \
fi
@if python -c "import json,simplejson,lxml"; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
$(distdir)/nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \
echo "is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
.PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps

View file

@ -14,6 +14,8 @@
# PARTICULAR PURPOSE.
@SET_MAKE@
# TODO: remove redundancies!
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
@ -47,6 +49,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
$(top_srcdir)/m4/nut_check_libfreeipmi.m4 \
$(top_srcdir)/m4/nut_check_libgd.m4 \
$(top_srcdir)/m4/nut_check_libhal.m4 \
$(top_srcdir)/m4/nut_check_libltdl.m4 \
$(top_srcdir)/m4/nut_check_libneon.m4 \
$(top_srcdir)/m4/nut_check_libnetsnmp.m4 \
$(top_srcdir)/m4/nut_check_libpowerman.m4 \
@ -127,6 +130,7 @@ CYGPATH_W = @CYGPATH_W@
DBLATEX = @DBLATEX@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DOC_BUILD_LIST = @DOC_BUILD_LIST@
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
@ -159,6 +163,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
LIBHAL_LIBS = @LIBHAL_LIBS@
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@
LIBIPMI_LIBS = @LIBIPMI_LIBS@
LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@
LIBLTDL_LIBS = @LIBLTDL_LIBS@
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
LIBNEON_LIBS = @LIBNEON_LIBS@
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
@ -179,6 +185,7 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NETLIBS = @NETLIBS@
NM = @NM@
@ -210,12 +217,14 @@ SHELL = @SHELL@
STATEPATH = @STATEPATH@
STRIP = @STRIP@
SUN_LIBUSB = @SUN_LIBUSB@
TREE_VERSION = @TREE_VERSION@
VERSION = @VERSION@
WORDS_BIGENDIAN = @WORDS_BIGENDIAN@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
@ -251,7 +260,6 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
@ -654,12 +662,13 @@ nut-scanner-deps:
fi
website:
@if python -c pass; then \
@if python -c "import json,simplejson,lxml"; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
$(top_srcdir)/tools/nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Python is not available."; \
echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \
echo "is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
@ -667,6 +676,7 @@ website:
# call the USB info script upon "make dist", and if Perl is present
# call the SNMP info script upon "make dist", and if Python is present
# and call both for building nut-scanner
# also generate HCL data files
dist-hook:
@if python -c 1; then \
echo "Regenerating the SNMP helper files."; \
@ -688,6 +698,17 @@ dist-hook:
echo "----------------------------------------------------------------------"; \
fi
@if python -c "import json,simplejson,lxml"; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
$(distdir)/nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \
echo "is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
.PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps
# Tell versions [3.59,3.63) of GNU make to not export all variables.

View file

@ -29,6 +29,7 @@ except ImportError:
import re
import sys
import os, errno
# HCL file location and name
rawHCL="../data/driver.list";
@ -238,13 +239,21 @@ def buildHTMLTable(deviceData):
table.append(tbody)
return etree.tostring(table, pretty_print=True)
# main program
deviceData = buildData(rawHCL)
# Dump device data as JSON
jsonData = "var UPSData = %s" % json.dumps(deviceData, encoding="utf-8")
# First, check if target directory exists (which is not the case for 'dist')
dir = os.path.dirname(webJsonHCL)
try:
os.makedirs(dir)
except OSError:
pass
try:
file = open(webJsonHCL, "w")
file.write(jsonData)

View file

@ -3,14 +3,18 @@ BUILT_SOURCES = nutscan-usb.h nutscan-snmp.h
nutscan-usb.h nutscan-snmp.h:
cd ..; $(MAKE) $(AM_MAKEFLAGS) nut-scanner-deps
lib_LTLIBRARIES = libnutscan.la
# Only build nut-scanner, and its library, if libltdl was found (required!)
if WITH_LIBLTDL
bin_PROGRAMS = nut-scanner
lib_LTLIBRARIES = libnutscan.la
endif
libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c \
nutscan-device.c nutscan-ip.c nutscan-display.c
libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS)
nutscan-device.c nutscan-ip.c nutscan-display.c nutscan-init.c \
scan_usb.c scan_snmp.c scan_xml_http.c scan_avahi.c
libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS) $(LIBLTDL_LIBS)
libnutscan_la_LDFLAGS = -version-info 1:0:0
libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include
libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include $(LIBLTDL_CFLAGS)
bin_PROGRAMS = nut-scanner
nut_scanner_SOURCES = nut-scanner.c
nut_scanner_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include
nut_scanner_LDADD = libnutscan.la
@ -20,27 +24,28 @@ if WITH_SSL
libnutscan_la_LIBADD += $(LIBSSL_LIBS)
endif
if WITH_USB
libnutscan_la_SOURCES += scan_usb.c
libnutscan_la_CFLAGS += $(LIBUSB_CFLAGS)
libnutscan_la_LIBADD += $(LIBUSB_LIBS)
endif
if WITH_SNMP
libnutscan_la_SOURCES += scan_snmp.c
libnutscan_la_CFLAGS += $(LIBNETSNMP_CFLAGS)
libnutscan_la_LIBADD += $(LIBNETSNMP_LIBS)
endif
if WITH_NEONXML
libnutscan_la_SOURCES += scan_xml_http.c
if WITH_NEON
libnutscan_la_CFLAGS += $(LIBNEON_CFLAGS)
libnutscan_la_LIBADD += $(LIBNEON_LIBS)
endif
if WITH_AVAHI
libnutscan_la_SOURCES += scan_avahi.c
libnutscan_la_CFLAGS += $(LIBAVAHI_CFLAGS)
libnutscan_la_LIBADD += $(LIBAVAHI_LIBS)
endif
if WITH_IPMI
libnutscan_la_CFLAGS += $(LIBIPMI_CFLAGS)
endif
dist_noinst_HEADERS = nut-scan.h nutscan-usb.h nutscan-snmp.h nutscan-device.h nutscan-ip.h
dist_noinst_HEADERS = nutscan-usb.h nutscan-snmp.h
if WITH_DEV
include_HEADERS = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h
else
dist_noinst_HEADERS += nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h
endif
CLEANFILES = nutscan-usb.h nutscan-snmp.h

View file

@ -37,23 +37,18 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
bin_PROGRAMS = nut-scanner$(EXEEXT)
@WITH_LIBLTDL_TRUE@bin_PROGRAMS = nut-scanner$(EXEEXT)
@WITH_SSL_TRUE@am__append_1 = $(LIBSSL_CFLAGS)
@WITH_SSL_TRUE@am__append_2 = $(LIBSSL_LIBS)
@WITH_USB_TRUE@am__append_3 = scan_usb.c
@WITH_USB_TRUE@am__append_4 = $(LIBUSB_CFLAGS)
@WITH_USB_TRUE@am__append_5 = $(LIBUSB_LIBS)
@WITH_SNMP_TRUE@am__append_6 = scan_snmp.c
@WITH_SNMP_TRUE@am__append_7 = $(LIBNETSNMP_CFLAGS)
@WITH_SNMP_TRUE@am__append_8 = $(LIBNETSNMP_LIBS)
@WITH_NEONXML_TRUE@am__append_9 = scan_xml_http.c
@WITH_NEONXML_TRUE@am__append_10 = $(LIBNEON_CFLAGS)
@WITH_NEONXML_TRUE@am__append_11 = $(LIBNEON_LIBS)
@WITH_AVAHI_TRUE@am__append_12 = scan_avahi.c
@WITH_AVAHI_TRUE@am__append_13 = $(LIBAVAHI_CFLAGS)
@WITH_AVAHI_TRUE@am__append_14 = $(LIBAVAHI_LIBS)
@WITH_USB_TRUE@am__append_3 = $(LIBUSB_CFLAGS)
@WITH_SNMP_TRUE@am__append_4 = $(LIBNETSNMP_CFLAGS)
@WITH_NEON_TRUE@am__append_5 = $(LIBNEON_CFLAGS)
@WITH_AVAHI_TRUE@am__append_6 = $(LIBAVAHI_CFLAGS)
@WITH_IPMI_TRUE@am__append_7 = $(LIBIPMI_CFLAGS)
@WITH_DEV_FALSE@am__append_8 = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h
subdir = tools/nut-scanner
DIST_COMMON = $(dist_noinst_HEADERS) $(srcdir)/Makefile.am \
DIST_COMMON = README $(am__dist_noinst_HEADERS_DIST) \
$(am__include_HEADERS_DIST) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
@ -66,6 +61,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
$(top_srcdir)/m4/nut_check_libfreeipmi.m4 \
$(top_srcdir)/m4/nut_check_libgd.m4 \
$(top_srcdir)/m4/nut_check_libhal.m4 \
$(top_srcdir)/m4/nut_check_libltdl.m4 \
$(top_srcdir)/m4/nut_check_libneon.m4 \
$(top_srcdir)/m4/nut_check_libnetsnmp.m4 \
$(top_srcdir)/m4/nut_check_libpowerman.m4 \
@ -104,34 +100,25 @@ am__nobase_list = $(am__nobase_strip_setup); \
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)$(libdir)" "$(DESTDIR)$(bindir)"
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(includedir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
@WITH_SSL_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
@WITH_USB_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
@WITH_SNMP_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1)
@WITH_NEONXML_TRUE@am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1)
@WITH_AVAHI_TRUE@am__DEPENDENCIES_6 = $(am__DEPENDENCIES_1)
libnutscan_la_DEPENDENCIES = ../../clients/libupsclient.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) \
$(am__DEPENDENCIES_5) $(am__DEPENDENCIES_6)
am__libnutscan_la_SOURCES_DIST = scan_nut.c scan_ipmi.c \
nutscan-device.c nutscan-ip.c nutscan-display.c scan_usb.c \
scan_snmp.c scan_xml_http.c scan_avahi.c
@WITH_USB_TRUE@am__objects_1 = libnutscan_la-scan_usb.lo
@WITH_SNMP_TRUE@am__objects_2 = libnutscan_la-scan_snmp.lo
@WITH_NEONXML_TRUE@am__objects_3 = libnutscan_la-scan_xml_http.lo
@WITH_AVAHI_TRUE@am__objects_4 = libnutscan_la-scan_avahi.lo
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_2)
am_libnutscan_la_OBJECTS = libnutscan_la-scan_nut.lo \
libnutscan_la-scan_ipmi.lo libnutscan_la-nutscan-device.lo \
libnutscan_la-nutscan-ip.lo libnutscan_la-nutscan-display.lo \
$(am__objects_1) $(am__objects_2) $(am__objects_3) \
$(am__objects_4)
libnutscan_la-nutscan-init.lo libnutscan_la-scan_usb.lo \
libnutscan_la-scan_snmp.lo libnutscan_la-scan_xml_http.lo \
libnutscan_la-scan_avahi.lo
libnutscan_la_OBJECTS = $(am_libnutscan_la_OBJECTS)
libnutscan_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(libnutscan_la_CFLAGS) \
$(CFLAGS) $(libnutscan_la_LDFLAGS) $(LDFLAGS) -o $@
@WITH_LIBLTDL_TRUE@am_libnutscan_la_rpath = -rpath $(libdir)
PROGRAMS = $(bin_PROGRAMS)
am_nut_scanner_OBJECTS = nut_scanner-nut-scanner.$(OBJEXT)
nut_scanner_OBJECTS = $(am_nut_scanner_OBJECTS)
@ -153,9 +140,12 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libnutscan_la_SOURCES) $(nut_scanner_SOURCES)
DIST_SOURCES = $(am__libnutscan_la_SOURCES_DIST) \
$(nut_scanner_SOURCES)
HEADERS = $(dist_noinst_HEADERS)
DIST_SOURCES = $(libnutscan_la_SOURCES) $(nut_scanner_SOURCES)
am__dist_noinst_HEADERS_DIST = nutscan-usb.h nutscan-snmp.h nut-scan.h \
nutscan-device.h nutscan-ip.h nutscan-init.h
am__include_HEADERS_DIST = nut-scan.h nutscan-device.h nutscan-ip.h \
nutscan-init.h
HEADERS = $(dist_noinst_HEADERS) $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -179,6 +169,7 @@ CYGPATH_W = @CYGPATH_W@
DBLATEX = @DBLATEX@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DOC_BUILD_LIST = @DOC_BUILD_LIST@
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
@ -211,6 +202,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
LIBHAL_LIBS = @LIBHAL_LIBS@
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@
LIBIPMI_LIBS = @LIBIPMI_LIBS@
LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@
LIBLTDL_LIBS = @LIBLTDL_LIBS@
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
LIBNEON_LIBS = @LIBNEON_LIBS@
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
@ -231,6 +224,7 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NETLIBS = @NETLIBS@
NM = @NM@
@ -262,12 +256,14 @@ SHELL = @SHELL@
STATEPATH = @STATEPATH@
STRIP = @STRIP@
SUN_LIBUSB = @SUN_LIBUSB@
TREE_VERSION = @TREE_VERSION@
VERSION = @VERSION@
WORDS_BIGENDIAN = @WORDS_BIGENDIAN@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
@ -303,7 +299,6 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
@ -328,21 +323,23 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
udevdir = @udevdir@
BUILT_SOURCES = nutscan-usb.h nutscan-snmp.h
lib_LTLIBRARIES = libnutscan.la
libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c nutscan-device.c \
nutscan-ip.c nutscan-display.c $(am__append_3) $(am__append_6) \
$(am__append_9) $(am__append_12)
@WITH_LIBLTDL_TRUE@lib_LTLIBRARIES = libnutscan.la
libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c \
nutscan-device.c nutscan-ip.c nutscan-display.c nutscan-init.c \
scan_usb.c scan_snmp.c scan_xml_http.c scan_avahi.c
libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS) \
$(am__append_2) $(am__append_5) $(am__append_8) \
$(am__append_11) $(am__append_14)
$(LIBLTDL_LIBS) $(am__append_2)
libnutscan_la_LDFLAGS = -version-info 1:0:0
libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include \
$(am__append_1) $(am__append_4) $(am__append_7) \
$(am__append_10) $(am__append_13)
$(LIBLTDL_CFLAGS) $(am__append_1) $(am__append_3) \
$(am__append_4) $(am__append_5) $(am__append_6) \
$(am__append_7)
nut_scanner_SOURCES = nut-scanner.c
nut_scanner_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include
nut_scanner_LDADD = libnutscan.la
dist_noinst_HEADERS = nut-scan.h nutscan-usb.h nutscan-snmp.h nutscan-device.h nutscan-ip.h
dist_noinst_HEADERS = nutscan-usb.h nutscan-snmp.h $(am__append_8)
@WITH_DEV_TRUE@include_HEADERS = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h
CLEANFILES = nutscan-usb.h nutscan-snmp.h
all: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) all-am
@ -411,7 +408,7 @@ clean-libLTLIBRARIES:
rm -f "$${dir}/so_locations"; \
done
libnutscan.la: $(libnutscan_la_OBJECTS) $(libnutscan_la_DEPENDENCIES)
$(libnutscan_la_LINK) -rpath $(libdir) $(libnutscan_la_OBJECTS) $(libnutscan_la_LIBADD) $(LIBS)
$(libnutscan_la_LINK) $(am_libnutscan_la_rpath) $(libnutscan_la_OBJECTS) $(libnutscan_la_LIBADD) $(LIBS)
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@ -467,6 +464,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-device.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-display.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-init.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-ip.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-scan_avahi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-scan_ipmi.Plo@am__quote@
@ -532,6 +530,13 @@ libnutscan_la-nutscan-display.lo: nutscan-display.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -c -o libnutscan_la-nutscan-display.lo `test -f 'nutscan-display.c' || echo '$(srcdir)/'`nutscan-display.c
libnutscan_la-nutscan-init.lo: nutscan-init.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -MT libnutscan_la-nutscan-init.lo -MD -MP -MF $(DEPDIR)/libnutscan_la-nutscan-init.Tpo -c -o libnutscan_la-nutscan-init.lo `test -f 'nutscan-init.c' || echo '$(srcdir)/'`nutscan-init.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnutscan_la-nutscan-init.Tpo $(DEPDIR)/libnutscan_la-nutscan-init.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nutscan-init.c' object='libnutscan_la-nutscan-init.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -c -o libnutscan_la-nutscan-init.lo `test -f 'nutscan-init.c' || echo '$(srcdir)/'`nutscan-init.c
libnutscan_la-scan_usb.lo: scan_usb.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -MT libnutscan_la-scan_usb.lo -MD -MP -MF $(DEPDIR)/libnutscan_la-scan_usb.Tpo -c -o libnutscan_la-scan_usb.lo `test -f 'scan_usb.c' || echo '$(srcdir)/'`scan_usb.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnutscan_la-scan_usb.Tpo $(DEPDIR)/libnutscan_la-scan_usb.Plo
@ -579,6 +584,26 @@ mostlyclean-libtool:
clean-libtool:
-rm -rf .libs _libs
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(includedir)" && rm -f $$files
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@ -669,7 +694,7 @@ all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
install-binPROGRAMS: install-libLTLIBRARIES
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)"; do \
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: $(BUILT_SOURCES)
@ -723,7 +748,7 @@ info: info-am
info-am:
install-data-am:
install-data-am: install-includeHEADERS
install-dvi: install-dvi-am
@ -769,7 +794,8 @@ ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES
uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-libLTLIBRARIES
.MAKE: all check install install-am install-strip
@ -780,13 +806,14 @@ uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES
html-am info info-am install install-am install-binPROGRAMS \
install-data install-data-am install-dvi install-dvi-am \
install-exec install-exec-am install-html install-html-am \
install-info install-info-am install-libLTLIBRARIES \
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-compile mostlyclean-generic \
mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
uninstall-am uninstall-binPROGRAMS uninstall-libLTLIBRARIES
install-includeHEADERS install-info install-info-am \
install-libLTLIBRARIES 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-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS \
uninstall-includeHEADERS uninstall-libLTLIBRARIES
nutscan-usb.h nutscan-snmp.h:

114
tools/nut-scanner/README Normal file
View file

@ -0,0 +1,114 @@
NUT device discovery
====================
Introduction
------------
linkman:nut-scanner[8] is available to discover supported NUT devices
(USB, SNMP, Eaton XML/HTTP and IPMI) and NUT servers (using Avahi or the
classic connection method).
This tool actually use a library, called *libnutscan*, to perform actual
processing.
Client access library
~~~~~~~~~~~~~~~~~~~~~
The nutscan library can be linked into other programs to give access
to NUT discovery. Both static and shared versions are provided.
linkman:nut-scanner[8] is provided as an example of how to use the nutscan
functions.
Here is a simple example that scans for USB devices, and use its own
iteration function to display results:
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Only enable USB scan */
#define HAVE_USB_H
#include "nut-scan.h"
int main()
{
nutscan_options_t * opt;
nutscan_device_t *device;
if ((device = nutscan_scan_usb()) == NULL) {
printf("No device found\n");
exit(EXIT_FAILURE);
}
/* Rewind the list */
while(device->prev != NULL) {
device = device->prev;
}
/* Print results */
do {
printf("USB device found\n\tdriver: \"%s\"\n\tport: \"%s\"\n",
device->driver, device->port);
/* process options (serial number, bus, ...) */
opt = &(device->opt);
do {
if( opt->option != NULL ) {
printf("\t%s",opt->option);
if( opt->value != NULL ) {
printf(": \"%s\"", opt->value);
}
printf("\n");
}
opt = opt->next;
} while( opt != NULL );
device = device->next;
}
while( device != NULL );
exit(EXIT_SUCCESS);
}
This library file and the associated header files are not installed by
default. You must `./configure --with-lib` to enable building and
installing these files. The libraries can then be built and installed
with `make` and `make install` as usual. This must be done before
building other (non-NUT) programs which depend on them.
For more information, refer to the linkman:nutscan[3],
manual page and the various
link:man/index.html#devscan[nutscan_*(3)] functions documentation
referenced in the same file.
Configuration helpers
~~~~~~~~~~~~~~~~~~~~~
NUT provides helper scripts to ease the configuration step of your program, by
detecting the right compilation and link flags.
For more information, refer to a
<<lib-info,Appendix B: NUT libraries complementary information>>.
Python
------
Python support for NUT discovery features is not yet available.
Perl
----
Perl support for NUT discovery features is not yet available.
Java
----
Java support for NUT discovery features is not yet available.

View file

@ -19,6 +19,7 @@
#ifndef NUT_SCAN_H
#define NUT_SCAN_H
#include <nutscan-init.h>
#include <nutscan-device.h>
#include <nutscan-ip.h>
@ -36,29 +37,19 @@ typedef struct nutscan_snmp {
} nutscan_snmp_t;
/* Scanning */
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
nutscan_device_t * nutscan_scan_snmp(const char * start_ip,const char * stop_ip,long usec_timeout, nutscan_snmp_t * sec);
#endif
#ifdef HAVE_USB_H
nutscan_device_t * nutscan_scan_usb();
#endif
#ifdef WITH_NEON
nutscan_device_t * nutscan_scan_xml_http(long usec_timeout);
#endif
nutscan_device_t * nutscan_scan_nut(const char * startIP, const char * stopIP, const char * port, long usec_timeout);
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
nutscan_device_t * nutscan_scan_avahi(long usec_timeout);
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
nutscan_device_t * nutscan_scan_ipmi(void);
#endif
/* Displaying */
/* Display functions */
void nutscan_display_ups_conf(nutscan_device_t * device);
void nutscan_display_parsable(nutscan_device_t * device);

View file

@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include "common.h"
#include "nut_version.h"
#include <unistd.h>
#include <string.h>
#ifdef HAVE_PTHREAD
@ -31,7 +32,9 @@
#define DEFAULT_TIMEOUT 5
const char optstring[] = "?ht:s:e:c:l:u:W:X:w:x:p:CUSMOAm:NPqI";
#define ERR_BAD_OPTION (-1)
const char optstring[] = "?ht:s:e:c:l:u:W:X:w:x:p:CUSMOAm:NPqIVa";
#ifdef HAVE_GETOPT_LONG
const struct option longopts[] =
@ -58,13 +61,14 @@ const struct option longopts[] =
{ "disp_parsable",no_argument,NULL,'P' },
{ "quiet",no_argument,NULL,'q' },
{ "help",no_argument,NULL,'h' },
{ "version",no_argument,NULL,'V' },
{ "available",no_argument,NULL,'a' },
{NULL,0,NULL,0}};
#else
#define getopt_long(a,b,c,d,e) getopt(a,b,c)
#endif /* HAVE_GETOPT_LONG */
static nutscan_device_t *dev[TYPE_END];
static pthread_t thread[TYPE_END];
static long timeout = DEFAULT_TIMEOUT*1000*1000; /* in usec */
static char * start_ip = NULL;
@ -72,14 +76,13 @@ static char * end_ip = NULL;
static char * port = NULL;
#ifdef HAVE_PTHREAD
#ifdef HAVE_USB_H
static pthread_t thread[TYPE_END];
static void * run_usb(void * arg)
{
dev[TYPE_USB] = nutscan_scan_usb();
return NULL;
}
#endif
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
static void * run_snmp(void * arg)
{
nutscan_snmp_t * sec = (nutscan_snmp_t *)arg;
@ -87,14 +90,11 @@ static void * run_snmp(void * arg)
dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,sec);
return NULL;
}
#endif
#ifdef WITH_NEON
static void * run_xml(void * arg)
{
dev[TYPE_XML] = nutscan_scan_xml_http(timeout);
return NULL;
}
#endif
static void * run_nut_old(void * arg)
{
@ -102,20 +102,16 @@ static void * run_nut_old(void * arg)
return NULL;
}
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
static void * run_avahi(void * arg)
{
dev[TYPE_AVAHI] = nutscan_scan_avahi(timeout);
return NULL;
}
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
static void * run_ipmi(void * arg)
{
dev[TYPE_IPMI] = nutscan_scan_ipmi();
return NULL;
}
#endif
#endif /* HAVE_PTHREAD */
static int printq(int quiet,const char *fmt, ...)
{
@ -147,9 +143,12 @@ int main(int argc, char *argv[])
int allow_ipmi = 0;
int quiet = 0;
void (*display_func)(nutscan_device_t * device);
int ret_code = EXIT_SUCCESS;
memset(&sec,0,sizeof(sec));
nutscan_init();
display_func = nutscan_display_ups_conf;
while((opt_ret = getopt_long(argc, argv, optstring, longopts, NULL))!=-1) {
@ -172,63 +171,87 @@ int main(int argc, char *argv[])
case 'm':
cidr = strdup(optarg);
break;
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
case 'c':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.community = strdup(optarg);
break;
case 'l':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.secLevel = strdup(optarg);
break;
case 'u':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.secName = strdup(optarg);
break;
case 'W':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.authPassword = strdup(optarg);
break;
case 'X':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.privPassword = strdup(optarg);
break;
case 'w':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.authProtocol = strdup(optarg);
break;
case 'x':
if(!nutscan_avail_snmp) {
goto display_help;
}
sec.privProtocol = strdup(optarg);
break;
#endif
case 'S':
if(!nutscan_avail_snmp) {
goto display_help;
}
allow_snmp = 1;
break;
case 'p':
port = strdup(optarg);
break;
case 'C':
allow_all = 1;
break;
#ifdef HAVE_USB_H
case 'U':
if(!nutscan_avail_usb) {
goto display_help;
}
allow_usb = 1;
break;
#endif
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
case 'S':
allow_snmp = 1;
break;
#endif
#ifdef WITH_NEON
case 'M':
if(!nutscan_avail_xml_http) {
goto display_help;
}
allow_xml = 1;
break;
#endif
case 'O':
allow_oldnut = 1;
break;
#ifdef WITH_AVAHI
case 'A':
if(!nutscan_avail_avahi) {
goto display_help;
}
allow_avahi = 1;
break;
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
case 'I':
if(!nutscan_avail_ipmi) {
goto display_help;
}
allow_ipmi = 1;
break;
#endif
case 'N':
display_func = nutscan_display_ups_conf;
break;
@ -238,51 +261,79 @@ int main(int argc, char *argv[])
case 'q':
quiet = 1;
break;
case 'h':
case 'V':
printf("Network UPS Tools - %s\n", NUT_VERSION_MACRO);
exit(EXIT_SUCCESS);
case 'a':
printf("OLDNUT\n");
if(nutscan_avail_usb) {
printf("USB\n");
}
if(nutscan_avail_snmp) {
printf("SNMP\n");
}
if(nutscan_avail_xml_http) {
printf("XML\n");
}
if(nutscan_avail_avahi) {
printf("AVAHI\n");
}
if(nutscan_avail_ipmi) {
printf("IPMI\n");
}
exit(EXIT_SUCCESS);
case '?':
ret_code = ERR_BAD_OPTION;
case 'h':
default:
puts("nut-scanner : detecting available UPS.\n");
display_help:
puts("nut-scanner : detecting available power devices.\n");
puts("OPTIONS:");
printf(" -C, --complete_scan : Scan all available devices (default).\n");
#ifdef HAVE_USB_H
printf(" -U, --usb_scan : Scan USB devices.\n");
#endif
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
printf(" -S, --snmp_scan : Scan SNMP devices.\n");
#endif
#ifdef WITH_NEON
printf(" -M, --xml_scan : Scan XML/HTTP devices.\n");
#endif
printf(" -O, --oldnut_scan : Scan NUT devices (old method).\n");
#ifdef WITH_AVAHI
printf(" -A, --avahi_scan : Scan NUT devices (avahi method).\n");
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
printf(" -I, --ipmi_scan : Scan IPMI devices.\n");
#endif
printf(" -C, --complete_scan: Scan all available devices (default).\n");
if( nutscan_avail_usb ) {
printf(" -U, --usb_scan: Scan USB devices.\n");
}
if( nutscan_avail_snmp ) {
printf(" -S, --snmp_scan: Scan SNMP devices.\n");
}
if( nutscan_avail_xml_http ) {
printf(" -M, --xml_scan: Scan XML/HTTP devices.\n");
}
printf(" -O, --oldnut_scan: Scan NUT devices (old method).\n");
if( nutscan_avail_avahi ) {
printf(" -A, --avahi_scan: Scan NUT devices (avahi method).\n");
}
if( nutscan_avail_ipmi ) {
printf(" -I, --ipmi_scan: Scan IPMI devices.\n");
}
printf(" -t, --timeout <timeout in seconds>: network operation timeout (default %d).\n",DEFAULT_TIMEOUT);
printf(" -s, --start_ip <IP address>: First IP address to scan.\n");
printf(" -e, --end_ip <IP address>: Last IP address to scan.\n");
printf(" -m, --mask_cidr <IP address/mask>: Give a range of IP using CIDR notation.\n");
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
printf("\nSNMP v1 specific options:\n");
printf(" -c, --community <community name>: Set SNMP v1 community name (default = public)\n");
if( nutscan_avail_snmp ) {
printf("\nSNMP v1 specific options:\n");
printf(" -c, --community <community name>: Set SNMP v1 community name (default = public)\n");
printf("\nSNMP v3 specific options:\n");
printf(" -l, --secLevel <security level>: Set the securityLevel used for SNMPv3 messages (allowed values: noAuthNoPriv,authNoPriv,authPriv)\n");
printf(" -u, --secName <security name>: Set the securityName used for authenticated SNMPv3 messages (mandatory if you set secLevel. No default)\n");
printf(" -a, --authProtocol <authentication protocol>: Set the authentication protocol (MD5 or SHA) used for authenticated SNMPv3 messages (default=MD5)\n");
printf(" -A, --authPassword <authentication pass phrase>: Set the authentication pass phrase used for authenticated SNMPv3 messages (mandatory if you set secLevel to authNoPriv or authPriv)\n");
printf(" -x, --privProtocol <privacy protocol>: Set the privacy protocol (DES or AES) used for encrypted SNMPv3 messages (default=DES)\n");
printf(" -X, --privPassword <privacy pass phrase>: Set the privacy pass phrase used for encrypted SNMPv3 messages (mandatory if you set secLevel to authPriv)\n");
#endif
printf("\nSNMP v3 specific options:\n");
printf(" -l, --secLevel <security level>: Set the securityLevel used for SNMPv3 messages (allowed values: noAuthNoPriv,authNoPriv,authPriv)\n");
printf(" -u, --secName <security name>: Set the securityName used for authenticated SNMPv3 messages (mandatory if you set secLevel. No default)\n");
printf(" -w, --authProtocol <authentication protocol>: Set the authentication protocol (MD5 or SHA) used for authenticated SNMPv3 messages (default=MD5)\n");
printf(" -W, --authPassword <authentication pass phrase>: Set the authentication pass phrase used for authenticated SNMPv3 messages (mandatory if you set secLevel to authNoPriv or authPriv)\n");
printf(" -x, --privProtocol <privacy protocol>: Set the privacy protocol (DES or AES) used for encrypted SNMPv3 messages (default=DES)\n");
printf(" -X, --privPassword <privacy pass phrase>: Set the privacy pass phrase used for encrypted SNMPv3 messages (mandatory if you set secLevel to authPriv)\n");
}
printf("\nNUT device specific options:\n");
printf(" -p, --port <port number>: Port number of remote NUT devices\n");
printf("\nNUT specific options:\n");
printf(" -p, --port <port number>: Port number of remote NUT upsd\n");
printf("\ndisplay specific options:\n");
printf(" -N, --disp_nut_conf : Display result in the ups.conf format\n");
printf(" -P, --disp_parsable : Display result in a parsable format\n");
return 0;
printf(" -N, --disp_nut_conf: Display result in the ups.conf format\n");
printf(" -P, --disp_parsable: Display result in a parsable format\n");
printf("\nMiscellaneous options:\n");
printf(" -V, --version: Display NUT version\n");
printf(" -a, --available: Display available bus that can be scanned\n");
printf(" -q, --quiet: Display only scan result. No information on currently scanned bus is displayed.\n");
return ret_code;
}
}
@ -296,120 +347,128 @@ int main(int argc, char *argv[])
allow_all = 1;
}
#ifdef HAVE_USB_H
if( allow_all || allow_usb) {
if( allow_all ) {
allow_usb = 1;
allow_snmp = 1;
allow_xml = 1;
allow_oldnut = 1;
allow_avahi = 1;
allow_ipmi = 1;
}
if( allow_usb && nutscan_avail_usb ) {
printq(quiet,"Scanning USB bus.\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_USB],NULL,run_usb,NULL);
if(pthread_create(&thread[TYPE_USB],NULL,run_usb,NULL)) {
nutscan_avail_usb = 0;
}
#else
dev[TYPE_USB] = nutscan_scan_usb();
#endif
#endif /* HAVE_PTHREAD */
}
#endif /* HAVE_USB_H */
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
if( allow_all || allow_snmp) {
if( allow_snmp && nutscan_avail_snmp ) {
if( start_ip == NULL ) {
printq(quiet,"No start IP, skipping SNMP\n");
}
else {
printq(quiet,"Scanning SNMP bus.\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&sec);
if( pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&sec)) {
nutscan_avail_snmp = 0;
}
#else
dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,&sec);
#endif
#endif /* HAVE_PTHREAD */
}
}
#endif /* HAVE_NET_SNMP_NET_SNMP_CONFIG_H */
#ifdef WITH_NEON
if( allow_all || allow_xml) {
if( allow_xml && nutscan_avail_xml_http) {
printq(quiet,"Scanning XML/HTTP bus.\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_XML],NULL,run_xml,NULL);
if(pthread_create(&thread[TYPE_XML],NULL,run_xml,NULL)) {
nutscan_avail_xml_http = 0;
}
#else
dev[TYPE_XML] = nutscan_scan_xml_http(timeout);
#endif
#endif /* HAVE_PTHREAD */
}
#endif
if( allow_all || allow_oldnut) {
if( allow_oldnut && nutscan_avail_nut) {
if( start_ip == NULL ) {
printq(quiet,"No start IP, skipping NUT bus (old connect method)\n");
}
else {
printq(quiet,"Scanning NUT bus (old connect method).\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_NUT],NULL,run_nut_old,NULL);
if(pthread_create(&thread[TYPE_NUT],NULL,run_nut_old,NULL)) {
nutscan_avail_nut = 0;
}
#else
dev[TYPE_NUT] = nutscan_scan_nut(start_ip,end_ip,port,timeout);
#endif
#endif /* HAVE_PTHREAD */
}
}
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
if( allow_all || allow_avahi) {
if( allow_avahi && nutscan_avail_avahi) {
printq(quiet,"Scanning NUT bus (avahi method).\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_AVAHI],NULL,run_avahi,NULL);
if(pthread_create(&thread[TYPE_AVAHI],NULL,run_avahi,NULL)) {
nutscan_avail_avahi = 0;
}
#else
dev[TYPE_AVAHI] = nutscan_scan_avahi();
#endif
dev[TYPE_AVAHI] = nutscan_scan_avahi(timeout);
#endif /* HAVE_PTHREAD */
}
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
if( allow_all || allow_ipmi) {
if( allow_ipmi && nutscan_avail_ipmi) {
printq(quiet,"Scanning IPMI bus.\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,NULL);
if(pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,NULL)) {
nutscan_avail_ipmi = 0;
}
#else
dev[TYPE_IPMI] = nutscan_scan_ipmi();
#endif
#endif /* HAVE_PTHREAD */
}
#endif
#ifdef HAVE_PTHREAD
#ifdef HAVE_USB_H
pthread_join(thread[TYPE_USB],NULL);
#endif
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
pthread_join(thread[TYPE_SNMP],NULL);
#endif
#ifdef WITH_NEON
pthread_join(thread[TYPE_XML],NULL);
#endif
pthread_join(thread[TYPE_NUT],NULL);
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
pthread_join(thread[TYPE_AVAHI],NULL);
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
pthread_join(thread[TYPE_IPMI],NULL);
#endif
if( allow_usb && nutscan_avail_usb ) {
pthread_join(thread[TYPE_USB],NULL);
}
if( allow_snmp && nutscan_avail_snmp ) {
pthread_join(thread[TYPE_SNMP],NULL);
}
if( allow_xml && nutscan_avail_xml_http ) {
pthread_join(thread[TYPE_XML],NULL);
}
if( allow_oldnut && nutscan_avail_nut ) {
pthread_join(thread[TYPE_NUT],NULL);
}
if( allow_avahi && nutscan_avail_avahi ) {
pthread_join(thread[TYPE_AVAHI],NULL);
}
if( allow_ipmi && nutscan_avail_ipmi ) {
pthread_join(thread[TYPE_IPMI],NULL);
}
#endif /* HAVE_PTHREAD */
#ifdef HAVE_USB_H
display_func(dev[TYPE_USB]);
nutscan_free_device(dev[TYPE_USB]);
#endif
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
display_func(dev[TYPE_SNMP]);
nutscan_free_device(dev[TYPE_SNMP]);
#endif
#ifdef WITH_NEON
display_func(dev[TYPE_XML]);
nutscan_free_device(dev[TYPE_XML]);
#endif
display_func(dev[TYPE_NUT]);
nutscan_free_device(dev[TYPE_NUT]);
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
display_func(dev[TYPE_AVAHI]);
nutscan_free_device(dev[TYPE_AVAHI]);
#endif
#ifdef HAVE_FREEIPMI_FREEIPMI_H
display_func(dev[TYPE_IPMI]);
nutscan_free_device(dev[TYPE_IPMI]);
#endif
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,52 @@
/* nutscan-init.c: init functions for nut scanner library
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
*
* This program is free software; you can redistribute it and/or modify
* 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-1307 USA
*/
#include "common.h"
int nutscan_avail_avahi = 0;
int nutscan_avail_ipmi = 0;
int nutscan_avail_nut = 1;
int nutscan_avail_snmp = 0;
int nutscan_avail_usb = 0;
int nutscan_avail_xml_http = 0;
int nutscan_load_usb_library(void);
int nutscan_load_snmp_library(void);
int nutscan_load_neon_library(void);
int nutscan_load_avahi_library(void);
int nutscan_load_ipmi_library(void);
void nutscan_init(void)
{
#ifdef WITH_USB
nutscan_avail_usb = nutscan_load_usb_library();
#endif
#ifdef WITH_SNMP
nutscan_avail_snmp = nutscan_load_snmp_library();
#endif
#ifdef WITH_NEON
nutscan_avail_xml_http = nutscan_load_neon_library();
#endif
#ifdef WITH_AVAHI
nutscan_avail_avahi = nutscan_load_avahi_library();
#endif
#ifdef WITH_FREEIPMI
nutscan_avail_ipmi = nutscan_load_ipmi_library();
#endif
}

View file

@ -0,0 +1,30 @@
/* nutscan-init.h: initialisation data
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
*
* This program is free software; you can redistribute it and/or modify
* 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-1307 USA
*/
#ifndef SCAN_INIT
#define SCAN_INIT
extern int nutscan_avail_avahi;
extern int nutscan_avail_ipmi;
extern int nutscan_avail_nut;
extern int nutscan_avail_snmp;
extern int nutscan_avail_usb;
extern int nutscan_avail_xml_http;
void nutscan_init(void);
#endif

View file

@ -20,6 +20,9 @@
#include "nutscan-ip.h"
#include <stdio.h>
#include "common.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
static void increment_IPv6(struct in6_addr * addr)
{
@ -42,12 +45,38 @@ static void invert_IPv6(struct in6_addr * addr1, struct in6_addr * addr2)
memcpy(addr2->s6_addr,addr.s6_addr,sizeof(addr.s6_addr));
}
static int ntop( struct in_addr * ip, char * host, size_t host_size)
{
struct sockaddr_in in;
memset(&in,0,sizeof(struct sockaddr_in));
in.sin_addr = *ip;
in.sin_family = AF_INET;
return getnameinfo((struct sockaddr *)&in,
sizeof(struct sockaddr_in),
host,host_size,NULL,0,NI_NUMERICHOST);
}
static int ntop6( struct in6_addr * ip, char * host, size_t host_size)
{
struct sockaddr_in6 in6;
memset(&in6,0,sizeof(struct sockaddr_in6));
memcpy( &in6.sin6_addr, ip, sizeof(struct in6_addr) );
in6.sin6_family = AF_INET6;
return getnameinfo((struct sockaddr *)&in6,
sizeof(struct sockaddr_in6),
host,host_size,NULL,0,NI_NUMERICHOST);
}
/* Return the first ip or NULL if error */
char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const char * stopIP)
{
int addr;
int i;
char buf[SMALLBUF];
struct addrinfo hints;
struct addrinfo *res;
struct sockaddr_in * s_in;
struct sockaddr_in6 * s_in6;
char host[SMALLBUF];
if( startIP == NULL ) {
return NULL;
@ -57,29 +86,51 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const
stopIP = startIP;
}
memset(&hints,0,sizeof(struct addrinfo));
hints.ai_family = AF_INET;
ip->type = IPv4;
/* Detecting IPv4 vs IPv6 */
if(!inet_aton(startIP, &ip->start)) {
if(getaddrinfo(startIP,NULL,&hints,&res) != 0) {
/*Try IPv6 detection */
ip->type = IPv6;
if(!inet_pton(AF_INET6, startIP, &ip->start6)){
hints.ai_family = AF_INET6;
if(getaddrinfo(startIP,NULL,&hints,&res) != 0) {
fprintf(stderr,"Invalid address : %s\n",startIP);
return NULL;
}
s_in6 = (struct sockaddr_in6 *)res->ai_addr;
memcpy(&ip->start6,&s_in6->sin6_addr,sizeof(struct in6_addr));
freeaddrinfo(res);
}
else {
s_in = (struct sockaddr_in *)res->ai_addr;
ip->start = s_in->sin_addr;
freeaddrinfo(res);
}
/* Compute stop IP */
if( ip->type == IPv4 ) {
if(!inet_aton(stopIP, &ip->stop)) {
hints.ai_family = AF_INET;
if(getaddrinfo(stopIP,NULL,&hints,&res) != 0) {
fprintf(stderr,"Invalid address : %s\n",stopIP);
return NULL;
}
s_in = (struct sockaddr_in *)res->ai_addr;
ip->stop = s_in->sin_addr;
freeaddrinfo(res);
}
else {
if(!inet_pton(AF_INET6, stopIP, &ip->stop6)){
hints.ai_family = AF_INET6;
if(getaddrinfo(stopIP,NULL,&hints,&res) != 0) {
fprintf(stderr,"Invalid address : %s\n",stopIP);
return NULL;
}
s_in6 = (struct sockaddr_in6 *)res->ai_addr;
memcpy(&ip->stop6,&s_in6->sin6_addr,sizeof(struct in6_addr));
freeaddrinfo(res);
}
/* Make sure start IP is lesser than stop IP */
@ -89,7 +140,12 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const
ip->start.s_addr = ip->stop.s_addr;
ip->stop.s_addr = addr;
}
return strdup(inet_ntoa(ip->start));
if( ntop(&ip->start, host, sizeof(host)) != 0 ) {
return NULL;
}
return strdup(host);
}
else { /* IPv6 */
for( i=0; i<16; i++ ) {
@ -100,7 +156,12 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const
break;
}
}
return strdup(inet_ntop(AF_INET6,&ip->start6,buf,sizeof(buf)));
if( ntop6(&ip->start6, host, sizeof(host)) != 0 ) {
return NULL;
}
return strdup(host);
}
@ -111,7 +172,7 @@ return NULL if there is no more IP
*/
char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip)
{
char buf[SMALLBUF];
char host[SMALLBUF];
if( ip->type == IPv4 ) {
/* Check if this is the last address to scan */
@ -122,7 +183,11 @@ char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip)
byte order, then pass back in network byte order */
ip->start.s_addr = htonl((ntohl(ip->start.s_addr)+1));
return strdup(inet_ntoa(ip->start));
if( ntop(&ip->start, host, sizeof(host)) != 0 ) {
return NULL;
}
return strdup(host);
}
else {
/* Check if this is the last address to scan */
@ -132,8 +197,11 @@ char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip)
}
increment_IPv6(&ip->start6);
if( ntop6(&ip->start6, host, sizeof(host)) != 0 ) {
return NULL;
}
return strdup(inet_ntop(AF_INET6,&ip->start6,buf,sizeof(buf)));
return strdup(host);
}
}
@ -146,8 +214,12 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip)
nutscan_ip_iter_t ip;
int mask_val;
int mask_byte;
long mask_bit;
char buf[SMALLBUF];
unsigned long mask_bit;
char host[SMALLBUF];
struct addrinfo hints;
struct addrinfo *res;
struct sockaddr_in * s_in;
struct sockaddr_in6 * s_in6;
*start_ip = NULL;
*stop_ip = NULL;
@ -166,15 +238,30 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip)
mask_val = atoi(mask);
/* Detecting IPv4 vs IPv6 */
memset(&hints,0,sizeof(struct addrinfo));
hints.ai_family = AF_INET;
ip.type = IPv4;
if(!inet_aton(first_ip, &ip.start)) {
/*Try IPv6 detection */
ip.type = IPv6;
if(!inet_pton(AF_INET6, first_ip, &ip.start6)){
/* Detecting IPv4 vs IPv6 */
if(getaddrinfo(first_ip,NULL,&hints,&res) != 0) {
/*Try IPv6 detection */
ip.type = IPv6;
hints.ai_family = AF_INET6;
int ret;
if((ret=getaddrinfo(first_ip,NULL,&hints,&res)) != 0) {
free(first_ip);
return 0;
}
}
return 0;
}
s_in6 = (struct sockaddr_in6 *)res->ai_addr;
memcpy(&ip.start6,&s_in6->sin6_addr,sizeof(struct in6_addr));
freeaddrinfo(res);
}
else {
s_in = (struct sockaddr_in *)res->ai_addr;
ip.start = s_in->sin_addr;
freeaddrinfo(res);
}
if( ip.type == IPv4 ) {
@ -190,13 +277,31 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip)
ip.stop.s_addr = htonl(ntohl(ip.start.s_addr)|mask_bit);
ip.start.s_addr = htonl(ntohl(ip.start.s_addr)&(~mask_bit));
*start_ip = strdup(inet_ntoa(ip.start));
*stop_ip = strdup(inet_ntoa(ip.stop));
if( ntop(&ip.start, host, sizeof(host)) != 0 ) {
*start_ip = NULL;
*stop_ip = NULL;
return 0;
}
*start_ip = strdup(host);
if( ntop(&ip.stop, host, sizeof(host)) != 0 ) {
free(*start_ip);
*start_ip = NULL;
*stop_ip = NULL;
return 0;
}
*stop_ip = strdup(host);
free(first_ip);
return 1;
}
else {
inet_pton(AF_INET6, first_ip, &ip.stop6);
if(getaddrinfo(first_ip,NULL,&hints,&res) != 0) {
return 0;
}
s_in6 = (struct sockaddr_in6 *)res->ai_addr;
memcpy(&ip.stop6,&s_in6->sin6_addr,sizeof(struct in6_addr));
freeaddrinfo(res);
mask_byte = mask_val / 8;
if( mask_byte < 16 ) {
@ -208,10 +313,20 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip)
ip.start6.s6_addr[mask_byte] &= (~mask_bit);
}
inet_ntop(AF_INET6,&ip.start6,buf,sizeof(buf));
*start_ip = strdup(buf);
inet_ntop(AF_INET6,&ip.stop6,buf,sizeof(buf));
*stop_ip = strdup(buf);
if( ntop6(&ip.start6, host, sizeof(host)) != 0 ) {
*start_ip = NULL;
*stop_ip = NULL;
return 0;
}
*start_ip = strdup(host);
if( ntop6(&ip.stop6, host, sizeof(host)) != 0 ) {
free(*start_ip);
*start_ip = NULL;
*stop_ip = NULL;
return 0;
}
*stop_ip = strdup(host);
}
free(first_ip);

View file

@ -19,9 +19,8 @@
#ifndef SCAN_IP
#define SCAN_IP
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
enum network_type {
IPv4,

View file

@ -37,6 +37,7 @@ static snmp_device_id_t snmp_device_table[] = {
{ ".1.3.6.1.4.1.705.1.1.1.0" , "mge", ".1.3.6.1.4.1.705.1"},
{ ".1.3.6.1.4.1.318.1.1.1.1.1.1.0" , "apcc", NULL},
{ ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1" , "baytech", NULL},
{ ".1.3.6.1.4.1.3808.1.1.1.1.1.1.0" , "cyberpower", ".1.3.6.1.4.1.3808"},
{ "1.3.6.1.4.1.232.165.3.1.1.0" , "cpqpower", NULL},
{ ".1.3.6.1.4.1.4555.1.1.1.1.1.1.0" , "netvision", ".1.3.6.1.4.1.4555.1.1.1"},
/* Terminating entry */

View file

@ -31,6 +31,7 @@ typedef struct {
/* USB IDs device table */
static usb_device_id_t usb_device_table[] = {
{ 0x0001, 0x0000, "blazer_usb" },
{ 0x03f0, 0x1f01, "bcmxcp_usb" },
{ 0x03f0, 0x1f02, "bcmxcp_usb" },
{ 0x03f0, 0x1f06, "usbhid-ups" },
@ -96,6 +97,7 @@ static usb_device_id_t usb_device_table[] = {
{ 0x09ae, 0x4006, "usbhid-ups" },
{ 0x09ae, 0x4007, "usbhid-ups" },
{ 0x09ae, 0x4008, "usbhid-ups" },
{ 0x0d9f, 0x0004, "usbhid-ups" },
{ 0x0d9f, 0x00a2, "usbhid-ups" },
{ 0x0d9f, 0x00a3, "usbhid-ups" },
{ 0x0d9f, 0x00a4, "usbhid-ups" },
@ -104,6 +106,7 @@ static usb_device_id_t usb_device_table[] = {
{ 0x0f03, 0x0001, "blazer_usb" },
{ 0x10af, 0x0001, "usbhid-ups" },
{ 0x14f0, 0x00c9, "blazer_usb" },
{ 0xffff, 0x0000, "blazer_usb" },
/* Terminating entry */
{ -1, -1, NULL }
};

View file

@ -17,14 +17,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "common.h"
#ifdef HAVE_AVAHI_CLIENT_CLIENT_H
#include "nut-scan.h"
#ifdef WITH_AVAHI
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include "timehead.h"
#include <avahi-client/client.h>
#include <avahi-client/lookup.h>
@ -33,6 +33,175 @@
#include <avahi-common/malloc.h>
#include <avahi-common/error.h>
#include <ltdl.h>
/* dynamic link library stuff */
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static AvahiClient* (*nut_avahi_service_browser_get_client)(AvahiServiceBrowser *);
static int (*nut_avahi_simple_poll_loop)(AvahiSimplePoll *s);
static void (*nut_avahi_client_free)(AvahiClient *client);
static int (*nut_avahi_client_errno)(AvahiClient*);
static void (*nut_avahi_free)(void *p);
static void (*nut_avahi_simple_poll_quit)(AvahiSimplePoll *s);
static AvahiClient* (*nut_avahi_client_new)(
const AvahiPoll *poll_api,
AvahiClientFlags flags,
AvahiClientCallback callback,
void *userdata,
int *error);
static void (*nut_avahi_simple_poll_free)(AvahiSimplePoll *s);
static AvahiServiceResolver * (*nut_avahi_service_resolver_new)(
AvahiClient *client,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *name,
const char *type,
const char *domain,
AvahiProtocol aprotocol,
AvahiLookupFlags flags,
AvahiServiceResolverCallback callback,
void *userdata);
static const char * (*nut_avahi_strerror)(int error);
static AvahiClient* (*nut_avahi_service_resolver_get_client)(AvahiServiceResolver *);
static AvahiServiceBrowser* (*nut_avahi_service_browser_new)(
AvahiClient *client,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *type,
const char *domain,
AvahiLookupFlags flags,
AvahiServiceBrowserCallback callback,
void *userdata);
static int (*nut_avahi_service_resolver_free)(AvahiServiceResolver *r);
static AvahiSimplePoll *(*nut_avahi_simple_poll_new)(void);
static char* (*nut_avahi_string_list_to_string)(AvahiStringList *l);
static int (*nut_avahi_service_browser_free)(AvahiServiceBrowser *);
static char * (*nut_avahi_address_snprint)(char *ret_s, size_t length, const AvahiAddress *a);
static const AvahiPoll* (*nut_avahi_simple_poll_get)(AvahiSimplePoll *s);
/* return 0 on error */
int nutscan_load_avahi_library()
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext("libavahi-client");
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_avahi_service_browser_get_client) = lt_dlsym(dl_handle, "avahi_service_browser_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_loop) = lt_dlsym(dl_handle, "avahi_simple_poll_loop");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_free) = lt_dlsym(dl_handle, "avahi_client_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_errno) = lt_dlsym(dl_handle, "avahi_client_errno");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_free) = lt_dlsym(dl_handle, "avahi_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_quit) = lt_dlsym(dl_handle, "avahi_simple_poll_quit");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_new) = lt_dlsym(dl_handle, "avahi_client_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_free) = lt_dlsym(dl_handle, "avahi_simple_poll_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_new) = lt_dlsym(dl_handle, "avahi_service_resolver_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_strerror) = lt_dlsym(dl_handle, "avahi_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_get_client) = lt_dlsym(dl_handle, "avahi_service_resolver_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_new) = lt_dlsym(dl_handle, "avahi_service_browser_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_free) = lt_dlsym(dl_handle, "avahi_service_resolver_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_new) = lt_dlsym(dl_handle, "avahi_simple_poll_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_string_list_to_string) = lt_dlsym(dl_handle, "avahi_string_list_to_string");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_free) = lt_dlsym(dl_handle, "avahi_service_browser_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_address_snprint) = lt_dlsym(dl_handle, "avahi_address_snprint");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_get) = lt_dlsym(dl_handle, "avahi_simple_poll_get");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
err:
fprintf(stderr, "%s\n", dl_error);
dl_handle = (void *)1;
return 0;
}
/* end of dynamic link library stuff */
static AvahiSimplePoll *simple_poll = NULL;
static nutscan_device_t * dev_ret = NULL;
static long avahi_usec_timeout = 0;
@ -187,7 +356,7 @@ static void resolve_callback(
switch (event) {
case AVAHI_RESOLVER_FAILURE:
fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, (*nut_avahi_strerror)((*nut_avahi_client_errno)((*nut_avahi_service_resolver_get_client)(r))));
break;
case AVAHI_RESOLVER_FOUND: {
@ -195,8 +364,8 @@ static void resolve_callback(
/* fprintf(stderr, "Service '%s' of type '%s' in domain '%s':\n", name, type, domain); */
avahi_address_snprint(a, sizeof(a), address);
t = avahi_string_list_to_string(txt);
(*nut_avahi_address_snprint)(a, sizeof(a), address);
t = (*nut_avahi_string_list_to_string)(txt);
/*
fprintf(stderr,
"\t%s:%u (%s)\n"
@ -217,11 +386,11 @@ static void resolve_callback(
!!(flags & AVAHI_LOOKUP_RESULT_CACHED));
*/
update_device(host_name,a,port,t,address->proto);
avahi_free(t);
(*nut_avahi_free)(t);
}
}
avahi_service_resolver_free(r);
(*nut_avahi_service_resolver_free)(r);
}
static void browse_callback(
@ -243,8 +412,8 @@ static void browse_callback(
switch (event) {
case AVAHI_BROWSER_FAILURE:
fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
avahi_simple_poll_quit(simple_poll);
fprintf(stderr, "(Browser) %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)((*nut_avahi_service_browser_get_client)(b))));
(*nut_avahi_simple_poll_quit)(simple_poll);
return;
case AVAHI_BROWSER_NEW:
@ -255,8 +424,8 @@ static void browse_callback(
the callback function is called the server will free
the resolver for us. */
if (!(avahi_service_resolver_new(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c)))
fprintf(stderr, "Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_client_errno(c)));
if (!((*nut_avahi_service_resolver_new)(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c)))
fprintf(stderr, "Failed to resolve service '%s': %s\n", name, (*nut_avahi_strerror)((*nut_avahi_client_errno)(c)));
break;
@ -265,7 +434,7 @@ static void browse_callback(
break;
case AVAHI_BROWSER_ALL_FOR_NOW:
avahi_simple_poll_quit(simple_poll);
(*nut_avahi_simple_poll_quit)(simple_poll);
case AVAHI_BROWSER_CACHE_EXHAUSTED:
/* fprintf(stderr, "(Browser) %s\n", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW"); */
break;
@ -278,8 +447,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN
/* Called whenever the client or server state changes */
if (state == AVAHI_CLIENT_FAILURE) {
fprintf(stderr, "Server connection failure: %s\n", avahi_strerror(avahi_client_errno(c)));
avahi_simple_poll_quit(simple_poll);
fprintf(stderr, "Server connection failure: %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)(c)));
(*nut_avahi_simple_poll_quit)(simple_poll);
}
}
@ -291,48 +460,55 @@ nutscan_device_t * nutscan_scan_avahi(long usec_timeout)
AvahiClient *client = NULL;
AvahiServiceBrowser *sb = NULL;
int error;
int ret = 1;
if( !nutscan_avail_avahi ) {
return NULL;
}
avahi_usec_timeout = usec_timeout;
/* Allocate main loop object */
if (!(simple_poll = avahi_simple_poll_new())) {
if (!(simple_poll = (*nut_avahi_simple_poll_new)())) {
fprintf(stderr, "Failed to create simple poll object.\n");
goto fail;
}
/* Allocate a new client */
client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error);
client = (*nut_avahi_client_new)((*nut_avahi_simple_poll_get)(simple_poll), 0, client_callback, NULL, &error);
/* Check wether creating the client object succeeded */
if (!client) {
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
fprintf(stderr, "Failed to create client: %s\n", (*nut_avahi_strerror)(error));
goto fail;
}
/* Create the service browser */
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_upsd._tcp", NULL, 0, browse_callback, client))) {
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
if (!(sb = (*nut_avahi_service_browser_new)(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_upsd._tcp", NULL, 0, browse_callback, client))) {
fprintf(stderr, "Failed to create service browser: %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)(client)));
goto fail;
}
/* Run the main loop */
avahi_simple_poll_loop(simple_poll);
ret = 0;
(*nut_avahi_simple_poll_loop)(simple_poll);
fail:
/* Cleanup things */
if (sb)
avahi_service_browser_free(sb);
(*nut_avahi_service_browser_free)(sb);
if (client)
avahi_client_free(client);
(*nut_avahi_client_free)(client);
if (simple_poll)
avahi_simple_poll_free(simple_poll);
(*nut_avahi_simple_poll_free)(simple_poll);
return dev_ret;
}
#endif /* HAVE_AVAHI_CLIENT_CLIENT_H */
#else /* WITH_AVAHI */
/* stub function */
nutscan_device_t * nutscan_scan_avahi(long usec_timeout)
{
return NULL;
}
#endif /* WITH_AVAHI */

View file

@ -1,6 +1,6 @@
/* scan_ipmi.c: detect NUT supported Power Supply Units
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
* Copyright (C) 2011 - Arnaud Quette <arnaud.quette@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +17,321 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "common.h"
#ifdef HAVE_FREEIPMI_FREEIPMI_H
#include "nut-scan.h"
/* TODO */
#ifdef WITH_IPMI
#include "upsclient.h"
#include <freeipmi/freeipmi.h>
#include <stdio.h>
#include <string.h>
#include <ltdl.h>
#define NUT_IPMI_DRV_NAME "nut-ipmipsu"
/* dynamic link library stuff */
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static int (*nut_ipmi_fru_parse_close_device_id) (ipmi_fru_parse_ctx_t ctx);
static void (*nut_ipmi_fru_parse_ctx_destroy) (ipmi_fru_parse_ctx_t ctx);
static void (*nut_ipmi_sdr_cache_ctx_destroy) (ipmi_sdr_cache_ctx_t ctx);
static void (*nut_ipmi_sdr_parse_ctx_destroy) (ipmi_sdr_parse_ctx_t ctx);
static ipmi_fru_parse_ctx_t (*nut_ipmi_fru_parse_ctx_create) (ipmi_ctx_t ipmi_ctx);
static int (*nut_ipmi_fru_parse_ctx_set_flags) (ipmi_fru_parse_ctx_t ctx, unsigned int flags);
static int (*nut_ipmi_fru_parse_open_device_id) (ipmi_fru_parse_ctx_t ctx, uint8_t fru_device_id);
static char * (*nut_ipmi_fru_parse_ctx_errormsg) (ipmi_fru_parse_ctx_t ctx);
static int (*nut_ipmi_fru_parse_read_data_area) (ipmi_fru_parse_ctx_t ctx,
unsigned int *area_type,
unsigned int *area_length,
void *areabuf,
unsigned int areabuflen);
static int (*nut_ipmi_fru_parse_next) (ipmi_fru_parse_ctx_t ctx);
static ipmi_ctx_t (*nut_ipmi_ctx_create) (void);
static int (*nut_ipmi_ctx_find_inband) (ipmi_ctx_t ctx,
ipmi_driver_type_t *driver_type,
int disable_auto_probe,
uint16_t driver_address,
uint8_t register_spacing,
const char *driver_device,
unsigned int workaround_flags,
unsigned int flags);
static char * (*nut_ipmi_ctx_errormsg) (ipmi_ctx_t ctx);
static int (*nut_ipmi_ctx_close) (ipmi_ctx_t ctx);
static void (*nut_ipmi_ctx_destroy) (ipmi_ctx_t ctx);
/* Return 0 on error */
int nutscan_load_ipmi_library()
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext("libfreeipmi");
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
/* Clear any existing error */
lt_dlerror();
*(void **) (&nut_ipmi_fru_parse_close_device_id) = lt_dlsym(dl_handle, "ipmi_fru_parse_close_device_id");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_sdr_cache_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_sdr_cache_ctx_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_sdr_parse_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_sdr_parse_ctx_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_ctx_create) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_ctx_set_flags) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_set_flags");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_open_device_id) = lt_dlsym(dl_handle, "ipmi_fru_parse_open_device_id");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_ctx_errormsg) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_errormsg");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_read_data_area) = lt_dlsym(dl_handle, "ipmi_fru_parse_read_data_area");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_fru_parse_next) = lt_dlsym(dl_handle, "ipmi_fru_parse_next");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_ctx_create) = lt_dlsym(dl_handle, "ipmi_ctx_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_ctx_find_inband) = lt_dlsym(dl_handle, "ipmi_ctx_find_inband");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_ctx_errormsg) = lt_dlsym(dl_handle, "ipmi_ctx_errormsg");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_ctx_close) = lt_dlsym(dl_handle, "ipmi_ctx_close");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ipmi_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_ctx_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
err:
fprintf(stderr, "%s\n", dl_error);
dl_handle = (void *)1;
return 0;
}
/* end of dynamic link library stuff */
/* Cleanup IPMI contexts */
static void nut_freeipmi_cleanup(ipmi_fru_parse_ctx_t fru_parse_ctx,
ipmi_sdr_cache_ctx_t sdr_cache_ctx,
ipmi_sdr_parse_ctx_t sdr_parse_ctx)
{
if (fru_parse_ctx) {
(*nut_ipmi_fru_parse_close_device_id) (fru_parse_ctx);
(*nut_ipmi_fru_parse_ctx_destroy) (fru_parse_ctx);
}
if (sdr_cache_ctx) {
(*nut_ipmi_sdr_cache_ctx_destroy) (sdr_cache_ctx);
}
if (sdr_parse_ctx) {
(*nut_ipmi_sdr_parse_ctx_destroy) (sdr_parse_ctx);
}
}
/* Return 1 if supported, 0 otherwise */
int is_ipmi_device_supported(ipmi_ctx_t ipmi_ctx, int ipmi_id)
{
int ret = -1;
unsigned int area_type = 0;
unsigned int area_length = 0;
uint8_t areabuf[IPMI_FRU_PARSE_AREA_SIZE_MAX+1];
ipmi_fru_parse_ctx_t fru_parse_ctx = NULL;
ipmi_sdr_cache_ctx_t sdr_cache_ctx = NULL;
ipmi_sdr_parse_ctx_t sdr_parse_ctx = NULL;
/* Parse FRU information */
if (!(fru_parse_ctx = (*nut_ipmi_fru_parse_ctx_create) (ipmi_ctx)))
{
fprintf(stderr, "ipmi_fru_parse_ctx_create()\n");
return 0;
}
/* lots of motherboards calculate checksums incorrectly */
if ((*nut_ipmi_fru_parse_ctx_set_flags) (fru_parse_ctx, IPMI_FRU_PARSE_FLAGS_SKIP_CHECKSUM_CHECKS) < 0)
{
nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx);
return 0;
}
if ((*nut_ipmi_fru_parse_open_device_id) (fru_parse_ctx, ipmi_id) < 0)
{
nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx);
return 0;
}
do
{
/* clear fields */
area_type = 0;
area_length = 0;
memset (areabuf, '\0', IPMI_FRU_PARSE_AREA_SIZE_MAX + 1);
/* parse FRU buffer */
if ((*nut_ipmi_fru_parse_read_data_area) (fru_parse_ctx,
&area_type,
&area_length,
areabuf,
IPMI_FRU_PARSE_AREA_SIZE_MAX) < 0)
{
nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx);
return 0;
}
if (area_length)
{
if (area_type == IPMI_FRU_PARSE_AREA_TYPE_MULTIRECORD_POWER_SUPPLY_INFORMATION)
{
/* Found a POWER_SUPPLY record */
nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx);
return 1;
}
}
} while ((ret = (*nut_ipmi_fru_parse_next) (fru_parse_ctx)) == 1);
/* No need for further errors checking */
nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx);
return 0;
}
/* return NULL on error */
nutscan_device_t * nutscan_scan_ipmi()
{
ipmi_ctx_t ipmi_ctx = NULL;
nutscan_device_t * nut_dev = NULL;
nutscan_device_t * current_nut_dev = NULL;
int ret = -1;
int ipmi_id = 0;
char port_id[10];
if( !nutscan_avail_ipmi ) {
return NULL;
}
/* Initialize the FreeIPMI library. */
if (!(ipmi_ctx = (*nut_ipmi_ctx_create) ()))
{
/* we have to force cleanup, since exit handler is not yet installed */
fprintf(stderr, "ipmi_ctx_create\n");
return NULL;
}
if ((ret = (*nut_ipmi_ctx_find_inband) (ipmi_ctx,
NULL,
0, /* don't disable auto-probe */
0,
0,
NULL,
0, /* workaround flags, none by default */
0 /* flags */
)) < 0)
{
fprintf(stderr, "ipmi_ctx_find_inband: %s\n",
(*nut_ipmi_ctx_errormsg) (ipmi_ctx));
return NULL;
}
if (!ret)
{
/* No local IPMI device detected */
return NULL;
}
/* Loop through all possible devices */
for (ipmi_id = 0 ; ipmi_id <= IPMI_FRU_DEVICE_ID_MAX ; ipmi_id++) {
if (is_ipmi_device_supported(ipmi_ctx, ipmi_id)) {
if ( (nut_dev = nutscan_new_device()) == NULL ) {
fprintf(stderr,"Memory allocation error\n");
nutscan_free_device(current_nut_dev);
break;
}
/* Fill the device structure (sufficient with driver and port) */
nut_dev->type = TYPE_IPMI;
nut_dev->driver = strdup(NUT_IPMI_DRV_NAME);
sprintf(port_id, "id%x", ipmi_id);
nut_dev->port = strdup(port_id);
current_nut_dev = nutscan_add_device_to_device(
current_nut_dev,
nut_dev);
memset (port_id, 0, sizeof(port_id));
}
}
/* Final cleanup */
if (ipmi_ctx) {
(*nut_ipmi_ctx_close) (ipmi_ctx);
(*nut_ipmi_ctx_destroy) (ipmi_ctx);
}
return current_nut_dev;
}
#else /* WITH_IPMI */
/* stub function */
nutscan_device_t * nutscan_scan_ipmi()
{
return NULL;
}
#endif /* HAVE_FREEIPMI_FREEIPMI_H */
#endif /* WITH_IPMI */

View file

@ -122,7 +122,6 @@ nutscan_device_t * nutscan_scan_nut(const char* startIP, const char* stopIP, con
int change_action_handler = 0;
int i;
struct scan_nut_arg *nut_arg;
#ifdef HAVE_PTHREAD
pthread_t thread;
pthread_t * thread_array = NULL;
@ -131,6 +130,10 @@ nutscan_device_t * nutscan_scan_nut(const char* startIP, const char* stopIP, con
pthread_mutex_init(&dev_mutex,NULL);
#endif
if( !nutscan_avail_nut ) {
return NULL;
}
/* Ignore SIGPIPE if the caller hasn't set a handler for it yet */
if( sigaction(SIGPIPE, NULL, &oldact) == 0 ) {
if( oldact.sa_handler == SIG_DFL ) {

View file

@ -18,15 +18,14 @@
*/
#include "common.h"
#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H
#include "nut-scan.h"
#ifdef WITH_SNMP
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <ltdl.h>
/* workaround for buggy Net-SNMP config
* from drivers/snmp-ups.h */
@ -63,18 +62,196 @@
static nutscan_device_t * dev_ret = NULL;
#ifdef HAVE_PTHREAD
static pthread_mutex_t dev_mutex;
static pthread_mutex_t lib_mutex;
static pthread_t * thread_array = NULL;
static int thread_count = 0;
#endif
long g_usec_timeout ;
/* dynamic link library stuff */
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static void (*nut_init_snmp)(const char *type);
static void (*nut_snmp_sess_init)(netsnmp_session * session);
static void * (*nut_snmp_sess_open)(struct snmp_session *session);
static int (*nut_snmp_sess_close)(void *handle);
static struct snmp_session * (*nut_snmp_sess_session)(void *handle);
static void * (*nut_snmp_parse_oid)(const char *input, oid *objid,
size_t *objidlen);
static struct snmp_pdu * (*nut_snmp_pdu_create) (int command );
netsnmp_variable_list * (*nut_snmp_add_null_var)(netsnmp_pdu *pdu,
const oid *objid, size_t objidlen);
static int (*nut_snmp_sess_synch_response) (void *sessp, netsnmp_pdu *pdu,
netsnmp_pdu **response);
static int (*nut_snmp_oid_compare) (const oid *in_name1, size_t len1,
const oid *in_name2, size_t len2);
static void (*nut_snmp_free_pdu) (netsnmp_pdu *pdu);
static int (*nut_generate_Ku)(const oid * hashtype, u_int hashtype_len,
u_char * P, size_t pplen, u_char * Ku, size_t * kulen);
static const char * (*nut_snmp_api_errstring) (int snmp_errnumber);
static int (*nut_snmp_errno);
static oid * (*nut_usmAESPrivProtocol);
static oid * (*nut_usmHMACMD5AuthProtocol);
static oid * (*nut_usmHMACSHA1AuthProtocol);
static oid * (*nut_usmDESPrivProtocol);
/* return 0 on error */
int nutscan_load_snmp_library()
{
#ifdef HAVE_PTHREAD
pthread_mutex_lock(&lib_mutex);
#endif
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext("libnetsnmp");
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_init_snmp) = lt_dlsym(dl_handle, "init_snmp");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_sess_init) = lt_dlsym(dl_handle,
"snmp_sess_init");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_sess_open) = lt_dlsym(dl_handle,
"snmp_sess_open");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_sess_close) = lt_dlsym(dl_handle,
"snmp_sess_close");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_sess_session) = lt_dlsym(dl_handle,
"snmp_sess_session");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_parse_oid) = lt_dlsym(dl_handle,
"snmp_parse_oid");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_pdu_create) = lt_dlsym(dl_handle,
"snmp_pdu_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_add_null_var) = lt_dlsym(dl_handle,
"snmp_add_null_var");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_sess_synch_response) = lt_dlsym(dl_handle,
"snmp_sess_synch_response");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_oid_compare) = lt_dlsym(dl_handle,
"snmp_oid_compare");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_free_pdu) = lt_dlsym(dl_handle,"snmp_free_pdu");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_generate_Ku) = lt_dlsym(dl_handle, "generate_Ku");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_api_errstring) = lt_dlsym(dl_handle,
"snmp_api_errstring");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_snmp_errno) = lt_dlsym(dl_handle, "snmp_errno");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usmAESPrivProtocol) = lt_dlsym(dl_handle,
"usmAESPrivProtocol");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usmHMACMD5AuthProtocol) = lt_dlsym(dl_handle,
"usmHMACMD5AuthProtocol");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usmHMACSHA1AuthProtocol) = lt_dlsym(dl_handle,
"usmHMACSHA1AuthProtocol");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usmDESPrivProtocol) = lt_dlsym(dl_handle,
"usmDESPrivProtocol");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
#ifdef HAVE_PTHREAD
pthread_mutex_unlock(&dev_mutex);
#endif
return 1;
err:
fprintf(stderr, "%s\n", dl_error);
dl_handle = (void *)1;
#ifdef HAVE_PTHREAD
pthread_mutex_unlock(&dev_mutex);
#endif
return 0;
}
/* end of dynamic link library stuff */
static void scan_snmp_add_device(nutscan_snmp_t * sec, struct snmp_pdu *response,char * mib)
{
nutscan_device_t * dev = NULL;
struct snmp_session * session;
char * buf;
session = snmp_sess_session(sec->handle);
session = (*nut_snmp_sess_session)(sec->handle);
if(session == NULL) {
return;
}
/* SNMP device found */
dev = nutscan_new_device();
dev->type = TYPE_SNMP;
@ -147,21 +324,21 @@ static struct snmp_pdu * scan_snmp_get_manufacturer(char* oid_str,void* handle)
/* create and send request. */
name_len = MAX_OID_LEN;
if (!snmp_parse_oid(oid_str, name, &name_len)) {
if (!(*nut_snmp_parse_oid)(oid_str, name, &name_len)) {
index++;
return NULL;
}
pdu = snmp_pdu_create(SNMP_MSG_GET);
pdu = (*nut_snmp_pdu_create)(SNMP_MSG_GET);
if (pdu == NULL) {
index++;
return NULL;
}
snmp_add_null_var(pdu, name, name_len);
(*nut_snmp_add_null_var)(pdu, name, name_len);
status = snmp_sess_synch_response(handle,pdu, &response);
status = (*nut_snmp_sess_synch_response)(handle,pdu, &response);
if( response == NULL ) {
index++;
return NULL;
@ -170,11 +347,11 @@ static struct snmp_pdu * scan_snmp_get_manufacturer(char* oid_str,void* handle)
if(status!=STAT_SUCCESS||response->errstat!=SNMP_ERR_NOERROR||
response->variables == NULL ||
response->variables->name == NULL ||
snmp_oid_compare(response->variables->name,
(*nut_snmp_oid_compare)(response->variables->name,
response->variables->name_length,
name, name_len) != 0 ||
response->variables->val.string == NULL ) {
snmp_free_pdu(response);
(*nut_snmp_free_pdu)(response);
index++;
return NULL;
}
@ -198,7 +375,7 @@ static void try_all_oid(void * arg)
scan_snmp_add_device(sec,response,snmp_device_table[index].mib);
snmp_free_pdu(response);
(*nut_snmp_free_pdu)(response);
response = NULL;
index++;
@ -207,7 +384,7 @@ static void try_all_oid(void * arg)
static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec)
{
snmp_sess_init(snmp_sess);
(*nut_snmp_sess_init)(snmp_sess);
snmp_sess->peername = sec->peername;
@ -279,16 +456,17 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec)
snmp_sess->securityAuthKeyLen = USM_AUTH_KU_LEN;
/* default to MD5 */
snmp_sess->securityAuthProto = usmHMACMD5AuthProtocol;
snmp_sess->securityAuthProtoLen =sizeof(usmHMACMD5AuthProtocol)/
sizeof(oid);
snmp_sess->securityAuthProto = (*nut_usmHMACMD5AuthProtocol);
snmp_sess->securityAuthProtoLen =
sizeof((*nut_usmHMACMD5AuthProtocol))/
sizeof(oid);
if( sec->authProtocol ) {
if (strcmp(sec->authProtocol, "SHA") == 0) {
snmp_sess->securityAuthProto =
usmHMACSHA1AuthProtocol;
(*nut_usmHMACSHA1AuthProtocol);
snmp_sess->securityAuthProtoLen =
sizeof(usmHMACSHA1AuthProtocol)/
sizeof((*nut_usmHMACSHA1AuthProtocol))/
sizeof(oid);
}
else {
@ -303,7 +481,7 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec)
/* set the authentication key to a MD5/SHA1 hashed version of
* our passphrase (must be at least 8 characters long) */
if (generate_Ku(snmp_sess->securityAuthProto,
if ((*nut_generate_Ku)(snmp_sess->securityAuthProto,
snmp_sess->securityAuthProtoLen,
(u_char *) sec->authPassword,
strlen(sec->authPassword),
@ -321,15 +499,17 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec)
}
/* default to DES */
snmp_sess->securityPrivProto=usmDESPrivProtocol;
snmp_sess->securityPrivProto=(*nut_usmDESPrivProtocol);
snmp_sess->securityPrivProtoLen =
sizeof(usmDESPrivProtocol)/sizeof(oid);
sizeof((*nut_usmDESPrivProtocol))/sizeof(oid);
if( sec->privProtocol ) {
if (strcmp(sec->privProtocol, "AES") == 0) {
snmp_sess->securityPrivProto=usmAESPrivProtocol;
snmp_sess->securityPrivProto=
(*nut_usmAESPrivProtocol);
snmp_sess->securityPrivProtoLen =
sizeof(usmAESPrivProtocol)/sizeof(oid);
sizeof((*nut_usmAESPrivProtocol))/
sizeof(oid);
}
else {
if (strcmp(sec->privProtocol, "DES") != 0) {
@ -344,7 +524,7 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec)
/* set the private key to a MD5/SHA hashed version of
* our passphrase (must be at least 8 characters long) */
snmp_sess->securityPrivKeyLen = USM_PRIV_KU_LEN;
if (generate_Ku(snmp_sess->securityAuthProto,
if ((*nut_generate_Ku)(snmp_sess->securityAuthProto,
snmp_sess->securityAuthProtoLen,
(u_char *) sec->privPassword,
strlen(sec->privPassword),
@ -365,7 +545,7 @@ static void * try_SysOID(void * arg)
{
struct snmp_session snmp_sess;
void * handle;
struct snmp_pdu *pdu, *response = NULL;
struct snmp_pdu *pdu, *response = NULL, *resp = NULL;
oid name[MAX_OID_LEN];
size_t name_len = MAX_OID_LEN;
nutscan_snmp_t * sec = (nutscan_snmp_t *)arg;
@ -381,7 +561,7 @@ static void * try_SysOID(void * arg)
snmp_sess.timeout = g_usec_timeout;
/* Open the session */
handle = snmp_sess_open(&snmp_sess); /* establish the session */
handle = (*nut_snmp_sess_open)(&snmp_sess); /* establish the session */
if (handle == NULL) {
fprintf(stderr,"Failed to open SNMP session for %s.\n",
sec->peername);
@ -389,24 +569,24 @@ static void * try_SysOID(void * arg)
}
/* create and send request. */
if (!snmp_parse_oid(SysOID, name, &name_len)) {
if (!(*nut_snmp_parse_oid)(SysOID, name, &name_len)) {
fprintf(stderr,"SNMP errors: %s\n",
snmp_api_errstring(snmp_errno));
snmp_sess_close(handle);
(*nut_snmp_api_errstring)((*nut_snmp_errno)));
(*nut_snmp_sess_close)(handle);
goto try_SysOID_free;
}
pdu = snmp_pdu_create(SNMP_MSG_GET);
pdu = (*nut_snmp_pdu_create)(SNMP_MSG_GET);
if (pdu == NULL) {
fprintf(stderr,"Not enough memory\n");
snmp_sess_close(handle);
(*nut_snmp_sess_close)(handle);
goto try_SysOID_free;
}
snmp_add_null_var(pdu, name, name_len);
(*nut_snmp_add_null_var)(pdu, name, name_len);
snmp_sess_synch_response(handle,
(*nut_snmp_sess_synch_response)(handle,
pdu, &response);
if (response) {
@ -424,25 +604,27 @@ static void * try_SysOID(void * arg)
continue;
}
name_len = MAX_OID_LEN;
if (!snmp_parse_oid(
if (!(*nut_snmp_parse_oid)(
snmp_device_table[index].sysoid,
name, &name_len)) {
index++;
continue;
}
if ( snmp_oid_compare(
if ( (*nut_snmp_oid_compare)(
response->variables->val.objid,
response->variables->val_len/sizeof(oid),
name, name_len) == 0 ) {
/* we have found a relevent sysoid */
snmp_free_pdu(response);
response = scan_snmp_get_manufacturer(
resp = scan_snmp_get_manufacturer(
snmp_device_table[index].oid,
handle);
scan_snmp_add_device(sec,response,
snmp_device_table[index].mib);
sysoid_found = 1;
if( resp != NULL ) {
scan_snmp_add_device(sec,resp,
snmp_device_table[index].mib);
sysoid_found = 1;
(*nut_snmp_free_pdu)(resp);
}
}
index++;
}
@ -453,11 +635,11 @@ static void * try_SysOID(void * arg)
try_all_oid(sec);
}
snmp_free_pdu(response);
(*nut_snmp_free_pdu)(response);
response = NULL;
}
snmp_sess_close(handle);
(*nut_snmp_sess_close)(handle);
try_SysOID_free:
if( sec->peername ) {
@ -478,12 +660,18 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip
pthread_t thread;
pthread_mutex_init(&dev_mutex,NULL);
pthread_mutex_init(&lib_mutex,NULL);
#endif
if( !nutscan_avail_snmp ) {
return NULL;
}
g_usec_timeout = usec_timeout;
/* Initialize the SNMP library */
init_snmp("nut-scanner");
(*nut_init_snmp)("nut-scanner");
ip_str = nutscan_ip_iter_init(&ip, start_ip, stop_ip);
@ -515,6 +703,11 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip
return dev_ret;
}
#endif /* HAVE_NET_SNMP_NET_SNMP_CONFIG_H */
#else /* WITH_SNMP */
nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip,long usec_timeout, nutscan_snmp_t * sec)
{
return NULL;
}
#endif /* WITH_SNMP */

View file

@ -18,12 +18,99 @@
*/
#include "common.h"
#ifdef HAVE_USB_H
#include "nut-scan.h"
#ifdef WITH_USB
#include "upsclient.h"
#include "nutscan-usb.h"
#include <stdio.h>
#include <string.h>
#include "nutscan-device.h"
#include <ltdl.h>
/* dynamic link library stuff */
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static int (*nut_usb_close)(usb_dev_handle *dev);
static int (*nut_usb_find_busses)(void);
static char * (*nut_usb_strerror)(void);
static void (*nut_usb_init)(void);
static int (*nut_usb_get_string_simple)(usb_dev_handle *dev, int index,
char *buf, size_t buflen);
static struct usb_bus * (*nut_usb_busses);
static usb_dev_handle * (*nut_usb_open)(struct usb_device *dev);
static int (*nut_usb_find_devices)(void);
/* return 0 on error */
int nutscan_load_usb_library()
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext("libusb");
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_usb_close) = lt_dlsym(dl_handle, "usb_close");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_find_busses) = lt_dlsym(dl_handle, "usb_find_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_strerror) = lt_dlsym(dl_handle, "usb_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_init) = lt_dlsym(dl_handle, "usb_init");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_get_string_simple) = lt_dlsym(dl_handle,
"usb_get_string_simple");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_busses) = lt_dlsym(dl_handle, "usb_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_open) = lt_dlsym(dl_handle, "usb_open");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **)(&nut_usb_find_devices) = lt_dlsym(dl_handle,"usb_find_devices");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
err:
fprintf(stderr, "%s\n", dl_error);
dl_handle = (void *)1;
return 0;
}
/* end of dynamic link library stuff */
static char* is_usb_device_supported(usb_device_id_t *usb_device_id_list,
int dev_VendorID, int dev_ProductID)
@ -57,12 +144,16 @@ nutscan_device_t * nutscan_scan_usb()
nutscan_device_t * nut_dev = NULL;
nutscan_device_t * current_nut_dev = NULL;
/* libusb base init */
usb_init();
usb_find_busses();
usb_find_devices();
if( !nutscan_avail_usb ) {
return NULL;
}
for (bus = usb_busses; bus; bus = bus->next) {
/* libusb base init */
(*nut_usb_init)();
(*nut_usb_find_busses)();
(*nut_usb_find_devices)();
for (bus = (*nut_usb_busses); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if ((driver_name =
is_usb_device_supported(usb_device_table,
@ -70,17 +161,17 @@ nutscan_device_t * nutscan_scan_usb()
dev->descriptor.idProduct)) != NULL) {
/* open the device */
udev = usb_open(dev);
udev = (*nut_usb_open)(dev);
if (!udev) {
fprintf(stderr,"Failed to open device, \
skipping. (%s)\n",
usb_strerror());
(*nut_usb_strerror)());
continue;
}
/* get serial number */
if (dev->descriptor.iSerialNumber) {
ret = usb_get_string_simple(udev,
ret = (*nut_usb_get_string_simple)(udev,
dev->descriptor.iSerialNumber,
string, sizeof(string));
if (ret > 0) {
@ -89,7 +180,7 @@ nutscan_device_t * nutscan_scan_usb()
}
/* get product name */
if (dev->descriptor.iProduct) {
ret = usb_get_string_simple(udev,
ret = (*nut_usb_get_string_simple)(udev,
dev->descriptor.iProduct,
string, sizeof(string));
if (ret > 0) {
@ -99,7 +190,7 @@ nutscan_device_t * nutscan_scan_usb()
/* get vendor name */
if (dev->descriptor.iManufacturer) {
ret = usb_get_string_simple(udev,
ret = (*nut_usb_get_string_simple)(udev,
dev->descriptor.iManufacturer,
string, sizeof(string));
if (ret > 0) {
@ -157,12 +248,17 @@ nutscan_device_t * nutscan_scan_usb()
memset (string, 0, sizeof(string));
usb_close(udev);
(*nut_usb_close)(udev);
}
}
}
return current_nut_dev;
}
#endif /* HAVE_USB_H */
#else /* WITH_USB */
nutscan_device_t * nutscan_scan_usb()
{
return NULL;
}
#endif /* WITH_USB */

View file

@ -18,16 +18,85 @@
*/
#include "common.h"
#include "nut-scan.h"
#ifdef WITH_NEON
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <sys/select.h>
#include <errno.h>
#include <arpa/inet.h>
#include <ne_xml.h>
#include "nutscan-device.h"
#include <ltdl.h>
/* dynamic link library stuff */
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static void (*nut_ne_xml_push_handler)(ne_xml_parser *p,
ne_xml_startelm_cb *startelm,
ne_xml_cdata_cb *cdata,
ne_xml_endelm_cb *endelm,
void *userdata);
static void (*nut_ne_xml_destroy)(ne_xml_parser *p);
static ne_xml_parser * (*nut_ne_xml_create)(void);
static int (*nut_ne_xml_parse)(ne_xml_parser *p, const char *block, size_t len);
/* return 0 on error */
int nutscan_load_neon_library()
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext("libneon");
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_ne_xml_push_handler) = lt_dlsym(dl_handle,
"ne_xml_push_handler");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_destroy) = lt_dlsym(dl_handle,"ne_xml_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_create) = lt_dlsym(dl_handle,"ne_xml_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_parse) = lt_dlsym(dl_handle,"ne_xml_parse");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
err:
fprintf(stderr, "%s\n", dl_error);
dl_handle = (void *)1;
return 0;
}
static int startelm_cb(void *userdata, int parent, const char *nspace, const char *name, const char **atts) {
nutscan_device_t * dev = (nutscan_device_t *)userdata;
@ -63,6 +132,9 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout)
nutscan_device_t * nut_dev = NULL;
nutscan_device_t * current_nut_dev = NULL;
if( !nutscan_avail_xml_http ) {
return NULL;
}
if((peerSocket = socket(AF_INET, SOCK_DGRAM, 0)) != -1)
{
@ -114,10 +186,12 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout)
continue;
}
if( getnameinfo(
(struct sockaddr *)&sockAddress,
sizeof(struct sockaddr_in),string,
sizeof(string),NULL,0,
NI_NUMERICHOST) != 0) {
if( inet_ntop(AF_INET,
&(sockAddress.sin_addr),
string,sizeof(buf)) == NULL ) {
fprintf(stderr,
"Error converting IP address \
: %d\n",errno);
@ -133,11 +207,11 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout)
nut_dev->type = TYPE_XML;
/* Try to read device type */
ne_xml_parser *parser = ne_xml_create();
ne_xml_push_handler(parser, startelm_cb, NULL,
NULL, nut_dev);
ne_xml_parse(parser, buf, strlen(buf));
ne_xml_destroy(parser);
ne_xml_parser *parser = (*nut_ne_xml_create)();
(*nut_ne_xml_push_handler)(parser, startelm_cb,
NULL, NULL, nut_dev);
(*nut_ne_xml_parse)(parser, buf, strlen(buf));
(*nut_ne_xml_destroy)(parser);
nut_dev->driver = strdup("netxml-ups");
sprintf(buf,"http://%s",string);
@ -157,4 +231,9 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout)
return current_nut_dev;
}
#else /* WITH_NEON */
nutscan_device_t * nutscan_scan_xml_http(long usec_timeout)
{
return NULL;
}
#endif /* WITH_NEON */

View file

@ -79,7 +79,7 @@ output_file.write( "/* SNMP IDs device table */\n" )
output_file.write( "static snmp_device_id_t snmp_device_table[] = {\n" )
for filename in glob.glob('../drivers/*-mib.c'):
list_of_line = file(filename,'r').read().split(';')
list_of_line = open(filename,'r').read().split(';')
for line in list_of_line:
if "mib2nut_info_t" in line:
#clean up line
@ -116,7 +116,7 @@ for filename in glob.glob('../drivers/*-mib.c'):
line = line.rstrip(" ")
line2 = line.split(" ")
sysoid = ""
sysoid = ""
for elem in line2:
if elem[0] == "\"":
clean_elem = re.sub("\"", "", elem)