moved from snmp2c to snmp3

This commit is contained in:
mischa 2022-09-24 10:47:34 +02:00
parent 1b9785b66c
commit 2c6743b8db
9 changed files with 39 additions and 100 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -16,7 +16,9 @@
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
RRDFILES="/home/mischa/rrd"
IMAGES="/var/www/rrdtool/obsda.ms"
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
@ -45,7 +47,7 @@ ${RRDTOOL} create ${RRDFILES}/${HOST}-cores.rrd \
RRA:MAX:0.5:1:20000
fi
snmp walk -v2c -c ${COMMUNITY} ${HOST} hrProcessorLoad | awk '{print $4}' > ${CPUINFO}
snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrProcessorLoad | awk '{print $4}' > ${CPUINFO}
CORES=$(cat ${CPUINFO} | wc -l)
ACT_CORES=$((${CORES}/2))
CPU_LOAD=$(cat ${CPUINFO} | paste -s -d: - | cut -d: -f1-${ACT_CORES})

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -16,7 +16,9 @@
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
RRDFILES="/home/mischa/rrd"
IMAGES="/var/www/rrdtool/obsda.ms"
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
@ -35,7 +37,7 @@ ${RRDTOOL} create ${RRDFILES}/${HOST}-cpu.rrd \
RRA:MAX:0.5:1:20000
fi
snmp walk -v2c -c ${COMMUNITY} ${HOST} hrProcessorLoad | awk '{print $4}' > ${CPUINFO}
snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrProcessorLoad | awk '{print $4}' > ${CPUINFO}
CORES=$(grep -cv "^0$" ${CPUINFO})
CPU_LOAD_SUM=$(awk '{sum += $1} END {print sum}' ${CPUINFO})
CPU_LOAD=$(echo "scale=2; ${CPU_LOAD_SUM}/${CORES}" | bc -l)

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -14,10 +14,12 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Get list of interfaces with: snmp walk -v2c -c public <host> ifDescr
# Get list of interfaces with: snmp walk -A <authpass> -l authPriv -u <user> -X <privpass> <host> ifDescr
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
snmp walk -v2c -c ${COMMUNITY} ${HOST} ifDescr
snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} ifDescr

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -14,13 +14,13 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Get list of interfaces with: snmp walk -v2c -c public <host> ifDescr
#
test -n "$1" || exit 1
test -n "$2" || exit 1
HOST="$1"
INTERFACE="$2"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
RRDFILES="/home/mischa/rrd"
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
IMAGES="/var/www/rrdtool/obsda.ms"
@ -46,9 +46,9 @@ ${RRDTOOL} create ${RRDFILES}/${HOST}-${INTERFACE}.rrd \
RRA:MAX:0.5:288:797
fi
IN=$(snmp walk -v2c -c ${COMMUNITY} ${HOST} ifInOctets.${INTERFACE} | awk '{print $4}')
OUT=$(snmp walk -v2c -c ${COMMUNITY} ${HOST} ifOutOctets.${INTERFACE} | awk '{print $4}')
DESCR=$(snmp walk -v2c -c ${COMMUNITY} ${HOST} ifDescr.${INTERFACE} | awk '{print $4}')
IN=$(snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} ifInOctets.${INTERFACE} | awk '{print $4}')
OUT=$(snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} ifOutOctets.${INTERFACE} | awk '{print $4}')
DESCR=$(snmp walk -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} ifDescr.${INTERFACE} | awk '{print $4}')
${RRDTOOL} update ${RRDFILES}/${HOST}-${INTERFACE}.rrd N:${IN}:${OUT}

View File

@ -1,73 +0,0 @@
#!/bin/sh
#
# Copyright (c) 2019-2020 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Get list of interfaces with: snmpctl snmp walk <host> community public oid ifDescr
#
test -n "$1" || exit 1
test -n "$2" || exit 1
HOST="$1"
INTERFACE="relayd"
COMMUNITY="public"
RRDFILES="/home/mischa/relayd"
WATERMARK="OpenBSD Amsterdam - https://obsda.ms"
IMAGES="/var/www/rrdtool/obsda.ms"
RRDTOOL="/usr/local/bin/rrdtool"
NOW=$(date "+%Y-%m-%d %H:%M:%S %Z" | sed 's/:/\\:/g')
if ! test -f "${RRDFILES}/${HOST}-${INTERFACE}.rrd"
then
echo "Creating ${RRDFILES}/${HOST}-${INTERFACE}.rrd"
${RRDTOOL} create ${RRDFILES}/${HOST}-${INTERFACE}.rrd \
--step 300 \
DS:ds0:COUNTER:600:0:1250000000 \
DS:ds1:COUNTER:600:0:1250000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
fi
IN=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid ifInOctets.${INTERFACE} | cut -d= -f2)
OUT=$(snmpctl snmp get ${HOST} community ${COMMUNITY} oid ifOutOctets.${INTERFACE} | cut -d= -f2)
DESCR="TEST"
${RRDTOOL} update ${RRDFILES}/${HOST}-${INTERFACE}.rrd N:${IN}:${OUT}
${RRDTOOL} graph ${IMAGES}/${HOST}-${INTERFACE}.png \
--start -43200 \
--title "${HOST} - ${VERSION} - ${DESCR}" \
--vertical-label "Bits per Second" \
--watermark "${WATERMARK}" \
--color BACK#ffffff \
--border 0 \
DEF:IN=${RRDFILES}/${HOST}-${INTERFACE}.rrd:ds0:AVERAGE \
DEF:OUT=${RRDFILES}/${HOST}-${INTERFACE}.rrd:ds1:AVERAGE \
CDEF:IN_CDEF="IN,8,*" \
CDEF:OUT_CDEF="OUT,8,*" \
AREA:IN_CDEF#00FF00:"In " \
GPRINT:IN_CDEF:MAX:"Max\:%5.2lf %s" \
GPRINT:IN_CDEF:AVERAGE:"Average\:%5.2lf %s" \
GPRINT:IN_CDEF:LAST:" Current\:%5.2lf %s\n" \
LINE2:OUT_CDEF#0000FF:"Out" \
GPRINT:OUT_CDEF:MAX:"Max\:%5.2lf %s" \
GPRINT:OUT_CDEF:AVERAGE:"Average\:%5.2lf %s" \
GPRINT:OUT_CDEF:LAST:" Current\:%5.2lf %s\n" \
COMMENT:"\\n" \
COMMENT:" Up for ${UPTIME} at ${NOW}"

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -15,7 +15,9 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
HOST="s1.obsda.ms"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
#15259107187 / 8640000 = days (+remainder) = 176.6107855324074
#0.6107855324074 * 24 = hours (+remainder) = 14.65885277777778
@ -23,7 +25,7 @@ COMMUNITY="public"
#0.53116666666667 * 60 = seconds.milliseconds = 31.87
echo
TICKS=$(snmp get -v2c -c ${COMMUNITY} ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
TICKS=$(snmp get -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
echo "TICKS: $TICKS"
TICKS="1193085988"

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -16,11 +16,13 @@
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
UPTIMEINFO="/tmp/${HOST}-uptime.txt"
rm -rf ${UPTIMEINFO}
TICKS=$(snmp get -v2c -c ${COMMUNITY} ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
TICKS=$(snmp get -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
DAYS=$(echo "${TICKS}/8640000" | bc -l)
HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@ -16,7 +16,9 @@
#
test -n "$1" || exit 1
HOST="$1"
COMMUNITY="public"
AUTHPASS="tropic shark reefs"
USER="random"
PRIVPASS="equ5xerhiffid7klevuk"
VERSIONINFO="/tmp/${HOST}-version.txt"
snmp get -v2c -c ${COMMUNITY} ${HOST} sysDescr.0 | awk '{print $6,$7}' > ${VERSIONINFO}
snmp get -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} sysDescr.0 | awk '{print $6,$7}' > ${VERSIONINFO}

View File

@ -17,7 +17,7 @@
#*/5 * * * * -n /home/mischa/rrdtool/wrapper.sh
#
SCRIPTS="/home/mischa/rrdtool"
SERVERS="16 1"
SERVERS="18 1"
MEGA="1 1"
# SERVERS