forked from zampat/icinga2-monitoring-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_import.sh
executable file
·116 lines (96 loc) · 3.31 KB
/
run_import.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
#/bin/bash
#Variables
ACTION="help"
ACTION=$1
ARG2=$2
# #Constants
FILES_IMPORT="import_files.tmp"
IMPORT_LOG="import_history.log"
IMPORT_DB=director
#################################################################################################
function import2icinga()
{
while read FILE
do
#sanitize files after copy
`/usr/bin/dos2unix ${SUBDIR}/${FILE} >> /dev/null` > /dev/null
#echo "reading line $FILE"
if [[ ${SUBDIR}/${FILE} =~ ".sh" ]]
then
echo "[+] Start script import of file: ${SUBDIR}/${FILE}" >> $IMPORT_LOG 2>&1
echo "[+] Start script import of file: ${SUBDIR}/${FILE}"
`/usr/bin/sh ${SUBDIR}/${FILE} >> $IMPORT_LOG 2>&1`
elif [[ ${SUBDIR}/${FILE} =~ ".sql" ]]
then
echo "[+] Start SQL injection of file: ${SUBDIR}/${FILE}" >> $IMPORT_LOG 2>&1
echo "[+] Start SQL injection of file: ${SUBDIR}/${FILE}"
cat ${SUBDIR}/${FILE} | mysql $IMPORT_DB >> $IMPORT_LOG 2>&1
fi
done < $FILES_IMPORT
}
## start of code
if [ "$ACTION" == "full" ]
then
echo "Import option: import of all icinga2 objects"
elif [ "$ACTION" == "fields" ]
then
echo "Import option: icinga2 director fields only"
elif [ "$ACTION" == "basket" ]
then
echo "Import option: import from provided basket"
else
echo "Advice: The icinga2 director templates had been refactored completely. Naming conventions had been introduced."
echo " The import of objects is now controled by parameter - choose one from below."
echo "Legacy advice: If you would like to use the old templates checkout branch legacy_templates_v1"
echo " https://github.com/zampat/icinga2-monitoring-templates/tree/legacy_templates_v1"
echo ""
echo "./run_import.sh full import of all icinga2 objects"
echo "./run_import.sh fields icinga2 director fields only"
echo "./run_import.sh basket <path/file.json> import from provided basket"
exit 3
fi
if [ ! -f /usr/bin/dos2unix ]; then
echo "Plese install dos2unix. We prefer sanitizing files first."
exit 3
fi
# Validation of pre-requisites
# 1) The import of Icinga2 ITL
#
# Pre-Requisites: Command: Powershell and service template "windows-powershell-generic"
RES=`icingacli director command exists "icinga"`
if [[ $RES =~ "does not exist" ]]
then
echo "[-] Pre-Requisite validation failed: Import of Icinga2 ITL into Director."
echo " The command 'icinga' ad not been found on this director installation."
echo " Please make sure to perform the Director Kickstart Wizard before running this import."
exit 3
fi
echo ">> Start of import procedure. Date: " `date` >> $IMPORT_LOG 2>&1
echo "- Logs are written to $IMPORT_LOG."
echo "- Import mode: $ACTION"
#### mode: Import fields
if [ "$ACTION" == "fields" ] || [ "$ACTION" == "full" ]
then
/usr/bin/ls director_fields | grep -v run_import.sh | grep -v .tmp > $FILES_IMPORT
SUBDIR="director_fields"
import2icinga
fi
#### mode: Import full
if [ "$ACTION" == "full" ]
then
/usr/bin/ls icinga_objects | grep -v run_import.sh | grep -v .tmp > $FILES_IMPORT
SUBDIR="icinga_objects"
import2icinga
fi
#### mode: Import basket
if [ "$ACTION" == "basket" ]
then
BASKET=$ARG2
if [ -s $BASKET ]
then
echo "Going to import basket: $BASKET"
/usr/bin/icingacli director basket restore < $BASKET
else
echo "Provided file not found: $BASKET"
fi
fi