summaryrefslogtreecommitdiff
blob: 67a2ac2ab0518140b8ef621e54de55355a9bc5ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-analyzer/centreon/centreon-1.4.2.4.ebuild,v 1.3 2008/04/03 08:30:17 hollow Exp $

inherit depend.apache depend.php confutils

DESCRIPTION="Centreon is a monitoring web-frontend based on the nagios monitoring engine"
HOMEPAGE="http://www.oreon-project.org"
SRC_URI="http://download.oreon-project.org/${PN}/${P}.tar.gz
	mirror://gentoo/${P}-path_sanity.patch.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="ldap"

DEPEND=""
RDEPEND=">=net-analyzer/nagios-2.10
	net-analyzer/rrdtool
	net-analyzer/net-snmp
	net-analyzer/snmptt
	app-admin/sudo
	dev-php/PEAR-PEAR
	dev-php/smarty
	>=dev-php/PEAR-Auth_SASL-1.0.1
	>=dev-php/PEAR-DB-1.7.6
	>=dev-php/PEAR-DB_DataObject-1.8.4
	>=dev-php/PEAR-DB_DataObject_FormBuilder-1.0.0_rc4
	>=dev-php/PEAR-Date-1.4.6
	>=dev-php/PEAR-HTML_Common-1.2.2
	>=dev-php/PEAR-HTML_QuickForm-3.2.5
	>=dev-php/PEAR-HTML_QuickForm_advmultiselect-1.1.0
	>=dev-php/PEAR-HTML_Table-1.6.1
	>=dev-php/PEAR-HTTP-1.2.2
	>=dev-php/PEAR-Image_Canvas-0.2.4
	>=dev-php/PEAR-Image_Color-1.0.2
	>=dev-php/PEAR-Image_Graph-0.7.1
	>=dev-php/PEAR-Image_GraphViz-1.1.0
	>=dev-php/PEAR-MDB2-2.0.0
	>=dev-php/PEAR-Mail-1.1.9
	>=dev-php/PEAR-Mail_Mime-1.3.1
	>=dev-php/PEAR-Net_Ping-2.4.1
	>=dev-php/PEAR-Net_SMTP-1.2.8
	>=dev-php/PEAR-Net_Socket-1.0.1
	>=dev-php/PEAR-Net_Traceroute-0.21
	>=dev-php/PEAR-Numbers_Roman-1.0.1
	>=dev-php/PEAR-Numbers_Words-0.14.0
	>=dev-php/PEAR-SOAP-0.10.1
	>=dev-php/PEAR-Validate-0.6.2
	dev-perl/Config-IniFiles
	dev-perl/Crypt-DES
	dev-perl/DBI
	dev-perl/Digest-HMAC
	dev-perl/Digest-SHA1
	dev-perl/GD
	dev-perl/IO-Socket-INET6
	dev-perl/Net-SNMP
	dev-perl/Socket6"

need_apache2
need_php5

setup_vars() {
	INSTALL_DIR_OREON="/usr/share/centreon"
	OREON_PATH=${INSTALL_DIR_OREON}

	INSTALL_DIR_NAGIOS="/usr/nagios"
	NAGIOS_ETC="/etc/nagios"
	NAGIOS_VAR="/var/nagios"
	NAGIOS_BIN="${INSTALL_DIR_NAGIOS}/bin"
	NAGIOS_PLUGINS="${INSTALL_DIR_NAGIOS}/libexec"
	NAGIOS_IMG="${INSTALL_DIR_NAGIOS}/share/images"
	NAGIOS_USER="nagios"
	NAGIOS_GROUP="nagios"

	BIN_RRDTOOL="/usr/bin/rrdtool"
	BIN_MAIL="/bin/mail"
}

pkg_setup() {
	confutils_require_built_with_all sys-devel/libperl ithreads
	confutils_require_built_with_all dev-lang/perl ithreads
	confutils_require_built_with_all net-analyzer/net-snmp perl
	confutils_require_built_with_all net-analyzer/rrdtool perl

	require_php_sapi_from apache2 cli
	require_php_with_any_use gd gd-external
	require_php_with_use mysql posix snmp truetype

	use ldap && require_php_with_use ldap

	setup_vars
}

src_unpack() {
	unpack ${A}
	cd "${S}"
	epatch "${WORKDIR}"/${P}-path_sanity.patch
}

varsubst() {
	local path=$1

	for var in "$@"; do
		sed -i -e "s:@${var}@:$(eval echo \$${var}):g" "${D}${path}"
	done
}

install_centreon() {
	cd "${S}"

	# copy www and doc files
	insinto "${OREON_PATH}"
	doins -r www
	dosym /usr/nagios/share/doc "${OREON_PATH}"/doc

	# sanitize file modes
	find "${D}${OREON_PATH}" -type d -exec chmod 755 {} \;
	find "${D}${OREON_PATH}" -type f -exec chmod 644 {} \;

	# keep important directories
	keepdir "${OREON_PATH}"/www/modules
	keepdir /var/log/centreon
	keepdir /var/cache/centreon/rrd
	keepdir /var/cache/centreon/smarty/{cache,config,compile}
	keepdir /var/cache/centreon/generate/{nagiosCFG,osm}
	keepdir /var/cache/centreon/upload/nagiosCFG

	# prepare SQL files
	varsubst "${OREON_PATH}"/www/install/insertBaseConf.sql \
		NAGIOS_{USER,GROUP,ETC,BIN,VAR,PLUGINS,IMG} \
		INSTALL_DIR_NAGIOS INSTALL_DIR_OREON \
		BIN_RRDTOOL BIN_MAIL

	varsubst "${OREON_PATH}"/www/install/createTablesODS.sql \
		NAGIOS_VAR

	# fix paths in php files
	varsubst "${OREON_PATH}"/www/include/configuration/configCGI/formCGI.php \
		NAGIOS_ETC INSTALL_DIR_NAGIOS

	varsubst "${OREON_PATH}"/www/include/options/oreon/upGrade/preUpdate.php \
		OREON_PATH

	# install apache config
	insinto "${APACHE_MODULES_CONFDIR}"
	doins "${FILESDIR}"/99_centreon.conf

	# install global installation config
	insinto "${OREON_PATH}"/www/install
	doins "${FILESDIR}"/installoreon.conf.php

	# set permissions
	fowners -R apache:apache \
		/var/cache/centreon \
		"${OREON_PATH}"/www

	fowners -R nagios:apache \
		/var/log/centreon
}

install_plugins() {
	cd "${S}"

	# install plugin configuration
	insinto /etc/centreon
	doins ./Plugins/src/centreon.conf
	rm -f ./Plugins/src/centreon.conf

	varsubst /etc/centreon/centreon.conf \
		INSTALL_DIR_NAGIOS INSTALL_DIR_OREON \
		NAGIOS_ETC NAGIOS_PLUGINS

	fowners -R apache:apache \
		/etc/centreon

	# install nagios plugins
	exeinto "${NAGIOS_PLUGINS}"

	for plugin in ./Plugins/src/*; do
		if [[ ! -d "${plugin}" ]]; then
			doexe "${plugin}"
			varsubst "${NAGIOS_PLUGINS}/$(basename "${plugin}")" \
				NAGIOS_PLUGINS NAGIOS_VAR
		fi
	done
}

install_traps() {
	cd "${S}"

	# install snmp traps plugins
	dodir "${NAGIOS_PLUGINS}"/traps
	dodir /etc/snmp/centreon

	exeinto "${NAGIOS_PLUGINS}"/traps/
	doexe Plugins/src/traps/plugins/*

	# install snmp configs
	insinto /etc/snmp/centreon
	doins Plugins/src/traps/conf/snmptt.ini
	fowners -R apache:nagios /etc/snmp/centreon

	insinto /etc/snmp/
	doins Plugins/src/traps/conf/snmp.conf
}

install_ods() {
	cd "${S}"

	# install ODS daemon
	insinto /usr
	dosbin ODS/ods

	# install ODS library files
	insinto /usr/lib/ods
	doins ODS/lib/*

	# install ODS init script
	newinitd "${FILESDIR}"/ods.initd ods

	# keep important directories
	keepdir /etc/ods
	keepdir /var/run/ods
	keepdir /var/log/ods
	keepdir /var/lib/ods
	keepdir /var/lib/ods/database

	# set permissions
	fowners -R nagios:nagios \
		/var/run/ods \
		/var/log/ods \
		/var/lib/ods/database
	fowners -R apache:nagios /etc/ods
}

install_cron() {
	cd "${S}"

	insinto "${OREON_PATH}"
	doins -r cron

	fperms +x "${OREON_PATH}"/cron/*.{pl,php}

	for i in $(find cron/ -type f); do
		varsubst "${OREON_PATH}"/${i} OREON_PATH
	done

	insinto /etc/cron.d
	newins "${FILESDIR}"/centreon.cron centreon
}

src_install() {
	install_centreon
	install_plugins
	install_traps
	install_ods
	install_cron
}

pkg_config() {
	setup_vars

	einfo "Setting permissions on ${ROOT}${NAGIOS_ETC}"
	chown apache:nagios "${ROOT}${NAGIOS_ETC}"
	chmod 0775 "${ROOT}${NAGIOS_ETC}"

	einfo "Setting permissions on ${ROOT}${NAGIOS_PLUGINS}"
	chown apache:nagios "${ROOT}${NAGIOS_PLUGINS}"
	chmod 0775 "${ROOT}${NAGIOS_PLUGINS}"

	einfo "Setting permissions on ${ROOT}${NAGIOS_PLUGINS}/contrib"
	chown apache:nagios "${ROOT}${NAGIOS_PLUGINS}"/contrib
	chmod 0775 "${ROOT}${NAGIOS_PLUGINS}"/contrib

	einfo "Adding user apache to group nagios"
	usermod -a -G nagios apache

	SUDOERS="${ROOT}etc/sudoers"

	if ! grep -q CENTREON "${SUDOERS}"; then
		einfo "Adding sudo configuration"
		echo >> "${SUDOERS}"
		echo "# centreon configuration" >> "${SUDOERS}"
		echo "User_Alias  CENTREON=apache" >> "${SUDOERS}"
		echo "CENTREON    ALL = NOPASSWD: /etc/init.d/nagios restart" >> "${SUDOERS}"
		echo "CENTREON    ALL = NOPASSWD: /etc/init.d/nagios reload"  >> "${SUDOERS}"
		echo "CENTREON    ALL = NOPASSWD: /etc/init.d/snmptrapd restart" >> "${SUDOERS}"
	fi
}