--- maxscale.spec.old	2016-03-08 10:17:37.000000000 +0100
+++ maxscale.spec	2016-03-09 10:01:27.000000000 +0100
@@ -1,10 +1,11 @@
+%global nagios_plugins_dir %{_libdir}/nagios/plugins
 %global _hardened_build 1
 %global errmsg_dir %{_datadir}/mariadb/english
 
 Summary:        A database-centric proxy that works with MariaDB and MySQL
 Name:           maxscale
 Version:        1.3.0
-Release:        2%{?dist}
+Release:        3%{?dist}
 License:        GPLv2+
 Group:          Applications/Databases
 URL:            https://mariadb.com/products/mariadb-maxscale
@@ -32,8 +33,6 @@
 BuildRequires:  ncurses-devel
 BuildRequires:  openssl-devel
 BuildRequires:  systemtap-sdt-devel
-# redhat-rpm-config is not pulled in automatically
-BuildRequires:  redhat-rpm-config
 BuildRequires:  systemd
 BuildRequires:  zlib-devel
 BuildRequires:  mariadb-embedded-devel
@@ -54,9 +53,6 @@
 Requires(preun): systemd
 Requires(postun): systemd
 
-# does not build on arm yet
-ExcludeArch:    %{arm}
-
 %description
 MaxScale is an open-source, database-centric proxy that works with MariaDB and
 MySQL
@@ -68,6 +64,14 @@
 MaxScale runs between the client application and the database cluster and
 currently offers connection and statement-based load balancing.
 
+%package -n     nagios-%{name}
+Summary:        Nagios plugins to monitor MaxScale
+Group:          Applications/System
+Requires:       nagios
+
+%description -n nagios-%{name}
+These plugins allow you to monitor MaxScale monitors, resources and threads.
+
 %prep
 
 %setup -q -n MaxScale-%{version}
@@ -135,14 +139,24 @@
 # provide the config
 mv %{buildroot}%{_sysconfdir}/maxscale.cnf.template %{buildroot}%{_sysconfdir}/maxscale.cnf
 
+# rearrange docs and files
+rm -rf %{buildroot}%{_datadir}/%{name}
+
+# nagios plugins
+install -d -m 755 %{buildroot}%{nagios_plugins_dir}
+install -p -m 755 plugins/nagios/*.pl %{buildroot}%{nagios_plugins_dir}
+
+install -d -m 0755 %{buildroot}%{_sysconfdir}/nagios/conf.d/
+install -p -m 644 plugins/nagios/maxscale_commands.cfg %{buildroot}%{_sysconfdir}/nagios/conf.d/%{name}.cfg
+
 %pre
 getent group %{name} >/dev/null || groupadd -r %{name}
 getent passwd %{name} >/dev/null || \
     useradd -r -g %{name} -d %{_localstatedir}/lib/%{name} -s /sbin/nologin \
     -c "MaxScale Server" %{name}
 
-
 %post
+/sbin/ldconfig
 # generate the unique .secrets file
 if [ -e %{_localstatedir}/lib/%{name}/etc/.secrets ]; then
     MAXSCALE_HOME=%{_localstatedir}/lib/%{name} %{_bindir}/maxkeys %{_localstatedir}/lib/%{name}/etc/
@@ -157,20 +171,21 @@
 
 %postun
 %systemd_postun_with_restart %{name}.service
+/sbin/ldconfig
 
 %files
-%doc %{_datadir}/%{name}/COPYRIGHT
-%doc %{_datadir}/%{name}/README
-%license %{_datadir}/%{name}/LICENSE
+%doc Changelog.txt COPYRIGHT README ReleaseNotes.txt UpgradingToMaxScale12.txt
+%doc etc/lsyncd_example.conf server/maxscale_binlogserver_template.cnf server/maxscale_template.cnf
+%license LICENSE
 
 %{_bindir}/*
 %dir %{_libdir}/%{name}
 %{_libdir}/%{name}/*.so
 %{_libdir}/liblog_manager.so*
 %{_libdir}/libquery_classifier.so*
-%{_datadir}/%{name}
 %{_unitdir}/%{name}.service
 
+%attr(0750,%{name},%{name}) %dir %{_localstatedir}/lib/maxscale/etc
 %attr(0400,%{name},%{name}) %config(noreplace) %{_localstatedir}/lib/maxscale/etc/.secrets
 %attr(0750,%{name},%{name}) %dir %{_localstatedir}/log/%{name}
 %attr(0750,%{name},%{name}) %dir %{_localstatedir}/lib/%{name}
@@ -180,12 +195,28 @@
 %{_localstatedir}/lib/%{name}/run
 
 %attr(0640,root,%{name}) %config(noreplace) %{_sysconfdir}/%{name}.cnf
+
+%attr(0755,root,root) %dir %{_sysconfdir}/logrotate.d
 %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
+
 %{_tmpfilesdir}/%{name}.conf
 %{_mandir}/man1/maxscale.1.*
 
+%files -n nagios-%{name}
+%doc plugins/nagios/server1.cfg
+%license LICENSE
+%config(noreplace) %{_sysconfdir}/nagios/conf.d/%{name}.cfg
+%{nagios_plugins_dir}/check_maxscale_monitors.pl
+%{nagios_plugins_dir}/check_maxscale_resources.pl
+%{nagios_plugins_dir}/check_maxscale_threads.pl
 
 %changelog
+* Wed Mar 09 2016 Oden Eriksson <oe@nux.se> 1.3.0-3
+- rearrange docs and files
+- comply to fedora packaging rules
+- added the nagios-maxscale sub package
+- builds for arm, at mageia anyway
+
 * Tue Mar 08 2016 Oden Eriksson <oe@nux.se> 1.3.0-2
 - sync with maxscale-1.3.0-5.mga6.src.rpm:
  - build against system pcre2 libs
