]>
Commit | Line | Data |
---|---|---|
cdc9189e JR |
1 | # Hook to register nagios object based plugins in Nagios NRPE daemon config. |
2 | # | |
3 | # Author: Elan Ruusamäe <glen@pld-linux.org> | |
4 | # | |
5 | # Usage: | |
6 | # -a NAME -- add command named NAME | |
7 | # -d NAME -- remove command named NAME | |
8 | # -f FILE -- specify plugin configuration FILE to extract command definition from | |
9 | # | |
10 | # Sample: | |
11 | # %triggerin -- nagios-nrpe | |
12 | # %nagios_nrpe -a %{plugin} -f %{_sysconfdir}/%{plugin}.cfg | |
13 | # | |
14 | # %triggerun -- nagios-nrpe | |
15 | # %nagios_nrpe -d %{plugin} -f %{_sysconfdir}/%{plugin}.cfg | |
16 | # | |
17 | # Requirements: | |
18 | # Requires: grep | |
19 | # Requires: sed >= 4.0 | |
20 | # BuildRequires: rpmbuild(macros) >= 1.685 | |
21 | %nagios_nrpe(a:d:c:f:) {\ | |
22 | if %{__grep} -q '^include_dir=/etc/nagios/nrpe.d' /etc/nagios/nrpe.cfg && [ -d /etc/nagios/nrpe.d ]; then \ | |
23 | file=/etc/nagios/nrpe.d/%{-a*}%{-d*}.cfg; \ | |
24 | else \ | |
25 | file=/etc/nagios/nrpe.cfg; \ | |
26 | fi; \ | |
27 | m=$(test -f $file && md5sum < $file); \ | |
28 | %{-a:# on -a and config exists \ | |
29 | if [ -f /etc/nagios/nrpe.cfg ]; then \ | |
30 | if [ ! -f $file ] || ! %{__grep} -q '^command\[%{-a*}\]' $file; then \ | |
31 | %{__sed} -ne 's/^[ \t]*command_line[ \t]\+\(.\+\)/command[%{-a*}]=\1/p' %{-f*} >> $file; \ | |
32 | fi; \ | |
33 | fi;} \ | |
34 | %{-d:# on package remove, -d and config exists \ | |
35 | if [ "$1" = "0" -a -f $file ]; then \ | |
36 | %{__sed} -i -e '/^[ \t]*command\[%{-d*}\]/d' $file; \ | |
37 | fi;} \ | |
38 | if [ "$m" != "$(md5sum < $file)" ]; then \ | |
39 | %service -q nrpe restart; \ | |
40 | fi; \ | |
41 | }%{nil} |