aboutsummaryrefslogtreecommitdiff
path: root/modules/private/monitoring/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'modules/private/monitoring/plugins')
-rwxr-xr-xmodules/private/monitoring/plugins/check_ftp_database11
-rwxr-xr-xmodules/private/monitoring/plugins/check_git68
-rwxr-xr-xmodules/private/monitoring/plugins/check_imap_connection52
-rwxr-xr-xmodules/private/monitoring/plugins/check_maison_bbc41
-rwxr-xr-xmodules/private/monitoring/plugins/notify_by_email4
-rwxr-xr-xmodules/private/monitoring/plugins/notify_by_slack46
-rwxr-xr-xmodules/private/monitoring/plugins/notify_maison_bbc_by_email27
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
3OUT=$(echo "ls" | lftp -u test_ftp,test_ftp eldiron.immae.eu | grep it_works | wc -l)
4
5if [ "$OUT" -eq 1 ]; then
6 echo "ftp connection OK - access to ftp is working"
7 exit 0
8else
9 echo "ftp connection CRITICAL - no access to ftp"
10 exit 2
11fi
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
3SSH_KEY="$1"
4
5TMPDIR=$(mktemp -d)
6
7if [ ! -d "$TMPDIR" ]; then
8 echo "gitolite UNKNOWN - impossible to create temp dir"
9 exit 3
10fi
11
12trap "rm -rf $TMPDIR" EXIT
13
14ERRORS=""
15OUTPUT=""
16
17cd "$TMPDIR"
18OUT=$(git clone -q git://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1)
19ERR=$?
20if [ -n "$OUT" ]; then
21OUTPUT="$OUTPUT
22$OUT"
23fi
24if [ "$ERR" != 0 ]; then
25 ERRORS="$ERRORS git://"
26fi
27rm -rf Monitor
28
29OUT=$(git clone -q http://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1)
30ERR=$?
31if [ -n "$OUT" ]; then
32OUTPUT="$OUTPUT
33$OUT"
34fi
35if [ "$ERR" != 0 ]; then
36 ERRORS="$ERRORS http://"
37fi
38rm -rf Monitor
39
40OUT=$(git clone -q https://git.immae.eu/perso/Immae/Projets/Ruby/Monitor.git 2>&1)
41ERR=$?
42if [ -n "$OUT" ]; then
43OUTPUT="$OUTPUT
44$OUT"
45fi
46if [ "$ERR" != 0 ]; then
47 ERRORS="$ERRORS https://"
48fi
49rm -rf Monitor
50
51OUT=$(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)
52ERR=$?
53if [ -n "$OUT" ]; then
54OUTPUT="$OUTPUT
55$OUT"
56fi
57if [ "$ERR" != 0 ]; then
58 ERRORS="$ERRORS ssh"
59fi
60rm -rf Monitor
61
62if [ -n "$ERRORS" ]; then
63 echo "gitolite CRITICAL - impossible to clone via$ERRORS|$OUTPUT"
64 exit 2
65else
66 echo "gitolite OK - ssh, git, http and https work|$OUTPUT"
67 exit 0
68fi
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
3use strict;
4use Getopt::Std;
5$| = 1;
6
7my %opts;
8getopts('h:u:p:H:', \%opts);
9
10my $STATE_OK = 0;
11my $STATE_WARNING = 1;
12my $STATE_CRITICAL = 2;
13my $STATE_UNKNOWN = 3;
14
15if ($opts{'h'} || !$opts{'u'} || !$opts{'p'} || !$opts{'H'}) {
16 &print_help();
17 exit($STATE_UNKNOWN);
18}
19
20my $user = $opts{'u'};
21my $password = $opts{'p'};
22my $host = $opts{'H'};
23
24my $cmd_result = `(echo "a login $user $password"; echo "b logout") | openssl s_client -quiet -ign_eof -connect $host -starttls imap 2>&1`;
25my $expected_result = "a OK Logged in";
26
27chomp($cmd_result);
28if ($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
36sub print_help() {
37 print << "EOF";
38Check whether imap works via ssl and is able to connect its database.
39
40Options:
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
50EOF
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
6alert=$(date +"%F %H:%M:%S" -d "3 hours ago")
7res=$(curl https://maison.bbc.bouya.org/stats.php)
8
9ignored_text="th_hr Exterieure th_hr Soufflage"
10
11ignored_bat="^$"
12ignored="^(th_hr Exterieure|th_hr Soufflage)$"
13
14missing() {
15 echo "to_entries|[.[]|select(.value < \"$alert\" and .key != \"bat\" $1)|.key + \": \" + .value]|join(\" ; \")"
16}
17
18missing_check=$(echo "$res" | jq -r "$(missing "and (.key | test(\"$ignored\") | not)")")
19missing_show=$(echo "$res" | jq -r "$(missing "")")
20
21battery() {
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
25bat_check=$(echo "$res" | jq -r "$(battery "and (.key | test(\"$ignored_bat\") | not)")")
26bat_show=$(echo "$res" | jq -r "$(battery "")")
27
28if [ -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
38else
39 echo "Zibase OK - Derniers événements il y a moins de 3h (ignorés : $ignored_text)"
40 exit 0
41fi
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 **"
27fi 27fi
28 28
29# sendwait waits for sendmail to finish its job, otherwise it continues in the 29echo "$message" | MAILRC=/dev/null mail -r "$ADMINEMAIL" -n -s "$subject" "$CONTACT"
30# background and gets killed too early
31echo "$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
3SLACK_CHANNEL="$1"
4SLACK_USERNAME="Naemon"
5SLACK_URL="$2"
6SLACK_USERICON="https://release.immae.eu/monitoring.png"
7
8if [ "$SERVICESTATE" = "CRITICAL" ]; then
9 ICON=":exclamation:"
10 COLOR="#DA0505"
11elif [ "$SERVICESTATE" = "WARNING" ]; then
12 ICON=":warning:"
13 COLOR="#F1E903"
14elif [ "$SERVICESTATE" = "OK" ]; then
15 ICON=":white_check_mark:"
16 COLOR="#36a64f"
17elif [ "$SERVICESTATE" = "UNKNOWN" ]; then
18 ICON=":question:"
19 COLOR="#000000"
20else
21 ICON=":white_medium_square:"
22 COLOR="#ffffff"
23fi
24
25payload=$(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
46curl -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
14NOTIFICATION_TYPE="$2"
15DATE="$4"
16CONTACT="$5"
17
18output=$(echo "$SERVICEOUTPUT" | awk '{gsub(" - ", "\n\n", $0); gsub (" (;|:) ", "\n ", $0); gsub(" dates: ", " dates:\n ", $0); gsub("Batteries: ", "Batteries:\n ", $0); print $0}')
19if [ "$NOTIFICATION_TYPE" = "RECOVERY" ]; then
20 subject="Fin d'alerte Maison BBC Zibase"
21 message=$(printf "%b" "Alerte terminée le $DATE.\nInformations:\n$output")
22else
23 subject="Alerte Maison BBC Zibase"
24 message=$(printf "%b" "Alerte lancée le $DATE.\nInformations:\n$output")
25fi
26
27echo "$message" | MAILRC=/dev/null mail -r "$ADMINEMAIL" -n -s "$subject" "$CONTACT"