File Zabbix.spec of Package Zabbix

Name:           zabbix
Version:        1.6.4
Release:        1
License:        GPL
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  apache2-devel apache2-prefork mysql-client mysql-devel
BuildRequires:  net-snmp net-snmp-devel curl-devel
Group:          System/Monitoring
Source:         %{name}-%{version}.tar.gz
Patch0:         zabbix.patch
Requires:       mysql-client net-snmp
Summary:        The ZABBIX server.

%define serverroot %(/usr/sbin/apxs2 -q datadir 2>/dev/null || /usr/sbin/apxs2 -q PREFIX)/htdocs/

%description
ZABBIX is an enterprise-class open source distributed monitoring solution.
The Zabbix server is the centre of the ZABBIX software. The Server can monitor other servers by using simple checks, SNMP and using the ZABBIX agent.
The Server is the central repository for configuration and monitored data.

%package agent
Group: System/Monitoring
Summary: ZABBIX agent

%description agent
ZABBIX is an enterprise-class open source distributed monitoring solution.
This Zabbix agent is used to actively monitor local resources and applications (such as harddrives, memory, processor statistics etc.).
The Agent is collecting data from the monitored system and report tihis to the ZABBIX server.

%package phpfrontend
Summary: ZABBIX web frontend (php).
Group: Productivity/Networking/Web/Frontends
Requires: php5 php5-bcmath

%description phpfrontend
ZABBIX is an enterprise-class open source distributed monitoring solution.
The the ZABBIX php frontend is used to allow easy access to the monitoring and configuration of the ZABBIX Server. Usually this runs on the same machine as the ZABBIX Server.

%prep
%setup -q
%patch0 -p1

%build
%configure --enable-server --enable-agent --with-mysql --with-ucd-snmp --with-libcurl

# adjust in several files /home/zabbix
for zabbixfile in misc/conf/* misc/init.d/suse/*/zabbix_* src/zabbix_server/server.c src/zabbix_server/alerter/alerter.c src/zabbix_agent/zbxconf.c; do
  sed -i -e "s#/home/zabbix/bin#%{_bindir}#g" \
         -e "s#PidFile=/var/tmp#PidFile=%{_localstatedir}/lib/zabbix#g" \
         -e "s#LogFile=/tmp#LogFile=%{_localstatedir}/lib/zabbix#g" \
         -e "s#/home/zabbix/lock#%{_localstatedir}/lib/zabbix#g" $zabbixfile
done

make

%pre
if [ -z "`grep zabbix etc/group`" ]; then
  usr/sbin/groupadd -r zabbix >/dev/null 2>&1
fi
if [ -z "`grep zabbix etc/passwd`" ]; then
  usr/sbin/useradd -r -d /var/lib/zabbix -g zabbix zabbix >/dev/null 2>&1
fi

%pre agent
if [ -z "`grep zabbix etc/group`" ]; then
  usr/sbin/groupadd -r zabbix >/dev/null 2>&1
fi
if [ -z "`grep zabbix etc/passwd`" ]; then
  usr/sbin/useradd -r -d /var/lib/zabbix -g zabbix zabbix >/dev/null 2>&1
fi

%post
%fillup_and_insserv -f zabbix_server

if [ -z "`grep zabbix_agent etc/services`" ]; then
  cat >>etc/services <<EOF
zabbix_agent    10050/tcp
EOF
fi

if [ -z "`grep zabbix_trap etc/services`" ]; then
  cat >>etc/services <<EOF
zabbix_trap     10051/tcp
EOF
fi

echo "########################################################"
echo "#                                                      #"
echo "#  Please create / update the mysql zabbix database.   #"
echo "#  Before starting the server.                         #"
echo "#                                                      #"
echo "#  Please read the ZABBIX manual on how-to do this.    #"
echo "#                                                      #"
echo "########################################################"

%post agent
%fillup_and_insserv -f zabbix_agentd

if [ -z "`grep zabbix_agent etc/services`" ]; then
  cat >>etc/services <<EOF
zabbix_agent    10050/tcp
EOF
fi

if [ -z "`grep zabbix_trap etc/services`" ]; then
  cat >>etc/services <<EOF
zabbix_trap     10051/tcp
EOF
fi

%preun
%stop_on_removal zabbix_server

%preun agent
%stop_on_removal zabbix_agentd

%postun
%insserv_cleanup

%postun agent
#%restart_on_update zabbix_agentd
%insserv_cleanup

%clean
rm -fr $RPM_BUILD_ROOT

%install
rm -fr $RPM_BUILD_ROOT
#make install DESTDIR=$RPM_BUILD_ROOT

# create directory structure
install -d %{buildroot}%{_bindir}
install -d %{buildroot}%{_sysconfdir}/%{name}
install -d %{buildroot}%{_sysconfdir}/init.d
install -d %{buildroot}%{serverroot}%{name}
install -d %{buildroot}%{_localstatedir}/lib/zabbix

# copy binaries
install -m 755 src/*/zabbix_agent %{buildroot}%{_bindir}
install -m 755 src/*/zabbix_agentd %{buildroot}%{_bindir}
install -m 755 src/*/zabbix_sender %{buildroot}%{_bindir}
install -m 755 src/*/zabbix_server %{buildroot}%{_bindir}

# copy conf files
install -m 644 misc/conf/zabbix_agent*.conf %{buildroot}%{_sysconfdir}/%{name}
install -m 640 misc/conf/zabbix_server.conf %{buildroot}%{_sysconfdir}/%{name}

# copy frontends
cp -r frontends/php/* %{buildroot}%{serverroot}%{name}

# SuSE Start Scripts
install -m 755 misc/init.d/suse/10.0/zabbix_* %{buildroot}%{_sysconfdir}/init.d/

%files
%defattr(-,root,root)
%doc AUTHORS COPYING NEWS README INSTALL create upgrades
%dir %{_sysconfdir}/%{name}
%config(noreplace) %attr(-,root,zabbix) %{_sysconfdir}/%{name}/zabbix_server.conf
%{_sysconfdir}/init.d/zabbix_server
%{_bindir}/zabbix_server
%dir %attr(-,zabbix,zabbix) %{_localstatedir}/lib/zabbix

%files agent
%defattr(-,root,root)
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/zabbix_agent*.conf
%{_sysconfdir}/init.d/zabbix_agentd
%{_bindir}/zabbix_agent*
%{_bindir}/zabbix_sender
%dir %attr(-,zabbix,zabbix) %{_localstatedir}/lib/zabbix

%files phpfrontend
%defattr(-,root,root)
%dir %{serverroot}%{name}
%{serverroot}%{name}/*

%changelog
* Wed Apr 29 2009 Martin Wilderoth <martin.wilderoth@linserv.se>
- Uppgrade to 1.6.4
* Fri Feb 15 2008 Martin Wilderoth <martin@linserv.se>
- Uppgrade to 1.4.4
- Minor bugfixes
* Sun Sep 02 2007 Martin Wilderoth <martin@linserv.se>
- Upgrade to 1.4.2
- Change to ucd-snmp
- added libcurl
* Sun Sep 02 2007 Martin Wilderoth <martin@linserv.se>
- Upgrade to 1.1.7
* Sat Nov 11 2006 Martin Wilderoth <martin@linserv.se>
- Added zabbix delta patch
* Wed Nov 8 2006 Martin Wilderoth <martin@linserv.se>
- upgrade to 1.1.3
* Fri May 19 2006 Martin Wilderoth <martin@linserv.se>
- initial package