File nrpe.spec of Package nrpe

#
# spec file for package nrpe
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#


#       default
%define nagios3only 0
# Macro that print mesages to syslog at package (un)install time
%define nnmmsg logger -t %{name}/rpm
%define nrpeport 5666
%if ! %{defined _rundir}
%define _rundir %{_localstatedir}/run
%endif

%if 0%{?suse_version} >= 1210
%bcond_without systemd
%else
%bcond_with systemd
%endif


Name:           nrpe
Version:        2.15
Release:        0
Summary:        Nagios Remote Plug-In Executor
License:        GPL-2.0+
Group:          System/Monitoring
Url:            http://www.nagios.org/
Source0:        nrpe-%{version}.tar.bz2
Source1:        nrpe.init
Source2:        nagios-nrpe-rpmlintrc
Source3:        nagios-nrpe-SuSEfirewall2
Source4:        nrpe.8
Source5:        check_nrpe.cfg
Source6:        nrpe.service
Source7:        nrpe@.service
Source8:        nrpe.socket
Source10:       README.SUSE
Source11:       README.SUSE.systemd-addon
# PATCH-FIX-openSUSE place the service disabled in the directory
Patch1:         nrpe-xinetd.patch
# PATCH-FIX-openSUSE adapts NRPE to support the standard buffersize of Nagios 3.x
Patch2:         nagios-nrpe-buffersize.patch
# PATCH-FIX-UPSTREAM produce more randomness and do not reduce entropy on Linux kernels
Patch3:         nrpe-more_random.patch
# PATCH-FIX-UPSTREAM improve help output of nrpe and check_nrpe
Patch4:         nrpe-improved_help.patch
# PATCH-FIX-UPSTREAM null buffer before using it
Patch5:         nrpe-weird_output.patch
# PATCH-FIX-UPSTREAM drop privileges before writing the pidfile for more safety
Patch6:         nrpe-drop_privileges_before_writing_pidfile.patch
# PATCH-FIX-openSUSE fix pathnames for nrpe_check_control command
Patch10:        nrpe_check_control.patch
# PATCH-FIX-UPSTREAM using implicit definitions of functions
Patch11:        nrpe-implicit_declaration.patch
PreReq:         %fillup_prereq
PreReq:         %insserv_prereq
PreReq:         /bin/logger
PreReq:         coreutils
PreReq:         grep
PreReq:         netcfg
PreReq:         pwdutils
PreReq:         sed
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} > 1130
%if 0%{?suse_version} <= 1230
PreReq:         sysvinit(network)
PreReq:         sysvinit(syslog)
%endif
%endif
#
BuildRequires:  monitoring-plugins-common
BuildRequires:  nagios-rpm-macros
BuildRequires:  tcpd-devel
#
%if 0%{?suse_version} > 1000
BuildRequires:  krb5-devel
%else
BuildRequires:  heimdal-devel
%endif
#
%if 0%{?suse_version} > 1020
BuildRequires:  libopenssl-devel
BuildRequires:  openssl
%else
BuildRequires:  openssl-devel
%endif
#
%if 0%{?suse_version} > 1020
Recommends:     inet-daemon
Recommends:     monitoring-plugins-users
Recommends:     monitoring-plugins-load
Recommends:     monitoring-plugins-disk
Recommends:     monitoring-plugins-procs
%else
Requires:       inet-daemon
Requires:       monitoring-plugins
%endif
#
Provides:       nagios-nrpe = %{version}
Obsoletes:      nagios-nrpe < 2.14
Provides:       nagios-nrpe-client = %{version}
Obsoletes:      nagios-nrpe-client < %{version}

%if %{with systemd}
BuildRequires:  systemd
%{?systemd_requires}
%endif

%{!?_tmpfilesdir:%global _tmpfilesdir /usr/lib/tmpfiles.d}

%description
NRPE can be used to run nagios plug-ins on a remote machine for
executing local checks.
This package contains the software for NRPE server.
It could be run by inet-daemon or as stand-alone daemon

%package doc
Summary:        Nagios Remote Plug-In Executor documentation
Group:          Documentation/Other
Provides:       nagios-nrpe-doc = %{version}
Obsoletes:      nagios-nrpe-doc < 2.14

%description doc
This package contains the README files, OpenOffice and PDF
documentation for the remote plugin executor (NRPE) for nagios.

%package -n monitoring-plugins-nrpe
Summary:        NRPE plugin
Group:          System/Monitoring
%if 0%{?suse_version} > 1020
Recommends:     monitoring_daemon
%endif
Provides:       nagios-nrpe-server = %{version}-%{release}
Obsoletes:      nagios-nrpe-server < 2.14
Provides:       nagios-plugins-nrpe = %{version}-%{release}
Obsoletes:      nagios-plugins-nrpe < 2.15-%{release}

%description -n monitoring-plugins-nrpe
This package contains the plug-in for the host runing the Nagios
daemon.

It is used to contact the NRPE process on remote hosts. The plugin
requests that a plugin be executed on the remote host and wait for the
NRPE process to execute the plugin and return the result.

The plugin then uses the output and return code from the plugin
execution on the remote host for its own output and return code.

%prep
%setup -q
%patch1 -p0
%if %{nagios3only}
%patch2 -p0
%endif
%patch3 -p0
%patch4 -p1
%patch5 -p0
%patch6 -p0
%patch10 -p0
%patch11 -p0
cp -a %{SOURCE10} .
%if 0%{?suse_version} >= 1210
sed -e '/Have a lot of fun/d' README.SUSE
cat %{SOURCE11} >> README.SUSE
%endif
chmod -x contrib/README.nrpe_check_control
%if 0%{?suse_version} > 01110
# increase the number of 'allowed' processes on newer systems:
sed -i "s|check_procs -w 150 -c 200|check_procs -w 250 -c 300|g" sample-config/nrpe.cfg.in  
%endif
# add the new include directory
sed -i "s|#include_dir=<someotherdirectory>|#include_dir=<someotherdirectory>\ninclude_dir=/etc/nrpe.d|g" sample-config/nrpe.cfg.in

%build
%configure \
	--sbindir=%{nagios_cgidir} \
	--libexecdir=%{nagios_plugindir} \
	--datadir=%{nagios_datadir} \
	--sysconfdir=%{_sysconfdir} \
	--localstatedir=%{nagios_logdir} \
	--exec-prefix=%{_sbindir} \
	--bindir=%{_sbindir} \
	--with-log_facility=daemon \
	--with-kerberos-inc=%{_includedir} \
	--with-nagios-user=%{nagios_user} \
	--with-nagios-group=%{nagios_group} \
	--with-nrpe-user=%{nagios_user} \
	--with-nrpe-group=%{nagios_group} \
	--with-nrpe-port=%nrpeport \
	--enable-command-args \
	--enable-bash-command-substitution \
	--enable-ssl
make %{?_smp_mflags} all

gcc %{optflags} -o contrib/nrpe_check_control contrib/nrpe_check_control.c

%install
%nagios_command_user_group_add
install -d %{buildroot}%{_sysconfdir}/xinetd.d
install -d %{buildroot}%{_rundir}/%{name}
install -d %{buildroot}%{_sysconfdir}/nrpe.d
make install install-daemon install-daemon-config install-xinetd \
    DESTDIR=%{buildroot} \
    INSTALL_OPTS="" \
    COMMAND_OPTS="" \
    CGICFGDIR="%{_sysconfdir}" \
    NAGIOS_INSTALL_OPTS="" \
    NRPE_INSTALL_OPTS="" \
    INIT_OPTS=""

install -Dm 644 %{SOURCE4} %{buildroot}%{_mandir}/man8/nrpe.8
%if 0%{?suse_version} <= 1230
install -Dm 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/nrpe
ln -s -f ../../etc/init.d/nrpe %{buildroot}%{_sbindir}/rcnrpe
%else
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rcnrpe
%endif

# install SuSEfirewall2 script
%if 0%{?suse_version} > 1020
install -Dm644 %{SOURCE3} %{buildroot}/%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/nrpe
%endif

# fix pid_file in nrpe.cfg
sed -i -e "s,^\(pid_file=\).*,\1%{_rundir}/%{name}/nrpe.pid," %{buildroot}/%{_sysconfdir}/nrpe.cfg

# create directory and pidfile (package them as ghost)
%if 0%{?suse_version} <= 1230
mkdir -p %{buildroot}%{_rundir}/%{name}
touch %{buildroot}%{_rundir}/%{name}/nrpe.pid
%endif

# create home directory of nagios user
mkdir -p %{buildroot}%{nagios_localstatedir}

# create contrib plugin
install -m0755 contrib/nrpe_check_control %{buildroot}%{nagios_plugindir}/nrpe_check_control
cat > nrpe_check_control.cfg <<'EOF'
define command {
    command_name    nrpe_check_control
    command_line    %{nagios_plugindir}/nrpe_check_control $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ "$HOSTNAME$"
}
EOF
install -Dm0644 nrpe_check_control.cfg %{buildroot}%{nagios_sysconfdir}/objects/nrpe_check_control.cfg

# install simple nrpe.cfg for the Nagios server in the objects directory
install -Dm644 %{SOURCE5} %{buildroot}%{nagios_sysconfdir}/objects/check_nrpe.cfg

%if %{with systemd}
# install systemd specific files
install -Dm644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}.service
install -Dm644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}@.service
sed -i -e "/User=/s/\(User=\).*/\1%{nagios_user}/" -e "/Group=/s/\(Group=\).*/\1%{nagios_group}/" %{buildroot}%{_unitdir}/%{name}.service
sed -i -e "/User=/s/\(User=\).*/\1%{nagios_user}/" -e "/Group=/s/\(Group=\).*/\1%{nagios_group}/" %{buildroot}%{_unitdir}/%{name}@.service
install -Dm644 %{SOURCE8} %{buildroot}%{_unitdir}/%{name}.socket
install -d -m 0755 %{buildroot}/%{_tmpfilesdir}
echo "d %{_rundir}/%{name} 0755 %{nagios_user} %{nagios_group} -" > %{buildroot}/%{_tmpfilesdir}/%{name}.conf
chmod 644 %{buildroot}/%{_tmpfilesdir}/%{name}.conf
%endif

%pre
# Create user and group on the system if necessary
%nagios_user_group_add
%nagios_command_user_group_add
# check if the port for nrpe is already defined in /etc/services
if grep -q %nrpeport /etc/services ; then
    : OK - port already defined
else
    %nnmmsg "Adding port %nrpeport to /etc/services"
	echo "nrpe            %nrpeport/tcp # Nagios nrpe" >> etc/services
fi
%if %{with systemd}
%service_add_pre nrpe.service
%endif

%preun
%stop_on_removal %{name}
%if %{with systemd}
%service_del_preun nrpe.service
%endif

%post
%if 0%{?suse_version} <= 1230
%{fillup_and_insserv -fy %{name}}
%else
%fillup_only %{name}
%endif
%if %{with systemd}
%service_add_post nrpe.service
%endif

%pre -n monitoring-plugins-nrpe
# Create user and group on the system if necessary
%nagios_user_group_add

%triggerun -- nagios-nrpe < 2.14
STATUS='/var/adm/update-scripts/nrpe'
if [ -x %{_sysconfdir}/init.d/nrpe ]; then
    %{_sysconfdir}/init.d/nrpe status >/dev/null
    if test $? = 0; then
        echo "%{_sysconfdir}/init.d/nrpe restart" >> "$STATUS"
    else
        touch "$STATUS"
    fi
    chmod +x "$STATUS"
fi
if [ -x %{_sysconfdir}/init.d/xinetd ]; then
    %{_sysconfdir}/init.d/xinetd status >/dev/null
    if test $? = 0; then
        echo "%{_sysconfdir}/init.d/xinetd try-restart" >> "$STATUS"
    else
        touch "$STATUS"
    fi
    chmod +x "$STATUS"
fi

%triggerpostun -- nagios-nrpe < 2.14 
# Move /etc/nagios/nrpe.cfg to /etc/nrpe.cfg when updating from an old version
# and inform the admin about the rename.
if test -e %{nagios_sysconfdir}/nrpe.cfg.rpmsave -a ! -e %{_sysconfdir}/nrpe.cfg.rpmnew; then
    mv %{_sysconfdir}/nrpe.cfg %{_sysconfdir}/nrpe.cfg.rpmnew
    mv %{nagios_sysconfdir}/nrpe.cfg.rpmsave %{_sysconfdir}/nrpe.cfg
    echo "# %{nagios_sysconfdir}/nrpe.cfg has been moved to %{_sysconfdir}/nrpe.cfg" > %{nagios_sysconfdir}/nrpe.cfg
    echo "# This file can be removed." >> %{nagios_sysconfdir}/nrpe.cfg
    echo "include=%{_sysconfdir}/nrpe.cfg" >> %{nagios_sysconfdir}/nrpe.cfg
fi
sed -i "s|%{nagios_sysconfdir}/nrpe.cfg|%{_sysconfdir}/nrpe.cfg|g" %{_sysconfdir}/xinetd.d/nrpe || :
sed -i "s|nrpe-service|%{name}|g" %{_sysconfdir}/sysconfig/SuSEfirewall2 || :
if [ -e /var/adm/update-scripts/nrpe ]; then
    /bin/sh /var/adm/update-scripts/nrpe
    rm /var/adm/update-scripts/nrpe
fi

%postun
%restart_on_update nrpe
%insserv_cleanup
%if %{with systemd}
%service_del_postun nrpe.service
%endif

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
%doc README.SUSE README.SSL SECURITY
%{_mandir}/man8/nrpe.8*
%dir %{_sysconfdir}/nrpe.d
%config(noreplace) %{_sysconfdir}/nrpe.cfg
%config(noreplace) %{_sysconfdir}/xinetd.d/nrpe
%if 0%{?suse_version} > 1020
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/nrpe
%endif
%if 0%{?suse_version} <= 1230
%{_sysconfdir}/init.d/nrpe
%ghost %dir %{_rundir}/%{name}
%ghost %{_rundir}/%{name}/nrpe.pid
%endif
%if %{with systemd}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}@.service
%{_unitdir}/%{name}.socket
%{_tmpfilesdir}/%{name}.conf
%endif
%attr(0755,root,root) %{_sbindir}/nrpe
%{_sbindir}/rcnrpe

%files doc
%defattr(0644,root,root,0755)
%doc Changelog LEGAL README README.SSL README.SUSE SECURITY docs/*.pdf

%files -n monitoring-plugins-nrpe
%defattr(-,root,root)
%doc contrib/README.nrpe_check_control
%dir %{nagios_libdir}
%attr(0755,root,%{nagios_command_group})           %dir %{nagios_sysconfdir}
%attr(0755,root,%{nagios_command_group})           %dir %{nagios_sysconfdir}/objects
%config(noreplace) %{nagios_sysconfdir}/objects/nrpe_check_control.cfg
%config(noreplace) %{nagios_sysconfdir}/objects/check_nrpe.cfg
%{nagios_plugindir}/check_nrpe
%{nagios_plugindir}/nrpe_check_control

%changelog
openSUSE Build Service is sponsored by