File syslog-ng.spec of Package syslog-ng

#
# spec file for package syslog-ng
#
# Copyright (c) 2014 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:           syslog-ng
%if %{defined _rundir}
%define         syslog_ng_rundir        %{_rundir}/syslog-ng
%else
%define         syslog_ng_rundir	%{_localstatedir}/run/syslog-ng
%endif
%define         syslog_ng_sockets_cfg	%{syslog_ng_rundir}/additional-log-sockets.conf
Version:        3.5.6
Release:        0
Summary:        The new-generation syslog-daemon
License:        GPL-2.0
Group:          System/Daemons
Url:            http://www.balabit.com/products/syslog_ng/
#Source0:        http://www.balabit.com/downloads/files/syslog-ng/sources/%%{version}/source/syslog-ng_%%{version}.tar.gz
Source0:        syslog-ng_%{version}.tar.gz
Source1:        syslog-ng.sysconfig
Source2:        syslog-ng.conf.default
Source3:        syslog-ng.service
Source4:        syslog-ng-service-prepare
%if 0%{?suse_version} >= 1210
%bcond_without  systemd
%bcond_without  dbi
%else
%bcond_with     systemd
%bcond_with     dbi
%endif
%if 0%{?suse_version} >= 1230
%bcond_with     systemv
%else
%bcond_without  systemv
%endif
%define         with_smtp           %suse_version >= 1210
%define         with_geoip          %suse_version >= 1210
# redis only available in openSUSE 13.1+
%bcond_without     redis
%if %{with systemd}
Provides:       syslog
Provides:       sysvinit(syslog)
Conflicts:      otherproviders(syslog)
Requires(pre):  %fillup_prereq
%if %{with systemv}
Requires(pre):  %insserv_prereq
Requires(pre):  syslog-service < 2.0
Requires(pre):  /etc/init.d/syslog
%else
Requires(pre):  syslog-service >= 2.0
%endif
%{?systemd_requires}
BuildRequires:  pkgconfig(systemd)
%else
Requires(pre):  %insserv_prereq %fillup_prereq /etc/init.d/syslog
BuildRequires:  klogd
%endif
%if 0%{with_smtp}
BuildRequires:  libesmtp-devel
%endif
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  gcc-c++
BuildRequires:  glib2-devel
%if 0%{?with_geoip}
BuildRequires:  libGeoIP-devel
%endif
%if %{with redis}
BuildRequires:  hiredis-devel
BuildRequires:  libhiredis0_10
%endif
BuildRequires:  libevtlog-devel
BuildRequires:  libjson-devel
BuildRequires:  libopenssl-devel
BuildRequires:  pcre-devel
BuildRequires:  pkgconfig
BuildRequires:  python
BuildRequires:  tcpd-devel
%if %{with dbi}
BuildRequires:  libdbi-devel
%endif
%if 0%{?suse_version} >= 1210
BuildRequires:  libcap-devel
BuildRequires:  libnet-devel
%else
BuildRequires:  libcap
BuildRequires:  libnet
%endif

# BuildRequires:  libxslt-tools

# uncomment, if you want to run "make check" (local builds only)
#BuildRequires:  timezone

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
syslog-ng is an enhanced log daemon, supporting a wide range of input and
output methods: syslog, unstructured text, message queues, databases (SQL
and NoSQL alike) and more.

Key features:

 * receive and send RFC3164 and RFC5424 style syslog messages
 * work with any kind of unstructured data
 * receive and send JSON formatted messages
 * classify and structure logs with builtin parsers (csv-parser(),
   db-parser(), ...)
 * normalize, crunch and process logs as they flow through the system
 * hand on messages for further processing using message queues (like
   AMQP), files or databases (like PostgreSQL or MongoDB).

The official home page of syslog-ng is:
http://www.balabit.com/network-security/syslog-ng/

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%if %{with dbi}

%package sql
Summary:        SQL support using DBI
Group:          System/Daemons
Requires:       %{name} = %{version}

%description sql
This package provides the libafsql module providing support for
logging into a SQL database using DBI.

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%endif

%if 0%{?with_smtp}

%package smtp
Summary:        SMTP output support
Group:          System/Daemons
Requires:       %{name} = %{version}

%description smtp
This package provides the afsmtp module providing support for
logging into SMTP.

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%endif

%if 0%{?with_geoip}

%package geoip
Summary:        GeoIP support
Group:          System/Daemons
Requires:       %{name} = %{version}

%description geoip
This package provides the tfgeoip module providing support for
logging country information.

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%endif

%if %{with redis}

%package redis
Summary:        Redis destination support
Group:          System/Daemons
Requires:       %{name} = %{version}

%description redis
This package provides the libredis module providing support for
logging to a redis destination.

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%endif

%package json
Summary:        JSON output support
Group:          System/Daemons
Requires:       %{name} = %{version}

%description json
This package provides the tfjson module providing support for
logging in JSON format. 

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%package devel
Summary:        Development files for syslog-ng
Group:          System/Daemons
Requires:       %{name} = %{version}

%description devel
This package provides files necessary for syslog-ng development.

Authors:
--------
    Balázs Scheidler <bazsi@balabit.hu>
    BalaBit IT Ltd. <info@balabit.hu>

%prep
%setup -q -n syslog-ng-%{version}
# fill out placeholders in the config,
# systemd service and prepare script.
for file in \
	syslog-ng.conf.default \
	syslog-ng.service \
	syslog-ng-service-prepare \
; do
	sed \
	-e 's;@sbindir@;%{_sbindir};g' \
	-e 's;RUN_DIR;%{syslog_ng_rundir};g' \
	-e 's;ADDITIONAL_SOCKETS;%{syslog_ng_sockets_cfg};g' \
	"%{_sourcedir}/${file}" > "${file}"
done
%ifarch s390 s390x
    sed -i -e 's/tty10/console/g' syslog-ng.conf.default
%endif

%build
##
## build ####################################################
##
export CFLAGS="$RPM_OPT_FLAGS"
%if 0%{?with_geoip}
export GEOIP_LIBS="-lGeoIP"
%endif
%configure \
	--enable-ipv6				\
	--enable-tcp-wrapper			\
	--enable-spoof-source			\
	--sysconfdir=/etc/syslog-ng		\
	--localstatedir=%{_localstatedir}/lib/syslog-ng	\
	--with-pidfile-dir=%{_localstatedir}/run	\
	--with-module-dir="%{_libdir}/syslog-ng"	\
	--with-module-path="%{_libdir}/syslog-ng"	\
	--with-default-modules="affile,afprog,afsocket,afuser,basicfuncs,csvparser,dbparser,syslogformat"	\
	--datadir="%{_datadir}/syslog-ng"	\
	--without-compile-date			\
	--enable-ssl				\
	--enable-pcre				\
%if 0%{?with_smtp}
        --with-libesmtp=/usr/lib                \
%endif
%if %{with systemd}
	--enable-systemd			\
%endif
%if %{with dbi}
	--enable-sql				\
%endif
        --enable-json                           \
	--enable-capabilities			\
	--enable-amqp				\
%if 0%{?with_geoip}
	--enable-geoip				\
%endif
	--enable-mongodb			\
%if %{with redis}
	--enable-redis				\
%endif
        --enable-dynamic-linking  
#
# - build syslog-ng
#
make %_smp_mflags

#%check
##
## check ####################################################
##
#make check

%install
##
## install ##################################################
##
export RPM_BUILD_ROOT
for dir in /sbin \
           %{_sysconfdir}/syslog-ng \
           %{_localstatedir}/lib/syslog-ng \
           %{_localstatedir}/run/syslog-ng \
           %{_localstatedir}/adm/fillup-templates ;
do
	test -d ${RPM_BUILD_ROOT}${dir} || \
	install -d -m755 ${RPM_BUILD_ROOT}${dir}
done
#
make DESTDIR=${RPM_BUILD_ROOT} install
#
%if %{with systemd} && ! %{with systemv}
install -d -m755 %{buildroot}%{_unitdir}/
install -c -m644 syslog-ng.service         %{buildroot}%{_unitdir}/
install -c -m755 syslog-ng-service-prepare %{buildroot}%{_sbindir}/
%endif
# install configs
install -m644 syslog-ng.conf.default \
              $RPM_BUILD_ROOT%{_sysconfdir}/syslog-ng/syslog-ng.conf
install -m644 $RPM_SOURCE_DIR/syslog-ng.sysconfig \
              $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.syslog-ng
# create empty /etc/syslog-ng/conf.d/
install -d -m755 %{buildroot}%{_sysconfdir}/syslog-ng/conf.d/

# create a compatibility link in /sbin
ln -sf %{_sbindir}/syslog-ng %{buildroot}/sbin/

# don't package update-patterndb now
rm %{buildroot}/usr/bin/update-patterndb

# decide which to keep
rm %{buildroot}/%{_libdir}/syslog-ng/libafsocket.so
rm %{buildroot}/%{_libdir}/syslog-ng/libafsocket-notls.so
mv %{buildroot}/%{_libdir}/syslog-ng/libafsocket-tls.so \
   %{buildroot}/%{_libdir}/syslog-ng/libafsocket.so

# create ghosts
install -d -m755 %{buildroot}%{syslog_ng_rundir}
touch            %{buildroot}%{syslog_ng_sockets_cfg}
chmod 644        %{buildroot}%{syslog_ng_sockets_cfg}

# remove some extra testing related files
rm %{buildroot}/%{_libdir}/pkgconfig/syslog-ng-test.pc
rm %{buildroot}/%{_libdir}/syslog-ng/libtest/libsyslog-ng-test.a

%clean
##
## clean build root #########################################
##
if [ -n "%{buildroot}" ] && [ "%{buildroot}" != "/" ] ; then
	rm -rf "%{buildroot}"
fi

%if %{with systemd} && ! %{with systemv}

%pre
%{service_add_pre syslog-ng.service}

%endif

%post
##
## post install #############################################
##
/sbin/ldconfig
#
# remove obsolete variables
#
%{remove_and_set -n syslog SYSLOG_DAEMON SYSLOG_REQUIRES_NETWORK}
%if %{with systemv}
%{fillup_and_insserv -ny syslog syslog}
%endif
#
# add SYSLOG_NG_* variables if needed
#
%{fillup_only -ans syslog ng}
%if %{with systemv}
#
# switch SYSLOG_DAEMON to outself
#
if test -f etc/sysconfig/syslog ; then
	sed -i \
		-e 's/^SYSLOG_DAEMON=.*/SYSLOG_DAEMON="syslog-ng"/g' \
        	etc/sysconfig/syslog
fi
%endif
#
# create dirs, touch log default files
#
mkdir -p var/log
touch var/log/messages;  chmod 640 var/log/messages
touch var/log/mail;      chmod 640 var/log/mail
touch var/log/mail.info; chmod 640 var/log/mail.info
touch var/log/mail.warn; chmod 640 var/log/mail.warn
touch var/log/mail.err;  chmod 640 var/log/mail.err
test -f var/log/news && mv -f var/log/news var/log/news.bak
mkdir -p -m 0750 var/log/news
chown news:news  var/log/news
touch var/log/news/news.crit;   chmod 640 var/log/news/news.crit
chown news:news var/log/news/news.crit
touch var/log/news/news.err;    chmod 640 var/log/news/news.err
chown news:news var/log/news/news.err
touch var/log/news/news.notice; chmod 640 var/log/news/news.notice
chown news:news var/log/news/news.notice
#
# touch the additional log files we are using
#
touch var/log/acpid;            chmod 640 var/log/acpid
touch var/log/firewall;         chmod 640 var/log/firewall
touch var/log/NetworkManager;   chmod 640 var/log/NetworkManager
#
# generate empty additional-log-sockets.conf file
# see also syslog-ng.conf.default in pkg src dir.
#
additional_sockets="%{syslog_ng_sockets_cfg}"
install -d -m750 ${additional_sockets%/*}
cat >$additional_sockets <<EOF
source chroots { };
EOF
chmod 640 "${additional_sockets#/}"
#
# Enable the syslog-ng systemd service
#
%if %{with systemd} && ! %{with systemv}
# This macro enables based on a systemctl preset config file only
%{service_add_post syslog-ng.service}
# But we want to enable a syslog-daemon regardless of the preset;
# force the creation of a syslog.service alias link (bnc#790805).
# We do not check the obsolete SYSLOG_DAEMON variable as we want
# to switch when installing it and there is a provider conflict.
/usr/bin/systemctl -f enable syslog-ng.service >/dev/null 2>&1 || :
%endif

%preun
##
## pre uninstall ############################################
##
%if %{with systemd} && ! %{with systemv}
%{service_del_preun syslog.socket}
%{service_del_preun syslog-ng.service}
%else
if test -x /etc/init.d/syslog ; then
	%{stop_on_removal syslog}
fi
#
# reset SYSLOG_DAEMON variable on removal
#
if test "$1" = "0" -a -f etc/sysconfig/syslog ; then
	sed -i \
		-e 's/^SYSLOG_DAEMON=.*/SYSLOG_DAEMON=""/g' \
		etc/sysconfig/syslog
fi
%endif

%postun
##
## post uninstall ###########################################
##
#
# update linker caches
#
/sbin/ldconfig
%if %{with systemd} && ! %{with systemv}
#
# cleanup init scripts
#
%{service_del_postun syslog-ng.service}
%else
#
# stop the rsyslogd daemon when it is running
#
if test -x /etc/init.d/syslog ; then
	%{restart_on_update syslog}
fi
#
# cleanup init scripts
#
%{insserv_cleanup}
%endif

%files
##
## file list ################################################
##
%defattr(-,root,root)
%doc COPYING AUTHORS NEWS
%doc syslog-ng.conf.default
%attr(755,root,root) /sbin/syslog-ng
%attr(755,root,root) %{_sbindir}/syslog-ng
%attr(755,root,root) %{_sbindir}/syslog-ng-ctl
%if %{with systemd} && ! %{with systemv}
%attr(755,root,root) %{_sbindir}/syslog-ng-service-prepare
%endif
%attr(755,root,root) %{_bindir}/loggen
%attr(755,root,root) %{_bindir}/pdbtool
%{_mandir}/man5/syslog-ng.conf.5*
%{_mandir}/man8/syslog-ng.8*
%{_mandir}/man1/pdbtool.1*
%{_mandir}/man1/loggen.1*
%{_mandir}/man1/syslog-ng-ctl.1*
%dir %{_libdir}/syslog-ng
%dir %{_datadir}/syslog-ng
%dir %{_datadir}/syslog-ng/include
%dir %{_datadir}/syslog-ng/include/scl
%dir %{_datadir}/syslog-ng/include/scl/pacct
%dir %{_datadir}/syslog-ng/include/scl/rewrite
%dir %{_datadir}/syslog-ng/include/scl/syslogconf
%dir %{_datadir}/syslog-ng/include/scl/system
%dir %{_datadir}/syslog-ng/xsd
%dir %{_sysconfdir}/syslog-ng
%dir %{_sysconfdir}/syslog-ng/conf.d
%config(noreplace) %{_sysconfdir}/syslog-ng/syslog-ng.conf
%config(noreplace) %{_sysconfdir}/syslog-ng/scl.conf
%if %{with systemd} && ! %{with systemv}
%{_unitdir}/syslog-ng.service
%endif
%dir %{_localstatedir}/lib/syslog-ng
%attr(0755,root,root) %dir %ghost %{syslog_ng_rundir}
%attr(0644,root,root) %ghost %{syslog_ng_sockets_cfg}
%{_localstatedir}/adm/fillup-templates/sysconfig.syslog-ng
%attr(755,root,root) %{_libdir}/libsyslog-ng*.so*
%attr(755,root,root) %{_libdir}/syslog-ng/libafamqp.so
%attr(755,root,root) %{_libdir}/syslog-ng/libaffile.so
%attr(755,root,root) %{_libdir}/syslog-ng/libafprog.so
%attr(755,root,root) %{_libdir}/syslog-ng/libafmongodb.so
%attr(755,root,root) %{_libdir}/syslog-ng/libafsocket.so
%attr(755,root,root) %{_libdir}/syslog-ng/libafstomp.so
%attr(755,root,root) %{_libdir}/syslog-ng/libafuser.so
%attr(755,root,root) %{_libdir}/syslog-ng/libbasicfuncs.so
%attr(755,root,root) %{_libdir}/syslog-ng/libconfgen.so
%attr(755,root,root) %{_libdir}/syslog-ng/libcsvparser.so
%attr(755,root,root) %{_libdir}/syslog-ng/libcryptofuncs.so
%attr(755,root,root) %{_libdir}/syslog-ng/libdbparser.so
%attr(755,root,root) %{_libdir}/syslog-ng/liblinux-kmsg-format.so
%attr(755,root,root) %{_libdir}/syslog-ng/libsyslog-ng-crypto.so
%attr(755,root,root) %{_libdir}/syslog-ng/libsyslogformat.so
%attr(755,root,root) %{_libdir}/syslog-ng/libsystem-source.so
%attr(644,root,root) %{_datadir}/syslog-ng/include/scl/pacct/plugin.conf
%attr(644,root,root) %{_datadir}/syslog-ng/include/scl/rewrite/cc-mask.conf
%attr(644,root,root) %{_datadir}/syslog-ng/include/scl/system/plugin.conf
%attr(644,root,root) %{_datadir}/syslog-ng/include/scl/syslogconf/README
%attr(755,root,root) %{_datadir}/syslog-ng/include/scl/syslogconf/convert-syslogconf.awk
%attr(644,root,root) %{_datadir}/syslog-ng/include/scl/syslogconf/plugin.conf
%attr(644,root,root) %{_datadir}/syslog-ng/xsd/*

%if %{with dbi}

%files sql
%defattr(-,root,root)
%dir %{_libdir}/syslog-ng
%attr(755,root,root) %{_libdir}/syslog-ng/libafsql.so

%endif

%files json
%defattr(-,root,root)
%dir %{_libdir}/syslog-ng
%attr(755,root,root) %{_libdir}/syslog-ng/libjson-plugin.so

%files devel
%defattr(-,root,root)
%attr(644,root,root) %{_libdir}/libsyslog-ng.la
%attr(644,root,root) %{_libdir}/syslog-ng/*.la
%attr(644,root,root) %{_libdir}/pkgconfig/syslog-ng.pc
%dir %{_includedir}/syslog-ng
%attr(-,root,root) %{_includedir}/syslog-ng/*
%dir %{_datadir}/syslog-ng/tools
%attr(755,root,root) %{_datadir}/syslog-ng/tools/merge-grammar.pl
%attr(644,root,root) %{_datadir}/syslog-ng/tools/cfg-grammar.y
%attr(644,root,root) %{_datadir}/syslog-ng/tools/lex-rules.am

%if 0%{?with_smtp}

%files smtp
%defattr(-,root,root)
%dir %{_libdir}/syslog-ng
%attr(755,root,root) %{_libdir}/syslog-ng/libafsmtp.so

%endif

%if 0%{?with_geoip}

%files geoip
%defattr(-,root,root)
%dir %{_libdir}/syslog-ng
%attr(755,root,root) %{_libdir}/syslog-ng/libtfgeoip.so

%endif

%if %{with redis}

%files redis
%defattr(-,root,root)
%dir %{_libdir}/syslog-ng
%attr(755,root,root) %{_libdir}/syslog-ng/libredis.so

%endif

%changelog
openSUSE Build Service is sponsored by