Line 0
Link Here
|
|
|
1 |
# Copyright 1999-2016 Gentoo Foundation |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# $Id$ |
4 |
|
5 |
EAPI="5" |
6 |
|
7 |
PYTHON_COMPAT=( python2_7 ) |
8 |
|
9 |
inherit eutils toolchain-funcs systemd python-r1 |
10 |
|
11 |
DESCRIPTION="General purpose Nagios/Icinga plugin for retrieving data" |
12 |
HOMEPAGE="http://mathias-kettner.de/check_mk.html" |
13 |
|
14 |
MY_P="${P/_p/p}" |
15 |
MY_PV="${MY_P/check_mk-/}" |
16 |
|
17 |
LICENSE="GPL-2" |
18 |
SLOT="0" |
19 |
KEYWORDS="~amd64 ~x86" |
20 |
IUSE="agent-only apache_status dmi_sysinfo livestatus logwatch mysql |
21 |
nfsexports oracle postgres smart wato xinetd zypper" |
22 |
|
23 |
DEPEND="wato? ( app-admin/sudo ) |
24 |
xinetd? ( sys-apps/xinetd ) |
25 |
!agent-only? ( || ( net-analyzer/nagios-core net-analyzer/icinga ) ) |
26 |
!agent-only? ( www-servers/apache ) |
27 |
media-libs/libpng:0" |
28 |
RDEPEND="${DEPEND}" |
29 |
|
30 |
REQUIRED_USE=" |
31 |
livestatus? ( !agent-only ) |
32 |
wato? ( !agent-only )" |
33 |
|
34 |
SRC_URI="http://mathias-kettner.de/download/${MY_P}.tar.gz" |
35 |
|
36 |
S="${WORKDIR}/${MY_P}" |
37 |
|
38 |
src_prepare() { |
39 |
# modify setup.sh for gentoo |
40 |
epatch "${FILESDIR}"/${PN}-1.2.4p5-setup.sh.patch |
41 |
} |
42 |
|
43 |
src_configure() { |
44 |
if has_version net-analyzer/nagios-core; then |
45 |
export mydaemon=nagios |
46 |
export nagpipe=/var/nagios/rw/nagios.cmd |
47 |
export check_result_path=/var/nagios/spool/checkresults |
48 |
export nagios_status_file=/var/nagios/status.dat |
49 |
export rrd_path=/var/nagios/perfdata |
50 |
else |
51 |
export mydaemon=icinga |
52 |
export nagpipe=/var/lib/icinga/rw/icinga.cmd |
53 |
export check_result_path=/var/lib/icinga/spool/checkresults |
54 |
export nagios_status_file=/var/lib/icinga/status.dat |
55 |
export rrd_path=/var/lib/icinga/perfdata |
56 |
fi |
57 |
|
58 |
export nagiosuser=${mydaemon} |
59 |
export nagios_binary=/usr/sbin/${mydaemon} |
60 |
export nagios_config_file=/etc/${mydaemon}/${mydaemon}.cfg |
61 |
export nagconfdir=/etc/${mydaemon}/check_mk.d |
62 |
export nagios_startscript=/etc/init.d/${mydaemon} |
63 |
export htpasswd_file=/etc/${mydaemon}/htpasswd.users |
64 |
export nagios_auth_name="${mydaemon} Access" |
65 |
export docdir=/usr/share/doc/${PF} |
66 |
export checkmandir=/usr/share/doc/${PF}/checks |
67 |
export check_icmp_path=/usr/lib/nagios/plugins/check_icmp |
68 |
export wwwuser=apache |
69 |
export wwwgroup=apache |
70 |
export apache_config_dir=/etc/apache2/modules.d/ |
71 |
|
72 |
if use livestatus; then |
73 |
export enable_livestatus=yes |
74 |
else |
75 |
export enable_livestatus=no |
76 |
fi |
77 |
|
78 |
export STRIPPROG=/bin/true |
79 |
} |
80 |
|
81 |
src_compile() { |
82 |
DESTDIR=${S} ./setup.sh --yes || die "Error while running setup.sh" |
83 |
|
84 |
# compile waitmax |
85 |
cd "${S}"/usr/share/check_mk/agents || die "Couldn't cd to ${S}/usr/share/check_mk/agents" |
86 |
if [[ -f waitmax ]]; then |
87 |
rm waitmax || die "Couldn't delete precompiled waitmax file" |
88 |
fi |
89 |
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" |
90 |
emake CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" CC="$(tc-getCC)" || die "Couldn't compile waitmax" |
91 |
|
92 |
# Fix broken png files |
93 |
pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/icons/bookcase.png" |
94 |
mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/icons/bookcase.png" || die |
95 |
pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/icon_auditlog.png" |
96 |
mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/icon_auditlog.png" || die |
97 |
pngfix -q --out=out.png "${S}/usr/share/check_mk/web/htdocs/images/button_auditlog_lo.png" |
98 |
mv -f out.png "${S}/usr/share/check_mk/web/htdocs/images/button_auditlog_lo.png" || die |
99 |
} |
100 |
|
101 |
src_install() { |
102 |
if ! use agent-only; then |
103 |
# Apache configuration |
104 |
insinto /etc/apache2/modules.d |
105 |
doins etc/apache2/modules.d/zzz_check_mk.conf |
106 |
|
107 |
if use wato; then |
108 |
# sudoers configuration |
109 |
cat << EOF > "${T}"/check_mk || die |
110 |
# Needed for WATO - the Check_MK Web Administration Tool |
111 |
Defaults:apache !requiretty |
112 |
apache ALL = (root) NOPASSWD: /usr/bin/check_mk --automation * |
113 |
EOF |
114 |
insinto /etc/sudoers.d |
115 |
doins "${T}"/check_mk |
116 |
fi |
117 |
|
118 |
# check_mk configuration |
119 |
keepdir /etc/check_mk |
120 |
insinto /etc/check_mk |
121 |
doins etc/check_mk/main.mk |
122 |
doins etc/check_mk/main.mk-${MY_PV} |
123 |
doins etc/check_mk/multisite.mk |
124 |
doins etc/check_mk/multisite.mk-${MY_PV} |
125 |
keepdir /etc/check_mk/conf.d |
126 |
insinto /etc/check_mk/conf.d |
127 |
doins etc/check_mk/conf.d/README |
128 |
keepdir /etc/check_mk/conf.d/wato |
129 |
touch "${D}"/etc/check_mk/conf.d/distributed_wato.mk |
130 |
keepdir /etc/check_mk/multisite.d |
131 |
keepdir /etc/check_mk/multisite.d/wato |
132 |
touch "${D}"/etc/check_mk/multisite.d/sites.mk |
133 |
|
134 |
insinto /etc/${mydaemon} |
135 |
doins etc/${mydaemon}/auth.serials |
136 |
|
137 |
# Nagios / Icinga check_mk templates |
138 |
insinto /etc/${mydaemon}/check_mk.d |
139 |
doins etc/${mydaemon}/check_mk.d/check_mk_templates.cfg |
140 |
|
141 |
dobin usr/bin/check_mk |
142 |
dobin usr/bin/mkp |
143 |
insinto /usr/bin |
144 |
doins usr/bin/cmk |
145 |
|
146 |
# remove compiled agent_modbus |
147 |
if [[ -f ${S}/usr/share/doc/${PF}/treasures/modbus/agent_modbus ]]; then |
148 |
rm "${S}"/usr/share/doc/${PF}/treasures/modbus/agent_modbus || die "Couldn't remove precompiled agent_modbus" |
149 |
fi |
150 |
|
151 |
insinto /usr/share/check_mk |
152 |
doins -r usr/share/check_mk/* |
153 |
|
154 |
keepdir /var/lib/check_mk/autochecks |
155 |
keepdir /var/lib/check_mk/cache |
156 |
keepdir /var/lib/check_mk/counters |
157 |
keepdir /var/lib/check_mk/logwatch |
158 |
keepdir /var/lib/check_mk/notify |
159 |
keepdir /var/lib/check_mk/packages |
160 |
insinto /var/lib/check_mk/packages |
161 |
doins var/lib/check_mk/packages/check_mk |
162 |
keepdir /var/lib/check_mk/precompiled |
163 |
keepdir /var/lib/check_mk/snmpwalks |
164 |
keepdir /var/lib/check_mk/tmp |
165 |
keepdir /var/lib/check_mk/wato |
166 |
keepdir /var/lib/check_mk/web |
167 |
|
168 |
# Update check_mk defaults |
169 |
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" |
170 |
cp "${D}"/usr/share/check_mk/modules/defaults "${D}"/usr/share/check_mk/web/htdocs/defaults.py || die "Couldn't copy check_mk defaults" |
171 |
|
172 |
# Change permissions |
173 |
fowners -R ${mydaemon}:apache /etc/${mydaemon}/auth.serials |
174 |
fperms -R 0660 /etc/${mydaemon}/auth.serials |
175 |
fowners -R ${mydaemon}:${mydaemon} /etc/${mydaemon}/check_mk.d |
176 |
fperms -R 0775 /etc/${mydaemon}/check_mk.d |
177 |
fowners -R root:apache /etc/check_mk/conf.d/wato |
178 |
fperms -R 0775 /etc/check_mk/conf.d/wato |
179 |
fowners root:apache /etc/check_mk/conf.d/distributed_wato.mk |
180 |
fperms 0664 /etc/check_mk/conf.d/distributed_wato.mk |
181 |
fowners -R root:apache /etc/check_mk/multisite.d/wato |
182 |
fperms -R 0775 /etc/check_mk/multisite.d/wato |
183 |
fowners root:apache /etc/check_mk/multisite.d/sites.mk |
184 |
fperms 0664 /etc/check_mk/multisite.d/sites.mk |
185 |
fowners root:${mydaemon} /var/lib/check_mk/cache |
186 |
fperms 0775 /var/lib/check_mk/counters |
187 |
fowners -R root:${mydaemon} /var/lib/check_mk/counters |
188 |
fperms 0775 /var/lib/check_mk/notify |
189 |
fowners -R root:${mydaemon} /var/lib/check_mk/notify |
190 |
fperms 0775 /var/lib/check_mk/logwatch |
191 |
fowners -R root:${mydaemon} /var/lib/check_mk/logwatch |
192 |
fperms 0775 /var/lib/check_mk/cache |
193 |
fowners -R root:${mydaemon} /var/lib/check_mk/cache |
194 |
fperms -R 0775 /var/lib/check_mk/tmp |
195 |
fowners -R root:apache /var/lib/check_mk/tmp |
196 |
fperms -R 0775 /var/lib/check_mk/web |
197 |
fowners -R root:apache /var/lib/check_mk/web |
198 |
fperms -R 0775 /var/lib/check_mk/wato |
199 |
fowners -R root:apache /var/lib/check_mk/wato |
200 |
fi |
201 |
|
202 |
# Install agent related files |
203 |
newbin usr/share/check_mk/agents/check_mk_agent.linux check_mk_agent |
204 |
dobin usr/share/check_mk/agents/waitmax |
205 |
|
206 |
# get around the filename restrictions of ${FILESDIR} |
207 |
cat "${FILESDIR}"/check-mk-agent.service >"${T}"/check-mk-agent\@.service |
208 |
systemd_dounit \ |
209 |
"${T}"/check-mk-agent\@.service \ |
210 |
"${FILESDIR}"/check-mk-agent.socket |
211 |
|
212 |
if use xinetd; then |
213 |
insinto /etc/xinetd.d |
214 |
newins usr/share/check_mk/agents/xinetd.conf check_mk |
215 |
fi |
216 |
|
217 |
keepdir /usr/lib/check_mk_agent/local |
218 |
keepdir /usr/lib/check_mk_agent/plugins |
219 |
|
220 |
# Install Livestatus |
221 |
if use livestatus; then |
222 |
cat << EOF > "${T}"/livestatus.cfg || die |
223 |
define module{ |
224 |
module_name mk-livestatus |
225 |
module_type neb |
226 |
path /usr/lib/check_mk/livestatus.o |
227 |
args /var/lib/${mydaemon}/rw/live |
228 |
} |
229 |
EOF |
230 |
|
231 |
insinto /etc/${mydaemon}/modules |
232 |
doins "${T}"/livestatus.cfg |
233 |
fowners ${mydaemon}:${mydaemon} /etc/${mydaemon}/modules/livestatus.cfg |
234 |
|
235 |
insinto /usr/lib/check_mk |
236 |
doins usr/lib/check_mk/livestatus.o |
237 |
|
238 |
dobin usr/bin/unixcat |
239 |
|
240 |
keepdir /usr/share/check_mk/livestatus |
241 |
fi |
242 |
|
243 |
# Documentation |
244 |
if ! use agent-only; then |
245 |
dodoc -r usr/share/doc/${PF}/* |
246 |
docompress -x /usr/share/doc/${PF}/checks/ |
247 |
else |
248 |
dodoc usr/share/doc/${PF}/AUTHORS usr/share/doc/${PF}/COPYING usr/share/doc/${PF}/ChangeLog |
249 |
docompress |
250 |
fi |
251 |
|
252 |
# Install the check_mk_agent logwatch plugin |
253 |
if use logwatch; then |
254 |
insinto /etc/check_mk |
255 |
doins usr/share/check_mk/agents/logwatch.cfg |
256 |
exeinto /usr/lib/check_mk_agent/plugins |
257 |
doexe usr/share/check_mk/agents/plugins/mk_logwatch |
258 |
fi |
259 |
|
260 |
# Install the check_mk_agent smart plugin |
261 |
if use smart; then |
262 |
exeinto /usr/lib/check_mk_agent/plugins |
263 |
doexe usr/share/check_mk/agents/plugins/smart |
264 |
fi |
265 |
|
266 |
# Install the check_mk_agent mysql plugin |
267 |
if use mysql; then |
268 |
exeinto /usr/lib/check_mk_agent/plugins |
269 |
doexe usr/share/check_mk/agents/plugins/mk_mysql |
270 |
fi |
271 |
|
272 |
# Install the check_mk_agent postgres plugin |
273 |
if use postgres; then |
274 |
exeinto /usr/lib/check_mk_agent/plugins |
275 |
doexe usr/share/check_mk/agents/plugins/mk_postgres |
276 |
fi |
277 |
|
278 |
# Install the check_mk_agent apache_status plugin |
279 |
if use apache_status; then |
280 |
exeinto /usr/lib/check_mk_agent/plugins |
281 |
doexe usr/share/check_mk/agents/plugins/apache_status |
282 |
fi |
283 |
|
284 |
# Install the check_mk_agent zypper plugin |
285 |
if use zypper; then |
286 |
exeinto /usr/lib/check_mk_agent/plugins |
287 |
doexe usr/share/check_mk/agents/plugins/mk_zypper |
288 |
fi |
289 |
|
290 |
# Install the check_mk_agent oracle plugin |
291 |
if use oracle; then |
292 |
exeinto /usr/lib/check_mk_agent/plugins |
293 |
doexe usr/share/check_mk/agents/plugins/mk_oracle |
294 |
fi |
295 |
|
296 |
# Install the check_mk_agent nfsexports plugin |
297 |
if use nfsexports; then |
298 |
exeinto /usr/lib/check_mk_agent/plugins |
299 |
doexe usr/share/check_mk/agents/plugins/nfsexports |
300 |
fi |
301 |
|
302 |
# Install the check_mk_agent dmi_sysinfo plugin |
303 |
if use dmi_sysinfo; then |
304 |
exeinto /usr/lib/check_mk_agent/plugins |
305 |
doexe usr/share/check_mk/agents/plugins/dmi_sysinfo |
306 |
fi |
307 |
} |
308 |
|
309 |
pkg_postinst() { |
310 |
if ! use agent-only; then |
311 |
elog "IMPORTANT: Please add the following line to your" |
312 |
elog "/etc/${mydaemon}/${mydaemon}.cfg, so that" |
313 |
elog "${mydaemon} can load your check_mk configuration." |
314 |
elog |
315 |
elog " cfg_dir=/etc/${mydaemon}/check_mk.d" |
316 |
elog |
317 |
fi |
318 |
if use wato; then |
319 |
elog "INFO: Your webserver needs write access to" |
320 |
elog "/etc/${mydaemon}/htpasswd.users!" |
321 |
elog "otherwise wato will not function correctly!" |
322 |
elog |
323 |
elog "chown ${mydaemon}: /etc/${mydaemon}/htpasswd.users" |
324 |
elog "chmod 660 /etc/${mydaemon}/htpasswd.users" |
325 |
elog |
326 |
fi |
327 |
if use xinetd && has_version sys-apps/systemd ; then |
328 |
elog "A systemd socket unit has been installed for check-mk-agent, and" |
329 |
elog "so you may prefer to use this instead of xinetd to report to other" |
330 |
elog "systems." |
331 |
fi |
332 |
} |