spec files broken: core, plugins and nrpe incompat packages

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
User avatar
Florin Andrei
Posts: 11
Joined: Mon Aug 26, 2013 6:04 pm
Location: California
Contact:

spec files broken: core, plugins and nrpe incompat packages

Post by Florin Andrei »

I'm preparing for the upgrade to Nagios v4 on a Red Hat 5 compatible server. I am building RPM packages out of the tarballs for nagios-core, nagios-plugins, and nrpe. It's pretty messy. Out the box, the packages are incompatible with each other. For most, the build process exits with errors. Nagios Core has 644 permissions on the plugins directory. The list goes on and on. One or two problems are specific to RH5, but many would affect most if not all 64 bit distros, some errors allow build to happen, but the packages won't work once installed - anywhere.

I think the spec files have fallen into neglect, and some kind of spring cleaning is necessary. I am not the one to do it, I don't have enough time. I've merely fixed the specs while keeping them close to the original version, which is probably not ideal. The spec files should be overhauled closer to the RPM guidelines.

First off, take a look at the attached files. These are the fixed specs. Just remove the .txt extension, put the tarball in the SOURCES directory in your RPM build area, and do a "rpmbuild -ba specfilename.spec" and it will build the packages for you.

Now let's discuss each spec file. I'll do a diff -u on each spec file and discuss the output.

Nagios Core 4.0.0

Firstly, compilation during the package build fails outright on RH5 with the default gcc-4.1.2 compiler. You need to install the gcc44 package (yum install gcc44), then do "export CC=gcc44", then try again "rpmbuild -ba nagios.spec". I've chosen to use gcc44 for all Nagios-related packages, not only for Core, just to keep things consistent, even though the other packages may build without it.

The issue has been filed here:

http://tracker.nagios.org/view.php?id=488

Let's discuss the diff:

Code: Select all

[root@oracle5 specs]# diff -u orig/nagios.spec fixed/nagios.spec 
--- orig/nagios.spec    2013-09-20 12:01:20.000000000 -0700
+++ fixed/nagios.spec   2013-10-23 11:37:20.000000000 -0700
@@ -65,7 +65,7 @@
 This package contains all the files from the contrib directory
 
 %prep
-%setup
+%setup -n %{name}
 
 # /usr/local/nagios is hardcoded in many places
 %{__perl} -pi.orig -e 's|/usr/local/nagios/var/rw|%{_localstatedir}/nagios/rw|g;' contrib/eventhandlers/submit_check_result
When unpacking most tarballs, the content will end up in a directory named %{name}-%{version}. The Nagios tarball unpacks into just %{name}. You have to explicitly indicate that, otherwise it will fail. This spec could never have worked with the original tarball. It was probably not tested before release.

Bug report filed here:

http://tracker.nagios.org/view.php?id=487

Code: Select all

@@ -153,10 +153,10 @@
 %{__cp} -afpv contrib/eventhandlers/* %{buildroot}%{_libdir}/nagios/plugins/eventhandlers/
 %{__mv} contrib/README contrib/README.contrib
 
-CGI=`/bin/find contrib/ -name '*.cgi' -type f |sed s/'contrib\/'//g`
+CGI=`find contrib/ -name '*.cgi' -type f |sed s/'contrib\/'//g`
 CGI=`for i in $CGI; do echo -n "$i|"; done |sed s/\|$//`
-/bin/find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep -ve "($CGI)" > cgi.files
-/bin/find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep "($CGI)" > contrib.files
+find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep -ve "($CGI)" > cgi.files
+find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep "($CGI)" > contrib.files
The spec file inconsistently uses either find, or the hardcoded path /bin/find. The problem is, there is no /bin/find on RH5. This would never work. Since plain find is used somewhere else in the spec, I've removed all the hardcoded paths.

Bug report filed here:

http://tracker.nagios.org/view.php?id=489

Code: Select all

@@ -206,7 +206,7 @@
 %attr(0755,root,root) %config %{_initrddir}/nagios
 %attr(0755,root,root) %{_bindir}/nagios
 %attr(0755,root,root) %{_bindir}/nagiostats
-%attr(0644,root,root) %{_libdir}/nagios/plugins/
+%attr(0755,root,root) %{_libdir}/nagios/plugins/
 %attr(0755,root,root) %{_datadir}/nagios/
 %attr(0755,nagios,nagios) %dir %{_sysconfdir}/nagios/
 %attr(0644,nagios,nagios) %config(noreplace) %{_sysconfdir}/nagios/*.cfg
644 permissions on the plugins directory. This has caused me a lot of grief, since the error is subtle and hard to troubleshoot. Basically, no plugin works unless you're root. This would never work in real life, when Nagios is run as a non-root user.

Nagios Plugins 1.5

You need to build this package as root, even though this is contrary to standard practice, otherwise some plugins would not install correctly.

Here's the diff:

Code: Select all

[root@oracle5 specs]# diff -u orig/nagios-plugins.spec fixed/nagios-plugins.spec 
--- orig/nagios-plugins.spec    2013-10-02 08:26:48.000000000 -0700
+++ fixed/nagios-plugins.spec   2013-10-23 11:37:27.000000000 -0700
@@ -7,12 +7,12 @@
        %define _prefix /opt/nagios
 #      %define _defaultdocdir %{_datadir}/doc
 %else
-       %define _libexecdir %{_exec_prefix}/lib/nagios/plugins
+       %define _libexecnagios "%{_libdir}/nagios/plugins"
 %endif
-%define _sysconfdir /etc/nagios
+%define _sysconfnagios "%{_sysconfdir}/nagios"
 
 %define npusr nagios
-%define nphome /opt/nagios
+%define nphome %{_localstatedir}/log/nagios
 %define npgrp nagios
 
 Name: nagios-plugins
%{_libexecdir} and %{_sysconfdir} are RPM macros. Never over-write them! There's no reason to do that. You could simply pick a different name for whatever macro you want to use. If you overwrite the default macros, the side-effects could be hard to predict. I've renamed these to the custom macros %{_libexecnagios} and %{_sysconfnagios} and you'll see them renamed again many times below.

Also, while the Core package correctly uses the %{_libdir} macro to choose the location for the plugins directory, which ends up in /usr/lib64/nagios/plugins on a 64 bit system (and /usr/lib/nagios/plugins on a 32 bit system), the Plugins spec hardcodes that path to */lib/nagios/plugins no matter what. Nothing will work if you build the Core and the Plugins packages from tarballs on 64 bit Linux, because the plugin locations will be different. The packages will be incompatible.

I've changed the definition of the plugins directory to match the Core tarball, and be consistent with the architecture of the OS where you're building it.

Code: Select all

@@ -30,8 +30,8 @@
 
 %if %{isaix}
 Prefix: %{_prefix}
-%else
-Prefix: %{_prefix}/lib/nagios/plugins
+#%else
+#Prefix: %{_prefix}/lib/nagios/plugins
 %endif
 Packager: Karl DeBisschop <kdebisschop@users.sourceforge.net>
 Vendor: Nagios Plugin Development Group
Again, an RPM default macro is being over-written. Don't do that.

Code: Select all

@@ -117,8 +117,8 @@
 %{?isaix: MAKE=gmake} ./configure \
 --prefix=%{_prefix} \
 --exec-prefix=%{_exec_prefix} \
---libexecdir=%{_libexecdir} \
---sysconfdir=%{_sysconfdir} \
+--libexecdir="%{_libdir}/nagios/plugins" \
+--sysconfdir=%{_sysconfnagios} \
 --datadir=%{_datadir} \
 --with-cgiurl=/nagios/cgi-bin
 ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-before
This is just a continuation of removing the over-write of the default macros.

Code: Select all

@@ -155,7 +155,7 @@
 %if %{islinux}
 getent passwd %{npusr} > /dev/null 2> /dev/null
 if [ $? -ne 0 ] ; then
-       useradd -r -d %{nshome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
+       useradd -r -d %{nphome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
                %nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
 fi
 %endif
A typo. I don't think the RPM would even build with this error. That macro must be unknown. Has this never been tested?

Code: Select all

@@ -163,30 +163,32 @@
 %install
 rm -rf $RPM_BUILD_ROOT
 make AM_INSTALL_PROGRAM_FLAGS="" DESTDIR=${RPM_BUILD_ROOT} install
-build-aux/install-sh -c  -d ${RPM_BUILD_ROOT}%{_sysconfdir}
-build-aux/install-sh -c  -m 664 command.cfg ${RPM_BUILD_ROOT}%{_sysconfdir}
+build-aux/install-sh -c  -d ${RPM_BUILD_ROOT}%{_sysconfnagios}
+#build-aux/install-sh -c  -m 664 command.cfg ${RPM_BUILD_ROOT}%{_sysconfnagios}
+build-aux/install-sh -c  -m 664 plugins/libnpcommon.a ${RPM_BUILD_ROOT}%{_libexecnagios}
 %find_lang %{name}
 echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
 echo "%defattr(755,root,root)" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
 echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
-echo "%{_libexecdir}/utils.pm" >> %{name}.lang
-echo "%{_libexecdir}/utils.sh" >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+echo "%{_libexecnagios}/utils.pm" >> %{name}.lang
+echo "%{_libexecnagios}/utils.sh" >> %{name}.lang
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 
 %files -f %{name}.lang
-%config(missingok,noreplace) %{_sysconfdir}/command.cfg
+#%config(missingok,noreplace) %{_sysconfnagios}/command.cfg
 %doc CODING COPYING FAQ INSTALL LEGAL README REQUIREMENTS SUPPORT THANKS
-%doc ChangeLog command.cfg
+%doc ChangeLog
 %if ! %{isaix}
 %{_datadir}/locale/de/LC_MESSAGES/nagios-plugins.mo
 %{_datadir}/locale/fr/LC_MESSAGES/nagios-plugins.mo
 %endif
+%{_libdir}/nagios/plugins/check_ldaps
 
 %changelog
 * Mon May 23 2005 Sean Finney <seanius@seanius.net> - cvs head
Again, restoring the default macros and using the alternative macro names. These are pretty big changes, I am not 100% sure these are correct, as I'm not very familiar with the software, but the package works well for me.

I think command.cfg was not even built, IIRC.

check_ldaps is installed, but it's not taken into the RPM for some reason, and the final stage of package building breaks. I don't have time to investigate why. Just add it here and it works. This is not a clean fix, sorry.

NRPE 2.15

This one also has to be built as root, otherwise changing the ownership on check_nrpe fails.

Here's the diff:

Code: Select all

[root@oracle5 specs]# diff -u orig/nrpe.spec fixed/nrpe.spec 
--- orig/nrpe.spec      2013-09-06 08:27:13.000000000 -0700
+++ fixed/nrpe.spec     2013-10-23 11:37:33.000000000 -0700
@@ -9,16 +9,14 @@
 %endif
 %if %{islinux}
        %define _init_dir /etc/init.d
-       %define _exec_prefix %{_prefix}/sbin
-       %define _bindir %{_prefix}/sbin
-       %define _sbindir %{_prefix}/lib/nagios/cgi
-       %define _libexecdir %{_prefix}/lib/nagios/plugins
-       %define _datadir %{_prefix}/share/nagios
-       %define _localstatedir /var/log/nagios
-       %define nshome /var/log/nagios
+       %define _bindir_nrpe %{_prefix}/sbin
+       %define _sbindir_nrpe %{_libdir}/nagios/cgi
+       %define _libexecdir_nrpe %{_libdir}/nagios/plugins
+       %define _datadir_nrpe %{_datadir}/nagios
+       %define nshome %{_localstatedir}/log/nagios
        %define _make make
 %endif
-%define _sysconfdir /etc/nagios
+%define _sysconfdir_nrpe %{_sysconfdir}/nagios
 
 %define name nrpe
 %define version 2.15
Lots and lots of over-riding default macros, hardcoding paths, etc. I'm not even sure I've fixed everything.

And again, the same issue with the compatibility with Core w.r.t. the location of the plugins directory. This package, again, was incorrectly hardcoding it to */lib/nagios/plugins, unlike Core. Fixed that to make these packages play nicely together.

Code: Select all

@@ -141,7 +139,7 @@
 %post
 /usr/bin/lssrc -s nrpe > /dev/null 2> /dev/null
 if [ $? -eq 1 ] ; then
-       /usr/bin/mkssys -p %{_bindir}/nrpe -s nrpe -u 0 -a "-c %{_sysconfdir}/nrpe.cfg -d -s" -Q -R -S -n 15 -f 9
+       /usr/bin/mkssys -p %{_bindir_nrpe}/nrpe -s nrpe -u 0 -a "-c %{_sysconfdir_nrpe}/nrpe.cfg -d -s" -Q -R -S -n 15 -f 9
 fi
 /usr/bin/startsrc -s nrpe
 %endif
Continuing down the path of reverting default macro over-rides.

Code: Select all

@@ -177,13 +175,11 @@
        --with-nrpe-user=%{nsusr} \
        --with-nrpe-group=%{nsgrp} \
        --prefix=%{_prefix} \
-       --exec-prefix=%{_exec_prefix} \
-       --bindir=%{_bindir} \
-       --sbindir=%{_sbindir} \
-       --libexecdir=%{_libexecdir} \
-       --datadir=%{_datadir} \
-       --sysconfdir=%{_sysconfdir} \
-       --localstatedir=%{_localstatedir} \
+       --bindir=%{_bindir_nrpe} \
+       --sbindir=%{_sbindir_nrpe} \
+       --libexecdir=%{_libexecdir_nrpe} \
+       --datadir=%{_datadir_nrpe} \
+       --sysconfdir=%{_sysconfdir_nrpe} \
        --enable-command-args
 %{_make} all
And again.

Code: Select all

@@ -193,17 +189,17 @@
 install -d -m 0755 ${RPM_BUILD_ROOT}%{_init_dir}
 %endif
 DESTDIR=${RPM_BUILD_ROOT} %{_make} install install-daemon-config
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_sysconfdir}
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_bindir}
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_libexecdir}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_sysconfdir_nrpe}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_bindir_nrpe}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_libexecdir_nrpe}
 
 # install templated configuration files
-#cp sample-config/nrpe.cfg ${RPM_BUILD_ROOT}%{_sysconfdir}/nrpe.cfg
+cp sample-config/nrpe.cfg ${RPM_BUILD_ROOT}%{_sysconfdir_nrpe}/nrpe.cfg
 #%if %{isaix}
-#cp init-script ${RPM_BUILD_ROOT}%{_init_dir}/nrpe
+cp init-script ${RPM_BUILD_ROOT}%{_init_dir}/nrpe
 #%endif
-#cp src/nrpe ${RPM_BUILD_ROOT}%{_bindir}
-#cp src/check_nrpe ${RPM_BUILD_ROOT}%{_libexecdir}
+#cp src/nrpe ${RPM_BUILD_ROOT}%{_bindir_nrpe}
+#cp src/check_nrpe ${RPM_BUILD_ROOT}%{_libexecdir_nrpe}
 
 %clean
 rm -rf $RPM_BUILD_ROOT
And again.

Not sure why the init script was not being copied to /etc/init.d. It's needed there for the NRPE service. I've enabled the copy. Same for the .cfg file.

Code: Select all

@@ -214,16 +210,16 @@
 %defattr(755,root,root)
 /etc/init.d/nrpe
 %endif
-%{_bindir}/nrpe
-%dir %{_sysconfdir}
+%{_bindir_nrpe}/nrpe
+%dir %{_sysconfdir_nrpe}
 %defattr(600,%{nsusr},%{nsgrp})
-%config(noreplace) %{_sysconfdir}/*.cfg
+%config(noreplace) %{_sysconfdir_nrpe}/*.cfg
 %defattr(755,%{nsusr},%{nsgrp})
 %doc Changelog LEGAL README 
 
 %files plugin
 %defattr(755,%{nsusr},%{nsgrp})
-%{_libexecdir}
+%{_libexecdir_nrpe}
 %defattr(644,%{nsusr},%{nsgrp})
 %doc Changelog LEGAL README
And again.
Attachments
nrpe.spec.txt
(7.35 KiB) Downloaded 534 times
nagios-plugins.spec.txt
(6.83 KiB) Downloaded 546 times
nagios.spec.txt
(8.31 KiB) Downloaded 425 times
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: spec files broken: core, plugins and nrpe incompat packa

Post by tmcdonald »

I'm gonna go ahead and bookmark this as "this guy knows his stuff". Entering this to our internal tracker. Awesome breakdown.
Former Nagios employee
TheQL
Posts: 1
Joined: Wed Jan 22, 2014 9:07 am

Re: spec files broken: core, plugins and nrpe incompat packa

Post by TheQL »

Hi Florin,

you're completely right, the .spec files are a catastrophe! Anyway, I tried yours for nrpe, but you still need to be root for the permission change, right? Isn't there a way around that? The 2.12 tarball builds fine.

Thanks!
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: spec files broken: core, plugins and nrpe incompat packa

Post by abrist »

Thanks a bunch. I have just let Eric (one of our core devs) know about the core spec issues (he probably already knows if you posted to tracker). I will look over the nagios-plugins spec file issues - I just took over the plugins project so fixing up the spec file will be a priority, but I cannot do much about the 1.5 tag tarball (maybe a maint release?). We should have a new release of the plugins very shortly though, so I will take a look at your patches and see if we can fix up the spec file before release.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
User avatar
Florin Andrei
Posts: 11
Joined: Mon Aug 26, 2013 6:04 pm
Location: California
Contact:

Re: spec files broken: core, plugins and nrpe incompat packa

Post by Florin Andrei »

TheQL wrote:I tried yours for nrpe, but you still need to be root for the permission change, right? Isn't there a way around that? The 2.12 tarball builds fine.
Yes, I believe at least one of the packages requires root while compiling / building. The way I see it, it seems more like something the software does, rather than something depending on the RPM build system. I'm sure a workaround could be concocted, but I haven't looked into it. I build my packages in a virtual instance - if something bad happens to it, I just make another one.
User avatar
Florin Andrei
Posts: 11
Joined: Mon Aug 26, 2013 6:04 pm
Location: California
Contact:

Re: spec files broken: core, plugins and nrpe incompat packa

Post by Florin Andrei »

abrist wrote:Thanks a bunch. I have just let Eric (one of our core devs) know about the core spec issues (he probably already knows if you posted to tracker). I will look over the nagios-plugins spec file issues - I just took over the plugins project so fixing up the spec file will be a priority, but I cannot do much about the 1.5 tag tarball (maybe a maint release?). We should have a new release of the plugins very shortly though, so I will take a look at your patches and see if we can fix up the spec file before release.
That's good news. You guys should sync up and work on the spec files together. All those different packages (core, plugins, nrpe, etc) need to agree on common locations and whatnot.

The EPEL packages are usually built very clean, very standard-like. I'm sure you could borrow some ideas from their spec files. I think they are breaking them up too much (one package for each little plugin), but otherwise their packaging philosophy is very sound. I would have stolen and hacked their specs if I had a bit more time; instead, I preferred quick fixes to the existing spec files.

http://dl.fedoraproject.org/pub/epel/6/ ... group.html
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: spec files broken: core, plugins and nrpe incompat packa

Post by sreinhardt »

Great comments Florin! Once Abrist and I get some more patches out for the plugins package, we will sit down and hash out at least the plugins spec, and I can work with Eric to deal with the core spec. I'll have to figure out who's handling the nrpe one, but agreed they should agree on locations of files, if they are not already, and not cause conflicts, if they are presently as you say. We created a bug on the nagios-plugins for this issue, feel free to add any comments you might have there too! https://github.com/nagios-plugins/nagio ... s/issues/7
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked