Update der Datei log_apcupsd.sh. Vollständige Pfadangabe notwendig, wenn Datei von /etc/cron.d/XXX aus aufgerufen wird. Umbenennung des Skriptes zum Importieren der Logdaten in vz-import_apcupsd.sh. Im Anhang außerdem meine /etc/cron.d/log_apcupsd, welche nun zusätzlich nächtlich die Daten des letzten Tages in den Volkszaehler schreibt.
Grüße Lars On Sat, 3 Oct 2015 21:20:46 +0200 alex <a...@elaon.de> wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Cool danke, dass kann ich gebrauchen. > > Lg > alex > > Am 03.10.2015 um 21:06 schrieb Lars Täuber: > > Hallo zusammen, > > für Interessenten habe ich im Anhang zwei Skripte. Das > > erste wird > hier per Cron jede Minute aufgerufen und fragt apcupsd nach Werten der > APC-USV. Das zweite Skript schreibt dann die gelogten Daten der USV > (Temperatur, Strom, Netzspannung, Restlaufzeit, Batteriespannung usw.) > in den Vokszaehler. > > Schöne Grüße > Lars > > - -- > Diese Nachricht wurde mit GnuPG unterschrieben. > Verwende GnuPG um mir eine verschlüsselte Nachricht zu senden. > Meinen öffentlichen Schlüssel hab ich als Anhang beigefügt. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2 > > iQIcBAEBCAAGBQJWECqOAAoJECLKk62ZWLvuWbEP/2aaNZVNuNJo3VrKLprYemVC > CFQq3P7yaD4X1VCpCqMG64jhdd0HRdXU9Xv1I9AviVpNW4Z9Fb8yTNJTL/zY1YTC > Dhr1d7YkUrvOkyi4piUL/xvs+YnSm9kcwdkTGHbgOlAWA/X1KJL3AjHJbBpBiwLi > auundhdN7Xyf5P/FW6uJ01oxo5zgA8qNZyZNo4PFfcCkKWt7vAn98AWDHROGQBZi > uXdTirye7Ul/9+8j2ANxTAFY+lNx7IySplTs+Ug+fcHQRhJkbg7y/fWGEKE9EckJ > /aMoc95kfggYwdaHyX9QhuBCb3rhg/BaV09/7/uT5Up3whwg6lILdz9KJZoZdQb/ > gsDDM9mzXp15/0LkqLbA4mxoLaK96Haw/jcB0NJHTOBJG7CoqnnDWlsdbuCxf3NF > GRNqzdy8MBn8DwZ8GUaGZhTmW7QwLicfLUpEiqe2L1OV/fJuCto/SAiLSNyFRTg3 > Is0UhMIJKMtfYydkvMRV/fujSRe4vWhUENuDiDmexHvGAqc6mnZ5mhK7iP8qqBXb > LtNV/t6rAJn1Y1pH0VuGUgtGd2g6VYSFR2c+xWNdLc2lKvkwP62JOXvIwxWUl0tL > 8kEE0G7VMSFbrkpxDNd1uIGKUEnRYB/KZHXObPTAgeRzf10lpA6AY7Q9zQVmVPh+ > bFuz3IIaqXD9X4azRh25 > =GiHp > -----END PGP SIGNATURE----- > -- Schöne Grüße Lars Täuber
log_apcupsd
Description: Binary data
#!/bin/bash # # # log the whole output of the UPS to a log file # # example conjob: # # * * * * * root /usr/local/bin/log_apcupsd.sh # LOG_FILE="/srv/apcupsd/$(date "+%Y-%m").log" APCACCESS=/sbin/apcaccess if [ ! -e "$LOG_FILE" ] # first log - write logfile index then LINE=$($APCACCESS | sed -e 's/ *: .*//' | tr '\n' \;) echo "${LINE%;}" >> "$LOG_FILE" fi LINE=$($APCACCESS | sed -e 's/[^:]*: *//' -e 's/ *$//' | tr '\n' \; ) echo "${LINE%;}" >> "$LOG_FILE"
#!/bin/bash # # This is a simple bash script to read Dimplex heat pump logs # log their values to the volkszaehler project. # # call it similiar like this: # # vz-import_apcupsd.sh [-] < logfile [ 2>/dev/null ] # # vz-import_apcupsd.sh logfile [logfile2] [...] [ 2>/dev/null ] # # @copyright Copyright (c) 2011, The volkszaehler.org project # @package controller # @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @author Lars Täuber # modifications from the original file log_dimplex.sh # # # This file is part of volkzaehler.org # # volkzaehler.org 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 3 of the License, or # any later version. # # volkzaehler.org 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 volkszaehler.org. If not, see <http://www.gnu.org/licenses/>. ## ## configuration # # middleware url URL="https://127.0.0.1/vz/middleware.php" # apcupsd sensor id => volkszaehler.org uuid # Values to UUIDs declare -A UUID UUID["Load"]="2ae31350-6627-11e5-ab1d-b376d13f71ec" UUID["Temp"]="edf45420-6626-11e5-a762-8bbd1e8e1c8b" UUID["TimeLeft"]="" UUID["BattCharge"]="70604890-6627-11e5-83bc-7f8c7ddfecaf" UUID["BattVolt"]="3fb84450-6627-11e5-88a3-d51bc1dd91b8" UUID["LineVolt"]="" UUID["LineFreq"]="" # additional options for curl # specify credentials, proxy etc here CURL_OPTS="-k" # uncomment this for a more verbose output #DEBUG=1 DEBUG_ONCE=$DEBUG+1 # ========= do not change anything under this line ============== declare -A INDEX INDEX["Load"]="LOADPCT" INDEX["Temp"]="ITEMP" INDEX["TimeLeft"]="TIMELEFT" INDEX["BattCharge"]="BCHARGE" INDEX["BattVolt"]="BATTV" INDEX["LineVolt"]="LINEV" INDEX["LineFreq"]="LINEFREQ" INDEX["Date"]="END APC" declare -A CALC CALC["Load"]='awk "{print \$1*450/100}"' # 450 Watts max power of USV CALC["Temp"]='sed "s/ .*//"' CALC["TimeLeft"]='sed "s/ .*//"' CALC["BattCharge"]='sed "s/ .*//"' CALC["BattVolt"]='sed "s/ .*//"' CALC["LineVolt"]='sed "s/ .*//"' CALC["LineFreq"]='sed "s/ .*//"' [ $# -eq 0 ] && set - "/dev/stdin" if [ $DEBUG ] then echo "enabling debugging output" echo -e "reading logs from:\t${1/#-*//dev/stdin}" fi O_IFS="$IFS" IFS=";" while [ $# -gt 0 ] do unset COLUMN declare -A COLUMN if [ "$1" = "${1#-}" ] then exec 3< "$1" echo "working on $1" else exec 3<&1 echo "working on stdin" fi read -a LINE -u 3 if [ "${LINE[0]}" != "APC" ] then echo "${1/#-*//dev/stdin} is not in dimplex log format. Skipping!" else for I in "${!INDEX[@]}" do for J in "${!LINE[@]}" do if [ "${INDEX[$I]}" = "${LINE[$J]}" ] then COLUMN[$I]="$J" fi done done while read -a LINE -u 3 do TS=`date +%s000 -d "${LINE[${COLUMN["Date"]}]% *}"` for I in "${!COLUMN[@]}" do test "$I" = "Date" && continue # we use it only for TS calculation if [ -z "${UUID[$I]}" ] then [ -n "$DEBUG_ONCE" ] && \ echo "value $I is not mapped to an uuid! Add the mapping to the array." >&2 continue fi VALUE=$(echo ${LINE[${COLUMN[$I]}]} | eval ${CALC[$I]}) REQUEST_URL="${URL}/data/${UUID[$I]}.json?value=$VALUE&ts=${TS}${URL_PARAMS}${DEBUG:+&debug=1}" if [ -n "$DEBUG" ] then echo -e "logging sensor:\t\t$I}" echo -e "with value:\t\t${LINE[${COLUMN[$I]}]}" echo -e "at:\t\t\t${LINE[0]}" echo -e "with request:\t\t${REQUEST_URL}" fi curl ${CURL_OPTS} --data "" "${REQUEST_URL}" >&2 done echo -en "\r${LINE[${COLUMN["Date"]}]% *}" DEBUG_ONCE="" done fi exec 3<&- shift done IFS="$O_IFS"