-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnagios-cloudformation.yaml
More file actions
397 lines (390 loc) · 12.7 KB
/
nagios-cloudformation.yaml
File metadata and controls
397 lines (390 loc) · 12.7 KB
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#
# Created by : Dorance Martinez C dorancemc@gmail.com
#
AWSTemplateFormatVersion: '2010-09-09'
Description: Stack the Nagios Servers
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: "Network Configuration"
Parameters:
- VPCID
- SubnetId
-
Label:
default: "Amazon EC2 Configuration"
Parameters:
- NagiosInstanceType
- FusionInstanceType
- LogInstanceType
- NNAInstanceType
-
Label:
default: "Management"
Parameters:
- EC2Keypair
- ManagementSrcIP
- ClientsSrcIP
ParameterLabels:
VPCID:
default: "Which VPC should this be deployed to?"
########################################################################
Parameters:
VPCID:
Description: VPC
Type: AWS::EC2::VPC::Id
SubnetId:
Description: SubnetId
Type: AWS::EC2::Subnet::Id
NagiosInstanceType:
Description: Instance Type for Nagios XI
Type: String
Default: t2.micro
AllowedValues:
- NONE
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
FusionInstanceType:
Description: Instance Type for Nagios Fusion
Type: String
Default: t2.micro
AllowedValues:
- NONE
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
LogInstanceType:
Description: Instance Type for Nagios Log Server
Type: String
Default: t2.medium
AllowedValues:
- NONE
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
NNAInstanceType:
Description: Instance Type for Nagios Network Analyzer
Type: String
Default: t2.small
AllowedValues:
- NONE
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
EC2Keypair:
Description: Keypair name for EC2 Instance
Type: "AWS::EC2::KeyPair::KeyName"
ManagementSrcIP:
Description: "IP or subnet allowed to access via SSH"
Type: String
Default: "0.0.0.0/32"
MinLength: '9'
MaxLength: '18'
AllowedPattern: '^([0-9]+\.){3}[0-9]+\/[0-9]+$'
ClientsSrcIP:
Description: "IP or subnet allowed to access via nrpe"
Type: String
Default: "172.31.0.0/16"
MinLength: '9'
MaxLength: '18'
AllowedPattern: '^([0-9]+\.){3}[0-9]+\/[0-9]+$'
########################################################################
Conditions:
NagiosInstanceCreate: !Not [!Equals [!Ref NagiosInstanceType, "NONE"]]
FusionInstanceCreate: !Not [!Equals [!Ref FusionInstanceType, "NONE"]]
LogInstanceCreate: !Not [!Equals [!Ref LogInstanceType, "NONE"]]
NNAInstanceCreate: !Not [!Equals [!Ref NNAInstanceType, "NONE"]]
########################################################################
Resources:
NagiosSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: 'Nagios Access Security Group'
GroupDescription: 'Nagios Access Security Group'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref ManagementSrcIP
- IpProtocol: tcp
FromPort: '5666'
ToPort: '5666'
CidrIp: !Ref ClientsSrcIP
- IpProtocol: icmp
FromPort: '-1'
ToPort: '-1'
CidrIp: !Ref ClientsSrcIP
Tags:
- Key: Name
Value: RulesInbound
NagiosXI:
Type: AWS::EC2::Instance
Condition: NagiosInstanceCreate
Properties:
Tags:
- Key: Name
Value: nagiosxi-cf
UserData:
Fn::Base64: !Sub |
#!/bin/bash
#disable selinux
sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config
#config hostname
hostname nagiosxi
echo "nagiosxi" >/etc/hostname
# configure awscli
yum install -y epel-release
yum install -y awscli
/usr/bin/easy_install --script-dir /opt/aws/bin https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
cp -v /usr/lib/python2*/site-packages/aws_cfn_bootstrap*/init/redhat/cfn-hup /etc/init.d
chmod +x /etc/init.d/cfn-hup
#/opt/aws/bin/cfn-init --stack ${AWS::StackId} --resource NagiosXI --region ${AWS::Region}
#/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource NagiosXI --region ${AWS::Region}
#installing nagionxi
cd /tmp/ &&
yum install -y wget &&
wget http://assets.nagios.com/downloads/nagiosxi/xi-latest.tar.gz &&
tar -zxf xi-latest.tar.gz &&
cd /tmp/nagiosxi/ &&
./fullinstall -n &&
# apache configuration for https redirect
echo "RewriteEngine On" >>/etc/httpd/conf/httpd.conf
echo "RewriteCond %{HTTPS} off" >>/etc/httpd/conf/httpd.conf
echo "RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]" >>/etc/httpd/conf/httpd.conf
#reboot the host
reboot
ImageId: ami-65e0e305
KeyName:
Ref: EC2Keypair
InstanceType:
Ref: NagiosInstanceType
SecurityGroupIds:
- !GetAtt NagiosSecurityGroup.GroupId
SubnetId: !Ref SubnetId
DependsOn: NagiosSecurityGroup
NagiosFusion:
Type: AWS::EC2::Instance
Condition: FusionInstanceCreate
Properties:
Tags:
- Key: Name
Value: nagiosfusion-cf
UserData:
Fn::Base64: !Sub |
#!/bin/bash
#disable selinux
sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config
#config hostname
hostname nagiosfusion
echo "nagiosfusion" >/etc/hostname
#installing nagiosfusion
service crond stop &&
cd /tmp/ &&
yum install -y wget &&
wget https://assets.nagios.com/downloads/nagiosfusion/fusion-latest.tar.gz &&
tar -zxf fusion-latest.tar.gz &&
cd /tmp/nagiosfusion/ &&
./fullinstall -n &&
yum install -y mod_ssl &&
# apache configuration for https redirect
echo "RewriteEngine On" >>/etc/httpd/conf/httpd.conf
echo "RewriteCond %{HTTPS} off" >>/etc/httpd/conf/httpd.conf
echo "RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]" >>/etc/httpd/conf/httpd.conf
#reboot the host
reboot
ImageId: ami-65e0e305
KeyName:
Ref: EC2Keypair
InstanceType:
Ref: FusionInstanceType
SecurityGroupIds:
- !GetAtt NagiosSecurityGroup.GroupId
SubnetId: !Ref SubnetId
DependsOn: NagiosSecurityGroup
NagiosLog:
Type: AWS::EC2::Instance
Condition: LogInstanceCreate
Properties:
Tags:
- Key: Name
Value: nagioslog-cf
UserData:
Fn::Base64: !Sub |
#!/bin/bash
#disable selinux
sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config
#config hostname
hostname nagioslog
echo "nagioslog" >/etc/hostname
#install nagios log server
cd /tmp/ &&
yum install -y wget &&
wget https://assets.nagios.com/downloads/nagios-log-server/nagioslogserver-latest.tar.gz &&
tar -zxf nagioslogserver-latest.tar.gz &&
cd /tmp/nagioslogserver/ &&
./fullinstall -m -n &&
yum install -y mod_ssl &&
# apache configuration for https redirect
sed -i 's/<\/VirtualHost>//g' /etc/httpd/conf.d/ssl.conf
cat << 'EOL' >> /etc/httpd/conf.d/ssl.conf
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|scripts|media|app|js|css|img|font|vendor|config.js)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagioslogserver/(.*)$ /var/www/html/nagioslogserver/www/index.php/$1 [L,QSA]
</IfModule>
</VirtualHost>
EOL
echo "RewriteEngine On" >>/etc/httpd/conf/httpd.conf
echo "RewriteCond %{HTTPS} off" >>/etc/httpd/conf/httpd.conf
echo "RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}" >>/etc/httpd/conf/httpd.conf
#reboot the host
reboot
ImageId: ami-65e0e305
KeyName:
Ref: EC2Keypair
InstanceType:
Ref: LogInstanceType
SecurityGroupIds:
- !GetAtt NagiosSecurityGroup.GroupId
SubnetId: !Ref SubnetId
DependsOn: NagiosSecurityGroup
NagiosNA:
Type: AWS::EC2::Instance
Condition: NNAInstanceCreate
Properties:
Tags:
- Key: Name
Value: nagiosna-cf
UserData:
Fn::Base64: !Sub |
#!/bin/bash
#disable selinux
sudo sed -i 's/enforcing/disabled/g' /etc/selinux/config
#config hostname
hostname nagiosna
echo "nagiosna" >/etc/hostname
#install nagios network analyzer
cd /tmp/ &&
yum install -y wget &&
wget https://assets.nagios.com/downloads/nagios-network-analyzer/nagiosna-latest.tar.gz &&
tar -zxf nagiosna-latest.tar.gz &&
cd /tmp/nagiosna/ &&
./fullinstall -n &&
yum install -y mod_ssl &&
# apache configuration for https redirect
sed -i 's/<\/VirtualHost>//g' /etc/httpd/conf.d/ssl.conf
cat << 'EOL' >> /etc/httpd/conf.d/ssl.conf
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|scripts|media|app|js|css|img|font|vendor|config.js)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosna/(.*)$ /var/www/html/nagiosna/www/index.php/$1 [L,QSA]
</IfModule>
</VirtualHost>
EOL
echo "RewriteEngine On" >>/etc/httpd/conf/httpd.conf
echo "RewriteCond %{HTTPS} off" >>/etc/httpd/conf/httpd.conf
echo "RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}" >>/etc/httpd/conf/httpd.conf
#reboot the host
reboot
ImageId: ami-65e0e305
KeyName:
Ref: EC2Keypair
InstanceType:
Ref: NNAInstanceType
SecurityGroupIds:
- !GetAtt NagiosSecurityGroup.GroupId
SubnetId: !Ref SubnetId
DependsOn: NagiosSecurityGroup
########################################################################
Outputs:
IPNagiosXI:
Description: Nagios XI IP
Condition: NagiosInstanceCreate
Value: !GetAtt NagiosXI.PublicIp
PrivateIPNagiosXI:
Description: Nagios XI IP Private
Condition: NagiosInstanceCreate
Value: !GetAtt NagiosXI.PrivateIp
WebNagiosXI:
Description: Nagios XI URL Web Site
Condition: NagiosInstanceCreate
Value:
!Join [ "", [ 'https://',!GetAtt NagiosXI.PublicDnsName ]]
LogNagiosXI:
Description: Check the Nagios installation on log
Condition: NagiosInstanceCreate
Value: "sudo tail -f /tmp/nagiosxi/install.log"
IPNagiosFusion:
Description: Nagios Fusion IP
Condition: FusionInstanceCreate
Value: !GetAtt NagiosFusion.PublicIp
PrivateIPFusion:
Description: Nagios Fusion IP Private
Condition: FusionInstanceCreate
Value: !GetAtt NagiosFusion.PrivateIp
WebNagiosFusion:
Description: Nagios Fusion URL Web Site
Condition: FusionInstanceCreate
Value:
!Join [ "", [ 'https://',!GetAtt NagiosFusion.PublicDnsName ]]
LogNagiosFusion:
Description: Check the Nagios Fusion installation on log
Condition: FusionInstanceCreate
Value: "sudo tail -f /tmp/nagiosfusion/install.log"
IPNagiosLog:
Description: Nagios Log Server IP
Condition: LogInstanceCreate
Value: !GetAtt NagiosLog.PublicIp
PrivateIPLog:
Description: Nagios Log IP Private
Condition: LogInstanceCreate
Value: !GetAtt NagiosLog.PrivateIp
WebNagiosLog:
Description: Nagios Log URL Web Site
Condition: LogInstanceCreate
Value:
!Join [ "", [ 'https://',!GetAtt NagiosLog.PublicDnsName ]]
LogNagiosLog:
Description: Check the Nagios Log installation on log
Condition: LogInstanceCreate
Value: "sudo tail -f /tmp/nagioslogserver/install.log"
IPNagiosNA:
Description: Nagios Network Analyzer IP
Condition: NNAInstanceCreate
Value: !GetAtt NagiosNA.PublicIp
PrivateIPNagionNA:
Description: Nagios Network Analyzer IP Private
Condition: NNAInstanceCreate
Value: !GetAtt NagiosNA.PrivateIp
WebNagiosNA:
Description: Nagios Network Analyzer URL Web Site
Condition: NNAInstanceCreate
Value:
!Join [ "", [ 'https://',!GetAtt NagiosNA.PublicDnsName ]]
LogNagiosNA:
Description: Check the Nagios Network Analyzer installation on log
Condition: NNAInstanceCreate
Value: "sudo tail -f /tmp/nagiosna/install.log"