diff options
Diffstat (limited to 'modules/private/monitoring/plugins')
7 files changed, 246 insertions, 3 deletions
diff --git a/modules/private/monitoring/plugins/check_ftp_database b/modules/private/monitoring/plugins/check_ftp_database new file mode 100755 index 0000000..9a41424 --- /dev/null +++ b/modules/private/monitoring/plugins/check_ftp_database | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | OUT=$(echo "ls" | lftp -u test_ftp,test_ftp eldiron.immae.eu | grep it_works | wc -l) | ||
4 | |||
5 | if [ "$OUT" -eq 1 ]; then | ||
6 | echo "ftp connection OK - access to ftp is working" | ||
7 | exit 0 | ||
8 | else | ||
9 | echo "ftp connection CRITICAL - no access to ftp" | ||
10 | exit 2 | ||
11 | fi | ||
diff --git a/modules/private/monitoring/plugins/check_git b/modules/private/monitoring/plugins/check_git new file mode 100755 index 0000000..8c09925 --- /dev/null +++ b/modules/private/monitoring/plugins/check_git | |||
@@ -0,0 +1,68 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | SSH_KEY="$1" | ||
4 | |||
5 | TMPDIR=$(mktemp -d) | ||
6 | |||
7 | if [ ! -d "$TMPDIR" ]; then | ||
8 | echo "gitolite UNKNOWN - impossible to create temp dir" | ||
9 | exit 3 | ||
10 | fi | ||
11 | |||
12 | trap "rm -rf $TMPDIR" EXIT | ||
13 | |||
14 | ERRORS="" | ||
15 | OUTPUT="" | ||
16 | |||
17 | cd "$TMPDIR" | ||
18 | OUT=$(git clone -q git://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1) | ||
19 | ERR=$? | ||
20 | if [ -n "$OUT" ]; then | ||
21 | OUTPUT="$OUTPUT | ||
22 | $OUT" | ||
23 | fi | ||
24 | if [ "$ERR" != 0 ]; then | ||
25 | ERRORS="$ERRORS git://" | ||
26 | fi | ||
27 | rm -rf Monitor | ||
28 | |||
29 | OUT=$(git clone -q http://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1) | ||
30 | ERR=$? | ||
31 | if [ -n "$OUT" ]; then | ||
32 | OUTPUT="$OUTPUT | ||
33 | $OUT" | ||
34 | fi | ||
35 | if [ "$ERR" != 0 ]; then | ||
36 | ERRORS="$ERRORS http://" | ||
37 | fi | ||
38 | rm -rf Monitor | ||
39 | |||
40 | OUT=$(git clone -q https://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1) | ||
41 | ERR=$? | ||
42 | if [ -n "$OUT" ]; then | ||
43 | OUTPUT="$OUTPUT | ||
44 | $OUT" | ||
45 | fi | ||
46 | if [ "$ERR" != 0 ]; then | ||
47 | ERRORS="$ERRORS https://" | ||
48 | fi | ||
49 | rm -rf Monitor | ||
50 | |||
51 | OUT=$(GIT_SSH_COMMAND="ssh -i $SSH_KEY -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no" git clone -q gitolite@git.immae.eu:perso/Immae/Projets/Ruby/Monitor 2>&1) | ||
52 | ERR=$? | ||
53 | if [ -n "$OUT" ]; then | ||
54 | OUTPUT="$OUTPUT | ||
55 | $OUT" | ||
56 | fi | ||
57 | if [ "$ERR" != 0 ]; then | ||
58 | ERRORS="$ERRORS ssh" | ||
59 | fi | ||
60 | rm -rf Monitor | ||
61 | |||
62 | if [ -n "$ERRORS" ]; then | ||
63 | echo "gitolite CRITICAL - impossible to clone via$ERRORS|$OUTPUT" | ||
64 | exit 2 | ||
65 | else | ||
66 | echo "gitolite OK - ssh, git, http and https work|$OUTPUT" | ||
67 | exit 0 | ||
68 | fi | ||
diff --git a/modules/private/monitoring/plugins/check_imap_connection b/modules/private/monitoring/plugins/check_imap_connection new file mode 100755 index 0000000..304eae6 --- /dev/null +++ b/modules/private/monitoring/plugins/check_imap_connection | |||
@@ -0,0 +1,52 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | |||
3 | use strict; | ||
4 | use Getopt::Std; | ||
5 | $| = 1; | ||
6 | |||
7 | my %opts; | ||
8 | getopts('h:u:p:H:', \%opts); | ||
9 | |||
10 | my $STATE_OK = 0; | ||
11 | my $STATE_WARNING = 1; | ||
12 | my $STATE_CRITICAL = 2; | ||
13 | my $STATE_UNKNOWN = 3; | ||
14 | |||
15 | if ($opts{'h'} || !$opts{'u'} || !$opts{'p'} || !$opts{'H'}) { | ||
16 | &print_help(); | ||
17 | exit($STATE_UNKNOWN); | ||
18 | } | ||
19 | |||
20 | my $user = $opts{'u'}; | ||
21 | my $password = $opts{'p'}; | ||
22 | my $host = $opts{'H'}; | ||
23 | |||
24 | my $cmd_result = `(echo "a login $user $password"; echo "b logout") | openssl s_client -quiet -ign_eof -connect $host -starttls imap 2>&1`; | ||
25 | my $expected_result = "a OK Logged in"; | ||
26 | |||
27 | chomp($cmd_result); | ||
28 | if ($cmd_result !~ /$expected_result/) { | ||
29 | print "IMAP CRITICAL - Unable to connect via imaps\n"; | ||
30 | exit($STATE_CRITICAL); | ||
31 | } else { | ||
32 | print "IMAP OK - imaps connected successfully\n"; | ||
33 | exit($STATE_OK); | ||
34 | } | ||
35 | |||
36 | sub print_help() { | ||
37 | print << "EOF"; | ||
38 | Check whether imap works via ssl and is able to connect its database. | ||
39 | |||
40 | Options: | ||
41 | -h | ||
42 | Print detailed help screen | ||
43 | -u | ||
44 | User to log in as | ||
45 | -p | ||
46 | Password to log in | ||
47 | -H | ||
48 | Host to log in to | ||
49 | |||
50 | EOF | ||
51 | } | ||
52 | |||
diff --git a/modules/private/monitoring/plugins/check_maison_bbc b/modules/private/monitoring/plugins/check_maison_bbc new file mode 100755 index 0000000..43a5817 --- /dev/null +++ b/modules/private/monitoring/plugins/check_maison_bbc | |||
@@ -0,0 +1,41 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # kw, kwh, th_hr Bureau, th_hr Chambre_RDC, th_hr Exterieure, th_hr | ||
4 | # Garage, th_hr Mezzanine, th_hr Sejour, th_hr Soufflage | ||
5 | |||
6 | alert=$(date +"%F %H:%M:%S" -d "3 hours ago") | ||
7 | res=$(curl https://maison.bbc.bouya.org/stats.php) | ||
8 | |||
9 | ignored_text="th_hr Exterieure th_hr Soufflage" | ||
10 | |||
11 | ignored_bat="^$" | ||
12 | ignored="^(th_hr Exterieure|th_hr Soufflage)$" | ||
13 | |||
14 | missing() { | ||
15 | echo "to_entries|[.[]|select(.value < \"$alert\" and .key != \"bat\" $1)|.key + \": \" + .value]|join(\" ; \")" | ||
16 | } | ||
17 | |||
18 | missing_check=$(echo "$res" | jq -r "$(missing "and (.key | test(\"$ignored\") | not)")") | ||
19 | missing_show=$(echo "$res" | jq -r "$(missing "")") | ||
20 | |||
21 | battery() { | ||
22 | echo ".bat|to_entries|[.[]|select((.value[0] < \"$alert\" or (.value[1] | test(\"^0|1|2$\") | not)) $1)|.key + \": \" + .value[0] + \" bat \" + .value[1]]|join(\" ; \")" | ||
23 | } | ||
24 | |||
25 | bat_check=$(echo "$res" | jq -r "$(battery "and (.key | test(\"$ignored_bat\") | not)")") | ||
26 | bat_show=$(echo "$res" | jq -r "$(battery "")") | ||
27 | |||
28 | if [ -n "$missing_check" -o -n "$bat_check" ]; then | ||
29 | text="" | ||
30 | if [ -n "$missing_show" ]; then | ||
31 | text="$text - Dernières dates: $missing_show" | ||
32 | fi | ||
33 | if [ -n "$bat_show" ]; then | ||
34 | text="$text - Batteries: $bat_show" | ||
35 | fi | ||
36 | echo "Zibase CRITICAL$text" | ||
37 | exit 2 | ||
38 | else | ||
39 | echo "Zibase OK - Derniers événements il y a moins de 3h (ignorés : $ignored_text)" | ||
40 | exit 0 | ||
41 | fi | ||
diff --git a/modules/private/monitoring/plugins/notify_by_email b/modules/private/monitoring/plugins/notify_by_email index ad0dcc7..959db26 100755 --- a/modules/private/monitoring/plugins/notify_by_email +++ b/modules/private/monitoring/plugins/notify_by_email | |||
@@ -26,6 +26,4 @@ else | |||
26 | subject="** $NOTIFICATION_TYPE Service Alert: $HOST_ALIAS/$SERVICEDESC is $SERVICESTATE **" | 26 | subject="** $NOTIFICATION_TYPE Service Alert: $HOST_ALIAS/$SERVICEDESC is $SERVICESTATE **" |
27 | fi | 27 | fi |
28 | 28 | ||
29 | # sendwait waits for sendmail to finish its job, otherwise it continues in the | 29 | echo "$message" | MAILRC=/dev/null mail -r "$ADMINEMAIL" -n -s "$subject" "$CONTACT" |
30 | # background and gets killed too early | ||
31 | echo "$message" | MAILRC=/dev/null mail -r "naemon@immae.eu" -n -Ssendwait -s "$subject" "$CONTACT" | ||
diff --git a/modules/private/monitoring/plugins/notify_by_slack b/modules/private/monitoring/plugins/notify_by_slack new file mode 100755 index 0000000..b59a403 --- /dev/null +++ b/modules/private/monitoring/plugins/notify_by_slack | |||
@@ -0,0 +1,46 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | SLACK_CHANNEL="$1" | ||
4 | SLACK_USERNAME="Naemon" | ||
5 | SLACK_URL="$2" | ||
6 | SLACK_USERICON="https://release.immae.eu/monitoring.png" | ||
7 | |||
8 | if [ "$SERVICESTATE" = "CRITICAL" ]; then | ||
9 | ICON=":exclamation:" | ||
10 | COLOR="#DA0505" | ||
11 | elif [ "$SERVICESTATE" = "WARNING" ]; then | ||
12 | ICON=":warning:" | ||
13 | COLOR="#F1E903" | ||
14 | elif [ "$SERVICESTATE" = "OK" ]; then | ||
15 | ICON=":white_check_mark:" | ||
16 | COLOR="#36a64f" | ||
17 | elif [ "$SERVICESTATE" = "UNKNOWN" ]; then | ||
18 | ICON=":question:" | ||
19 | COLOR="#000000" | ||
20 | else | ||
21 | ICON=":white_medium_square:" | ||
22 | COLOR="#ffffff" | ||
23 | fi | ||
24 | |||
25 | payload=$(echo "{}" | jq -r \ | ||
26 | --arg "icon_url" "$SLACK_USERICON" \ | ||
27 | --arg "channel" "$SLACK_CHANNEL" \ | ||
28 | --arg "username" "$SLACK_USERNAME" \ | ||
29 | --arg "text" "${ICON} ${SERVICEDESC} on ${HOST} is ${SERVICESTATE}" \ | ||
30 | --arg "color" "$COLOR" \ | ||
31 | --arg "host" "$HOST" \ | ||
32 | --arg "desc" "$SERVICEDESC" \ | ||
33 | --arg "state" "$SERVICESTATE" \ | ||
34 | --arg "output" "$SERVICEOUTPUT" \ | ||
35 | '.icon_url = $icon_url | | ||
36 | .channel = $channel | | ||
37 | .username = $username | | ||
38 | .text = $text | | ||
39 | .attachments = [{fallback:"", color:$color,fields: [{},{},{},{}]}] | | ||
40 | .attachments[0].fields[0] = {title:"Host",value:$host,short:true} | | ||
41 | .attachments[0].fields[1] = {title:"Service description",value:$desc,short:true} | | ||
42 | .attachments[0].fields[2] = {title:"Status",value:$state,short:true} | | ||
43 | .attachments[0].fields[3] = {title:"Message",value:$output,short:false} | ||
44 | ') | ||
45 | |||
46 | curl -X POST --data "payload=$payload" $SLACK_URL | ||
diff --git a/modules/private/monitoring/plugins/notify_maison_bbc_by_email b/modules/private/monitoring/plugins/notify_maison_bbc_by_email new file mode 100755 index 0000000..84958b8 --- /dev/null +++ b/modules/private/monitoring/plugins/notify_maison_bbc_by_email | |||
@@ -0,0 +1,27 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # $1 = service/host | ||
4 | |||
5 | # $2 = type (PROBLEM RECOVERY ACKNOWLEDGEMENT FLAPPINGSTART FLAPPINGSTOP FLAPPINGDISABLED DOWNTIMESTART DOWNTIMESTOP DOWNTIMECANCELLED) | ||
6 | # http://www.naemon.org/documentation/usersguide/macrolist.html#notificationtype | ||
7 | |||
8 | # $3 = host alias | ||
9 | |||
10 | # $4 = date (YYYY-MM-DDTHH:MM:SS) | ||
11 | |||
12 | # $5 = E-mail | ||
13 | |||
14 | NOTIFICATION_TYPE="$2" | ||
15 | DATE="$4" | ||
16 | CONTACT="$5" | ||
17 | |||
18 | output=$(echo "$SERVICEOUTPUT" | awk '{gsub(" - ", "\n\n", $0); gsub (" (;|:) ", "\n ", $0); gsub(" dates: ", " dates:\n ", $0); gsub("Batteries: ", "Batteries:\n ", $0); print $0}') | ||
19 | if [ "$NOTIFICATION_TYPE" = "RECOVERY" ]; then | ||
20 | subject="Fin d'alerte Maison BBC Zibase" | ||
21 | message=$(printf "%b" "Alerte terminée le $DATE.\nInformations:\n$output") | ||
22 | else | ||
23 | subject="Alerte Maison BBC Zibase" | ||
24 | message=$(printf "%b" "Alerte lancée le $DATE.\nInformations:\n$output") | ||
25 | fi | ||
26 | |||
27 | echo "$message" | MAILRC=/dev/null mail -r "$ADMINEMAIL" -n -s "$subject" "$CONTACT" | ||