File nagiosgrapher.spec of Package nagiosgrapher

#
# spec file for package nagiosgrapher
#
# Copyright (c) 2019 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 https://bugs.opensuse.org/
#


%define         realname NagiosGrapher
%define         realversion 1.7.1
%if 0%{?suse_version} >= 1230
%bcond_without systemd
%else
%bcond_with systemd
%endif

Name:           nagiosgrapher
Version:        1.7.1
Release:        0
Summary:        Performancemonitoring for Nagios
License:        GPL-2.0-or-later
URL:            https://www.netways.de/de/produkte/nagios_addons/nagiosgrapher/
Group:          System/Monitoring
Source0:        %{realname}-%{realversion}.tar.bz2
Source1:        nagiosgrapher.logrotate
Source2:        nagiosgrapher.init
Source3:        nagiosgrapher.README.SUSE
Source4:        nagiosgrapher-rpmlintrc
Source5:        nagiosgrapher.systemd
Source6:        nagiosgrapher.tmpfile
# PATCH-FIX-OPENSUSE -- Do not use chown/chgrp in Makefile: use the filelist in rpm instead
Patch1:         nagiosgrapher-1.7.1-buildroot.patch
BuildRequires:  apache2
BuildRequires:  autoconf
BuildRequires:  nagios
BuildRequires:  nagios-rpm-macros
BuildRequires:  nagios-www
BuildRequires:  perl(CGI)
BuildRequires:  perl(CGI::Carp)
BuildRequires:  perl(Calendar::Simple)
BuildRequires:  perl(Carp)
BuildRequires:  perl(Data::Dumper)
BuildRequires:  perl(File::Basename)
BuildRequires:  perl(File::Copy)
BuildRequires:  perl(GD)
BuildRequires:  perl(IO::Handle)
BuildRequires:  perl(Image::Magick)
BuildRequires:  perl(POSIX)
BuildRequires:  perl(RRDs)
BuildRequires:  perl(Storable)
BuildRequires:  perl(Time::HiRes)
BuildRequires:  perl(Time::Local)
BuildRequires:  perl(URI::Escape)
#
Requires:       logrotate
Requires:       nagios
Requires:       nagios-www
Requires:       perl-base
Requires:       perl(CGI)
Requires:       perl(CGI::Carp)
Requires:       perl(Calendar::Simple)
Requires:       perl(Carp)
Requires:       perl(Data::Dumper)
Requires:       perl(File::Basename)
Requires:       perl(File::Copy)
Requires:       perl(GD)
Requires:       perl(IO::Handle)
Requires:       perl(Image::Magick)
Requires:       perl(POSIX)
Requires:       perl(RRDs)
Requires:       perl(Storable)
Requires:       perl(Time::HiRes)
Requires:       perl(Time::Local)
Requires:       perl(URI::Escape)
%if %{with systemd}
BuildRequires:  systemd
%{?systemd_requires}
%else
Requires(pre):  %insserv_prereq
%endif
%if 0%{?suse_version} >= 1110
BuildRequires:  fdupes
%endif

%description
The "NETWAYS Nagios Grapher" is a Graphing system which uses templates
to assign services to various data sources (RRDs). Thus it is possible
to create a quantity of graphs using only a small configuration,
keeping it easy to manage. These templates are automatically applied to
incoming data, thus creating a new service in Nagios will automatically
create the graph once valid data is seen for that service. Corrolations
between different graphs is also possible.

%prep
%setup -q -n %{realname}-%{realversion}
rm doc/INSTALL
cat >> config.layout << EOF

# layout for suse rpm install
<Layout SUSE>
  prefix:                              %{_datadir}/%{name}
  nagios_config:                       %{nagios_sysconfdir}/nagios.cfg
  nagios_config_cgi:                   %{nagios_sysconfdir}/cgi.cfg
  nagios_images:                       %{nagios_datadir}/images
  nagios_images_logos:                 %{nagios_datadir}/images/logos
  nagios_folder_cgi:                   %{nagios_cgidir}
  perl_inc:                            %{perl_vendorlib}
  nagios_contribution:                 %{nagios_plugindir}/contrib
  ng_config:                           %{nagios_sysconfdir}
  ng_config_sub:                       %{nagios_sysconfdir}/ngraph.d
  ng_daemon:                           %{_localstatedir}/run/%{name}
  ng_srvext_file:                      %{nagios_sysconfdir}/serviceextinfo.cfg
  ng_srvext_dir:                       %{nagios_sysconfdir}/serviceext
  ng_interface_pipe:                   %{_localstatedir}/run/%{name}/ngraph.pipe
  ng_logfile:                          %{nagios_logdir}/ngraph.log
  ng_rrd:                              %{nagios_localstatedir}/rrd/%{name}
  ng_rrd_font:                         %{_datadir}/fonts/truetype/DejaVuSansMono.ttf
  ng_cgi:                              /nagios/cgi-bin
  ng_logos:                            /nagios/images/logos
%if %{with systemd}
  init_script_dir:                     %{_sbindir}
%else
  init_script_dir:                     %{_sysconfdir}/init.d
%endif
</Layout>
EOF
%patch1
# install README.SUSE
sed -e 's@__LIBDIR__@%{_prefix}/lib@g' %{SOURCE3} > README.SUSE
# fix encoding
sed -i "s|^M||g" doc/*

%build
autoconf
%configure \
    --with-layout=SUSE \
    --with-distro=suse \
%if 0%{?suse_version} >= 1110
    --pdfdir=%{_defaultdocdir}/%{name} \
%endif
    --with-ng-interface=pipe \
    --with-ng-loglevel=63

%check
make %{?_smp_mflags} testdeps

%install
%make_install PERL_INC=%{perl_vendorlib}

# install init file
test -f %{buildroot}%{_sysconfdir}/init.d/nagios_grapher && rm %{buildroot}%{_sysconfdir}/init.d/nagios_grapher
test -f %{buildroot}%{_sbindir}/nagios_grapher && rm %{buildroot}%{_sbindir}/nagios_grapher
%if %{with systemd}
install -D -m0644 %{SOURCE5} %{buildroot}/%{_unitdir}/%{name}.service
install -D -m0644 %{SOURCE6} %{buildroot}/%{_prefix}/lib/tmpfiles.d/%{name}.conf
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service  %{buildroot}%{_sbindir}/rc%{name}
%else
install -D -m 755 %{SOURCE2} %{buildroot}%{_sysconfdir}/init.d/%{name}
install -d -m 0755 %{buildroot}/%{_sbindir}
ln -sf %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif

# install logrotate scripts
test -f %{buildroot}/nagios_grapher && rm %{buildroot}/nagios_grapher
install -d -m 0755 %{buildroot}%{_sysconfdir}/logrotate.d/
install -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%if 0%{?suse_version} > 01140
# additional security feature for logrotate since 3.8: 'su'
sed -i "s|postrotate|su nagios nagcmd\n    postrotate|g" %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%endif

# fix permissions
chmod +x %{buildroot}%{nagios_cgidir}/*.cgi
chmod -x %{buildroot}%{nagios_sysconfdir}/*.ncfg
chmod -x %{buildroot}%{nagios_sysconfdir}/ngraph.d/*.ncfg

# make rpmlint happy
%if 0%{?suse_version} >= 1110
%fdupes %{buildroot}%{nagios_datadir}/images
%endif

# create the ghost files
mkdir -p %{buildroot}%{nagios_logdir}
touch %{buildroot}%{nagios_logdir}/ngraph.log
%if ! %{with systemd}
mkdir -p %{buildroot}%{_localstatedir}/run/%{name}
touch %{buildroot}%{_localstatedir}/run/%{name}/ngraph.pipe
touch %{buildroot}%{nagios_sysconfdir}/serviceextinfo.cfg
%endif


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

%post
%service_add_post %{name}.service
systemd-tmpfiles --create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%fillup_only

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%else
%preun
%stop_on_removal %{name}

%postun
%restart_on_update %{name}
%insserv_cleanup
%endif


%files
%doc README.SUSE doc/*
%{nagios_cgidir}/*.cgi
%{nagios_plugindir}/contrib
%if %{with systemd}
%{_unitdir}/%{name}.service
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%else
%{_sysconfdir}/init.d/%{name}
%ghost %config(noreplace,missingok) %{_localstatedir}/run/%{name}/ngraph.pipe
%endif
%{_sbindir}/rc%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{nagios_sysconfdir}/ngraph.d
%attr(644,root,root) %{nagios_datadir}/images/*.png
%attr(644,root,root) %{nagios_datadir}/images/logos/*.png
%{perl_vendorlib}/*.pm
%{perl_vendorlib}/NagiosGrapher
%ghost %config(missingok,noreplace) %{_sysconfdir}/nagios/serviceextinfo.cfg
#
%defattr(-,%{nagios_user},%{nagios_command_group})
%dir %{nagios_sysconfdir}/serviceext
%dir %{nagios_localstatedir}/rrd
%dir %{nagios_localstatedir}/rrd/%{name}
%dir %{nagios_logdir}
%config(noreplace) %{nagios_sysconfdir}/ngraph.ncfg
%ghost %config(noreplace,missingok) %{nagios_logdir}/ngraph.log
%ghost %dir %{_localstatedir}/run/%{name}

%changelog