File pnp4nagios.spec of Package pnp4nagios

#
# spec file for package pnp4nagios 
#
# https://github.com/pnp4nagios/pnp4nagios (Fork)

%if %{?centos_version:1}0
%define init                    1
Requires:       chkconfig
Requires:	perl-Time-HiRes shadow-utils glibc-common
BuildRequires:  perl-Time-HiRes shadow-utils glibc-common
AutoReqProv:    no
%endif

%if 0%{?suse_version} >= 1315
BuildRequires:  unzip pwdutils aaa_base glibc
%endif

%if 0%{?rhel_version} == 800
BuildRequires:  unzip
%endif

Requires:       snagview-nagios

Name:  		pnp4nagios
Version:	0.6.25
Release:	3
License:	GPL-2.0-only
Summary:	RRDTools based performance charts
Group:		nagios/perfgraph
Source:		pnp4nagios-0.6.25.tar.gz	
BuildRoot:%{_tmppath}/%{name}-%{version}-build

BuildRequires:	rrdtool
#BuildRequires:	sv-nagios
BuildRequires:	-post-build-checks

Requires:	rrdtool
Requires:	sv-nagios

%define nagios_user nagios
%define nagios_group daemon

%description
PNP is an addon for the Nagios Network Monitoring System. PNP provides easy to use, easy to configure RRDTools based performance charts feeded by the performance data output of the Nagios Plugins.

%prep
cd %{_builddir}
tar -xf %{_sourcedir}/pnp4nagios-0.6.25.tar.gz

%build
cd %{_builddir}/pnp4nagios-0.6.25/
./configure --bindir=/usr/bin \
--sbindir=/usr/sbin \
--libexecdir=/var/lib/nagios/libexec \
--sysconfdir=/etc/npcd/ \
--localstatedir=/var \
--libdir=/usr/lib \
--includedir=/usr/include \
--with-nagios-user=%{nagios_user} \
--with-nagios-group=%{nagios_group} \
--with-perfdata-logfile=/var/log/nagios \
--with-perfdata-dir=/var/lib/nagios/perfdata \
--with-perfdata-spool-dir=/var/spool/nagios/perfdata \
--with-init-dir=/etc/init.d 



make all

%install
# Nagios user doesnt exist during build. Creating files with building user. See %files for install user;

# Make directories
install -c -m 755 -o abuild -g abuild -d %{buildroot}/usr/bin/
install -c -m 755 -o abuild -g abuild -d %{buildroot}/usr/lib64/
install -c -m 755 -o abuild -g abuild -d %{buildroot}/var/
#install -c -m 755 -o abuild -g abuild -d %{buildroot}/var/lib/nagios/perfdata/
#install -c -m 775 -o abuild -g abuild -d %{buildroot}/var/spool/nagios/perfdata/
install -c -m 755 -o abuild -g abuild -d %{buildroot}/usr/share/man/man8/
install -c -m 755 -o abuild -g abuild -d %{buildroot}/var/lib/nagios/libexec/

# Binary
install -c -m 754 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/src/npcd %{buildroot}/usr/bin/
strip %{buildroot}/usr/bin/npcd
# Objectfile
install -c -m 754 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/src/npcdmod.o %{buildroot}/usr/lib64/
strip %{buildroot}/usr/lib64/npcdmod.o
# Manual entry for npcd
install -c -m 644 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/man/npcd.8 %{buildroot}/usr/share/man/man8/
# Scripts
install -c -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/process_perfdata.pl %{buildroot}/var/lib/nagios/libexec/
install -c -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/check_pnp_rrds.pl %{buildroot}/var/lib/nagios/libexec/
install -c -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/rrd_convert.pl %{buildroot}/var/lib/nagios/libexec/
install -c -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/rrd_modify.pl %{buildroot}/var/lib/nagios/libexec/
# Initscript
# 2020-06-15 # Disable init scripts
#install -c -D -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/rc.npcd %{buildroot}/etc/init.d/npcd
#install -c -D -m 755 -o abuild -g abuild %{_builddir}/pnp4nagios-0.6.25/scripts/rc.pnp_gearman_worker %{buildroot}/etc/init.d/pnp_gearman_worker
install -D %{_sourcedir}/npcd.service %{buildroot}%{_unitdir}/npcd.service


# Config
install -D -m 644 -o abuild -g abuild %{_sourcedir}/npcd.conf %{buildroot}/etc/npcd/npcd.cfg
install -D -m 644 -o abuild -g abuild %{_sourcedir}/process_perfdata.cfg %{buildroot}/etc/npcd/process_perfdata.cfg
# Files and Directories needed while running
install -d -m 755 -o abuild -g abuild %{buildroot}/var/log/npcd/
install -d -m 775 -o abuild -g abuild %{buildroot}/var/lib/nagios/perfdata/
mkdir -p %{buildroot}/var/lib/nagios/
mkdir -p %{buildroot}/var/lib/nagios/perfdata-stats

install -D -o abuild -g abuild -m 644 %{_sourcedir}/npcd.logrotate %{buildroot}/etc/logrotate.d/npcd

%preun
# 2020-06-15 # Disable init scripts: /sbin/chkconfig --del npcd &>/dev/null
systemctl disable npcd

%pre
#getent group %{nagios_group} >/dev/null || groupadd -r %{nagios_group} 
#getent passwd %{nagios_user} >/dev/null || useradd -r %{nagios_user} -g %{nagios_group}

%post
getent group %{nagios_group} >/dev/null || groupadd -r %{nagios_group}
getent passwd %{nagios_user} >/dev/null || useradd -r %{nagios_user} -g %{nagios_group}
# 2020-06-15 # Disable init scripts: /sbin/chkconfig --add npcd &>/dev/null
systemctl enable npcd
%if 0%{?rhel_version} == 800
sed -s 's/tv_interval $t0, $t1/tv_interval $t0/g' -i  /var/lib/nagios/libexec/process_perfdata.pl
%endif


%files
%defattr (-, %{nagios_user}, %{nagios_group}, -)
%dir /var/log/npcd

#%dir /var/lib/nagios/perfdata
#%dir /var/spool/nagios/perfdata
%dir /var/lib/nagios/perfdata-stats

%{_bindir}/npcd
/usr/lib64/npcdmod.o
/usr/share/man/man8/npcd.8.gz
/var/lib/nagios/libexec/check_pnp_rrds.pl
/var/lib/nagios/libexec/process_perfdata.pl
/var/lib/nagios/libexec/rrd_convert.pl
/var/lib/nagios/libexec/rrd_modify.pl

%config(noreplace) %attr(0644,root,root) /etc/logrotate.d/npcd

%defattr (-, root, root, -)
%dir /etc/npcd
#/etc/init.d/npcd
#/etc/init.d/pnp_gearman_worker
%attr(0644,root,root) %{_unitdir}/npcd.service

%config(noreplace) /etc/npcd/npcd.cfg
%config(noreplace) /etc/npcd/process_perfdata.cfg

openSUSE Build Service is sponsored by