File prometheus-json_exporter.spec of Package prometheus-json_exporter

#
# spec file for package prometheus-json_exporter
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%{go_nostrip}

%bcond_without  apparmor

Name:           prometheus-json_exporter
Version:        0.5.0
Release:        0
Summary:        Prometheus exporter for JSON metrics
License:        Apache-2.0
Group:          System/Management
URL:            https://github.com/prometheus-community/json_exporter
Source:         json_exporter-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        prometheus-json_exporter.service
Source3:        apparmor-usr.bin.json_exporter
Source4:        prometheus-json_exporter.sysconfig
Source5:        config.yml
BuildRequires:  fdupes
BuildRequires:  golang-packaging
BuildRequires:  golang(API)
%{?systemd_ordering}
Requires(post): %fillup_prereq
Requires(pre):  shadow
%if %{with apparmor}
BuildRequires:  apparmor-abstractions
BuildRequires:  apparmor-rpm-macros
Recommends:     apparmor-abstractions
%endif
%{go_provides}
Provides:       json_exporter
Provides:       prometheus(json_exporter)

%description
A prometheus exporter which scrapes remote JSON by JSONPath.

%prep
%autosetup -a1 -p1 -n json_exporter-%{version}

%build
%goprep github.com/prometheus-community/json_exporter
%gobuild -mod=vendor "" ...

%install
%goinstall
install -D -m 0755 %{_builddir}/go/bin/json_exporter %{buildroot}/%{_bindir}/json_exporter
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/prometheus-json_exporter.service
%if %{with apparmor}
# AppArmor profile
mkdir -p %{buildroot}%{_sysconfdir}/apparmor.d
install -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/apparmor.d/usr.bin.json_exporter
%endif
install -D -m 0644 %{SOURCE4} %{buildroot}%{_fillupdir}/sysconfig.prometheus-json_exporter
install -D -m0644 %{SOURCE5} %{buildroot}%{_sysconfdir}/prometheus/json_exporter.yml
%fdupes %{buildroot}

%check
%gotest github.com/prometheus-community/json_exporter -mod=vendor

%pre
%service_add_pre prometheus-json_exporter.service
getent group prometheus >/dev/null || %{_sbindir}/groupadd -r prometheus
getent passwd prometheus >/dev/null || %{_sbindir}/useradd -r -g prometheus -d %{_localstatedir}/lib/prometheus -M -s /sbin/nologin prometheus

%post
%service_add_post prometheus-json_exporter.service
%fillup_only -n prometheus-json_exporter
%if %{with apparmor}
%apparmor_reload %{_sysconfdir}/apparmor.d/usr.bin.json_exporter
%endif

%preun
%service_del_preun prometheus-json_exporter.service

%postun
%service_del_postun prometheus-json_exporter.service

%files
%doc README.md
%license LICENSE
%{_bindir}/json_exporter
%{_unitdir}/prometheus-json_exporter.service
%{_fillupdir}/sysconfig.prometheus-json_exporter
%dir %{_sysconfdir}/prometheus
%config(noreplace) %{_sysconfdir}/prometheus/json_exporter.yml
%if %{with apparmor}
%dir %{_sysconfdir}/apparmor.d
%config %{_sysconfdir}/apparmor.d/usr.bin.json_exporter
%endif

%changelog
openSUSE Build Service is sponsored by