This commit is contained in:
Simon Vieille 2019-06-12 11:32:52 +02:00
revīzija 95c1295818
Parakstījis: deblan
GPG atslēgas ID: 03383D15A1D31745
28 mainīti faili ar 308 papildinājumiem un 0 dzēšanām

6
helpers/apt Normal file
Parādīt failu

@ -0,0 +1,6 @@
#/bin/sh
get_updates() {
LANG=en apt-get --just-print upgrade | grep "not upgraded" | grep -Eo '[0-9]{1,4}' | tr ' ' '\n' | awk '{sum+=$0}END{print sum}'
}

5
helpers/date Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
get_date() {
LANG=fr_FR.UTF-8 date
}

5
helpers/df Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
get_df() {
df -h
}

5
helpers/hostname Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
get_hostname() {
hostname
}

5
helpers/mount Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
get_mount() {
mount
}

6
helpers/smart Normal file
Parādīt failu

@ -0,0 +1,6 @@
#!/bin/sh
get_smart() {
smartctl -H "$1"
}

5
helpers/template Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
render_template() {
envsubst < "$TEMPLATE/$1.tpl"
}

5
helpers/uptime Normal file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
get_uptime() {
uptime | sed 's/^\s//'
}

1
hooks/on-finish Executable file
Parādīt failu

@ -0,0 +1 @@
#!/bin/sh

11
hooks/on-start Executable file
Parādīt failu

@ -0,0 +1,11 @@
#!/bin/sh
if ! apt-get update >/dev/null 2>/dev/null; then
printf "La mise à jour de la liste des paquets à échoué.\n"
fi
if ! which envsubst 2>/dev/null >/dev/null; then
printf "Le programme \`envsubst\` est nécessaire. Installer \`gettext-base\`.\n"
exit 1
fi

45
report Executable file
Parādīt failu

@ -0,0 +1,45 @@
#!/bin/sh
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export _SCRIPT_NAME="$(realpath "$0")"
export _SCRIPT_PATH="$(dirname "$_SCRIPT_NAME")"
# export EMAIL_RECIPIENT=you@example.com
# export EMAIL_SENDER=system@example.com
# export EMAIL_SUBJECT="[$(hostname)] Rapport journalier"
# export HTML_OUTPUT=/tmp/report.html
# export MUNIN_DIRECTORY=/var/cache/munin/www/localhost/localhost
# export SMART_DEVICES="/dev/sda /dev/sdb /dev/sdc"
if [ -z "$TEMPLATE" ]; then
export TEMPLATE="$_SCRIPT_PATH/templates/deblan"
fi
cd "$_SCRIPT_PATH"
./hooks/on-start
REPORT="$(
./scripts/header
./scripts/system
./scripts/mount
./scripts/df
./scripts/smart
./scripts/footer
)"
if [ -n "$HTML_OUTPUT" ]; then
export REPORT
./scripts/html
fi
if [ -n "$EMAIL_RECIPIENT" ]; then
export REPORT
./scripts/email
fi
./hooks/on-finish

8
scripts/df Executable file
Parādīt failu

@ -0,0 +1,8 @@
#!/bin/sh
. ./helpers/template
. ./helpers/df
export df="$(get_df)"
render_template df

22
scripts/email Executable file
Parādīt failu

@ -0,0 +1,22 @@
#!/bin/sh
. ./helpers/template
export BOUNDARY="-$(date | md5sum | cut -d ' ' -f 1)"
(
render_template mail
if [ -n "$MUNIN_DIRECTORY" -a -d "$MUNIN_DIRECTORY" ]; then
cd "$MUNIN_DIRECTORY"
for file in *day.png; do
export file
export base64="$(base64 "$file")"
render_template mail-png-attachment
done
fi
printf "\n--%s--\n" "$BOUNDARY"
)| sendmail "$EMAIL_RECIPIENT"

5
scripts/footer Executable file
Parādīt failu

@ -0,0 +1,5 @@
#!/bin/sh
. ./helpers/template
render_template footer

10
scripts/header Executable file
Parādīt failu

@ -0,0 +1,10 @@
#!/bin/sh
. ./helpers/template
. ./helpers/hostname
. ./helpers/date
export hostname="$(get_hostname)"
export date="$(get_date)"
render_template header

7
scripts/html Executable file
Parādīt failu

@ -0,0 +1,7 @@
#!/bin/sh
. ./helpers/template
export content="$REPORT"
render_template plain > "$HTML_OUTPUT"

8
scripts/mount Executable file
Parādīt failu

@ -0,0 +1,8 @@
#!/bin/sh
. ./helpers/template
. ./helpers/mount
export mount="$(get_mount)"
render_template mount

12
scripts/smart Executable file
Parādīt failu

@ -0,0 +1,12 @@
#!/bin/sh
. ./helpers/template
. ./helpers/smart
for device in $SMART_DEVICES; do
export device
export result="$(get_smart "$device")"
render_template smart
done

22
scripts/system Executable file
Parādīt failu

@ -0,0 +1,22 @@
#!/bin/sh
. ./helpers/template
. ./helpers/uptime
. ./helpers/apt
updates=$(get_updates)
export uptime="$(get_uptime)"
if [ $updates -gt 1 ]; then
export apt_color="#ff5e1e"
export apt_text="$(printf "%d paquets à mettre à jour" $updates)"
elif [ $updates -eq 1 ]; then
export apt_color="#ff5e1e"
export apt_text="$(printf "%d paquet à mettre à jour" $updates)"
else
export apt_color="#77c81b"
export apt_text="Système à jour"
fi
render_template system

7
templates/deblan/df.tpl Normal file
Parādīt failu

@ -0,0 +1,7 @@
<div class="title">
Espace(s) disque(s)
</div>
<div class="content">
<pre>${df}</pre>
</div>

Parādīt failu

@ -0,0 +1,3 @@
</body>
</html>

Parādīt failu

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
html {
margin: 0;
padding: 0;
background: #191e2b;
}
body {
margin: 0;
padding: 0;
font-family: Calibri;
background: #191e2b;
}
ul {
padding: 10px;
margin: 0;
}
li {
padding: 0;
margin: 0 0 0 15px;
list-style: none;
color: #fff;
}
.title {
background: #283044;
color: #fff;
padding: 15px;
margin: 0;
font-size: 24px;
}
.content {
padding: 10px;
background: #191e2b;
color: #fff;
}
</style>
</head>
<body>
<div style="padding: 10px; background: #3b4664;">
<table width="100%">
<tr>
<td valign="middle" width="245">
<img src="https://upload.deblan.org/u/2019-05/5cefbc0a.png">
</td>
<td width="10"></td>
<td valign="middle" style="font-size: 22px">
<ul>
<li><strong>${hostname}</strong></li>
<li>${date}</li>
</ul>
</td>
</tr>
</table>
</div>

Parādīt failu

@ -0,0 +1,9 @@
--${BOUNDARY}
Content-type: image/png;
name="${file}"
Content-Transfer-Encoding: base64
Content-ID: <${file}>
Content-Disposition: attachement;
filename="${file}"
${base64}

10
templates/deblan/mail.tpl Normal file
Parādīt failu

@ -0,0 +1,10 @@
From: ${EMAIL_SENDER}
To: ${EMAIL_RECIPIENT}
Subject: ${EMAIL_RECIPIENT}
Content-type: multipart/mixed;
boundary="${BOUNDARY}"
--$BOUNDARY
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
${REPORT}

Parādīt failu

@ -0,0 +1,7 @@
<div class="title">
Point(s) de montage(s)
</div>
<div class="content">
<pre>${mount}</pre>
</div>

Parādīt failu

@ -0,0 +1 @@
${content}

Parādīt failu

@ -0,0 +1,7 @@
<div class="title">
Smart ${device}
</div>
<div class="content">
<pre>${result}</pre>
</div>

Parādīt failu

@ -0,0 +1,9 @@
<div class="title">
Système
</div>
<div class="content">
<span style="color: ${apt_color}; font-weight:bold">${apt_text}</span>
<pre>${uptime}</pre>
</div>