-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobservium-alerts.sh
executable file
·53 lines (44 loc) · 1.28 KB
/
observium-alerts.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
#!/bin/bash
# Exit if there is an error
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Help
if [ $# == 0 ]; then
echo "
Usage:
observium-alerts.sh export [<filename.sql>]
observium-alerts.sh import [<filename.sql>]
"
exit
fi
# Check all required variables are set
: "${OBSERVIUM_MYSQL_PASSWORD:?must be set}"
OBSERVIUM_MYSQL_USERNAME=${OBSERVIUM_MYSQL_USERNAME:-observium}
OBSERVIUM_MYSQL_DB=${OBSERVIUM_MYSQL_DB:-observium}
COMMAND=${1,,}
FILENAME=${2}
QUIET=${3}
: "${FILENAME:?must be set}"
# Commands
case $COMMAND in
"export")
/usr/bin/mysqldump -u$OBSERVIUM_MYSQL_USERNAME -p$OBSERVIUM_MYSQL_PASSWORD $OBSERVIUM_MYSQL_DB alert_tests alert_assoc > $FILENAME
echo "Observium alerts exported to $FILENAME"
;;
"import")
if [ -z "$QUIET" ]
then
read -p "This will remove your existing alerts - are you sure? (y/n)" -n 1 -r
echo $QUIET
fi
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -n "$QUIET" ]]
then
/usr/bin/mysql -u$OBSERVIUM_MYSQL_USERNAME -p$OBSERVIUM_MYSQL_PASSWORD $OBSERVIUM_MYSQL_DB < $FILENAME
echo "Observium alerts imported from $FILENAME"
fi
;;
*)
echo "Unknown command: $COMMAND"
exit
;;
esac