-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·186 lines (162 loc) · 5.1 KB
/
deploy.sh
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
#!/bin/bash
# Initialize boolean switches as false
ALL=false
ENHANCED_EMAIL=false
NETBOX_PATH=false
REQUEST_TRACKER=false
SLACK=false
PUSHOVER=false
REQUIREMENTS=false
# default icinga2 user
ICINGA2_USER="nagios"
# hardcode the script dir, change this if you want another base directory
ICINGA2_SCRIPT_DIR="/etc/icinga2/scripts"
# Check the provided arguments
while [[ "$#" -gt 0 ]]; do
arg="$1"
case $arg in
-a|--all)
ALL=true
shift # Remove --enhanced-email from processing
;;
-n|--netbox-path)
NETBOX_PATH=true
shift # Remove --netbox-path from processing
;;
-e|--enhanced-email)
ENHANCED_EMAIL=true
shift # Remove --enhanced-email from processing
;;
-r|--request-tracker)
REQUEST_TRACKER=true
shift # Remove --request-tracker from processing
;;
-s|--slack)
SLACK=true
shift # Remove --slack from processing
;;
-s|--pushover)
PUSHOVER=true
shift # Remove --pushover from processing
;;
-p|--requirements)
REQUIREMENTS=true
shift # Remove --requirements from processing
;;
-u|--icinga2-user)
ICINGA2_USER=$2
shift # Remove --icinga-user from processing
shift # Remove --icinga-user from value
;;
*)
# Unknown option
echo "Unknown argument: $arg"
exit 1
;;
esac
done
deploy_library() {
mkdir -p "$ICINGA2_SCRIPT_DIR/lib/"
echo " copying ./src/lib/* to $ICINGA2_SCRIPT_DIR/lib/"
cp ./src/lib/* "$ICINGA2_SCRIPT_DIR/lib/"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/lib/*"
}
install_all_requirements() {
python3 -m pip install -r requirements.txt
}
install_netbox_path_requirements() {
python3 -m pip install -r requirements-netbox-path-impact.txt
}
install_enhanced_email_requirements() {
python3 -m pip install -r requirements-enhanced-email.txt
}
install_request_tracker_requirements() {
python3 -m pip install -r requirements-request-tracker.txt
}
install_slack_requirements() {
python3 -m pip install -r requirements-slack.txt
}
install_pushover_requirements() {
python3 -m pip install -r requirements-pushover.txt
}
deploy_config() {
file=$1
file_name=$(basename "$file")
if [[ ! -f "$ICINGA2_SCRIPT_DIR/config/$file_name" ]]; then
echo " copying $file to $ICINGA2_SCRIPT_DIR/config/$file_name"
cp "$file" "$ICINGA2_SCRIPT_DIR/config/"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/config/*"
else
echo " config $file_name exists in $ICINGA2_SCRIPT_DIR/config/"
fi
}
deploy_enhanced_email() {
deploy_library
deploy_config ./src/config/enhanced-mail-notification.json
cp ./src/enhanced-mail-notification.py "$ICINGA2_SCRIPT_DIR"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/enhanced-mail-notification.py"
chmod +x "$ICINGA2_SCRIPT_DIR/enhanced-mail-notification.py"
}
deploy_netbox_path() {
deploy_config ./src/config/netbox-path-impact-notification.json
cp ./src/netbox-path-impact-notification.py "$ICINGA2_SCRIPT_DIR"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/netbox-path-impact-notification.py"
chmod +x "$ICINGA2_SCRIPT_DIR/netbox-path-impact-notification.py"
}
deploy_request_tracker() {
deploy_config ./src/config/request-tracker-notification.json
cp ./src/request-tracker-notification.py "$ICINGA2_SCRIPT_DIR"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/request-tracker-notification.py"
chmod +x "$ICINGA2_SCRIPT_DIR/request-tracker-notification.py"
}
deploy_slack() {
cp ./src/slack-notification.py "$ICINGA2_SCRIPT_DIR"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/slack-notification.py"
chmod +x "$ICINGA2_SCRIPT_DIR/slack-notification.py"
}
deploy_pushover() {
cp ./src/pushover-notification.py "$ICINGA2_SCRIPT_DIR"
chown $ICINGA2_USER:$ICINGA2_USER "$ICINGA2_SCRIPT_DIR/pushover-notification.py"
chmod +x "$ICINGA2_SCRIPT_DIR/pushover-notification.py"
}
if $ALL || $ENHANCED_EMAIL; then
echo "Deploying Enhanced Email Notifications"
deploy_enhanced_email
if $REQUIREMENTS; then
install_enhanced_email_requirements
fi
fi
if $ALL || $NETBOX_PATH; then
echo "Deploying Netbox Path Impact Notifications"
deploy_netbox_path
if $REQUIREMENTS; then
install_netbox_path_requirements
fi
fi
if $ALL || $REQUEST_TRACKER; then
echo "Deploying Request Tracker Notifications"
deploy_request_tracker
if $REQUIREMENTS; then
install_request_tracker_requirements
fi
fi
if $ALL || $SLACK; then
echo "Deploying Slack Notifications"
deploy_slack
if $REQUIREMENTS; then
install_slack_requirements
fi
fi
if $ALL || $PUSHOVER; then
echo "Deploying Pushover Notifications"
deploy_pushover
if $REQUIREMENTS; then
install_pushover_requirements
fi
fi
if $ALL || $ENHANCED_EMAIL || $NETBOX_PATH || $REQUEST_TRACKER || $SLACK || $PUSHOVER; then
deploy_library
if $REQUIREMENTS; then
install_all_requirements
fi
fi