# Contributor: Katie Holly <holly@fuslvz.ws>
# Maintainer: Konstantin Kulikov <k.kulikov2@gmail.com>
pkgname=telegraf
pkgver=1.34.4
pkgrel=0
_commit=e7ce1e1e7 # git rev-parse --short HEAD
_branch=release-${pkgver%.*}
pkgdesc="A plugin-driven server agent for collecting & reporting metrics, part of the InfluxDB project"
url="https://www.influxdata.com/time-series-platform/telegraf/"
arch="x86_64 aarch64"
license="MIT"
makedepends="go linux-headers"
checkdepends="tzdata bash"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
options="net"
source="telegraf-$pkgver.tar.gz::https://github.com/influxdata/telegraf/archive/v$pkgver.tar.gz
	telegraf.initd
	telegraf.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local pkg="github.com/influxdata/telegraf/internal"
	local ldflags="-X $pkg.Version=$pkgver -X $pkg.Branch=$_branch -X $pkg.Commit=$_commit"
	go build -ldflags "$ldflags" ./cmd/telegraf

	# Generate sample config.
	./telegraf config >telegraf.conf
}

check() {
	# plugins/processors/scale: broken with 8.2 != 8.2000000000000001 on arm
	# plugin/outputs/sql: mismatched metric count in test; 1 != 6
	# shellcheck disable=2046
	go test -short $(go list ./... | grep -Ev '(plugins/processors/scale|plugins/outputs/sql)')
}

package() {
	install -Dm755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
	install -Dm755 "$builddir/$pkgname" "$pkgdir/usr/bin/$pkgname"
	install -Dm644 "$builddir/$pkgname.conf" "$pkgdir/etc/$pkgname.conf"
	install -dm755 "$pkgdir/etc/$pkgname.conf.d"
	install -Dm644 "$builddir/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

sha512sums="
9c52f9b42875a4c78bd7f8a11cdb31b91218c043ae6d66505653c4ddad4b499d1d0b8e65efce8dd2f721f611022b199ec32e6d16640c3a079d8e3854951fbefd  telegraf-1.34.4.tar.gz
abe483deb8e12fe140de2c36d17bbfbc97ed7a5de8c3d76162357f7ba6575b8236b7197b92a26ed6d54f95c1ccbfc12ca62d6cc0371bf49d10a1ea5622a51ed1  telegraf.initd
d1a9aa57f8b5179f2d8396518b9db757fe1c40337b515c1f750cf577683ff15f3174bc757afa70d880a1fef809c873e6aa0da1b903a5a97934c14965712d47a4  telegraf.confd
"
