File nagios.spec of Package nagios.import4839
#
# spec file for package nagios
#
# 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/
#
Name: nagios
%define nsusr nagios
%define nsgrp nagios
%define cmdusr wwwrun
%define cmdgrp nagcmd
%define nslockfile_dir /var/run/%{name}
%define nslockfile %nslockfile_dir/%{name}.pid
%define apache2_sysconfdir %(/usr/sbin/apxs2 -q SYSCONFDIR)/conf.d
# Macro that print mesages to syslog at package (un)install time
%define nnmmsg logger -t %{name}/rpm
Summary: The Nagios Network Monitor
Version: 3.2.3
Release: 3.<RELEASE4>
License: GPLv2+
Group: System/Monitoring
Url: http://www.nagios.org/
Source0: %{name}-%{version}.tar.bz2
Source1: rc%{name}
Source2: %{name}-rpmlintrc
Source3: %{name}.sysconfig
Source4: suse.de-nagios
Source5: nagios.8
Source6: nagiosstats.8
#
Source10: %{name}-README.SuSE
# PATCH-FIX-UPSTREAM fix for missing expression in return statement bnc#395203
Patch1: nagios.run_async_service_check.return.patch
# PATCH-FIX-UPSTREAM Fixes the output of spurious $ signs in commandoutput (deb#480001)
Patch2: nagios-fix_spurious_dollar_signs_added_to_command_lines.patch
# PATCH-FIX-UPSTREAM unescape hex characters in CGI input - avoid addional '+'
Patch3: nagios-fix_encoding_trends.cgi.patch
# PATCH-FIX-UPSTREAM Fixes handling of forced checks
Patch4: nagios-fix_forced_servicechecks.patch
# PATCH-FIX-UPSTREAM Fixes CVE-2011-1523 and CVE-2011-2179
Patch5: nagios-3.2.3-CVE-2011-1523.patch
# PATCH-FIX-UPSTREAM deleting comments removed more elements from the hashlist than it should (http://tracker.nagios.org/view.php?id=80)
Patch7: nagios-3.2.1-delete_correct_comment.patch
# PATCH-FIX-OPENSUSE openSUSE uses a special location for p1.pl
Patch10: nagios-p1.pl-location.patch
# PATCH-FIX-OPENSUSE disable Nagios online update checks for distributed packages
Patch11: nagios-disable_phone_home.patch
#
BuildRoot: %{_tmppath}/%{name}-%{version}-build
PreReq: %fillup_prereq
PreReq: %insserv_prereq
PreReq: /bin/logger
PreReq: coreutils
PreReq: grep
PreReq: pwdutils
PreReq: sed
BuildRequires: apache2-devel
BuildRequires: freetype2-devel
BuildRequires: gd-devel
BuildRequires: iputils
BuildRequires: libjpeg-devel
BuildRequires: libpng-devel
BuildRequires: mailx
BuildRequires: openssl-devel
BuildRequires: pcre-devel
BuildRequires: net-tools
BuildRequires: zlib-devel
%if 0%{?suse_version} < 1010
BuildRequires: XFree86-devel
BuildRequires: XFree86-libs
BuildRequires: libapr0
Requires: cron
%else
BuildRequires: libapr-util1-devel
BuildRequires: xorg-x11-devel
Recommends: cron
Recommends: %{name}-www
# we enable nagios embedded perl, but if people disable it...
Recommends: perl = %{perl_version}
%endif
%if 0%{?suse_version} > 1020
BuildRequires: fdupes
Recommends: %{name}-plugins
%else
Requires: %{name}-plugins
%endif
Requires: mailx
%description
Nagios is a program that will monitor hosts and services on your
network. It has the ability to email or page you when a problem arises
and when a problem is resolved. Nagios is written in C and is designed
to run under Linux (and some other *NIX variants) as a background
process, intermittently running checks on various services that you
specify.
The actual service checks are performed by separate "plugin" programs
which return the status of the checks to Nagios. The plugins are
available at http://sourceforge.net/projects/nagiosplug
This package provide core programs for nagios. The web interface,
documentation, and development files are built as separate packages
Authors:
--------
Ethan Galstad <nagios@nagios.org>
%package www
License: GPLv2+
Summary: Provides the HTML and CGI files for the Nagios web interface
Group: System/Monitoring
PreReq: /bin/logger
PreReq: apache2
PreReq: coreutils
PreReq: gawk
PreReq: grep
PreReq: pwdutils
PreReq: sed
Requires: %{name} = %{version}
Requires: gd php5 mod_php_any
%description www
Nagios is a program that will monitor hosts and services on your
network. It has the ability to email or page you when a problem arises
and when a problem is resolved. Nagios is written in C and is designed
to run under Linux (and some other *NIX variants) as a background
process, intermittently running checks on various services that you
specify.
Several CGI programs are included with Nagios in order to allow you to
view the current service status, problem history, notification history,
and log file via the web. This package provides the HTML and CGI files
for the Nagios web interface. In addition, HTML documentation is
included in this package.
Authors:
--------
Ethan Galstad <nagios@nagios.org>
%package devel
License: GPLv2+
Summary: Development files for nagios
Group: Development/Libraries/C and C++
Requires: %{name} = %{version}
Requires: gcc
%description devel
Nagios is a program that will monitor hosts and services on your
network. It has the ability to email or page you when a problem arises
and when a problem is resolved. Nagios is written in C and is designed
to run under Linux (and some other *NIX variants) as a background
process, intermittently running checks on various services that you
specify.
This package provides include files that Nagios-related applications
may compile against.
Authors:
--------
Ethan Galstad <nagios@nagios.org>
%prep
%setup -q -n %{name}-%{version}
%patch1 -p0
%patch2 -p0
%patch3 -p0
%patch4 -p0
%patch5 -p0
%patch7 -p0
%patch10 -p0
%patch11 -p0
find -name ".cvsignore" | xargs rm
find -name ".gitignore" | xargs rm
# fix p1.pl pathname of mini_epn
sed -i 's|p1.pl|%{_prefix}/lib/%{name}/p1.pl|g' contrib/mini_epn.c
sed -i 's|p1.pl|%{_prefix}/lib/%{name}/p1.pl|g' contrib/new_mini_epn.c
%build
# if the following command fails, then apache dependencies are not met
/usr/sbin/apxs2 -q DATADIR >/dev/null
%configure \
--prefix=%{_prefix} \
--exec-prefix=%{_sbindir} \
--bindir=%{_sbindir} \
--sbindir=%{_prefix}/lib/%{name}/cgi \
--libexecdir=%{_prefix}/lib/%{name}/plugins \
--datadir=%{_datadir}/%{name} \
--sysconfdir=%{_sysconfdir}/%{name} \
--with-init-dir=%{_sysconfdir}/init.d \
--localstatedir=/var/lib/%{name} \
--with-cgiurl=/%{name}/cgi-bin \
--with-htmurl=/%{name} \
--with-httpd-conf=%{apache2_sysconfdir} \
--with-checkresult-dir=/var/spool/%{name} \
--with-lockfile=%{nslockfile} \
--with-nagios-user=%{nsusr} \
--with-nagios-group=%{nsgrp} \
--with-command-user=%{cmdusr} \
--with-command-group=%{cmdgrp} \
--with-gd-lib=%{_libdir} \
--with-gd-inc=%{_includedir} \
--with-template-objects \
--with-template-extinfo \
--with-perlcache \
--enable-event-broker \
--enable-embedded-perl
#
# %bindir/p1.pl is not a good place for a perl-_module_!
#
sed -i 's#@p1pldir@#%{_prefix}/lib/nagios#g' Makefile include/locations.h sample-config/nagios.cfg
#
# fix p1.pl debug-path
#
sed -i 's#/usr/local/nagios/var/#/var/log/%{name}/#g' p1.pl
# make rpmlint happy: add shebang to p1.pl
echo "#!/usr/bin/perl" > p1.pl.new
cat p1.pl >> p1.pl.new
mv p1.pl.new p1.pl
#
# make daemonchk.cgi and event handlers
#
make %{?jobs:-j%jobs} all
make %{?jobs:-j%jobs} -C contrib
pushd contrib/eventhandlers 1>/dev/null
for f in `find . -type f` ; do
F=`mktemp temp.XXXXXX`
sed "s=/usr/local/nagios/var/rw/=/var/spool/%{name}/=; \
s=NscaBin\=\"/usr/local/nagios/libexec/send_nsca\"=NscaBin\=/usr/bin/send_nsca=; \
s=/usr/local/nagios/libexec/eventhandlers/=%{_prefix}/lib/%{name}/plugins/eventhandlers/=; \
s=/usr/local/nagios/libexec/=%{_prefix}/lib/%{name}/plugins/=; \
s=/usr/local/nagios/etc/=%{_sysconfdir}/%{name}/=; \
s=/usr/local/nagios/test/var=/var/log/%{name}=" ${f} > ${F}
mv ${F} ${f}
done
popd 1>/dev/null
%install
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}/archives
mkdir -p %{buildroot}%{_sbindir}
mkdir -p %{buildroot}%apache2_sysconfdir/
mkdir -p %{buildroot}%nslockfile_dir
%{__make} install install-commandmode install-config install-webconf \
DESTDIR=%{buildroot} \
INSTALL_OPTS="" \
COMMAND_OPTS="" \
CGICFGDIR="%{_sysconfdir}/%{name}" \
INIT_OPTS=""
%{__make} install -C contrib \
DESTDIR=%{buildroot} \
INSTALL_OPTS=""
# install event handlers
%{__install} -d -m0755 %{buildroot}%{_prefix}/lib/%{name}/plugins/eventhandlers/
%{__cp} -afpv contrib/eventhandlers/* %{buildroot}%{_prefix}/lib/%{name}/plugins/eventhandlers/
# install directory for event brokers like ndoutils
%{__install} -d -m0755 %{buildroot}%{_prefix}/lib/%{name}/brokers
# install headers for development package
%{__install} -d -m0755 %{buildroot}%{_includedir}/%{name}/
pushd include
for file in *.h; do
if test "x${file}" != "xconfig.h" -a "x${file}" != "xsnprintf.h" -a "x${file}" != "xcgiutils.h" ; then
install -m 644 $file %{buildroot}%{_includedir}/%{name}/
fi;
done
popd
#
# cleanup sample-conf dir for including in docdir
#
find sample-config/ -name "*.in" -exec rm {} \;
find sample-config/ -name "*.in.orig" -exec rm {} \;
sed -e 's|command_file=.*|command_file=/var/spool/%{name}/nagios.cmd|g' \
-e 's|log_file=/var/lib/nagios/nagios.log|log_file=/var/log/nagios/nagios.log|g' \
-e 's|log_archive_path=/var/lib/nagios/archives|log_archive_path=/var/log/nagios/archives|g' \
-e 's|^lock_file=.*|lock_file=%nslockfile|g' \
%{buildroot}%{_sysconfdir}/%{name}/nagios.cfg > %{buildroot}%{_sysconfdir}/%{name}/nagios.cfg.tmp
mv %{buildroot}%{_sysconfdir}/%{name}/nagios.cfg.tmp %{buildroot}%{_sysconfdir}/%{name}/nagios.cfg
#
# install SuSE specials
#
# README.SuSE file
sed -e 's@DATADIR@%{_datadir}/%{name}@g' -e 's@SYSCONFDIR@%{_sysconfdir}/%{name}@g' %{S:10} > %_builddir/%{name}-%version/README.SuSE
# init-script
%{__install} -D -m 0755 %{S:1} %{buildroot}%{_sysconfdir}/init.d/%{name}
ln -sf ../../etc/init.d/%{name} %{buildroot}%{_sbindir}/rc%{name}
# sysconfig script
%{__install} -D -m 0644 %{S:3} %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}
# install cronjob (gzip' the logfiles)
%{__install} -D -m 0640 %{S:4} %{buildroot}%{_sysconfdir}/cron.weekly/%{name}
# important ghost files
touch %{buildroot}%{_sysconfdir}/%{name}/htpasswd.users
touch %{buildroot}%{_localstatedir}/lib/%{name}/retention.dat
touch %{buildroot}%{_localstatedir}/lib/%{name}/status.dat
touch %{buildroot}%{_localstatedir}/log/%{name}/config.err
touch %{buildroot}%nslockfile
# install manpages
install -Dm644 %{S:5} %{buildroot}%{_mandir}/man8/%{name}.8
install -Dm644 %{S:6} %{buildroot}%{_mandir}/man8/nagiosstats.8
# some rpmlint stuff
%if 0%{?suse_version} > 1020
%fdupes -s %{buildroot}
%endif
%check
make test-perl
%clean
%{__rm} -rf %{buildroot}
%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 group: nagcmd
if
getent group %{cmdgrp} >/dev/null
then
: OK group %{cmdgrp} already present
else
groupadd -r %{cmdgrp} 2>/dev/null || :
%{nnmmsg} "Added group %{cmdgrp} 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/%{name} %{nsusr} 2> /dev/null || :
%{nnmmsg} "Added user %{nsusr} for package %{name}"
fi
# update?
if [ ${1:-0} -gt 1 ]; then
# in the past, group www was used as cmdgrp - now we use the default: nagcmd
if id -Gn %{nsusr} 2>/dev/null | grep -q %{cmdgrp} >/dev/null 2>&1 ; then
: # %{nsusr} is already in %cmdgrp group
else
# Add %{nsusr} to %cmdgrp.
groupmod -A %{nsusr} %{cmdgrp} 2>/dev/null
%{nnmmsg} "Added %{nsusr} to %{cmdgrp}"
fi
fi
%post
%{fillup_and_insserv nagios}
# Update ?
if [ ${1:-0} -gt 1 ]; then
if [ -f %{_sysconfdir}/%{name}/nagios.cfg ]; then
DATE=$(date "+%Y-%m-%d-%H:%M")
TMPFILE=$(mktemp /tmp/%{name}-XXXXXX)
NAGIOS_CFG=%{_sysconfdir}/%{name}/nagios.cfg
cp -f $NAGIOS_CFG ${NAGIOS_CFG}_${DATE}
if ! grep -q ^lock_file=%{nslockfile} $NAGIOS_CFG ; then
echo "- updating pid lock_file= to %{nslockfile} in $NAGIOS_CFG" >> $TMPFILE
sed -i "s@^lock_file=.*@lock_file=%{nslockfile}@" $NAGIOS_CFG
fi
if grep -q ^service_reaper_frequency $NAGIOS_CFG ; then
echo "- renaming service_reaper_frequency to check_result_reaper_frequency in $NAGIOS_CFG" >> $TMPFILE
sed -i "s@service_reaper_frequency@check_result_reaper_frequency@" $NAGIOS_CFG
fi
if grep -q ^aggregate_status_updates $NAGIOS_CFG ; then
echo "- aggregate_status_updates option has been removed from $NAGIOS_CFG" >> $TMPFILE
sed -i "s@^aggregate_status_updates@# aggregate_status_updates@" $NAGIOS_CFG
fi
if grep -q ^downtime_file $NAGIOS_CFG ; then
set -- $(grep ^downtime_file $NAGIOS_CFG | sed 's@=@ @')
shift
file=$(echo $*)
if [ -n "$file" ]; then
if [ -f "$file" ]; then
set -- $(grep ^state_retention_file $NAGIOS_CFG | sed 's@=@ @')
shift
state_retention_file=$(echo $*)
echo "- adding the content of of $file to $state_retention_file" >> $TMPFILE
cat "$file" >> "$state_retention_file"
fi
fi
echo "- removing downtime_file variable (no longer supported) in $NAGIOS_CFG" >> $TMPFILE
sed -i "s@^downtime_file@# downtime_file@" $NAGIOS_CFG
fi
if grep -q ^comment_file $NAGIOS_CFG ; then
set -- $(grep ^comment_file $NAGIOS_CFG | sed 's@=@ @')
shift
file=$(echo $*)
if [ -n "$file" ]; then
if [ -f "$file" ]; then
echo "- adding the content of $file to $state_retention_file" >> $TMPFILE
cat "$file" >> "$state_retention_file"
fi
fi
echo "- removing comment_file variable (no longer supported) in $NAGIOS_CFG" >> $TMPFILE
sed -i "s@^comment_file@# comment_file@" $NAGIOS_CFG
fi
%{nnmmsg} $(cat $TMPFILE)
rm $TMPFILE
fi
else
# First installation: create an alias for the default nagiosadmin user
if [ -r etc/aliases ]; then
if ! grep -q "^nagiosadmin:" etc/aliases; then
echo -e "nagiosadmin:\troot" >> etc/aliases
%{nnmmsg} "Added alias for user nagiosadmin to /etc/aliases"
if [ -x usr/bin/newaliases ]; then
usr/bin/newaliases &>/dev/null || true
else
%{nnmmsg} "Cannot execute newaliases. Please run it manually."
fi
fi
fi
fi
%preun
%stop_on_removal %{name}
%postun
if [ -f %nslockfile ]; then
chown -v %{nsusr} %{nslockfile}
fi
%restart_on_update %{name}
%{insserv_cleanup}
%post www
wwwusr=""
if [ -f etc/apache2/uid.conf ]; then
# If apache is installed, and we can find the apache user, set a shell var
wwwusr=$(awk '/^[ \t]*User[ \t]+[a-zA-Z0-9]+/ {print $2}' etc/apache2/uid.conf)
fi
if [ "z" = "z$wwwusr" ]; then # otherwise, use the default
wwwusr=%{cmdusr}
fi
# if apache user is not in cmdgrp, add it
if id -Gn $wwwusr 2>/dev/null | grep -q %{cmdgrp} >/dev/null 2>&1 ; then
: # $wwwusr (default: %cmdusr) is already in nagiocmd group
else
# modify apache user, adding it to cmdgrp
groupmod -A $wwwusr %{cmdgrp} 2>/dev/null
%nnmmsg "User $wwwusr added to group %{cmdgrp} so sending commands to Nagios from the CGI is possible."
fi
%restart_on_update apache2
%preun www
%restart_on_update apache2
%files
%defattr(-,root,root)
%doc Changelog LEGAL LICENSE README README.SuSE sample-config/
%{_mandir}/man8/%{name}*
%_sysconfdir/init.d/%name
%ghost %config(missingok,noreplace) /var/log/%name/config.err
%config(noreplace) %_sysconfdir/%name/resource.cfg
%config(noreplace) %_sysconfdir/%name/cgi.cfg
%config(noreplace) %_sysconfdir/%name/%{name}.cfg
%config(noreplace) %_sysconfdir/%name/objects/*.cfg
%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}
%defattr(755,root,root)
%{_sysconfdir}/cron.weekly/*
%{_prefix}/lib/%name/
%exclude %{_prefix}/lib/%name/cgi/*
%{_sbindir}/convertcfg
%{_sbindir}/mini_epn
%{_sbindir}/new_mini_epn
%{_sbindir}/rc%name
# defattr change
%defattr(-,%{nsusr},%{cmdgrp})
%dir %_sysconfdir/%name
%dir %_sysconfdir/%name/objects
%dir /var/spool/%name
# defattr change
%defattr(-,%{nsusr},%nsgrp)
%dir /var/lib/%name
%dir /var/log/%name
%dir /var/log/%name/archives
%ghost %dir %nslockfile_dir
%attr(0644,%nsusr,%nsgrp) %verify(not md5 size mtime) %ghost %config(missingok,noreplace) %nslockfile
%attr(0600,%nsusr,%nsgrp) %verify(not md5 size mtime) %ghost %config(missingok,noreplace) /var/lib/%name/retention.dat
%attr(0664,%nsusr,%nsgrp) %verify(not md5 size mtime) %ghost %config(missingok,noreplace) /var/lib/%name/status.dat
%attr(0750,root,%{cmdgrp}) %{_sbindir}/%{name}
%attr(0750,root,%{cmdgrp}) %{_sbindir}/nagiostats
%files www
%defattr(755,root,root)
%{_prefix}/lib/%{name}/cgi/*
# defattr change
%defattr(-,root,root)
%{_datadir}/%{name}/
%config(noreplace) %{apache2_sysconfdir}/%{name}.conf
%attr(0640,root,%cmdgrp) %ghost %config(missingok,noreplace) %{_sysconfdir}/%{name}/htpasswd.users
%files devel
%defattr(-,root,root)
%{_includedir}/%{name}/
%changelog