Skip to content

Commit

Permalink
Merge pull request #631 from narc-Ontakac2/debian
Browse files Browse the repository at this point in the history
Back to DEP-14
  • Loading branch information
narc-Ontakac2 authored Mar 5, 2024
2 parents b81f82b + dbf0ab0 commit 3fff08e
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
debian/ export-ignore
# This preserves the changlog during a merge (not during a rebase). It requires
# git config merge.ours.driver true
debian/changelog merge=ours
14 changes: 9 additions & 5 deletions .github/workflows/debuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
environment: main
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set env
# Here we are setting a variable from an expression.
run: echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
Expand All @@ -34,8 +34,10 @@ jobs:
gpg --keyserver $KEYSERVER --recv-key $CLOUD_KEY_ID
sudo -E gpg -v --output "$KEYFILE" --export $CLOUD_KEY_ID
sudo apt-get update
- name: update repo information
run: sudo apt-get update
- name: install devscripts
run: sudo apt-get install equivs devscripts pipx
run: sudo apt-get install equivs devscripts pipx hub
- name: install dependencies
run: sudo mk-build-deps -ri
- name: debuild
Expand Down Expand Up @@ -83,19 +85,21 @@ jobs:
needs: debuild
strategy:
matrix:
architecture: [armhf, arm64, amd64]
architecture: [armel, armhf, arm64, amd64]
distribution: [trixie, bookworm, bullseye]
runs-on: ubuntu-latest
environment: main
env:
PBRT: /var/cache/pbuilder
steps:
- name: update repo information
run: sudo apt-get update
- name: install pbuilder
run: |
sudo apt-get install pbuilder qemu-user-static \
debian-archive-keyring
debian-archive-keyring hub
# Needed for the release download
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set env
# Here we are setting a variable from an expression.
run: echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENDIF()

set(VZLOGGER_MAJOR_VERSION 0)
set(VZLOGGER_MINOR_VERSION 8)
set(VZLOGGER_SUB_VERSION 2)
set(VZLOGGER_SUB_VERSION 3)
set(VERSION_SEP "-")
set(VZLOGGER_SHORT_VERSION "${VZLOGGER_MAJOR_VERSION}${VERSION_SEP}${VZLOGGER_MINOR_VERSION}")
set(VZLOGGER_VERSION "${VZLOGGER_SHORT_VERSION}${VERSION_SEP}${VZLOGGER_SUB_VERSION}")
Expand Down
5 changes: 2 additions & 3 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
vzlogger (0.8.2-1) unstable; urgency=medium
vzlogger (0.8.3-1) unstable; urgency=medium

* Initial upload (Closes: #864255)

-- Joachim Zobel <[email protected]> Mon, 10 Jul 2023 16:53:23 +0200

-- Joachim Zobel <[email protected]> Mon, 04 Mar 2024 19:03:44 +0100
25 changes: 19 additions & 6 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ Source: vzlogger
Section: net
Priority: optional
Maintainer: Joachim Zobel <[email protected]>
Build-Depends: debhelper-compat (= 13), pkg-config (>= 0.25),
libjson-c-dev (>= 0.9), libcurl4-openssl-dev (>= 7.19),
libmicrohttpd-dev (>= 0.4.6), libsml-dev (>= 1.0), cmake, libsasl2-dev,
libssl-dev (>= 3.0), libgcrypt-dev, libgnutls28-dev, uuid-dev, libunistring-dev,
libgmock-dev, libgtest-dev, pandoc, libmosquitto-dev
Build-Depends: debhelper-compat (= 13),
pkgconf,
libjson-c-dev,
libcurl4-openssl-dev,
libmicrohttpd-dev (>= 0.4.6),
libsml-dev (>= 1.0),
cmake,
libsasl2-dev,
libssl-dev (>= 3.0),
libgcrypt-dev,
libgnutls28-dev,
uuid-dev,
libunistring-dev,
libgmock-dev,
libgtest-dev,
pandoc,
libmosquitto-dev
Standards-Version: 4.6.2
Rules-Requires-Root: no
Homepage: http://wiki.volkszaehler.org/software/controller/vzlogger
Vcs-Git: https://github.com/volkszaehler/vzlogger.git -b debian
Vcs-Browser: https://github.com/volkszaehler/vzlogger/tree/debian

Package: vzlogger
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, adduser, libsml1
Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
Pre-Depends: ${misc:Pre-Depends}
Description: program for logging measurements to a volkszaehler.org middleware
vzlogger...
Expand Down
8 changes: 6 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ override_dh_auto_configure:
dh_auto_configure -- -DBUILD_TEST=off
endif

override_dh_installsystemd:
# stop the service during install, see man dh_installsystemd
dh_installsystemd --no-restart-after-upgrade

ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test: ;
endif

execute_after_dh_auto_build:
pandoc -o vzlogger.1 -s -t man debian/vzlogger.1.md
pandoc -o vzlogger.8 -s -t man debian/vzlogger.8.md

execute_after_dh_clean:
rm -f vzlogger.1
rm -f vzlogger.8

%:
dh $@
2 changes: 2 additions & 0 deletions debian/source/lintian-overrides
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# May be odd, but I don't want to change the (non debian) past
odd-historical-debian-changelog-version *0.3.4-rc1*
# Having a debian watch file in the native package is easier to maintain
debian-watch-file-in-native-package *
3 changes: 3 additions & 0 deletions debian/vzlogger.1.md → debian/vzlogger.8.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
% VZLOGGER(8) Volkszaehler project | System management commands
% Joachim Zobel <[email protected]>

# NAME

vzlogger -- A tool to read and log measurements of a wide variety of smart meters and sensors
Expand Down
4 changes: 2 additions & 2 deletions debian/vzlogger.init
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DAEMON=/usr/bin/vzlogger
DAEMON_ARGS="-d" # Arguments to run the daemon with
#PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
USER=vzlogger
GROUP=vzlogger
USER=_vzlogger
GROUP=_vzlogger

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
Expand Down
2 changes: 1 addition & 1 deletion debian/vzlogger.manpages
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vzlogger.1
vzlogger.8
28 changes: 19 additions & 9 deletions debian/vzlogger.postinst
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#!/bin/sh -e

set -e

case "$1" in
configure)
if ! id vzlogger > /dev/null 2>&1 ; then
adduser --system --no-create-home --home /nonexistent \
--group --disabled-password --shell /bin/false \
vzlogger
usermod -a -G dialout vzlogger
if id vzlogger > /dev/null 2>&1 ; then
# maintain compatibility with existing native installations
usermod -l _vzlogger vzlogger
groupmod --new-name _vzlogger vzlogger
fi
if ! id _vzlogger > /dev/null 2>&1 ; then
adduser --quiet --system --no-create-home --home /nonexistent \
--group --disabled-password --shell /bin/false \
_vzlogger
usermod -a -G dialout _vzlogger
fi

touch /var/log/vzlogger.log
chown vzlogger:adm /var/log/vzlogger.log
touch /var/log/vzlogger.log
chown _vzlogger:adm /var/log/vzlogger.log
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "$0 called with unknown argument \`$1'" >&2
exit 1
echo "$0 called with unknown argument \`$1'" >&2
exit 1
;;
esac

#DEBHELPER#

exit 0

25 changes: 25 additions & 0 deletions debian/vzlogger.postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh -e

set -e

case "$1" in
purge)
rm -f /var/log/vzlogger.log*
;;

remove|abort-install|abort-upgrade|disappear)
;;

upgrade|failed-upgrade)
;;

*)
echo "$0 called with unknown argument \`$1'" >&2
exit 1
;;
esac

#DEBHELPER#

exit 0

4 changes: 2 additions & 2 deletions debian/vzlogger.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ After=network.target ntp.service

[Service]
ExecStart=/usr/bin/vzlogger -c /etc/vzlogger.conf
User=vzlogger
Group=vzlogger
User=_vzlogger
Group=_vzlogger
ExecReload=
StandardOutput=null

Expand Down
6 changes: 6 additions & 0 deletions etc/vzlogger_generic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@
"enum": ["avg", "max", "sum", "none"],
"description": "AVeraGe for power (W), MAXimum for meter (Wh), SUMmary for counter (S0)",
"default": "none"
},
"duplicates": {
"type": "integer",
"minimum": 0,
"default": 0,
"description": "default 0 (send duplicate values), >0 = send duplicate values only each <duplicates> seconds. Activate only for abs. counter values (Zaehlerstaende) and not for impulses!"
}
},
"required": ["api", "uuid", "identifier", "host"]
Expand Down
1 change: 1 addition & 0 deletions include/PushData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef __push_data_hpp_
#define __push_data_hpp_

#include <cstdint>
#include <list>
#include <pthread.h>
#include <queue>
Expand Down
4 changes: 4 additions & 0 deletions include/api/InfluxDB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class InfluxDB : public ApiIF {
std::list<Reading> _values;
CurlResponse::Ptr _response;

int64_t _last_timestamp; /* remember last timestamp */
// duplicates support:
Reading *_lastReadingSent;

typedef struct {
CURL *curl;
struct curl_slist *headers;
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pushd "$lib_dir"
echo "libmosquitto-dev is not installed"
exit 1
else
cmake_args="${cmake_args} -ENABLE_MQTT=on"
cmake_args="${cmake_args} -DENABLE_MQTT=on"
fi
fi

Expand Down
75 changes: 60 additions & 15 deletions src/api/InfluxDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
extern Config_Options options;

vz::api::InfluxDB::InfluxDB(const Channel::Ptr &ch, const std::list<Option> &pOptions)
: ApiIF(ch), _response(new vz::api::CurlResponse()) {
: ApiIF(ch), _response(new vz::api::CurlResponse()), _last_timestamp(0), _lastReadingSent(0) {
OptionList optlist;
print(log_debug, "InfluxDB API initialize", ch->name());

Expand Down Expand Up @@ -278,6 +278,10 @@ void vz::api::InfluxDB::send() {
print(log_debug, "cleaned buffer, now %i items", channel()->name(), buf->size());
}

int64_t timestamp = 1;
const int duplicates = channel()->duplicates();
const int duplicates_ms = duplicates * 1000;

// build request body from buffer contents
buf->lock();
for (it = buf->begin(); it != buf->end(); it++) {
Expand All @@ -286,25 +290,66 @@ void vz::api::InfluxDB::send() {
channel()->name());
break;
}

bool sendData = false;

timestamp = it->time_ms();

print(log_finest, "Reading buffer: timestamp %lld value %f", channel()->name(),
it->time_ms(), it->value());
request_body.append(_measurement_name);
if (_send_uuid) {
request_body.append(",uuid=");
request_body.append(channel()->uuid());

print(log_debug, "compare: %lld %lld", channel()->name(), _last_timestamp, timestamp);
// we can only add/consider a timestamp if the ms resolution is not before than from
// previous one:
if (_last_timestamp <= timestamp) {
if (0 == duplicates) { // send all values
sendData = true;
_last_timestamp = timestamp;
} else {
const Reading &r = *it;
// duplicates should be ignored
// but send at least each <duplicates> seconds

if (!_lastReadingSent) { // first one from the duplicate consideration -> send it
sendData = true;
_lastReadingSent = new Reading(r);
_last_timestamp = timestamp;
} else { // one reading sent already. compare
// a) timestamp
// b) duplicate value
if ((timestamp >= (_last_timestamp + duplicates_ms)) ||
(r.value() != _lastReadingSent->value())) {
// send the current one:
sendData = true;
_last_timestamp = timestamp;
*_lastReadingSent = r;
} else {
// ignore it
}
}
}
}
if (!_tags.empty()) {
request_body.append(",");
request_body.append(_tags);

if (sendData) {
request_body.append(_measurement_name);
if (_send_uuid) {
request_body.append(",uuid=");
request_body.append(channel()->uuid());
}
if (!_tags.empty()) {
request_body.append(",");
request_body.append(_tags);
}
std::stringstream value_str;
value_str << " value=" << std::fixed << std::setprecision(6) << it->value();
request_body.append(value_str.str());
request_body.append(" ");
request_body.append(std::to_string(timestamp));
request_body.append("\n"); // each measurement on new line
request_body_lines++;
}
std::stringstream value_str;
value_str << " value=" << std::fixed << std::setprecision(6) << it->value();
request_body.append(value_str.str());
request_body.append(" ");
request_body.append(std::to_string(it->time_ms()));
request_body.append("\n"); // each measurement on new line

it->mark_delete();
request_body_lines++;
}

buf->unlock();
Expand Down
Loading

0 comments on commit 3fff08e

Please sign in to comment.