%define kernel_version 2.6.35
%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
%define perl_vendorarch %(eval "`perl -V:installvendorarch`"; echo $installvendorarch)

%define _libexecdir %{_libdir}/nagios/plugins
%define extraplugins cluster cluster2 cpqarray hltherm ipxping rbl timeout uptime

Summary: Host/service/network monitoring program plugins for Nagios
Name: nagios-plugins
Version: 1.4.15
Release: 1%{_dist_release}
License: GPL
Group: Applications/System
URL: http://nagiosplug.sourceforge.net/

Source: http://dl.sf.net/nagiosplug/nagios-plugins-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

AutoReq: no
BuildRequires: fping, bind-utils, ntp, samba-client, openssh-clients
BuildRequires: openldap-devel, mysql-devel, postgresql-devel
BuildRequires: net-snmp-devel, net-snmp-utils
BuildRequires: kernel-source = %{kernel_version}
Requires: perl, net-snmp-perl, fping
Requires: nagios

%description
This package contains the basic plugins necessary for use with the
Nagios package.  This package should install cleanly on almost any
RPM-based system.

But you may need additional packages. Depending on what plugins you
use, the following packages may be required:

    bind-utils, mysql, net-snmp-utils, ntp, openldap,
    openssh-clients, openssl, postgresql-libs
    qstat, radiusclient, samba-client, sendmail

%prep
%setup

### Allow non-root builds
%{__perl} -pi.orig -e 's|^INSTALL_OPTS|#INSTALL_OPTS|' configure

%{__perl} -pi -e 's|/usr/src/linux|/usr/src/linux-%{kernel_version}|g' contrib/*.c contrib/*.h

### FIXME: Change to real perl and plugins location. (Please fix upstream)
find contrib -type f -exec %{__perl} -pi -e '
		s|^#!/.*bin/perl|#!%{__perl}|i;
		s|/usr/local/nagios/libexec/|%{_libdir}/nagios/plugins/|;
		s|/usr/libexec/nagios/plugins/|%{_libdir}/nagios/plugins/|;
	' {} \;

%build
PATH="/sbin:/bin:/usr/sbin:/usr/sbin:$PATH" \
%configure \
	--with-cgiurl="/nagios/cgi-bin" \
	--with-mysql="%{_prefix}" \
	--with-pgsql="%{_prefix}"
#	--with-nagios-user="nagios" \
#	--with-nagios-group="nagios" \
%{__make} %{?_smp_mflags}

### Build some contrib plugins
for plugin in %{extraplugins}; do
	${CC:-%{__cc}} %{optflags} -I. -Igl/ -Ilib/ -Iplugins/ -I%{_datadir}/gettext/ -o check_$plugin contrib/check_$plugin.c || :
done

%install
%{__rm} -rf %{buildroot}
%makeinstall
%find_lang %{name}

%{__install} -d -m0755 %{buildroot}%{_libdir}/nagios/plugins/contrib/
%{__install} -m0755 contrib/check* %{buildroot}%{_libdir}/nagios/plugins/contrib/
%{__install} -m0755 check_* %{buildroot}%{_libdir}/nagios/plugins/

%{__install} -Dp -m0644 plugins-scripts/utils.pm %{buildroot}%{perl_vendorlib}/utils.pm
%{__install} -Dp -m0644 command.cfg %{buildroot}%{_sysconfdir}/nagios/command-plugins.cfg

%clean
%{__rm} -rf %{buildroot}

%files -f %{name}.lang
#%defattr(-, nagios, nagios, 0755)
%defattr(-, root, root, 0755)
%doc ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CODING COPYING ChangeLog FAQ
%doc INSTALL LEGAL NEWS README REQUIREMENTS SUPPORT THANKS command.cfg
%config(noreplace) %{_sysconfdir}/nagios/*
%dir %{_libdir}/nagios/
%{_libdir}/nagios/plugins/
%{perl_vendorlib}/utils.pm

%changelog
* Thu May 26 2011 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.15-1
- new upstream release.

* Fri Jul 10 2009 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.13-1
- new upstream release.

* Fri Apr 11 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 1.4.11-1
- new upstream release.

* Wed Nov 15 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.4-0vl1
- initial build for Vine Linux based on DAG package.

* Wed Nov 01 2006 Dag Wieers <dag@wieers.com> - 1.4.4-1 - 4481+/dries
- Updated to release 1.4.4.
- Fixed the problem where --with-pgsql defaults to 'yes'. (Jason Kim)

* Mon May 29 2006 Dag Wieers <dag@wieers.com> - 1.4.3-1
- Updated to release 1.4.3.

* Tue Mar 07 2006 Dag Wieers <dag@wieers.com> - 1.4.2-1
- Updated to release 1.4.2.

* Fri Aug 05 2005 Dag Wieers <dag@wieers.com> - 1.4.1-1
- Updated to release 1.4.1.

* Sun Feb 13 2005 Dag Wieers <dag@wieers.com> - 1.4-2
- Fixed setuid bit for ping and fping.
- Added /sbin and /usr/sbin to $PATH.
- Updated to release 1.4.

* Tue Apr 27 2004 Dag Wieers <dag@wieers.com> - 1.3.1-10
- Everything owned by user root. (James Wilkinson)

* Mon Apr 26 2004 Dag Wieers <dag@wieers.com> - 1.3.1-9
- Removed nagios requirement (for nrpe). (James Wilkinson)

* Fri Apr 09 2004 Dag Wieers <dag@wieers.com> - 1.3.1-8
- Added postgresql plugins for RHEL3.

* Mon Mar 01 2004 Dag Wieers <dag@wieers.com> - 1.3.1-7
- Added net-snmp-utils as a BuildRequires. (Dan Tucny)

* Wed Feb 11 2004 Dag Wieers <dag@wieers.com> - 1.3.1-6
- Changed BuildRequires to allow building for RHEL.

* Tue Oct 14 2003 Dag Wieers <dag@wieers.com> - 1.3.1-5
- Fixed a problem with check_ping on RH80. (Tom Diehl)
- With user nagios and group nagios. (Tom Diehl)
- Added commands-plugins.cfg.

* Thu Oct 09 2003 Dag Wieers <dag@wieers.com> - 1.3.1-4
- Added check_game.

* Sat Oct 04 2003 Dag Wieers <dag@wieers.com> - 1.3.1-3
- Fixed build environment /etc/mtab for check_disk command.

* Mon Aug 18 2003 Dag Wieers <dag@wieers.com> - 1.3.1-2
- Added check_cluster and check_dhcp.
- Moved the needed perl module to perl include path.

* Sat Jul 12 2003 Dag Wieers <dag@wieers.com> - 1.3.1-1
- Fixed paths of some scripts.
- Updated to release 1.3.1.

* Fri Apr 18 2003 Dag Wieers <dag@wieers.com> - 1.3.0-0
- Updated to release 1.3.0.

* Mon Feb 17 2003 Dag Wieers <dag@wieers.com> - 1.2.93-0
- Updated to release 1.3.0-beta3.
- Initial package. (using DAR)
