Imported Upstream version 2.7.4

This commit is contained in:
Laurent Bigonville 2016-07-18 02:11:41 +02:00
parent fd413a3168
commit c9cb2187ee
290 changed files with 7473 additions and 2607 deletions

View file

@ -3,12 +3,13 @@
# an auxiliary script to produce a "stub" snmp-ups subdriver from
# SNMP data from a real agent or from dump files
#
# Version: 0.4
# Version: 0.6
#
# See also: docs/snmp-subdrivers.txt
#
# Copyright (C)
# 2011 - 2012 Arnaud Quette <arnaud.quette@free.fr>
# 2011 - 2012 Arnaud Quette <arnaud.quette@free.fr>
# 2015 Arnaud Quette <ArnaudQuette@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
@ -38,13 +39,24 @@ usage() {
echo "mode 1: get SNMP data from a real agent"
echo " -H host_address -- SNMP host IP address or name"
echo " -c community -- SNMP v1 community name (default: public)"
echo " -s XXXX -- override SNMP OID entry point (sysOID). Ex: '.1.3.6.1.4.1.534.10'"
echo ""
echo "mode 2: get data from files (snmpwalk dumps of 'sysOID' subtree)"
echo " -s XXXX -- SNMP OID entry point (sysOID). Ex: '.1.3.6.1.4.1.705.1'"
echo " -s XXXX -- SNMP OID entry point (sysOID). Ex: '.1.3.6.1.4.1.534.6.6.7'"
echo " file1 file2 -- read from files instead of an host (using Net SNMP)"
echo " file1: numeric SNMP walk (snmpwalk -On ... <sysOID>)"
echo " file2: string SNMP walk (snmpwalk -Os ... <sysOID>)"
# FIXME: EXAMPLES
echo ""
echo "Notes:"
echo " For both modes, prefer to copy the specific MIB file(s) for your device in the $0 script directory"
echo " In such case, for mode 2, also add \"-M.\" to allow the name resolution of OIDs"
echo ""
echo "Example:"
echo "mode 1: $0 -H 192.168.0.1 -n mibname -c mycommunity"
echo "mode 2: (using sysOID .1.3.6.1.4.1.534.6.6.7)"
echo " snmpwalk -On -v1 -c mycommunity 192.168.0.1 .1.3.6.1.4.1.534.6.6.7 2>/dev/null 1> numeric-walk-file"
echo " snmpwalk -Os -v1 -m ALL -M+. -c mycommunity 192.168.0.1 .1.3.6.1.4.1.534.6.6.7 2>/dev/null 1> string-walk-file"
echo " $0 -s .1.3.6.1.4.1.534.6.6.7 numeric-walk-file string-walk-file"
}
# variables
@ -66,10 +78,14 @@ TMP_NUMWALKFILE=`mktemp "$TMPDIR/$NAME-TMP-NUMWALK.XXXXXX"`
TMP_STRWALKFILE=`mktemp "$TMPDIR/$NAME-TMP-STRWALK.XXXXXX"`
get_snmp_data() {
# 1) get the sysOID (points the mfr specif MIB)
SYSOID=`snmpget -v1 -c $COMMUNITY -Ov $HOSTNAME .1.3.6.1.2.1.1.2.0 | cut -d' ' -f2`
echo "sysOID retrieved: ${SYSOID}"
# 1) get the sysOID (points the mfr specif MIB), apart if there's an override
if [ -z "$SYSOID" ]
then
SYSOID=`snmpget -On -v1 -c $COMMUNITY -Ov $HOSTNAME .1.3.6.1.2.1.1.2.0 | cut -d' ' -f2`
echo "sysOID retrieved: ${SYSOID}"
else
echo "Using the provided sysOID override ($SYSOID)"
fi
# 2) get the content of the mfr specif MIB
echo "Retrieving SNMP information. This may take some time"
@ -83,7 +99,7 @@ while [ $# -gt 0 ]; do
DRIVER="$2"
shift 2
elif [ $# -gt 1 -a "$1" = "-M" ]; then
MIBS_DIRLIST="+$2"
MIBS_DIRLIST="$MIBS_DIRLIST:$2"
shift 2
elif [ "$1" = "-k" ]; then
KEEP=yes
@ -166,7 +182,7 @@ fi
cleanup () {
rm -f "$DEBUG $DFL_NUMWALKFILE $TMP_NUMWALKFILE $DFL_STRWALKFILE $TMP_STRWALKFILE"
}
if [ -z "$KEEP" ]; then
if [ -n "$KEEP" ]; then
trap cleanup EXIT
fi
@ -272,7 +288,7 @@ cat > "$CFILE" <<EOF
* static info_lkp_t onbatt_info[] = {
* { 1, "OB" },
* { 2, "OL" },
* { 0, "NULL" }
* { 0, NULL }
* };
*/
@ -301,7 +317,7 @@ static snmp_info_t ${LDRIVER}_mib[] = {
* static info_lkp_t onbatt_info[] = {
* { 1, "OB" },
* { 2, "OL" },
* { 0, "NULL" }
* { 0, NULL }
* };
*/
EOF
@ -323,7 +339,7 @@ while IFS= read -r line; do
fi
# get the matching numeric OID
NUM_OID="`sed -n ${LINENB}p ${NUMWALKFILE} | cut -d' ' -f1`"
printf "\t/* ${FULL_STR_OID} */\n\t{ \"unmapped.${STR_OID}\", ${ST_FLAG_TYPE}, ${SU_INFOSIZE}, \"${NUM_OID}\", NULL, SU_FLAG_OK, NULL },\n"
printf "\t/* ${FULL_STR_OID} */\n\t{ \"unmapped.${STR_OID}\", ${ST_FLAG_TYPE}, ${SU_INFOSIZE}, \"${NUM_OID}\", NULL, SU_FLAG_OK, NULL, NULL },\n"
done < ${STRWALKFILE} >> ${CFILE}
# append footer