-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
197 lines (163 loc) · 7.93 KB
/
Dockerfile
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
############################################################
# Dockerfile to build a Naemon/Adagios server
# Based on appcontainers/nagios
############################################################
FROM centos:7
MAINTAINER "Gardar Thorsteinsson" <[email protected]>
#LABEL com.example.version="0.0.1-beta"
LABEL vendor1="Opin Kerfi hf."
#LABEL com.example.release-date="2019-11-14"
ENV container docker
ENV ADAGIOS_HOST adagios.local
ENV ADAGIOS_USER thrukadmin
ENV ADAGIOS_PASS thrukadmin
# Systemd - preparation
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
# Systemd - preparation ends
# First install the opensource.is and consol labs repositories
RUN rpm -ihv http://opensource.is/repo/ok-release.rpm \
&& rpm -Uvh https://labs.consol.de/repo/stable/rhel7/x86_64/labs-consol-stable.rhel7.noarch.rpm \
&& yum update -y ok-release
# Redhat/Centos users need to install the epel repositories (fedora users skip this step)
RUN yum install -y epel-release && yum clean all && yum -y update
# Install naemon, adagios and other needed packages
RUN yum --enablerepo=ok-testing install -y naemon naemon-livestatus git adagios okconfig acl pnp4nagios python-setuptools postfix python-pip
# Now all the packages have been installed, and we need to do a little bit of
# configuration before we start doing awesome monitoring
# Lets make sure adagios can write to naemon configuration files, and that
# it is a valid git repo so we have audit trail
WORKDIR /etc/naemon
RUN git init /etc/naemon ;\
git config user.name "admin" ;\
git config user.email "[email protected]" ;\
git add . ;\
git commit -a -m "Initial commit"
# Fix permissions for naemon and pnp4nagios
RUN chown -R naemon:naemon \
/etc/naemon \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg \
/var/log/okconfig
# ACL group permissions need g+rwx
RUN chmod g+rwx -R \
/etc/naemon \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg /var/log/okconfig
RUN setfacl -R -m group:naemon:rwx -m d:group:naemon:rwx \
/etc/naemon/ \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg \
/var/log/okconfig
# Make sure nagios doesn't interfere
RUN mkdir /etc/nagios/disabled ;\
mv /etc/nagios/{nagios,cgi}.cfg /etc/nagios/disabled/
# Make objects created by adagios go to /etc/naemon/adagios
RUN mkdir -p /etc/naemon/adagios ;\
pynag config --append cfg_dir=/etc/naemon/adagios
# Make adagios naemon aware
RUN sed 's|/etc/nagios/passwd|/etc/thruk/htpasswd|g' -i /etc/httpd/conf.d/adagios.conf ;\
sed 's|user=nagios|user=naemon|g' -i /etc/httpd/conf.d/adagios.conf ;\
sed 's|group=nagios|group=naemon|g' -i /etc/httpd/conf.d/adagios.conf ;\
sed 's|/etc/nagios/nagios.cfg|/etc/naemon/naemon.cfg|g' -i /etc/adagios/adagios.conf ;\
sed 's|nagios_url = "/nagios|nagios_url = "/naemon|g' -i /etc/adagios/adagios.conf ;\
sed 's|/etc/nagios/adagios/|/etc/naemon/adagios/|g' -i /etc/adagios/adagios.conf ;\
sed 's|/etc/init.d/nagios|/etc/init.d/naemon|g' -i /etc/adagios/adagios.conf ;\
sed 's|nagios_service = "nagios"|nagios_service = "naemon"|g' -i /etc/adagios/adagios.conf ;\
sed 's|livestatus_path = None|livestatus_path = "/var/cache/naemon/live"|g' -i /etc/adagios/adagios.conf ;\
sed 's|/usr/sbin/nagios|/usr/bin/naemon|g' -i /etc/adagios/adagios.conf
# Make okconfig naemon aware
RUN sed 's|/etc/nagios/nagios.cfg|/etc/naemon/naemon.cfg|g' -i /etc/okconfig.conf ;\
sed 's|/etc/nagios/okconfig/|/etc/naemon/okconfig/|g' -i /etc/okconfig.conf ;\
sed 's|/etc/nagios/okconfig/examples|/etc/naemon/okconfig/examples|g' -i /etc/okconfig.conf
RUN okconfig init && okconfig verify
# Add naemon to apache group so it has permissions to pnp4nagios's session files
RUN usermod -G apache naemon
# Allow Adagios to control the service
RUN sed 's|nagios|naemon|g' -i /etc/sudoers.d/adagios ;\
sed 's|/usr/sbin/naemon|/usr/bin/naemon|g' -i /etc/sudoers.d/adagios
# Make naemon use nagios plugins, more people are doing it like that. And configure pnp4nagios
RUN sed -i 's|/usr/lib64/naemon/plugins|/usr/lib64/nagios/plugins|g' /etc/naemon/resource.cfg ;\
sed -i 's|/etc/nagios/passwd|/etc/thruk/htpasswd|g' /etc/httpd/conf.d/pnp4nagios.conf ;\
sed -i 's|user = nagios|user = naemon|g' /etc/pnp4nagios/npcd.cfg ;\
sed -i 's|group = nagios|group = naemon|g' /etc/pnp4nagios/npcd.cfg
# Enable Naemon performance data and service performance data
RUN pynag config --set "process_performance_data=1" ;\
pynag config --set 'service_perfdata_file=/var/lib/naemon/service-perfdata' ;\
pynag config --set 'service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$' ;\
pynag config --set 'service_perfdata_file_mode=a' ;\
pynag config --set 'service_perfdata_file_processing_interval=15';\
pynag config --set 'service_perfdata_file_processing_command=process-service-perfdata-file'
# host performance data
RUN pynag config --set 'host_perfdata_file=/var/lib/naemon/host-perfdata' ;\
pynag config --set 'host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$' ;\
pynag config --set 'host_perfdata_file_mode=a' ;\
pynag config --set 'host_perfdata_file_processing_interval=15' ;\
pynag config --set 'host_perfdata_file_processing_command=process-host-perfdata-file'
# host commands
RUN pynag add command command_name=process-service-perfdata-file command_line='/bin/mv /var/lib/naemon/service-perfdata /var/spool/pnp4nagios/service-perfdata.$TIMET$' ;\
pynag add command command_name=process-host-perfdata-file command_line='/bin/mv /var/lib/naemon/host-perfdata /var/spool/pnp4nagios/host-perfdata.$TIMET$' ;\
pynag config --append cfg_dir=/etc/naemon/commands/
RUN mv /etc/httpd/conf.d/thruk_cookie_auth_vhost.conf /etc/httpd/conf.d/thruk_cookie_auth_vhost.conf.disabled
RUN htpasswd -b /etc/thruk/htpasswd "$ADAGIOS_USER" "$ADAGIOS_PASS" ;\
rm -f /etc/nagios/passwd ;\
ln -s /etc/thruk/htpasswd /etc/nagios/passwd
# Redirect root URL to /adagios
RUN echo "RedirectMatch ^/$ /adagios" > /etc/httpd/conf.d/redirect.conf
# Fix permissions for naemon and pnp4nagios
RUN chown -R naemon:naemon \
/etc/naemon \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg \
/var/log/okconfig
# ACL group permissions need g+rwx
RUN chmod g+rwx -R \
/etc/naemon \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg \
/var/log/okconfig
RUN setfacl -R -m group:naemon:rwx -m d:group:naemon:rwx \
/etc/naemon/ \
/etc/adagios \
/var/lib/adagios \
/var/lib/pnp4nagios \
/var/log/pnp4nagios \
/var/spool/pnp4nagios \
/etc/pnp4nagios/process_perfdata.cfg \
/var/log/okconfig
# Enable services
RUN systemctl enable httpd naemon npcd
# Remove yum cache
RUN yum clean all -y && rm -rf /var/cache/yum
WORKDIR /etc/naemon
EXPOSE 80
VOLUME ["/etc/naemon", "/var/log/naemon"]
CMD ["/usr/sbin/init"]
HEALTHCHECK --interval=2m --timeout=3s CMD curl -f http://localhost:80/ || exit 1