-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
242 lines (213 loc) · 6.35 KB
/
fabfile.py
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
import os
from fabric.api import run,local,env
from fabric.contrib import files
from fabric.operations import sudo
import boto
from boto.ec2.connection import EC2Connection
from boto.ec2 import *
import time
dwndir = '/home/%s/installs' % env.user
env.user = 'ec2-user'
#env.hosts = 'pub_dns'
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
key_pair = ''
ec2_conn = EC2Connection('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY')
def CreateInstance():
"""
Used to Create New Instance
"""
reservation = ec2_conn.run_instances('ami-31814f58', min_count='1',
max_count='1', key_name='My-Key-Pair',
instance_type='t1.micro')
instance = reservation.instances[0]
print "Waiting for Instance to start ...."
status = instance.update()
while status != "running":
status = instance.update()
print status
time.sleep(25)
env.hosts = instance.public_dns_name
print env.hosts
def DownloadNagios():
"""
Used to Download Nagios
"""
MKDIR_CMD = "mkdir /home/%s/installs" % env.user
run(MKDIR_CMD)
DWNNAGIOS_CMD = "wget -P %s http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz/download" % (dwndir)
run(DWNNAGIOS_CMD)
def UbuntuDependencyInstall():
sudo("apt-get install build-essential")
sudo("apt-get install php")
sudo("apt-get install gd gd-devel")
sudo("apt-get install apache2")
sudo("apt-get install xinetd")
sudo("apt-get install openssl libssl-dev libcurl3-openssl-dev")
def NonUbuntuDependencyInstall():
sudo("yum groupinstall -y 'Development Tools'")
sudo("yum install -y php")
sudo("yum install -y gd")
sudo("yum install -y gd-devel")
sudo("yum install -y httpd")
sudo("yum install -y gcc glibc glibc-common")
sudo("yum install -y gcc glibc glibc-common")
sudo("yum install -y xinetd")
sudo("yum install -y openssl openssl-devel")
def DependencyInstall():
"""
Used to install Dependencies
"""
os = run("uname -a | cut -d' ' -f4 | cut -c 5-10")
if os == "Ubuntu":
UbuntuDependencyInstall()
else:
NonUbuntuDependencyInstall()
def ExtractNagios():
"""
Used TO Extract Nagios Downloaded Package
"""
TAR_CMD = "cd %s && tar -zxvf nagios-3.3.1.tar.gz" % (dwndir)
run(TAR_CMD)
def Createuser():
"""
Used to Create Nagios User, Group & Adding Nagios User & Apache USer to Nagios Group
"""
sudo("useradd -m nagios")
sudo("groupadd nagcmd")
sudo("usermod -a -G nagcmd nagios")
sudo("usermod -a -G nagcmd apache")
def RunConfigScript():
"""
Used to Run Nagios Configure Script
"""
CONF_CMD = "cd %s/nagios && ./configure --with-command-group=nagcmd" % (dwndir)
sudo(CONF_CMD)
def CompileSource():
"""
Used to Compile Nagios Source Code
"""
COMP_CMD = "cd %s/nagios && make all" % (dwndir)
sudo(COMP_CMD)
def InstallSource():
"""
Used to Install Compiled Source Code
"""
INST_CMD = "cd %s/nagios && make install" % (dwndir)
sudo(INST_CMD)
INIT_CMD = "cd %s/nagios && make install-init" % (dwndir)
sudo(INIT_CMD)
INST_CONF_CMD = "cd %s/nagios && make install-config" % (dwndir)
sudo(INST_CONF_CMD)
INST_CMD_MODE = "cd %s/nagios && make install-commandmode" % (dwndir)
sudo(INST_CMD_MODE)
INST_WEB_CMD = "cd %s/nagios && make install-webconf" % (dwndir)
sudo(INST_WEB_CMD)
CRT_USR_CMD = "cd %s/nagios && htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin" % (dwndir)
sudo(CRT_USR_CMD)
def ApacheRestart():
"""
Used to Restart Apache Server
"""
sudo("/etc/init.d/httpd restart")
def NagiosPluginDownload():
"""
Used to Download Nagios Plugin
"""
DWNPLUGIN_CMD = "wget -P %s http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download" % (dwndir)
run(DWNPLUGIN_CMD)
TAR_PLG_CMD = "cd %s && tar -zxvf nagios-plugins-1.4.15.tar.gz" % (dwndir)
run(TAR_PLG_CMD)
def PluginConfig():
"""
Used to Run Plugin Configure Script
"""
PLG_CONF_CMD = "cd %s/nagios-plugins-1.4.15 && ./configure --with-nagios-user=nagios --with-nagios-group=nagios" % (dwndir)
run(PLG_CONF_CMD)
def InstallPlugin():
"""
Used to Install Nagios Plugin
"""
PLG_COMP_CMD = "cd %s/nagios-plugins-1.4.15 && make" % (dwndir)
sudo(PLG_COMP_CMD)
PLG_INST_CMD = "cd %s/nagios-plugins-1.4.15 && make install" % (dwndir)
sudo(PLG_INST_CMD)
def NagiosServiceAdd():
"""
Used to Add Nagios Service in System Startup
"""
SRVC_ADD_CMD = "chkconfig --add nagios && chkconfig nagios on"
sudo(SRVC_ADD_CMD)
def NagiosVerify():
"""
Used to Verify Nagios Sample Config Files
"""
NGS_VRF_CMD = "/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg"
sudo(NGS_VRF_CMD)
def NagiosRestart():
"""
Used to Restart Nagios Service
"""
NGS_RST_CMD = "/etc/init.d/nagios restart"
sudo(NGS_RST_CMD)
def NagiosFullInstall():
"""
Used to Install Full Nagios
"""
DependencyInstall()
DownloadNagios()
ExtractNagios()
Createuser()
RunConfigScript()
CompileSource()
InstallSource()
ApacheRestart()
def NagiosPluginFullInstall():
"""
Used to Install Full Nagios Plugin
"""
NagiosPluginDownload()
PluginConfig()
InstallPlugin()
NagiosServiceAdd()
NagiosVerify()
NagiosRestart()
def Nagiosnrpe():
"""
Used to Download Nagios NRPE Client
"""
NRPE_DWNL_CMD = "wget -P %s http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz" % (dwndir)
run(NRPE_DWNL_CMD)
NRPE_EXT_CMD = "cd %s && tar -zxvf nrpe-2.13.tar.gz" % (dwndir)
def NrpeSetup():
"""
Used to Configure & Install NRPE Client NOTE: Before Running this command make sure openssl & openssl-devel packages are installed
"""
NRPE_CONF_CMD = "cd %s/nrpe-2.13 && ./configure" % (dwndir)
run(NRPE_CONF_CMD)
NRPE_MAKE_CMD = "cd %s && make all" % (dwndir)
sudo(NRPE_MAKE_CMD)
NRPE_PLG_CMD = "cd %s && make install-plugin" % (dwndir)
sudo(NRPE_PLG_CMD)
NRPE_DMN_CMD = "cd %s && make install-daemon" % (dwndir)
sudo(NRPE_DMN_CMD)
NRPE_DMNCONF_CMD = "cd %s && make install-daemon-config" % (dwndir)
sudo(NRPE_DMNCONF_CMD)
NRPE_XINETD_CMD = "cd %s && make install-xinetd" % (dwndir)
sudo(NRPE_XINETD_CMD)
NRPE_SRVC_CMD = "echo 'nrpe 5666/tcp # NRPE' >> /etc/services"
sudo(NRPE_SRVC_CMD)
NRPE_STRT_CMD = "/etc/init.d/xinetd restart"
sudo(NRPE_STRT_CMD)
def NrpeRestart():
"""
Used to Restart NRPE Service
"""
NRPE_STRT_CMD = "/etc/init.d/xinetd restart"
sudo(NRPE_STRT_CMD)
def NrpeFullInstall():
"""
Used to Install NRPE NOTE: Before Running this command make sure openssl & openssl-devel packages are installed
"""
Nagiosnrpe()
NrpeSetup()