File nagios-nrpe.spec of Package nagios-nrpe

#
# spec file for package nagios-nrpe
#
# Copyright (c) 2011 SUSE LINUX Products 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 nsusr nagios
%define nsgrp nagios
%define nrpeport 5666
%define _libexecdir %{_prefix}/lib/nagios/plugins

Name:           nagios-nrpe
Version:        2.12
Release:        25
License:        GPL-2.0+
Summary:        Nagios Remote Plug-In Executor
Url:            http://www.nagios.org/
Group:          System/Monitoring
Source0:        nrpe-%{version}.tar.bz2
Source1:        nrpe.init
Source2:        nagios-nrpe-rpmlintrc
Source3:        nagios-nrpe-SuSEfirewall2
Source4:        nrpe.8
Source10:       README.SuSE
# PATCH-FIX-openSUSE change the installation order
Patch0:         nrpe-2.12-Makefile.patch
# PATCH-FIX-openSUSE place the service disabled in the directory
Patch1:         nrpe-2.12-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-UPSTREAM compiler complains about this unused variable
Patch7:         nrpe-unused_variable.patch
# PATCH-FIX-UPSTREAM fix compiler warnings
Patch8:         nrpe-return_value.patch
# PATCH-FIX-UPSTREAM fix compiler warnings
Patch9:         nrpe-uninitialized_variable.patch
# PATCH-FIX-openSUSE fix pathnames for nrpe_check_control command
Patch10:        nrpe_check_control.diff
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
PreReq:         sysvinit(network)
PreReq:         sysvinit(syslog)
%endif
#
BuildRequires:  nagios-plugins
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:     nagios-plugins
%else
Requires:       inet-daemon
Requires:       nagios-plugins
%endif
#
Provides:       %{name}-client = %{version}
Obsoletes:      %{name}-client < %{version}

%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
License:        GPL-2.0+
Summary:        Nagios Remote Plug-In Executor documentation
Group:          Documentation/Other

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

%package -n nagios-plugins-nrpe
License:        GPL-2.0+
Summary:        Nagios NRPE plugin
Group:          System/Monitoring
%if 0%{?suse_version} > 1020
Recommends:     nagios
%endif
Provides:       %{name}-server = %{version}
Obsoletes:      %{name}-server < %{version}

%description -n nagios-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 -n nrpe-%{version}
%patch0 -p1
%patch1 -p1
%if %{nagios3only}
%patch2
%endif
%patch3 -p0
%patch4 -p0
%patch5 -p0
%patch6 -p0
%patch7 -p0
%patch8 -p0
%patch9 -p0
%patch10 -p0
cp -a %{SOURCE10} .

%build
%configure CFLAGS="%{optflags} -fno-strict-aliasing -D_GNU_SOURCE" \
	--sbindir=%{_prefix}/lib/nagios/cgi \
	--libexecdir=%{_libexecdir} \
	--datadir=%{_datadir}/nagios \
	--sysconfdir=%{_sysconfdir}/nagios \
	--localstatedir=/var/log/nagios \
	--exec-prefix=%{_sbindir} \
	--bindir=%{_sbindir} \
	--with-log_facility=daemon \
	--with-kerberos-inc=%{_includedir} \
	--with-init-dir=%{_sysconfdir}/init.d \
	--with-nagios-user=%nsusr \
	--with-nagios-group=%nsgrp \
	--with-nrpe-user=%nsusr \
	--with-nrpe-group=%nsgrp \
	--with-nrpe-port=%nrpeport \
	--enable-command-args \
	--enable-ssl
make %{?_smp_mflags} all

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

%install
make install-all \
    DESTDIR=%{buildroot} \
    INSTALL_OPTS="" \
    COMMAND_OPTS="" \
    CGICFGDIR="%{_sysconfdir}/nagios" \
    NAGIOS_INSTALL_OPTS="" \
    NRPE_INSTALL_OPTS="" \
    INIT_OPTS=""

install -d %{buildroot}%{_localstatedir}/run/nagios
install -Dm 644 %{SOURCE4} %{buildroot}%{_mandir}/man8/nrpe.8
install -Dm 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/nrpe
ln -s -f ../../etc/init.d/nrpe %{buildroot}%{_sbindir}/rcnrpe

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

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

# create directory and pidfile (package them as ghost)
mkdir -p %{buildroot}%{_localstatedir}/run/nrpe
touch %{buildroot}%{_localstatedir}/run/nrpe/nrpe.pid

# create home directory of nagios user
mkdir -p %{buildroot}%{_localstatedir}/lib/nagios

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

%pre
# Create user and group on the system if necessary
# default group: nagios
if
    getent group %nsgrp >/dev/null
then
    : OK group %nsgrp already present
else
    groupadd -r %nsgrp 2>/dev/null || :
    %nnmmsg "Added group %nsgrp for package %{name}"
fi
# default user: nagios
if
    id %nsusr > /dev/null 2>&1
then
    : OK user %nsusr already present
else
    useradd  -r -o -g %nsgrp -s /bin/false -c "User for Nagios" -d /var/lib/nagios %nsusr 2> /dev/null || :
    %nnmmsg "Added user %nsusr for package %{name}"
fi
# 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

%preun
%stop_on_removal nrpe

%post
%{fillup_and_insserv -fy nrpe}

%postun
%restart_on_update nrpe
%insserv_cleanup

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
%doc README.SuSE
%{_mandir}/man8/nrpe.8*
%dir %{_sysconfdir}/nagios/
%dir %{_localstatedir}/lib/nagios
%config(noreplace) %{_sysconfdir}/nagios/nrpe.cfg
%config(noreplace) %{_sysconfdir}/xinetd.d/nrpe
%if 0%{?suse_version} > 1020
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/nrpe-service
%endif
%{_sysconfdir}/init.d/nrpe
%{_sbindir}/nrpe
%{_sbindir}/rcnrpe
%ghost %dir %{_localstatedir}/run/nrpe
%ghost %{_localstatedir}/run/nrpe/nrpe.pid

%files doc
%defattr(644,root,root,755)
%doc Changelog LEGAL README README.SSL README.SuSE SECURITY docs/*

%files -n nagios-plugins-nrpe
%defattr(-,root,root)
%doc contrib/README.nrpe_check_control
%{_libexecdir}/check_nrpe
%dir %{_sysconfdir}/nagios/objects
%config(noreplace) %{_sysconfdir}/nagios/objects/nrpe_check_control.cfg
%{_libexecdir}/nrpe_check_control

%changelog
openSUSE Build Service is sponsored by