File nsca.spec of Package nsca

#
# spec file for package nsca
#
# Copyright (c) 2021 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/
#


%bcond_without systemd

#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
Name:           nsca
Version:        2.10.3
Release:        0
Summary:        The Nagios Service Check Acceptor
License:        GPL-2.0-or-later
Group:          System/Monitoring
URL:            https://www.nagios.org/
Source0:        %{name}-%{version}.tar.gz
Source1:        rcnsca
Source3:        nsca-SuSEfirewall2
Source4:        send_nsca.1
Source5:        nsca.1
Source6:        usr.bin.nsca
Source7:        nsca.service
Source8:        nsca-sysconfig
# PATCH-FIX-OPENSUSE disable the xinetd service per default - in that case it is also not
# needed to bind on any specific address
Patch2:         nsca.xinetd.patch
# PATCH-FIX-OPENSUSE adapt the spool directory to follow openSUSE guidelines
Patch3:         nsca.spooldir.patch
# PATCH-FIX-UPSTREAM - make sure there are no extraneous group memberships when dropping root privileges
Patch4:         nsca-clean-setgroups.patch
# PATCH-FIX-UPSTREAM - https://github.com/NagiosEnterprises/nsca/pull/50
#Patch5:         send_nsca_implicit_declaration.patch
BuildRequires:  nagios-rpm-macros
BuildRequires:  tcpd-devel
Requires(post): %fillup_prereq
Recommends:     apparmor-parser
Recommends:     monitoring_daemon
Provides:       nagios-nsca = %{version}
Obsoletes:      nagios-nsca < 2.9.0
%if %suse_version < 1500
BuildRequires:  libmcrypt-devel
%endif
%if 0%{?suse_version}
Requires(pre):  %fillup_prereq
%endif
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build


%description
The purpose of this add-on is to allow the execution of NetSaint and
Nagios plug-ins on a remote host in a manner that is as transparent as
possible. This is the server part including the daemon without the
client program.

%package client
Summary:        The Nagios Service Check Acceptor Client
Group:          System/Monitoring
Provides:       nagios-nsca-client = %{version}
Obsoletes:      nagios-nsca-client < 2.9.0

%description client
The purpose of this add-on is to allow the execution of NetSaint and
Nagios plug-ins on a remote host in a manner that is as transparent as
possible. This package includes only the client program.

%prep
%autosetup -p1

%build
export CFLAGS="%{optflags}"
export CFLAGS="$CFLAGS -fstack-protector"
%configure \
	--sysconfdir=%{_sysconfdir} \
	--localstatedir=%{nagios_spooldir} \
	--with-nsca-user=%{nagios_user} \
	--with-nsca-grp=%{nagios_group} \
	--with-nsca-port=5667
make all

%install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_sbindir}
mkdir -p %{buildroot}%{_sysconfdir}/apparmor.d/local
mkdir -p %{buildroot}%{_initddir}/
mkdir -p %{buildroot}%{_sysconfdir}/xinetd.d/
mkdir -p %{buildroot}%{_fillupdir}
install -m 755 src/nsca %{buildroot}%{_bindir}/
install -m 755 src/send_nsca %{buildroot}%{_bindir}/
install -m 644 sample-config/nsca.cfg %{buildroot}%{_sysconfdir}/
install -m 644 sample-config/send_nsca.cfg %{buildroot}%{_sysconfdir}/
install -m 644 sample-config/nsca.xinetd %{buildroot}%{_sysconfdir}/xinetd.d/nsca
install -m 644 %{SOURCE8} %{buildroot}%{_fillupdir}/sysconfig.nsca
# startup scripts
install -Dm0644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}.service
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
# sysconfig file
install -D -m 0644 %{SOURCE8} %{buildroot}%{_fillupdir}/sysconfig.%{name}
# install SuSEfirewall2 script
%if 0%{?suse_version} <= 1500
install -Dm644 %{SOURCE3} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
# install man pages
install -Dm644 %{SOURCE4} %{buildroot}%{_mandir}/man1/send_nsca.1
install -m644  %{SOURCE5} %{buildroot}%{_mandir}/man1/nsca.1
# install apparmor profile
install -Dm644 %{SOURCE6} %{buildroot}%{_sysconfdir}/apparmor.d/usr.bin.nsca
echo "# Site-specific additions and overrides for 'usr.bin.nsca'" > %{buildroot}%{_sysconfdir}/apparmor.d/local/usr.bin.nsca

%pre
%service_add_pre %{name}.service

%post
%{fillup_only nsca}
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%triggerun -- nagios-nsca < 2.9.2
STATUS='%{_localstatedir}/adm/update-scripts/%{name}'

if [ -x %{_bindir}/systemctl ]; then
	%{_bindir}/systemctl status nsca.service >/dev/null
	if test $? = 0; then
		echo "%{_bindir}/systemctl restart nsca.service" >> "$STATUS"
	else
        touch "$STATUS"
    fi
	%{_bindir}/systemctl status xinetd.service >/dev/null
	if test $? = 0; then
		echo "%{_bindir}/systemctl try-restart xinetd.service" >> "$STATUS"
	else
        touch "$STATUS"
    fi
    chmod +x "$STATUS"
fi

%triggerpostun -- nagios-nsca < 2.9.2
# Move /etc/nagios/nsca.conf to /etc/nsca.conf when updating from an old version
# and inform the admin about the move.
cd %{_sysconfdir}
if test -e nagios/nsca.conf.rpmsave -a ! -e nsca.conf.rpmnew; then
    mv nsca/nsca.conf nsca.conf.rpmnew
    mv nagios/nsca.conf.rpmsave nsca.conf
    test -L %{nagios_sysconfdir}/nsca.conf || ln -s %{_sysconfdir}/nsca.conf %{nagios_sysconfdir}/nsca.conf
fi
sed -i "s|%{nagios_sysconfdir}/nsca.cfg|%{_sysconfdir}/nsca.cfg|g" %{_sysconfdir}/xinetd.d/nsca || :
if [ -e %{_localstatedir}/adm/update-scripts/%{name} ]; then
    /bin/sh %{_localstatedir}/adm/update-scripts/%{name}
    rm %{_localstatedir}/adm/update-scripts/%{name}
fi

%triggerpostun -- nagios-nsca-client < 2.9.2
# Move /etc/nagios/send_nsca.cfg to /etc/send_nsca.cfg when updating from an old version
# and inform the admin about the move.
cd %{_sysconfdir}
if test -e nagios/send_nsca.cfg.rpmsave -a ! -e send_nsca.cfg.rpmnew; then
	mv nsca/send_nsca.cfg send_nsca.cfg.rpmnew
	mv nagios/send_nsca.cfg send_nsca.cfg
    test -L %{nagios_sysconfdir}/send_nsca.cfg || ln -s %{_sysconfdir}/send_nsca.cfg %{nagios_sysconfdir}/send_nsca.cfg
fi

%check
%{buildroot}%{_bindir}/send_nsca -h || :

%files
%defattr(-,root,root)
%doc CHANGELOG.md CONTRIBUTORS.md README.md SECURITY.md
%license LICENSE.md
%dir %{_sysconfdir}/apparmor.d
%dir %{_sysconfdir}/apparmor.d/local
%{_bindir}/nsca
%if %{with systemd}
%{_unitdir}/%{name}.service
%else
%{_sysconfdir}/init.d/nsca
%endif
%{_sbindir}/rcnsca
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.bin.nsca
%config(noreplace) %{_sysconfdir}/apparmor.d/local/usr.bin.nsca
%config(noreplace) %{_sysconfdir}/nsca.cfg
%if 0%{?suse_version} >= 1500
%dir %{_sysconfdir}/xinetd.d
%endif
%config(noreplace) %{_sysconfdir}/xinetd.d/nsca
%if 0%{?suse_version} <= 1500
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
%{_fillupdir}/sysconfig.%{name}
%{_mandir}/man1/nsca.1%{?ext_man}

%files client
%defattr(-,root,root)
%{_bindir}/send_nsca
%{_mandir}/man1/send_nsca.1%{?ext_man}
%config(noreplace) %{_sysconfdir}/send_nsca.cfg

%changelog
openSUSE Build Service is sponsored by