Makefile: Add default LDFLAGS and make it overridable
[nagios-reports-module.git] / reports-module.spec.in
blob161062a3a9b1876f9f9a12ad88145c8a3b96993c
1 %define mod_path /opt/monitor/op5/reports/module
2 %define old_mod_path /opt/monitor/op5/ndbneb
4 %define latest_db_version 2
5 # prevent stripping of binaries
6 %define __spec_install_post /usr/lib/rpm/brp-compress
8 %{?dgroup:%define daemon_group %{dgroup}}
10 Name: monitor-reports-module
11 Summary: %name is a database logging event broker module for op5 Monitor
12 Version: @@VERSION@@
13 Release: @@RELEASE@@
14 License: GPL
15 Group: op5/Monitor
16 URL: http://www.op5.se
17 Source0: %name-%version.tar.gz
18 Prefix: /opt/monitor
19 Requires: monitor >= 4.0, mysql
20 BuildRequires: mysql-devel
21 BuildRoot: /override/%name-%version
22 PreReq: monitor-nacoma >= 3.3.0
24 %description
25 %name is an event broker module running inside op5 Monitor. It gets
26 called when a host or service check has been processed, when host or
27 service downtime starts and stops, and when the op5 Monitor process
28 is stopped or started. It inserts information about these events into
29 a database, where it is later used by the monitor-reports package to
30 generate accurate and pretty reports very quickly.
33 %prep
34 %setup -q
36 %build
37 CFLAGS="%optflags" make
39 %install
40 rm -rf %buildroot
41 make DESTDIR=%buildroot%mod_path install
42 # we create this link for backwards compatibility with
43 # pre-1.0.1 backups of the reports-module package (when it
44 # was installed in a different directory)
45 ln -s reports/module %buildroot%prefix/op5/ndbneb
47 #mkdir -p %buildroot/etc/op5-backup/modules
48 #install -m 644 report-data.backup %buildroot/etc/op5-backup/modules/monitor-report-data
50 %pre
51 # If we're upgrading the module while Nagios makes a call
52 # into it, we'll end up with a core-dump due to some weirdness
53 # in dlopen(). If we're installing anew, we need to update the
54 # config and then restart. Either way, it's safe to stop it
55 # unconditionally here
56 sh /etc/rc.d/init.d/monitor stop || :
57 sh /etc/rc.d/init.d/monitor slay || :
58 # This is required when we're updating from 1.0.0 of this
59 # package, which was named ndbneb and installed to
60 # %prefix/op5/ndbneb. Since we're creating a linko where
61 # the old package used to be installed, we need to remove
62 # that old package first, or we'll get a cpio error when
63 # our files are being installed. This only happens when
64 # we're being installed over reports-module-1.0.0.
65 rm -rf %prefix/op5/ndbneb
68 %preun
69 if [ $1 -eq 0 ]; then
70 # removing the ndbneb module entirely
71 sh /etc/rc.d/init.d/monitor stop || :
72 sh /etc/rc.d/init.d/monitor slay || :
73 sed -i /ndbneb.so/d %prefix/etc/nagios.cfg
74 sh /etc/rc.d/init.d/monitor start || :
77 %post
78 # first fix database permissions. We do this unconditionally
79 mysql -e \
80 'GRANT ALL ON monitor_reports.* TO monitor@localhost IDENTIFIED BY "monitor"'
81 mysql -e 'FLUSH PRIVILEGES'
83 # next we check if we need to create the database
84 query="SELECT id FROM report_data LIMIT 1"
85 mysql monitor_reports -Be "$query" >/dev/null 2>&1 || {
86 echo "Creating database"
87 mysqladmin create monitor_reports >/dev/null 2>&1 || :
88 mysql monitor_reports < %mod_path/scripts/monitor_reports.sql
91 # since "import" supports incremental imports, we might as well
92 # always run it. It will never import anything if we're already
93 # up to date, and it will make retroactively fixing a broken module
94 # as simple as updating the package
95 php %mod_path/find_configured.php > /tmp/%name.interesting
98 # now try to find out if there are any files. This is
99 # trivial to do in shell, but hard to know if it's a
100 # user-error or just missing files in import.c
101 archived="/opt/monitor/var/archives/nagios-*.log"
102 for f in $archived; do
103 if ! [ -f "$f" ]; then
104 archived=
106 done
107 nagioslog=/opt/monitor/var/nagios.log
108 test -f $nagioslog || nagioslog=
111 query="SELECT version FROM db_version"
112 current_db_version=$(mysql monitor_reports -Be "$query" -N 2>/dev/null)
114 # if lower version than 2, run full import, set version=2
115 if [ %latest_db_version -eq 2 ] && [ $current_db_version -lt %latest_db_version ]; then
116 echo -n "Running full database import ... ";
117 test "$nagioslog$archived" && \
118 %mod_path/import --truncate-db \
119 $archived $nagioslog
120 mysql monitor_reports -Be "UPDATE db_version SET version=%latest_db_version"
121 echo "done.";
122 else
123 echo -n "Run incremental database import ... ";
124 # only run the import if there are any files
125 test "$nagioslog$archived" && \
126 %mod_path/import --incremental \
127 --interesting /tmp/%name.interesting \
128 $archived $nagioslog
130 echo "done.";
133 rm -f /tmp/%name.interesting
136 # On upgrade, make sure to point Nagios to the new module
137 # location, since it changed between 1.0.0 and 1.0.1
138 sed -i 's,%old_mod_path,%mod_path,g' %prefix/etc/nagios.cfg
140 # Add the module to the nagios configuration
141 grep -q ndbneb.so %prefix/etc/nagios.cfg || \
142 sed -i 's#^log_file.*#broker_module=%mod_path/ndbneb.so %mod_path/ndbneb.conf\n\n&#' \
143 %prefix/etc/nagios.cfg
145 # now start monitor again
146 /etc/rc.d/init.d/monitor start
149 %files
150 %defattr(-,root,root)
151 %mod_path
152 %prefix/op5/ndbneb
153 #/etc/op5-backup/modules/monitor-report-data
156 %clean
157 rm -rf %buildroot
160 %changelog
161 * Wed May 7 2008 Andreas Ericsson <ae@op5.se>
162 - Relocated module to %mod_path
164 * Fri Nov 30 2007 Andreas Ericsson <ae@op5.se>
165 - Semi-fleshed spec-file skeleton created