A new user interface for you!

File collectd.spec of Package collectd

# spec file for package collectd
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2005-2013 Pascal Bleser <pascal.bleser@opensuse.org>
# 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/

%bcond_with modbus
%define _unpackaged_files_terminate_build 0
%define pcap_version %({rpm -q --qf='%{VERSION}\n' libpcap-devel 2>/dev/null || echo 0.0.0} | gawk -F. '{print $1*10000+$2*100+$3}')
%define snmp       1
%define with_esmtp 1
%define ipvs_plugin ipvs
%define plugins apache apcups %{expand:%{bind_plugin}} cgroups curl %{expand:%{curl_json_plugin}} %{expand:%{curl_xml_plugin}} conntrack contextswitch cpu cpufreq csv df disk %{expand:%{dns_plugin}} email entropy exec filecount fscache hddtemp interface %{expand:%{ipvs_plugin}} irq load logfile match_empty_counter match_hashed match_regex match_timediff match_value mbmon memory netlink network nfs nginx ntpd perl protocols processes serial swap syslog table tail target_notification target_replace target_scale target_set target_v5upgrade tcpconns thermal threshold unixsock uptime users uuid vmem write_http %{expand:%{ascent_plugin}} %{expand:%{iptables_plugin}} aggregation ethstat md numa tail_csv write_graphite fhcount ipc log_logstash write_log write_log
%if 0%{?_with_xmms:1}0
%define xmms 1
%define xmms 0
%if 0%{?_with_java:1} || 0%{?suse_version} > 1030 && ! 0%{?_without_java:1} && ! 0%{?sles_version}
%define java 1
%define java 0
%if 0%{?_with_virt:1} || 0%{?suse_version} > 1030
%define virt 1
%define virt 0
%if ! 0%{?_without_dbi:1}
%define dbi 1
%define dbi 0
%if 0%{?suse_version} > 1020
%define ipmi   1
%define ascent 1
%define ascent_plugin ascent
%define iptables 1
%define iptables_plugin iptables
%define ipmi   0
%define ascent 0
%define ascent_plugin %{nil}
%define iptables 0
%define iptables_plugin %{nil}
%if %{pcap_version} >= 10000
%define dns        1
%define dns_plugin dns
%define dns        0
%define dns_plugin %{nil}
%if 0%{?suse_version} >= 1000
%define yajl 1
%define curl_json_plugin curl_json
%define curl_xml_plugin  curl_xml
%define with_snmp_plugin 1
%define with_pgsql 1
%define with_mysql 1
%define with_bind  1
%define bind_plugin bind
%define pinba_plugin pinba
%define yajl 0
%define curl_json_plugin %{nil}
%define curl_xml_plugin  %{nil}
%define with_snmp_plugin 0
%define with_pgsql 0
%define with_mysql 0
%define with_bind  0
%define bind_plugin %{nil}
%define pinba_plugin %{nil}
%if 0%{?suse_version} >= 1210
%define has_systemd 1
BuildRequires:  systemd
# FIXME: use proper Requires(pre/post/preun/...)
PreReq:         %insserv_prereq
Name:           collectd
Version:        5.5.0
Release:        0
Summary:        Statistics Collection Daemon for filling RRD Files
License:        GPL-2.0
Group:          System/Monitoring
Url:            http://collectd.org/
Source:         http://collectd.org/files/collectd-%{version}.tar.bz2
Source1:        collectd.suse.init
Source2:        collectd.apache2.conf
Source3:        collectd-js.apache2.conf
# workaround for missing pthread.pc on openSUSE, required by OpenIPMIpthread.pc
# see https://bugzilla.novell.com/show_bug.cgi?id=388026
Source20:       collectd-pthread.pc
Source99:       collectd-rpmlintrc
Patch7:         collectd-fix-config.patch
Patch9:         collectd-version.patch
Patch10:        collectd-perl-vendor.patch
# see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467072
Patch11:        collectd-fix_broken_perl-5.10.patch
Patch18:        collectd-fix_collection_cgi.patch
Patch20:        collectd-split_README.patch
Patch21:        collectd-fix_collectd_config_path_in_snmp_probe.patch
Patch23:        collectd-javac_target.patch
Patch25:        collectd-df-remove-duplicates.patch
# for /etc/apache2/... ownership (rpmlint):
BuildRequires:  apache2
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  bind-devel
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  freetype2-devel
BuildRequires:  gcc
BuildRequires:  gettext
BuildRequires:  gettext-devel
BuildRequires:  intltool
# for ipvs and madwifi:
BuildRequires:  kernel-source
BuildRequires:  libart_lgpl-devel
BuildRequires:  libevent-devel
BuildRequires:  libmnl-devel
BuildRequires:  libnetlink-devel
BuildRequires:  libpcap
BuildRequires:  libpng-devel
BuildRequires:  libstatgrab-devel
BuildRequires:  libtool
BuildRequires:  libxml2-devel
BuildRequires:  linux-kernel-headers
BuildRequires:  make
BuildRequires:  perl
BuildRequires:  pkgconfig
BuildRequires:  python-devel
BuildRequires:  xfsprogs-devel
BuildRequires:  zlib-devel
# FIXME: use proper Requires(pre/post/preun/...)
PreReq:         %fillup_prereq
# in case we'd like to split it later:
Provides:       collectd-perl = %{version}-%{release}
# play nice with collectd-beta:
Obsoletes:      collectd-beta < %{version}
Provides:       collectd-beta = %{version}-%{release}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Should not be used - since Mon Apr 23 10:56:57 UTC 2012
# except for 11.4
%if 0%{?suse_version} > 1200
BuildRequires:  libdb-4_8-devel
%if 0%{?suse_version} > 1020
BuildRequires:  libdb-4_5-devel
BuildRequires:  db-devel
%if 0%{?suse_version} > 910
BuildRequires:  libgcrypt-devel
BuildRequires:  libgcrypt
%if %java
BuildRequires:  java-devel
%endif #java
%if %{with_esmtp}
BuildRequires:  libesmtp-devel
%if %{with_mysql}
BuildRequires:  mysql-devel >= 4.1.0
%if %{with_pgsql}
BuildRequires:  postgresql-devel
%if %{yajl}
BuildRequires:  libyajl-devel
%if 0%{?suse_version} >= 1030
BuildRequires:  libcurl-devel
BuildRequires:  curl-devel
%if %{ipmi}
# for ipmi:
BuildRequires:  OpenIPMI-devel
BuildRequires:  gdbm-devel
%endif #ipmi
%if %{snmp}
# for snmp:
BuildRequires:  net-snmp-devel
%endif #snmp
%if 0%{?suse_version} >= 1030
BuildRequires:  libpcap-devel
%if %{xmms}
# for xmms:
BuildRequires:  xmms-devel
%if %{virt}
# for libvirt:
BuildRequires:  libvirt-devel
%if %{dbi}
BuildRequires:  libdbi-devel
%if %{with modbus}
BuildRequires:  libmodbus-devel
%if 0%{?suse_version} < 1220
%if 0%{?suse_version} > 1020
BuildRequires:  iptables-devel
BuildRequires:  libiptc-devel
BuildRequires:  libxtables-devel

collectd is a small daemon written in C for performance.  It reads various
system  statistics  and updates  RRD files,  creating  them if necessary.
Since the daemon doesn't need to startup every time it wants to update the
files it's very fast and easy on the system. Also, the statistics are very
fine grained since the files are updated every 10 seconds.

%package doc
Summary:        Documentation for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description doc
Documentation (MAN Pages and Examples) for %{name}

%package plugin-ceph
Summary:        CEPH Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}
%description plugin-ceph
CEPH Plugin for %{name}

%package plugin-drbd
Summary:        DRBD Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}
%description plugin-drbd
DRBD Plugin for %{name}

%if %{ipmi}
%package plugin-ipmi
Summary:        OpenIPMI Monitoring Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-ipmi
Optional %{name} plugin to monitor sensors using the OpenIPMI
library, for IPMI enabled systems.
%endif #ipmi

%if %{snmp}
%package plugin-snmp
Summary:        SNMP Monitoring Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}
Requires:       perl(Config::General)
Requires:       perl(SNMP)
Requires:       perl(Socket6)

%description plugin-snmp
Optional %{name} plugin to monitor devices using SNMP.
%endif #snmp

%if %{with_mysql}
%package plugin-mysql
Summary:        MySQL Monitoring Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-mysql
Optional %{name} plugin to monitor MySQL server instances.
%endif #with_mysql

%if %{with_pgsql}
%package plugin-postgresql
Summary:        PostgreSQL Monitoring Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-postgresql
Optional %{name} plugin to monitor PostgreSQL server instances.
%endif #with_pgsql

%package plugin-python
Summary:        Python API for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-python
Optional %{name} Python API in order to write %{name} plugins in

%if %java
%package plugin-java
Summary:        Java API for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-java
Optional %{name} Java API in order to write %{name} plugins in
%endif #java

%if %{virt}
%package plugin-virt
Summary:        Virtual Machine Statistics Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-virt
Optional %{name} plugin to gather statistics from virtual
machines using libvirt.

%if %{xmms}
%package plugin-xmms
Summary:        XMMS Monitoring Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-xmms
Optional %{name} plugin to gather sampling frequencies and file
bitrates of files played with XMMS.
%endif #xmms

%if %{dbi}
%package plugin-dbi
Summary:        DBI Storage Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-dbi
Optional %{name} plugin to store sampling results into
various databases as supported by libdbi.
%endif #dbi

%if %{with modbus}
%package plugin-modbus
Summary:        ModBus Plugin for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}

%description plugin-modbus
Optional %{name} plugin to collect data using ModBus protocol.
%endif #modbus

%package plugins-all
Summary:        All Monitoring Plugins for %{name}
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-plugin-python = %{version}-%{release}
Requires:       %{name}-plugin-drbd = %{version}-%{release}
Requires:       %{name}-plugin-ceph = %{version}-%{release}

%if %{ipmi}
Requires:       %{name}-plugin-ipmi = %{version}-%{release}
%endif #ipmi
%if %{snmp}
Requires:       %{name}-plugin-snmp = %{version}-%{release}
%endif #snmp
%if %{with_mysql}
Requires:       %{name}-plugin-mysql = %{version}-%{release}
%endif #with_mysql
%if %{with_pgsql}
Requires:       %{name}-plugin-postgresql = %{version}-%{release}
%if %java
Requires:       %{name}-plugin-java = %{version}-%{release}
%endif #java
%if %{virt}
Requires:       %{name}-plugin-virt = %{version}-%{release}
%endif #virt
%if %{dbi}
Requires:       %{name}-plugin-dbi = %{version}-%{release}
%endif #dbi
%if %{with modbus}
Requires:       %{name}-plugin-modbus = %{version}-%{release}
%endif #modbus

%description plugins-all
Metapackage that installs %{name} and all the available
monitoring plugin subpackages, except %{name}-plugin-xmms

%package -n libcollectdclient1
Summary:        Library for %{name} clients
Group:          System/Monitoring
Provides:       libcollectdclient = %{version}-%{release}

%description -n libcollectdclient1
Library which abstracts communication with the %{name}
unixsock plugin for clients.

%package -n libcollectdclient-devel
Summary:        Development Environment for %{name} clients
Group:          Development/Libraries/C and C++
Requires:       libcollectdclient1 = %{version}-%{release}

%description -n libcollectdclient-devel
Library which abstracts communication with the %{name}
unixsock plugin for clients.
This package contains the required development environment
to write %{name} unixsock clients.

%setup -q -n "collectd-%{version}"
%patch9 -p1
%patch23 -p1

sed -i 's|@@VERSION@@|%{version}|g' configure.ac

# workaround for missing pthread.pc on openSUSE, required by OpenIPMIpthread.pc
install -D -m0644 "%{SOURCE20}" pkgconfig/pthread.pc
sed 's|@@LIB@@|%{_lib}|g' pkgconfig/pthread.pc

perl -p -i -e 's|(-L\$withval/lib)\b|${1}64|g' configure.ac configure

# unneeded files:
rm -fr \
     contrib/fedora \
     contrib/solaris-smf \
     contrib/redhat \

# remove -Werror everywhere
find . -name 'configure*' -o -name 'Makefile*' -exec sed -i 's|-Werror||g' {} \;


autoreconf -fiv

# set JAVA_HOME properly
[ -n "$JAVA_HOME" -a -d "$JAVA_HOME" ] || export JAVA_HOME="%{_libdir}/jvm/java"
[ -n "$JDK_HOME"  -a -d "$JDK_HOME"  ] || export JDK_HOME="$JAVA_HOME"
[ -n "$JRE_HOME"  -a -d "$JRE_HOME"  ] || export JRE_HOME="$JAVA_HOME"
export PATH="$JDK_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/bin:$PATH"

export CFLAGS="%{optflags} -fno-strict-aliasing"
# workaround for missing pthread.pc on openSUSE, required by OpenIPMIpthread.pc
export KERNEL_DIR=%{_prefix}/src/linux
%configure \
    --without-libstatgrab \
    --without-rrdtool \
    --disable-rrdcached \
    --disable-madwifi \
    --disable-powerdns \
    --disable-teamspeak2 \
    --disable-wireless \
    --disable-vserver \
    --disable-varnish \
    --disable-olsrd \
    --enable-static \
%if %{dns}
    --enable-dns \
    --disable-dns \
    --disable-nut \
    --enable-netlink \
    --enable-python \
    --with-librrd \
%if %{iptables}
    --enable-iptables \
    --disable-iptables \
    --without-iptc \
%endif #iptables
%if %{ascent}
    --enable-ascent \
    --disable-ascent \
%endif #ascent
%if %{ipmi}
    --enable-ipmi \
    --disable-ipmi \
%endif #ipmi
%if %java
    --enable-java \
    --with-java="$JAVA_HOME/" \
    --disable-java \
%endif #java
%if %{dbi}
    --enable-dbi \
    --disable-dbi \
%endif #dbi
    --disable-memcached \
%if %{with modbus}
    --enable-modbus \
    --disable-modbus \
%endif #modbus
%if 0%{?suse_version} < 930
    --disable-mysql \
%ifos linux
%endif #os linux

make %{?_smp_flags} \
%if 0%{?suse_version} < 1120
     JAVAC_TARGET="-source 1.5 -target 1.5"
     JAVAC_TARGET="-source 1.5 -target 1.6"

make DESTDIR=%{buildroot} install %{?_smp_mflags}

# delete .la files
rm -f "%{buildroot}%{_libdir}"/*.{a,la}
rm -f "%{buildroot}%{_libdir}/collectd"/*.a

sed -i '/^dependency_libs=/ s|-L'"${RPM_BUILD_DIR}/%{name}-%{version}"'/src||g' "%{buildroot}%{_libdir}/collectd/python.la"

# delete if it exists (not packaged any more on openSUSE):
rm -rf "%{buildroot}%{_localstatedir}/adm/perl-modules/%{name}"

%if !%java
rm -f "%{buildroot}%{_mandir}/man5"/collectd-java.5*
rm -rf "%{buildroot}%{_datadir}/collectd/java"
%endif #!java
mkdir -p _rpmdoc_/java
mv contrib/GenericJMX.conf _rpmdoc_/java/

# fix permissions:
chmod 0755 "%{buildroot}%{_libdir}/collectd"/*.so
chmod 0644 "%{buildroot}%{_libdir}/collectd"/*.la

# create /var/lib/collectd to add it to the %files section:
install -d -m 0755 "%{buildroot}%{_localstatedir}/lib/collectd"

# Apache2 configuration for the CGI frontend:
install -D -m 0644 "%{SOURCE2}" "%{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}.conf"
install -D -m 0755 contrib/collection.cgi "%{buildroot}/srv/www/collectd/collection.cgi"
install -D -m 0644 contrib/collection.conf "%{buildroot}%{_sysconfdir}/collectd/collection.conf"
sed -i 's|@@LIBDIR@@|%{_libdir}|g' "%{buildroot}%{_sysconfdir}/collectd/collection.conf"
# remove it from contrib, to avoid having it end up in the main package as well:
rm contrib/collection.cgi contrib/collection.conf

rm -rf "%{buildroot}%{_localstatedir}/adm/perl-modules"/*

# web-js CGI frontend (_must_ be installed _after_ perl_process_packlist)
install -d "%{buildroot}/srv/www/collectd-js"
mkdir -p _rpmdoc_/web-js
mv contrib/collection3/README _rpmdoc_/web-js/README
find contrib/collection3/ -name .htaccess -exec rm {} \;
cp -a \
     contrib/collection3/bin/* \
     contrib/collection3/share/* \
mkdir -p "%{buildroot}%{_libexecdir}/collectd-js"
mv contrib/collection3/lib/* "%{buildroot}%{_libexecdir}/collectd-js/"

install -D -m 0644 contrib/collection3%{_sysconfdir}/collection.conf \
rm -fr contrib/collection3/etc
install -D -m 0644 "%{SOURCE3}" "%{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}-js.conf"

# cussh script from contrib:
install -m0755 contrib/cussh.pl "%{buildroot}%{_bindir}/cussh"
install -d "%{buildroot}%{_mandir}/man1"
pod2man \
     -c "Collectd UNIX Socket Shell" \
     -n "CUSSH" \
     -s 1 \
     contrib/cussh.pl > "%{buildroot}%{_mandir}/man1/cussh.1"
rm contrib/cussh.pl

# snmp:
mkdir -p _rpmdoc_/snmp
sed -n '/^snmp-data\.conf/,$ p' contrib/README > _rpmdoc_/snmp/README
sed -i '/^snmp-data\.conf/,$ d' contrib/README
mv contrib/snmp-data.conf _rpmdoc_/snmp/
sed -i 's|\(\./\)snmp-probe-host\.px|collectd-snmp-probe-host|g' contrib/snmp-probe-host.px
pod2man \
     -c "Collectd SNMP Host Probe" \
     -s 1 \
     contrib/snmp-probe-host.px \
     > "%{buildroot}%{_mandir}/man1/collectd-snmp-probe-host.1"
install -D -m0755 contrib/snmp-probe-host.px "%{buildroot}%{_bindir}/collectd-snmp-probe-host"
rm contrib/snmp-probe-host.px
install -d "%{buildroot}%{_mandir}/man1"

find contrib/ -name '*.orig' -exec rm {} \;

%if !%{with_pgsql}
rm -f "%{buildroot}%{_datadir}/collectd/postgresql_default.conf"

%if !%{with_snmp_plugin}
rm -f "%{buildroot}%{_mandir}/man5/collectd-snmp.5"

# plugin list:
echo -n > plugins.lst
for plugin in %{plugins}; do
     for ext in so la; do
     	 echo "%{_libdir}/collectd/${plugin}.${ext}" >> plugins.lst

cat<<EOF >README.plugins-all
This package is empty but depends on all collectd plugin subpackages.

install -d -m 0755 "%{buildroot}%{_prefix}/sbin"

%if 0%{?has_systemd}
install -D -m0644 contrib/collectd.service %{buildroot}%{_unitdir}/collectd.service
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
# init script:
install -D -m 0755 "%{SOURCE1}" "%{buildroot}%{_initddir}/collectd"
ln -s "../..%{_initddir}/collectd" "%{buildroot}%{_sbindir}/rccollectd"

%stop_on_removal collectd

%if 0%{?has_systemd}
%service_del_preun %{name}.service

%restart_on_update collectd

%if 0%{?has_systemd}
%service_del_postun %{name}.service


%if 0%{?has_systemd}
%service_add_pre %{name}.service

%{fillup_only collectd}

%if 0%{?has_systemd}
%service_add_post %{name}.service

%post   -n libcollectdclient1 -p /sbin/ldconfig

%postun -n libcollectdclient1 -p /sbin/ldconfig

%files -f plugins.lst
%config(noreplace) %{_sysconfdir}/collectd.conf
%dir %{_sysconfdir}/collectd
%dir %{_libdir}/collectd
%if %{with_esmtp}
%endif #with_esmtp
%dir %{_datadir}/collectd
%dir %{perl_vendorlib}/Collectd
%dir %{_localstatedir}/lib/collectd
%if 0%{?has_systemd}

%files doc
%doc contrib
%doc %{_mandir}/man1/collectd.1%{ext_man}
%doc %{_mandir}/man1/collectdctl.1%{ext_man}
%doc %{_mandir}/man1/collectdmon.1%{ext_man}
%doc %{_mandir}/man1/collectd-tg.1%{ext_man}
%doc %{_mandir}/man1/collectd-nagios.1%{ext_man}
%doc %{_mandir}/man1/cussh.1%{ext_man}
%doc %{_mandir}/man5/collectd.conf.5%{ext_man}
%doc %{_mandir}/man5/collectd-email.5%{ext_man}
%doc %{_mandir}/man5/collectd-exec.5%{ext_man}
%doc %{_mandir}/man5/collectd-perl.5%{ext_man}
%doc %{_mandir}/man5/collectd-threshold.5%{ext_man}
%doc %{_mandir}/man5/collectd-unixsock.5%{ext_man}
%doc %{_mandir}/man5/types.db.5%{ext_man}
%doc %{perl_man3dir}/Collectd::Unixsock.%{perl_man3ext}%{ext_man}

%files plugin-ceph

%files plugin-drbd

%if %{ipmi}
%files plugin-ipmi
%endif #ipmi

%if %{snmp}
%files plugin-snmp
%doc _rpmdoc_/snmp/*
%doc %{_mandir}/man1/collectd-snmp-probe-host.1%{ext_man}
%if %{with_snmp_plugin}
%doc %{_mandir}/man5/collectd-snmp.5%{ext_man}
%endif #with_snmp_plugin
%endif #snmp

%if 0%{?suse_version} >= 930
%files plugin-mysql

%if %{with_pgsql}
%files plugin-postgresql
%config %{_datadir}/collectd/postgresql_default.conf
%endif #with_pgsql

%files plugin-python
%doc %{_mandir}/man5/collectd-python.5%{ext_man}

%if %java
%files plugin-java
%doc _rpmdoc_/java/GenericJMX.conf
%doc %{_mandir}/man5/collectd-java.5%{ext_man}
%endif #java

%if %{virt}
%files plugin-virt
%endif #virt

%if %{xmms}
%files plugin-xmms
%endif #xmms

%if %{dbi}
%files plugin-dbi
%endif #dbi

%if %{with modbus}
%files plugin-modbus
%endif #modbus

%files plugins-all
%doc README.plugins-all

%files -n libcollectdclient1

%files -n libcollectdclient-devel