-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfabfile.py
117 lines (94 loc) · 3.03 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
#
# Fabric tasks for Zabbix
#
# Boris HUISGEN <bhuisgen@>
#
from fabric.api import *
from fabric.utils import *
import ConfigParser
import os
env.colorize_errors = True
env.roledefs = {
# role: ['host1', 'host2']
}
local_path = os.getcwd()
remote_path = "/home/%s/fabric" % (env.user)
#
# TASKS
#
@task
def start():
"""
start zabbix agent
"""
sudo("/etc/init.d/zabbix-agent start")
@task
def stop():
"""
stop zabbix agent
"""
sudo("/etc/init.d/zabbix-agent stop")
@task
def restart():
"""
restart zabbix agent
"""
sudo("/etc/init.d/zabbix-agent restart")
@task
def install():
"""
install zabbix agent
"""
sudo("apt-get install zabbix-agent")
@task
def configure(file="./config.ini"):
"""
configure zabbix agent
file: configuration file to read (default: ./config.ini)
"""
config = ConfigParser.RawConfigParser()
config.read(file)
if config.get("Agent", "LogFile") == "syslog":
sudo("sed -i '/^LogFile\=.*/d' /etc/zabbix/zabbix_agentd.conf")
else:
sudo("sed -i 's/^LogFile\=.*/LogFile\=%s/' /etc/zabbix/zabbix_agentd.conf" % (config.get("Agent", "LogFile")))
sudo("sed -i 's/^Server\=.*/Server\=%s/' /etc/zabbix/zabbix_agentd.conf" % (config.get("Agent", "Server")))
sudo("sed -i 's/^ServerActive\=.*/ServerActive\=%s/' /etc/zabbix/zabbix_agentd.conf" % (config.get("Agent", "ServerActive")))
sudo("sed -i 's/^Hostname\=.*/Hostname\=%s/' /etc/zabbix/zabbix_agentd.conf" % (env.host_string))
sudo("sed -i 's/^StartAgents\=.*/StartAgents\=%s/' /etc/zabbix/zabbix_agentd.conf" % (config.get("Agent", "StartAgents")))
sudo("sed -i 's/^Include\=.*/Include\=%s/' /etc/zabbix/zabbix_agentd.conf" % (config.get("Agent", "Include").replace("/", "\/")))
with warn_only():
sudo("mv /etc/zabbix/zabbix_agentd.d/ /etc/zabbix/zabbix_agentd.conf.d/")
sudo("/etc/init.d/zabbix-agent stop")
with warn_only():
sudo("mkdir /var/lib/zabbix")
sudo("chmod 700 /var/lib/zabbix")
sudo("chown zabbix:zabbix /var/lib/zabbix")
sudo("usermod -d /var/lib/zabbix zabbix")
sudo("usermod -a -G adm,nslcd,clamav zabbix")
sudo("/etc/init.d/zabbix-agent start")
with warn_only():
sudo("rm /etc/cron.daily/tripwire")
sudo("sed -i 's/^MAIL-ON-WARNING\=.*$/MAIL-ON-WARNING\=\"\"/' /etc/rkhunter.conf")
sudo("sed -i 's/^RUN_DAILY\=.*$/RUN_DAILY\=\"false\"/' /etc/chkrootkit.conf")
@task
def deploy():
"""
deploy scripts files
"""
run("mkdir -p %s/zabbix" % (remote_path))
put("%s/zabbix" % (local_path), "%s" % (remote_path), mirror_local_mode=True)
sudo("rsync -a %s/zabbix/scripts/ /etc/zabbix/scripts/" % (remote_path))
sudo("rsync -a %s/zabbix/zabbix_agentd.conf.d/ /etc/zabbix/zabbix_agentd.conf.d/" % (remote_path))
sudo("chown -R root:zabbix /etc/zabbix/scripts")
sudo("chmod -R o-rwx /etc/zabbix/scripts")
sudo("chown -R root:zabbix /etc/zabbix/zabbix_agentd.conf.d")
sudo("chmod -R o-rwx /etc/zabbix/zabbix_agentd.conf.d")
sudo("/etc/init.d/zabbix-agent restart")
run("rm -fr %s/zabbix" % (remote_path))
@task
def trapper(name):
"""
run trapper script
"""
sudo("su -s /bin/bash -c \"/etc/zabbix/scripts/trapper/%s\" zabbix" % (name))