summaryrefslogtreecommitdiffstats
path: root/nagios-server-addons.spec.in
blob: fe96e52ccd66780e45d32a6f3753a2e308210aa7 (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
%global _hardened_build 1

%global _for_fedora_koji_builds 0

%if ( 0%{?fedora} && 0%{?fedora} > 16 ) || ( 0%{?rhel} && 0%{?rhel} > 6 )
%global _with_systemd true
%endif

%if ( 0%{?fedora} && 0%{?fedora} > 17 ) || ( 0%{?rhel} && 0%{?rhel} > 6 )
%global _with_firewalld true
%endif

# From https://fedoraproject.org/wiki/Packaging:Python#Macros
%if ( 0%{?rhel} && 0%{?rhel} <= 5 )
%{!?python_sitelib: %global python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%{!?python_sitearch: %global python_sitearch %(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%endif

%if ( 0%{?_with_systemd:1} )
%define _init_enable()  /bin/systemctl enable %1.service ;
%define _init_disable() /bin/systemctl disable %1.service ;
%define _init_restart() /bin/systemctl restart %1.service ;
%define _init_try_restart() /bin/systemctl try-restart %1.service ;
%define _init_stop()    /bin/systemctl stop %1.service ;
%define _init_install() install -D -p -m 0644 %1 %{buildroot}%{_unitdir}/%2.service ;
%else
%define _init_enable()  /sbin/chkconfig --add %1 ;
%define _init_disable() /sbin/chkconfig --del %1 ;
%define _init_restart() /sbin/service %1 restart &>/dev/null ;
%define _init_try_restart() /sbin/service %1 condrestart &>/dev/null ;
%define _init_stop()    /sbin/service %1 stop &>/dev/null ;
%define _init_install() install -D -p -m 0755 %1 %{buildroot}%{_sysconfdir}/init.d/%2 ;
%endif

Summary: Gluster node management add-ons for Nagios
Name:             @PACKAGE_NAME@
Version:          @PACKAGE_VERSION@
Release:          @PACKAGE_RELEASE@%{?dist}
License:          GPLv2+
Group:            Applications/System
URL:              http://www.redhat.com
Vendor:           Red Hat, Inc.
Source0:          %{name}-%{version}.tar.gz
BuildRoot:        %{_tmppath}/%{name}-%{version}-root
BuildRequires:    pyflakes
BuildRequires:    python-pep8
BuildRequires:    python-mock
BuildRequires:    python-inotify
BuildRequires:    python-netaddr
BuildRequires:    libselinux-python
BuildRequires:    python-nose
BuildRequires:    python-devel
BuildRequires:    python-argparse
BuildRequires:    python-ethtool
BuildRequires:    gluster-nagios-common
BuildRequires:    pynag
%if ( 0%{?_with_systemd:1} )
BuildRequires:    systemd-units
Requires(post):   systemd-units
%else
Requires(post):   /sbin/service
Requires(post):   /sbin/chkconfig
%endif
%if ( 0%{?_with_firewalld:1} )
Requires(post):   firewalld
%else
Requires(post):   iptables
%endif
Requires:         check-mk-livestatus
Requires:         gluster-nagios-common
Requires:         httpd
Requires:         mod_ssl
Requires:         nagios
Requires:         nagios-plugins-dummy
Requires:         nagios-plugins-nrpe
Requires:         nagios-plugins-ping
Requires:         nsca
Requires:         php
Requires:         pnp4nagios
Requires:         python-argparse
Requires:         python-ethtool
Requires:         python-netaddr
Requires:         python-pthreading
Requires:         python-inotify
Requires:         libselinux-python
Requires:         rrdtool-perl
Requires:         pynag
Requires:         net-snmp-utils

%description
Nagios plugin, scripts, configuration files etc for gluster nodes.

%package tests
Summary:          Unit/functional tests of Gluster node management add-ons for Nagios
Group:            Development/Tools
Requires:         %{name} = %{version}-%{release}
Requires:         pyflakes
Requires:         python-pep8
Requires:         python-mock
Requires:         python-nose
Requires:         python-devel

%description tests
Unit/functional tests for Nagios plugin, scripts, configuration files etc for gluster nodes.

%prep
%setup -q

%build
%{configure}
make

%check
make check

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}

%clean
rm -rf %{buildroot}

%post
NagiosCFGFile="/etc/nagios/nagios.cfg"
sed -i '/etc\/nagios\/objects\/localhost.cfg/d' $NagiosCFGFile

if grep -q "#process_performance_data=0" $NagiosCFGFile; then
  sed -i -e 's/#process_performance_data=0/process_performance_data=1/g' $NagiosCFGFile
elif grep -q "process_performance_data=0" $NagiosCFGFile ; then
  sed -i -e 's/process_performance_data=0/process_performance_data=1/g' $NagiosCFGFile
fi

if grep -q "#enable_environment_macros=0" $NagiosCFGFile; then
  sed -i -e 's/#enable_environment_macros=0/enable_environment_macros=1/g' $NagiosCFGFile   
elif grep -q "process_performance_data=0" $NagiosCFGFile ; then
  sed -i -e 's/enable_environment_macros=0/enable_environment_macros=1/g' $NagiosCFGFile
fi

NagiosConfFile=/etc/httpd/conf.d/nagios.conf
if grep -q "#.*SSLRequireSSL" $NagiosConfFile; then
  sed -i -e 's/#.*SSLRequireSSL/   SSLRequireSSL/g' $NagiosConfFile
fi

cat > /etc/httpd/conf.d/glusternagios.conf << EOF
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/nagios|^/pnp4nagios https://%{HTTP_HOST}%{REQUEST_URI}
EOF

if ! grep -q "#rhs performance monitoring" $NagiosCFGFile; then
cat >> $NagiosCFGFile <<EOF
#rhs performance monitoring

# Definitions specific to gluster
cfg_dir=/etc/nagios/gluster

service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata
broker_module=/usr/lib64/check_mk/livestatus.o @nagioslivestatussocketpath@
EOF
fi

CommandFile="/etc/nagios/objects/commands.cfg"
if [ -f $CommandFile ]; then
sed -i -e "/# 'process-host-perfdata' command definition/,+5d" $CommandFile
sed -i -e "/# 'process-service-perfdata' command definition/,+5d" $CommandFile

if ! grep -q "check_nrpe" $CommandFile; then
cat >> $CommandFile <<EOF
define command{
       command_name check_nrpe
       command_line \$USER1\$/check_nrpe -H \$HOSTADDRESS\$ -c \$ARG1\$
}
EOF
fi

if ! grep -q "gluster nagios template" $CommandFile; then
cat >> $CommandFile <<EOF

### gluster nagios template ###
define command {
       command_name    process-service-perfdata
       command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl
}

define command {
       command_name    process-host-perfdata
       command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl -d HOSTPERFDATA
}

EOF
fi
fi

%if ( 0%{?_with_firewalld:1} )
/bin/firewall-cmd --permanent --add-port=80/tcp
/bin/firewall-cmd --add-port=80/tcp
/bin/firewall-cmd --add-port=5667/tcp
%else
/sbin/iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT 1 -p tcp --dport 5667 -j ACCEPT
/sbin/service iptables save
%_init_restart iptables
%endif

%_init_enable nagios
%_init_enable httpd
%_init_restart nagios
%_init_restart httpd

%files
%defattr(-,root,root,-)
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_cpu_multicore.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_disk_and_inode.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_interfaces.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_memory.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_swap_usage.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_vol_utilization.php
%{_datadir}/nagios/html/pnp4nagios/templates.dist/check_brick_usage.php
%attr(0755, -, -) %{_libdir}/nagios/plugins/gluster/*
%attr(0775, root, nagios) %dir %{_sysconfdir}/nagios/gluster
%attr(-, root, nagios) %{_sysconfdir}/nagios/gluster/snmpmanagers.conf
%{_sysconfdir}/nagios/gluster/*
/usr/share/snmp/mibs/*

%files tests
%defattr(-,root,root,-)
%{_datadir}/%{name}/tests/*

%changelog
* Sat Mar 08 2014 Bala FA <barumuga@redhat.com>
- Initial build.