summaryrefslogtreecommitdiff
blob: ef7a70f9a76add0e9b22c5bd46461d4b521bb461 (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI="5"

PYTHON_COMPAT=( python2_7 )

inherit eutils toolchain-funcs python-r1

DESCRIPTION="General purpose Nagios/Icinga plugin for retrieving data"
HOMEPAGE="http://mathias-kettner.de/check_mk.html"

MY_P="${P/_p/p}"
MY_PV="${MY_P/check_mk-/}"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="agent-only apache_status dmi_sysinfo livestatus logwatch mysql
	nfsexports oracle postgres smart wato xinetd zypper"

DEPEND="${PYTHON_DEPS}
	wato? ( app-admin/sudo )
	xinetd? ( sys-apps/xinetd )
	!agent-only? ( || ( net-analyzer/nagios-core net-analyzer/icinga ) )
	!agent-only? ( www-servers/apache www-apache/mod_python )
	media-libs/libpng:0
	!!net-analyzer/check_mk_agent"
RDEPEND="${DEPEND}"

REQUIRED_USE="
	${PYTHON_REQUIRED_USE}
	livestatus? ( !agent-only )
	wato? ( !agent-only )"

SRC_URI="http://mathias-kettner.de/download/${MY_P}.tar.gz"

S="${WORKDIR}/${MY_P}"

src_prepare() {
	# modify setup.sh for gentoo
	epatch "${FILESDIR}"/${PN}-1.2.4p5-setup.sh.patch
}

src_configure() {
	if has_version net-analyzer/nagios-core; then
		export mydaemon=nagios
		export nagpipe=/var/nagios/rw/nagios.cmd
		export check_result_path=/var/nagios/spool/checkresults
		export nagios_status_file=/var/nagios/status.dat
		export rrd_path=/var/nagios/perfdata
	else
		export mydaemon=icinga
		export nagpipe=/var/lib/icinga/rw/icinga.cmd
		export check_result_path=/var/lib/icinga/spool/checkresults
		export nagios_status_file=/var/lib/icinga/status.dat
		export rrd_path=/var/lib/icinga/perfdata
	fi

	export nagiosuser=${mydaemon}
	export nagios_binary=/usr/sbin/${mydaemon}
	export nagios_config_file=/etc/${mydaemon}/${mydaemon}.cfg
	export nagconfdir=/etc/${mydaemon}/check_mk.d
	export nagios_startscript=/etc/init.d/${mydaemon}
	export htpasswd_file=/etc/${mydaemon}/htpasswd.users
	export nagios_auth_name="${mydaemon} Access"
	export docdir=/usr/share/doc/${PF}
	export checkmandir=/usr/share/doc/${PF}/checks
	export check_icmp_path=/usr/lib/nagios/plugins/check_icmp
	export wwwuser=apache
	export wwwgroup=apache
	export apache_config_dir=/etc/apache2/modules.d/

	if use livestatus; then
		export enable_livestatus=yes
	else
		export enable_livestatus=no
	fi

	export STRIPPROG=/bin/true
}

src_compile() {
	DESTDIR=${S} ./setup.sh --yes || die "Error while running setup.sh"

	# compile waitmax
	cd "${S}"/usr/share/check_mk/agents || die "Couldn't cd to ${S}/usr/share/check_mk/agents"
	if [[ -f waitmax ]]; then
		rm waitmax || die "Couldn't delete precompiled waitmax file"
	fi
	sed -i -e 's#gcc -s -o waitmax waitmax\.c#gcc -o waitmax waitmax.c#' "${S}"/usr/share/check_mk/agents/Makefile || die "Couldn't modify remove strip from waitmax Makefile"
	emake CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" CC="$(tc-getCC)" || die "Couldn't compile waitmax"

	# Fix broken png files
	pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/icons/bookcase.png"
	mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/icons/bookcase.png" || die
	pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/icon_auditlog.png"
	mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/icon_auditlog.png" || die
	pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/button_auditlog_lo.png"
	mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/button_auditlog_lo.png" || die
}

src_install() {
	if ! use agent-only; then
		# Apache configuration
		insinto /etc/apache2/modules.d
		doins etc/apache2/modules.d/zzz_check_mk.conf

		if use wato; then
			# sudoers configuration
			cat << EOF > "${T}"/check_mk || die
# Needed for WATO - the Check_MK Web Administration Tool
Defaults:apache !requiretty
apache ALL = (root) NOPASSWD: /usr/bin/check_mk --automation *
EOF
			insinto /etc/sudoers.d
			doins "${T}"/check_mk
		fi

		# check_mk configuration
		keepdir /etc/check_mk
		insinto /etc/check_mk
		doins etc/check_mk/main.mk
		doins etc/check_mk/main.mk-${MY_PV}
		doins etc/check_mk/multisite.mk
		doins etc/check_mk/multisite.mk-${MY_PV}
		keepdir /etc/check_mk/conf.d
		insinto /etc/check_mk/conf.d
		doins etc/check_mk/conf.d/README
		keepdir /etc/check_mk/conf.d/wato
		touch "${D}"/etc/check_mk/conf.d/distributed_wato.mk
		keepdir /etc/check_mk/multisite.d
		keepdir /etc/check_mk/multisite.d/wato
		touch "${D}"/etc/check_mk/multisite.d/sites.mk

		insinto /etc/${mydaemon}
		doins etc/${mydaemon}/auth.serials

		# Nagios / Icinga check_mk templates
		insinto /etc/${mydaemon}/check_mk.d
		doins etc/${mydaemon}/check_mk.d/check_mk_templates.cfg

		dobin usr/bin/check_mk
		dobin usr/bin/mkp
		insinto /usr/bin
		doins usr/bin/cmk

		# remove compiled agent_modbus
		if [[ -f ${S}/usr/share/doc/${PF}/treasures/modbus/agent_modbus ]]; then
			rm "${S}"/usr/share/doc/${PF}/treasures/modbus/agent_modbus || die "Couldn't remove precompiled agent_modbus"
		fi

		insinto /usr/share/check_mk
		doins -r usr/share/check_mk/*

		keepdir /var/lib/check_mk/autochecks
		keepdir /var/lib/check_mk/cache
		keepdir /var/lib/check_mk/counters
		keepdir /var/lib/check_mk/logwatch
		keepdir /var/lib/check_mk/notify
		keepdir /var/lib/check_mk/packages
		insinto /var/lib/check_mk/packages
		doins var/lib/check_mk/packages/check_mk
		keepdir /var/lib/check_mk/precompiled
		keepdir /var/lib/check_mk/snmpwalks
		keepdir /var/lib/check_mk/tmp
		keepdir /var/lib/check_mk/wato
		keepdir /var/lib/check_mk/web

		# Update check_mk defaults
		sed -i -e "s#^\(check_mk_automation\s*= 'sudo -u\) portage \(.*\)\$#\1 ${mydaemon} \2#" "${D}"/usr/share/check_mk/modules/defaults || die "Couldn't update check_mk defaults"
		cp "${D}"/usr/share/check_mk/modules/defaults "${D}"/usr/share/check_mk/web/htdocs/defaults.py || die "Couldn't copy check_mk defaults"

		# Change permissions
		fowners -R ${mydaemon}:apache /etc/${mydaemon}/auth.serials
		fperms -R 0660 /etc/${mydaemon}/auth.serials
		fowners -R ${mydaemon}:${mydaemon} /etc/${mydaemon}/check_mk.d
		fperms -R 0775 /etc/${mydaemon}/check_mk.d
		fowners -R root:apache /etc/check_mk/conf.d/wato
		fperms -R 0775 /etc/check_mk/conf.d/wato
		fowners root:apache /etc/check_mk/conf.d/distributed_wato.mk
		fperms 0664 /etc/check_mk/conf.d/distributed_wato.mk
		fowners -R root:apache /etc/check_mk/multisite.d/wato
		fperms -R 0775 /etc/check_mk/multisite.d/wato
		fowners root:apache /etc/check_mk/multisite.d/sites.mk
		fperms 0664 /etc/check_mk/multisite.d/sites.mk
		fowners root:${mydaemon} /var/lib/check_mk/cache
		fperms 0775 /var/lib/check_mk/counters
		fowners -R root:${mydaemon} /var/lib/check_mk/counters
		fperms 0775 /var/lib/check_mk/notify
		fowners -R root:${mydaemon} /var/lib/check_mk/notify
		fperms 0775 /var/lib/check_mk/logwatch
		fowners -R root:${mydaemon} /var/lib/check_mk/logwatch
		fperms 0775 /var/lib/check_mk/cache
		fowners -R root:${mydaemon} /var/lib/check_mk/cache
		fperms -R 0775 /var/lib/check_mk/tmp
		fowners -R root:apache /var/lib/check_mk/tmp
		fperms -R 0775 /var/lib/check_mk/web
		fowners -R root:apache /var/lib/check_mk/web
		fperms -R 0775 /var/lib/check_mk/wato
		fowners -R root:apache /var/lib/check_mk/wato
	fi

	# Install agent related files
	newbin usr/share/check_mk/agents/check_mk_agent.linux check_mk_agent
	dobin usr/share/check_mk/agents/waitmax

	if use xinetd; then
		insinto /etc/xinetd.d
		newins usr/share/check_mk/agents/xinetd.conf check_mk
	fi

	keepdir /usr/lib/check_mk_agent/local
	keepdir /usr/lib/check_mk_agent/plugins

	# Install Livestatus
	if use livestatus; then
		cat << EOF > "${T}"/livestatus.cfg || die
define module{
	module_name		mk-livestatus
	module_type		neb
	path			/usr/lib/check_mk/livestatus.o
	args			/var/lib/${mydaemon}/rw/live
	}
EOF

		insinto /etc/${mydaemon}/modules
		doins "${T}"/livestatus.cfg
		fowners ${mydaemon}:${mydaemon} /etc/${mydaemon}/modules/livestatus.cfg

		insinto /usr/lib/check_mk
		doins usr/lib/check_mk/livestatus.o

		dobin usr/bin/unixcat

		keepdir /usr/share/check_mk/livestatus
	fi

	# Documentation
	if ! use agent-only; then
		dodoc -r usr/share/doc/${PF}/*
		docompress -x /usr/share/doc/${PF}/checks/
	else
		dodoc usr/share/doc/${PF}/AUTHORS usr/share/doc/${PF}/COPYING usr/share/doc/${PF}/ChangeLog
		docompress
	fi

	# Install the check_mk_agent logwatch plugin
	if use logwatch; then
		insinto /etc/check_mk
		doins usr/share/check_mk/agents/logwatch.cfg
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/mk_logwatch
	fi

	# Install the check_mk_agent smart plugin
	if use smart; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/smart
	fi

	# Install the check_mk_agent mysql plugin
	if use mysql; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/mk_mysql
	fi

	# Install the check_mk_agent postgres plugin
	if use postgres; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/mk_postgres
	fi

	# Install the check_mk_agent apache_status plugin
	if use apache_status; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/apache_status
	fi

	# Install the check_mk_agent zypper plugin
	if use zypper; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/mk_zypper
	fi

	# Install the check_mk_agent oracle plugin
	if use oracle; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/mk_oracle
	fi

	# Install the check_mk_agent nfsexports plugin
	if use nfsexports; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/nfsexports
	fi

	# Install the check_mk_agent dmi_sysinfo plugin
	if use dmi_sysinfo; then
		exeinto /usr/lib/check_mk_agent/plugins
		doexe usr/share/check_mk/agents/plugins/dmi_sysinfo
	fi
}

pkg_postinst() {
	if ! use agent-only; then
		elog "IMPORTANT: Please add the following line to your"
		elog "/etc/${mydaemon}/${mydaemon}.cfg, so that"
		elog "${mydaemon} can load your check_mk configuration."
		elog
		elog "  cfg_dir=/etc/${mydaemon}/check_mk.d"
		elog
	fi
	if use wato; then
		elog "INFO: Your webserver needs write access to"
		elog "/etc/${mydaemon}/htpasswd.users!"
		elog "otherwise wato will not function correctly!"
		elog
		elog "chown ${mydaemon}: /etc/${mydaemon}/htpasswd.users"
		elog "chmod 660 /etc/${mydaemon}/htpasswd.users"
		elog
	fi
}