Makefile: Add target to run sql-dependant tests
[nagios-reports-module.git] / reports-module.spec.in
blobae30bdd74169d9a2a79bd91c2bf94fabbdda0714
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 query="SELECT version FROM db_version"
99 current_db_version=$(mysql monitor_reports -Be "$query" -N 2>/dev/null)
101 # if lower version than 2, run full import, set version=2
102 if [ %latest_db_version -eq 2 ] && [ $current_db_version -lt %latest_db_version ]; then
103 echo "Running full database import ... ";
104 %mod_path/import --truncate-db --nagios-cfg=%prefix/etc/nagios.cfg
105 mysql monitor_reports -Be "UPDATE db_version SET version=%latest_db_version"
106 else
107 echo "Running incremental database import ... ";
108 # only run the import if there are any files
109 %mod_path/import --incremental --interesting /tmp/%name.interesting \
110 --nagios-cfg=%prefix/etc/nagios.cfg
113 rm -f /tmp/%name.interesting
116 # On upgrade, make sure to point Nagios to the new module
117 # location, since it changed between 1.0.0 and 1.0.1
118 sed -i 's,%old_mod_path,%mod_path,g' %prefix/etc/nagios.cfg
120 # Add the module to the nagios configuration
121 grep -q ndbneb.so %prefix/etc/nagios.cfg || \
122 sed -i 's#^log_file.*#broker_module=%mod_path/ndbneb.so %mod_path/ndbneb.conf\n\n&#' \
123 %prefix/etc/nagios.cfg
125 # now start monitor again
126 /etc/rc.d/init.d/monitor start
129 %files
130 %defattr(-,root,root)
131 %mod_path
132 %prefix/op5/ndbneb
133 #/etc/op5-backup/modules/monitor-report-data
136 %clean
137 rm -rf %buildroot
140 %changelog
141 * Wed May 7 2008 Andreas Ericsson <ae@op5.se>
142 - Relocated module to %mod_path
144 * Fri Nov 30 2007 Andreas Ericsson <ae@op5.se>
145 - Semi-fleshed spec-file skeleton created