File ndoutils.spec of Package ndoutils

#
# spec file for package ndoutils
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2015-2016 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/
#

%if 0%{?suse_version} >= 1230
%bcond_without systemd
%else
%bcond_with systemd
%endif

Name:           ndoutils
Summary:        Nagios v3.x Data Output Utilities
License:        GPL-2.0+
Group:          System/Monitoring
Version:        2.1.1
Release:        0
Url:            http://www.nagios.org/
Source0:        %{name}-%{version}.tar.bz2
Source1:        %{name}-init
Source2:        ndoutils-README.SUSE
Source3:        ndoutils-rpmlintrc
Patch0:         ndoutils-2.1.0-add_includes.patch
Patch1:         ndoutils-2.1.0-return-non-void-queue.patch
Requires(pre):  %insserv_prereq
BuildRequires:  nagios-rpm-macros
BuildRequires:  libmysqlclient-devel
BuildRequires:  nagios-devel >= 3.0
BuildRequires:  procps
# postgresql is currently not supported but will likely be added in the future
# BuildRequires:  postgresql-devel
BuildRequires:  tcpd
%if 0%{?suse_version} > 1030 || 0%{?fedora_version} > 8
BuildRequires:  fdupes
%endif
Requires:       nagios >= 3.0
%if %{with systemd}
BuildRequires:  systemd
%{?systemd_requires}
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
NDOUtils is an Nagios addon allowing you to store Nagios data (current status
information, state history, notification history, etc.) in a MySQL database.

This addon consists of an event broker module and a daemon.

Consider this addon to be experimental for the moment, although it will likely
play a central role in the a new Nagios web interface in the future.


%package doc
Summary:        Main documentation for ndoutils
Group:          Documentation/Other
Recommends:     %{name} = %{version}

%description doc
This package includes the main documentation for ndoutils.


%prep
%setup -q
%patch0 -p1
%patch1 -p1
install -m644 %{SOURCE2} README.SUSE
## rpmlint
# wrong-file-end-of-line-encoding
pushd docs/docbook/en-en
%{__perl} -p -i -e 's|\r\n|\n|' Makefile.in ent/documents.ent ent/version.ent
popd

# fix permissions of documentation to prevent false duplicates issued by rpmlint (bnc#784670)
find docs -type f -exec chmod 0644 {} +

%build
%configure \
    --enable-mysql \
    --localstatedir=%{_localstatedir}/lib/ndo \
    --with-piddir=%{_localstatedir}/run/ndo \
    --with-ndo2db-user=%{nagios_user} \
    --with-ndo2db-group=%{nagios_group}
# do not use jobs here, makefile dependencies are unsafe
make all

%install
install -d %{buildroot}%{nagios_sysconfdir}
install -d %{buildroot}%{_sbindir}
install -d %{buildroot}%{_bindir}
install -d %{buildroot}%{_prefix}/lib/nagios/brokers
install -d %{buildroot}%{_localstatedir}/lib/ndo
install -d %{_builddir}/%{name}-%{version}/examples

install -m0755 src/ndo2db-3x     %{buildroot}%{_sbindir}/ndo2db
install -m0755 src/file2sock     %{buildroot}%{_bindir}/file2sock
install -m0755 src/log2ndo       %{buildroot}%{_bindir}/log2ndo
install -m0755 src/sockdebug     %{buildroot}%{_bindir}/sockdebug
install -m0755 src/ndomod-3x.o   %{buildroot}%{_prefix}/lib/nagios/brokers/ndomod.o
#
# startup scripts
#
%if %{with systemd}
install -D -m0644 startup/default-socket  %{buildroot}/%{_unitdir}/%{name}.socket
install -D -m0644 startup/default-service %{buildroot}/%{_unitdir}/%{name}.service
install -D -m0644 startup/tmpfile.conf    %{buildroot}/%{_prefix}/lib/tmpfiles.d/%{name}.conf
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcndo2db
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%else
install -d %{buildroot}%{_localstatedir}/run/ndo
install -d %{buildroot}%{_sysconfdir}/init.d
install -m0755 %{SOURCE1}        %{buildroot}%{_sysconfdir}/init.d/ndo2db
ln -s %{_sysconfdir}/init.d/ndo2db %{buildroot}%{_sbindir}/rcndo2db
%endif

#
# fix path names in config
#
sed -e "s@^socket_name=.*@socket_name=%{nagios_spooldir}/ndo.sock@g" \
    -e "s@^debug_file=.*@debug_file=%{nagios_logdir}/ndo2db.debug@g" config/ndo2db.cfg-sample > %{buildroot}%{nagios_sysconfdir}/ndo2db.cfg

sed -e "s@^output=.*@output=%{nagios_spooldir}/ndo.sock@g" \
    -e "s@^buffer_file=.*@buffer_file=%{nagios_spooldir}/ndomod.tmp@g" config/ndomod.cfg-sample > %{buildroot}%{nagios_sysconfdir}/ndomod.cfg

cat > %{_builddir}/%{name}-%{version}/config/nagios.cfg << EOF
# SAMPLE NAGIOS CONFIG SNIPPET FOR NDOMOD
#
# In order to have Nagios run the NDOMOD event broker module, you'll need
# to place a statement like the one found below in your main Nagios
# configuration file (nagios.cfg).

# Uncomment the line below if you're running Nagios 3.x
#broker_module=%{_prefix}/lib/nagios/brokers/ndomod.o config_file=%{nagios_sysconfdir}/ndo2db.cfg
EOF

cat > %{_builddir}/%{name}-%{version}/config/misccommands.cfg << EOF
# SAMPLE NDO FILE ROTATION COMMAND
#
# This is an example Nagios command definition that can be used to
# rotate the NDO output file on a regular basis.  Adjust the paths, etc.
# to suit your needs.  This definition will need to be included in your
# Nagios config files if you want to use it.

define command {
        command_name    rotate_ndo_log
        command_line    /bin/mv %{nagios_spooldir}/ndo.dat %{nagios_spooldir}/ndo.\`date +%s\`
}
EOF
# install docu
mkdir -p %{buildroot}/%{_defaultdocdir}/%{name}/
cp -r db docs Changelog README* REQUIREMENTS TODO UPGRADING config/misccommands.cfg config/nagios.cfg %{buildroot}/%{_defaultdocdir}/%{name}/

# some rpmlint stuff
## files-duplicate
%if 0%{?fedora_version} > 8
fdupes -q -n -r %{buildroot}
%endif
%if 0%{?suse_version} 
%fdupes -s %{buildroot}
%endif



%if 0%{?suse_version}
%preun
%if %{with systemd}
%service_del_preun %{name}.service
%service_del_preun %{name}.socket
%else
%stop_on_removal ndo2db
%endif

%postun
%if %{with systemd}
%service_del_postun %{name}.service
%service_del_postun %{name}.socket
%else
%insserv_cleanup ndo2db
%restart_on_update
%endif

%post
%if %{with systemd}
%service_add_post %{name}.service
%service_add_post %{name}.socket
systemd-tmpfiles --create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%else
install -d -o %{nagios_user} -g %{nagios_group}  %{_localstatedir}/run/ndo
%endif

%if %{with systemd}
%pre
%service_add_pre %{name}.service
%service_add_pre %{name}.socket
%endif

%endif # suse_version

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
%exclude %{_defaultdocdir}/%{name}/docs
%config(noreplace) %attr(664,%{nagios_user},%{nagios_command_group}) %{nagios_sysconfdir}/ndomod.cfg
%config(noreplace) %attr(660,%{nagios_user},%{nagios_command_group}) %{nagios_sysconfdir}/ndo2db.cfg
%attr(0755,%{nagios_user},%{nagios_group}) %dir %{_localstatedir}/lib/ndo
%{_bindir}/file2sock
%{_bindir}/log2ndo
%{_bindir}/sockdebug
%{_sbindir}/ndo2db
%{_sbindir}/rcndo2db
%if %{with systemd}
%{_unitdir}/%{name}.socket
%{_unitdir}/%{name}.service
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%{_sbindir}/rc%{name}
%else
%ghost %dir %{_localstatedir}/run/ndo
%{_sysconfdir}/init.d/ndo2db
%endif
%dir %{_prefix}/lib/nagios/brokers
%{_prefix}/lib/nagios/brokers/ndomod.o

# change defattr
%defattr(0644,root,root,0755)
%doc  %{_defaultdocdir}/%{name}

%files doc
%defattr(0644,root,root,0755)
%doc %{_defaultdocdir}/%{name}/docs

%changelog
openSUSE Build Service is sponsored by