nagios.spec 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. ##
  2. ## nagios.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
  5. ##
  6. ## Permission to use, copy, modify, and distribute this software for
  7. ## any purpose with or without fee is hereby granted, provided that
  8. ## the above copyright notice and this permission notice appear in all
  9. ## copies.
  10. ##
  11. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  12. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  15. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  17. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  20. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  21. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. ## SUCH DAMAGE.
  23. ##
  24. # package versions
  25. %define V_nagios 2.8
  26. %define V_nagios_plugins 1.4.7
  27. %define V_perl_nagios_plugin 0.14
  28. %define V_perl_nagios_object 0.17
  29. %define V_perl_nagios_cmd 0.05
  30. # package information
  31. Name: nagios
  32. Summary: System and Network Monitoring
  33. URL: http://www.nagios.org/
  34. Vendor: Ethan Galstad et al.
  35. Packager: OpenPKG Foundation e.V.
  36. Distribution: OpenPKG Community
  37. Class: PLUS
  38. Group: Monitoring
  39. License: GPL
  40. Version: %{V_nagios}
  41. Release: 20070329
  42. # package options
  43. %option with_perl yes
  44. %option with_fsl yes
  45. # list of sources
  46. Source0: http://switch.dl.sourceforge.net/sourceforge/nagios/nagios-%{V_nagios}.tar.gz
  47. Source1: http://switch.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-%{V_nagios_plugins}.tar.gz
  48. Source2: http://www.cpan.org/authors/id/T/TO/TONVOON/Nagios-Plugin-%{V_perl_nagios_plugin}.tar.gz
  49. Source3: http://www.cpan.org/authors/id/T/TO/TOBEYA/Nagios-Object-%{V_perl_nagios_object}.tar.gz
  50. Source4: http://www.cpan.org/authors/id/T/TO/TOBEYA/Nagios-Cmd-%{V_perl_nagios_cmd}.tar.gz
  51. Source5: nagios.txt
  52. Source6: rc.nagios
  53. Source7: fsl.nagios
  54. Patch0: nagios.patch
  55. # build information
  56. Prefix: %{l_prefix}
  57. BuildRoot: %{l_buildroot}
  58. BuildPreReq: OpenPKG, openpkg >= 20060823, gcc
  59. PreReq: OpenPKG, openpkg >= 20060823, apache, MTA
  60. %if "%{with_perl}" == "yes"
  61. BuildPreReq: perl-openpkg
  62. BuildPreReq: perl, perl-net, perl-util
  63. %endif
  64. PreReq: perl, perl-net, perl-util
  65. BuildPreReq: zlib, jpeg, png, gd
  66. PreReq: zlib, jpeg, png, gd
  67. BuildPreReq: traceroute, openssl, openssh, coreutils, inetutils, fping, nail, snmp
  68. PreReq: traceroute, openssl, openssh, coreutils, inetutils, fping, nail, snmp
  69. %if "%{with_fsl}" == "yes"
  70. BuildPreReq: fsl >= 1.3.0
  71. PreReq: fsl >= 1.3.0
  72. %endif
  73. AutoReq: no
  74. AutoReqProv: no
  75. %description
  76. Nagios is a system and network monitoring application. It watches
  77. hosts and services that you specify, alerting you when things go bad
  78. and when they get better.
  79. %track
  80. prog nagios = {
  81. version = %{V_nagios}
  82. url = http://prdownloads.sourceforge.net/nagios/
  83. regex = nagios-(\d+(\.\d+)+)\.tar\.gz
  84. }
  85. prog nagios:plugins = {
  86. version = %{V_nagios_plugins}
  87. url = http://prdownloads.sourceforge.net/nagiosplug/
  88. regex = nagios-plugins-(\d+(\.\d+)+)\.tar\.gz
  89. }
  90. prog nagios:Nagios-Plugin = {
  91. version = %{V_perl_nagios_plugin}
  92. url = http://www.cpan.org/authors/id/T/TO/TONVOON/
  93. regex = Nagios-Plugin-(__VER__)\.tar\.gz
  94. }
  95. prog nagios:Nagios-Object = {
  96. version = %{V_perl_nagios_object}
  97. url = http://www.cpan.org/authors/id/T/TO/TOBEYA/
  98. regex = Nagios-Object-(__VER__)\.tar\.gz
  99. }
  100. prog nagios:Nagios-Cmd = {
  101. version = %{V_perl_nagios_cmd}
  102. url = http://www.cpan.org/authors/id/T/TO/TOBEYA/
  103. regex = Nagios-Cmd-(__VER__)\.tar\.gz
  104. }
  105. %prep
  106. %setup -q
  107. %setup -q -T -D -a 1
  108. %setup -q -T -D -a 2
  109. %setup -q -T -D -a 3
  110. %setup -q -T -D -a 4
  111. %patch -p0
  112. %{l_shtool} subst \
  113. -e 's;/usr/local/nagios/var/;%{l_prefix}/var/nagios/log;' \
  114. p1.pl
  115. %build
  116. # configure and build Nagios
  117. CC="%{l_cc}" \
  118. CFLAGS="%{l_cflags -O}" \
  119. LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
  120. LIBS="%{l_fsl_libs} -lpng -lz -ljpeg" \
  121. PATH_TO_TRACEROUTE="%{l_prefix}/sbin/traceroute" \
  122. ./configure \
  123. --prefix=%{l_prefix} \
  124. --sbindir=%{l_prefix}/cgi/nagios \
  125. --sysconfdir=%{l_prefix}/etc/nagios \
  126. --libexecdir=%{l_prefix}/libexec/nagios \
  127. --localstatedir=%{l_prefix}/var/nagios \
  128. --datadir=%{l_prefix}/share/nagios \
  129. --with-cgiurl=/nagios/cgi \
  130. --with-htmurl=/nagios \
  131. --with-nagios-user=%{l_rusr} \
  132. --with-nagios-group=%{l_rgrp} \
  133. --with-command-user=%{l_nusr} \
  134. --with-command-group=%{l_ngrp} \
  135. --with-gd-lib=%{l_prefix}/lib \
  136. --with-gd-inc=%{l_prefix}/include \
  137. --with-lockfile=%{l_prefix}/var/nagios/run/nagios.pid \
  138. %if "%{with_perl}" == "yes"
  139. --enable-embedded-perl \
  140. --with-perlcache \
  141. %endif
  142. --without-init-dir
  143. %{l_make} %{l_mflags} all
  144. # configure and build Nagios plugins
  145. ( cd nagios-plugins-%{V_nagios_plugins}/
  146. ( echo "ac_cv_ping_packets_first=yes"
  147. echo "ac_cv_ping_has_timeout=no"
  148. ) >config.cache
  149. CC="%{l_cc}" \
  150. CFLAGS="%{l_cflags -O}" \
  151. LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
  152. LIBS="-lssl -lcrypto" \
  153. ./configure \
  154. --cache-file=./config.cache \
  155. --prefix=%{l_prefix}/libexec/nagios \
  156. --libexecdir=%{l_prefix}/libexec/nagios \
  157. --with-cgiurl=/nagios/cgi \
  158. --with-openssl=%{l_prefix} \
  159. --with-perl=%{l_prefix}/bin/perl \
  160. --with-df-command="%{l_prefix}/bin/gdf" \
  161. --with-ping-command="%{l_prefix}/bin/gping -n -c %d %s" \
  162. --with-ssh-command="%{l_prefix}/bin/ssh" \
  163. --with-snmpget-command="%{l_prefix}/bin/snmpget" \
  164. --with-snmpgetnext-command="%{l_prefix}/bin/snmpgetnext"
  165. %{l_make} %{l_mflags}
  166. ) || exit $?
  167. %install
  168. rm -rf $RPM_BUILD_ROOT
  169. # create installation hierarchy
  170. %{l_shtool} mkdir -f -p -m 755 \
  171. $RPM_BUILD_ROOT%{l_prefix}/etc/nagios \
  172. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  173. $RPM_BUILD_ROOT%{l_prefix}/libexec/nagios \
  174. $RPM_BUILD_ROOT%{l_prefix}/var/nagios/log \
  175. $RPM_BUILD_ROOT%{l_prefix}/var/nagios/run \
  176. $RPM_BUILD_ROOT%{l_prefix}/var/nagios/cmd
  177. # install Nagios
  178. %{l_make} install DESTDIR="$RPM_BUILD_ROOT" INSTALL_OPTS="" COMMAND_OPTS=""
  179. # install Nagios plugins
  180. ( cd nagios-plugins-%{V_nagios_plugins}/
  181. %{l_make} install DESTDIR="$RPM_BUILD_ROOT" \
  182. MKINSTALLDIRS="%{l_shtool} install -d"
  183. ) || exit $?
  184. %if "%{with_perl}" == "yes"
  185. # install Perl modules
  186. %{l_prefix}/bin/perl-openpkg prepare
  187. %{l_prefix}/bin/perl-openpkg -d Nagios-Plugin-%{V_perl_nagios_plugin} configure build install
  188. %{l_prefix}/bin/perl-openpkg -d Nagios-Object-%{V_perl_nagios_object} configure build install
  189. %{l_prefix}/bin/perl-openpkg -d Nagios-Cmd-%{V_perl_nagios_cmd} configure build install
  190. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  191. %else
  192. >perl-openpkg-files
  193. %endif
  194. # post-adjust installation
  195. %if "%{with_perl}" == "yes"
  196. mv $RPM_BUILD_ROOT%{l_prefix}/bin/p1.pl \
  197. $RPM_BUILD_ROOT%{l_prefix}/libexec/nagios/p1.pl
  198. %endif
  199. chmod 0755 $RPM_BUILD_ROOT%{l_prefix}/libexec/nagios/utils.sh
  200. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/nagios/archives
  201. rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/nagios/share
  202. # install default configuration
  203. for name in `grep "^<file" %{SOURCE nagios.txt} | sed -e 's;^.*name=";;' -e 's;".*$;;'`; do
  204. (echo ""; cat %{SOURCE nagios.txt}; echo "") |\
  205. sed -e "1,/^<file name=\"$name\">/d" -e "/<\/file>/,\$d" >$name
  206. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  207. $name $RPM_BUILD_ROOT%{l_prefix}/etc/nagios/
  208. done
  209. # install run-command script
  210. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  211. %{SOURCE rc.nagios} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  212. # install OSSP fsl configuration
  213. %{l_shtool} mkdir -f -p -m 755 \
  214. $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
  215. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  216. %{SOURCE fsl.nagios} \
  217. $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/
  218. # determine installation files
  219. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  220. %{l_files_std} `cat perl-openpkg-files` \
  221. '%not %dir %{l_prefix}/etc/fsl' \
  222. '%config %{l_prefix}/etc/fsl/fsl.nagios' \
  223. '%config %{l_prefix}/etc/nagios/*' \
  224. '%config %attr(600,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/nagios/resource.cfg' \
  225. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/nagios/*' \
  226. '%attr(2775,%{l_rusr},%{l_ngrp}) %{l_prefix}/var/nagios/cmd'
  227. %files -f files
  228. %clean
  229. rm -rf $RPM_BUILD_ROOT
  230. %post
  231. if [ $1 -eq 1 ]; then
  232. # add hook to Apache configuration
  233. apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
  234. if [ -f $apacheconf ]; then
  235. ( echo "Include $RPM_INSTALL_PREFIX/etc/nagios/apache.conf"
  236. ) | $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
  237. -a -i "$RPM_INSTALL_PREFIX:nagios" $apacheconf
  238. fi
  239. # display final hints on initial installation
  240. ( echo "To complete this installation of Nagios please start the"
  241. echo "Nagios daemon (backend) Apache webserver (frontend) with:"
  242. echo " \$ $RPM_INSTALL_PREFIX/etc/rc nagios start"
  243. echo " \$ $RPM_INSTALL_PREFIX/etc/rc apache start"
  244. echo "After this you can connect to the Nagios frontend via URL"
  245. echo " http://127.0.0.1/nagios/"
  246. echo "and login with username \"nagios\" and password \"nagios\"."
  247. echo "You can change the password with:"
  248. echo " \$ $RPM_INSTALL_PREFIX/bin/htpasswd \\ "
  249. echo " $RPM_INSTALL_PREFIX/etc/nagios/apache.passwd nagios"
  250. ) | %{l_rpmtool} msg -b -t notice
  251. fi
  252. if [ $1 -eq 2 ]; then
  253. # after upgrade, restart service
  254. eval `%{l_rc} nagios status 2>/dev/null`
  255. [ ".$nagios_active" = .yes ] && %{l_rc} nagios restart
  256. fi
  257. exit 0
  258. %preun
  259. if [ $1 -eq 0 ]; then
  260. # remove hook from Apache configuration
  261. apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
  262. if [ -f $apacheconf ]; then
  263. $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
  264. -r -i "$RPM_INSTALL_PREFIX:nagios" $apacheconf
  265. fi
  266. # before erase, stop service and remove log files
  267. %{l_rc} nagios stop 2>/dev/null
  268. rm -f $RPM_INSTALL_PREFIX/var/nagios/log/* >/dev/null 2>&1 || true
  269. rm -f $RPM_INSTALL_PREFIX/var/nagios/run/* >/dev/null 2>&1 || true
  270. rm -f $RPM_INSTALL_PREFIX/var/nagios/cmd/* >/dev/null 2>&1 || true
  271. fi
  272. exit 0