File nagtrap.spec of Package nagtrap

#
# spec file for package nagtrap
#
# 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/
#


%define         phpdir %{_datadir}/%{name}
Name:           nagtrap
Version:        1.5.0
Release:        0
Summary:        Manage and administrate recipient snmptraps
License:        GPL-2.0+
Group:          System/Monitoring
Url:            https://wiki.icinga.org/display/howtos/NagTrap
# http://sourceforge.net/projects/nagtrap/files/
Source0:        %{name}-%{version}.tar.bz2
Source1:        nagtrap-stylesheets.tar.bz2
Source2:        nagtrap-httpd.conf
Patch1:         nagtrap-install-webconf.patch
# PATCH-FIX-UPSTREAM - use the same headers for all php files
Patch2:         nagtrap-phpheader.patch
# PATCH-FIX-OPENSUSE - use a config file in /etc/nagtrap
Patch3:         nagtrap-check_snmptraps-use_config.patch
Patch4:         nagtrap-check_jobs-use_config.patch
# for %%pre/%%post checks
BuildRequires:  apache2
BuildRequires:  nagios-rpm-macros
Requires:       perl(Config::Simple)
#PreReq:         nagios-www => monitoring_webfrontend
PreReq:         apache2
Recommends:     snmptt
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
%if 0%{?suse_version} > 1020
BuildRequires:  fdupes
%endif

%description
NagTrap is a webinterface written in PHP for Nagios. You can manage and
administrate recipient snmptraps from SNMPTT. NagTrap can easy in Icinga /
Nagios integrate and automatically adapts to the Icinga- / Nagios-Design.
NagTrap picks the snmptraps from the database of SNMPTT.

%prep
%setup -q -a1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
sed -e "s|___PHPDIR___|%{phpdir}|g" %{SOURCE2} > nagtrap-httpd.conf

%build
%configure \
		--with-monitoring-user=%{nagios_user} \
		--with-monitoring-group=%{nagios_group} \
		--with-command-user=%{nagios_command_user} \
		--with-command-group=%{nagios_command_group} \
		--with-htmurl=/%{name} \
		--with-httpd-conf=%{_sysconfdir}/apache2/conf.d \
		--with-log-dir=%{_var}/log/%{name} \
		--datadir=%{_datadir}/%{name} \
		--sysconfdir=%{_sysconfdir}/%{name} \
		--with-monitoring_libexecdir=%{nagios_plugindir} \
		--with-monitoring_installdir=%{_datadir}/%{name} \
		--with-htpasswdusers-file=%{nagios_sysconfdir}/htpasswd.users

%install
# prepare directories not created by make
mkdir -p %{buildroot}%{_sysconfdir}/apache2/conf.d
mkdir -p %{buildroot}%{nagios_plugindir}
mkdir -p %{buildroot}%{_defaultdocdir}/%{name}/
# start installation
make DESTDIR=%{buildroot} install %{?_smp_mflags} INSTALL_OPTS='' INSTALL_OPTS_WEB='' COMMAND_OPTS='' DATAROOTDIR='%{_datadir}/%{name}'
# install documentation
cp -r doc/* %{buildroot}%{_defaultdocdir}/%{name}/
# check for missing stylesheets (as nagtrap is installed in own directory)
pushd share/include/css >/dev/null
for i in *.css; do
    test -f %{buildroot}%{_datadir}/%{name}/include/css/$i || cp $i %{buildroot}%{_datadir}/%{name}/include/css/
done
popd >/dev/null
# install config files
install -m644 nagtrap-httpd.conf %{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}.conf
cp %{buildroot}%{_sysconfdir}/%{name}/config.ini.php-dist %{buildroot}%{_sysconfdir}/%{name}/config.ini.php
cat >> %{buildroot}%{_sysconfdir}/%{name}/check_snmp_traps.conf <<EOF
MYSQL=%{_bindir}/mysql
MYSQL_USER=snmptt
MYSQL_DB=snmptt
MYSQL_PASS=snmptt
MYSQL_TABLE=snmptt
MYSQL_HOST=localhost
EOF
# save some space, create symlinks
%if 0%{?suse_version} > 1020
%fdupes %{buildroot}%{phpdir}
%endif

%postun
if [ "$1" = "0" ]; then
    # deinstallation of the package - remove the apache flag
    test -x %{_sbindir}/a2disflag && %{_sbindir}/a2disflag NAGTRAP >/dev/null
    %restart_on_update apache2
fi

%pre
if [ "$1" = "1" ]; then
    # enable php5 in apache config
    test -x %{_sbindir}/a2enmod && %{_sbindir}/a2enmod php5 >/dev/null
    # enable NAGTRAP in /etc/sysconfig/apache2
    test -x %{_sbindir}/a2enflag && %{_sbindir}/a2enflag NAGTRAP >/dev/null
fi

%post
%restart_on_update apache2


%files
%defattr(0644,root,root,0755)
%doc %{_defaultdocdir}/%{name}/
%dir %{_datadir}/%{name}
%dir %{nagios_libdir}
%dir %{nagios_plugindir}
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/apache2/conf.d/%{name}.conf
%attr(0640,root,www) %config(noreplace) %{_sysconfdir}/%{name}/config.ini.php
%attr(0640,root,%{nagios_group}) %config(noreplace) %{_sysconfdir}/%{name}/check_snmp_traps.conf
%config %{_sysconfdir}/%{name}/config.ini.php-dist
%{_datadir}/%{name}
%defattr(0755,root,root,0755)
%{nagios_plugindir}/*
%defattr(0755,%{nagios_user},%{nagios_group})
%{_var}/log/%{name}

%changelog
openSUSE Build Service is sponsored by