2 contributor
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
dir=$1
function nginx () {
nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local"
nc -zw2 sebmarque.hd.free.fr 80 || echo "injoignable sur port 80 distant"
nc -zw2 sebmarque.hd.free.fr 443 || echo "injoignable sur port 443 distant"
}
function searx () {
_turn 5 || return
nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
}
function gitprep () {
_turn 5 || return
nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
}
function webapps () {
_turn 3 || return
awk -v sq="'" '
/^[^#]+#\s*monitoring\s/ {
if ($1 == "listen") {
port = ":" gensub(";", "", "1", $2)
proto = gensub(";", "", "1", $3) == "ssl" ? "https" : "http"
pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/, "1", "1")
if (proto == "https" && port == ":443") port = ""
}
if ($1 == "server_name") {
server_name = gensub(";", "", "1", $2)
sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/, "1", "1")
}
if ($1 == "location" && sname != "" && pname != "" && sname == pname) {
l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "1")
split(l, location, /\s*,\s*/)
if (location[2] == sname) {
monitoring[location[2]][location[1]]["monitoring"] = location[3]
monitoring[location[2]][location[1]]["response_code"] = location[4]
monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5]
if (location[6] != "")
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq
else
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq
}
}
}
END {
for (mid in monitoring) {
for (locid in monitoring[mid]) {
curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s",
monitoring[mid][locid]["user-agent"],
monitoring[mid][locid]["url"])
curl | getline response_code
close(curl)
if (response_code != monitoring[mid][locid]["response_code"] && response_code != "000")
printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code)
}
}
}
' /etc/nginx/sites-enabled/*
}
function section () {
nc -zw5 cloud.paris12.pcf.fr 443 || echo "cloud inaccessible"
nc -zw5 cloud.paris12.pcf.fr 2200 || echo "section inaccessible"
}
function core_temp () {
local min=60
local level=("warning" "severe" "danger!")
local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
if test $step -gt 5000; then
step=$((step / 10000))
test $step -le 2 || step=2
echo "${level[step]}: température > $((min + step * 10))°"
fi
}
function core_alim () {
eval $(/opt/vc/bin/vcgencmd measure_volts core)
volt_fmt=${volt/\.}
volt_fmt=${volt_fmt/V}
test $volt_fmt -lt 12000 -o $volt_fmt -gt 15000 && echo "$volt"
}
function clean_swap () {
_turn 2 || return
echo 1 > /proc/sys/vm/drop_caches
if LANG=C free -m | awk '
/^Swap:/ {
used = $3
}
END {
bash_exit_code = !(used > 62)
exit bash_exit_code
}
'; then
systemctl stop dphys-swapfile \
&& systemctl stop zram \
&& systemctl start zram \
&& systemctl start dphys-swapfile \
|| echo 'erreur'
fi
}
function mem_pressure () {
local meminfo=($(</proc/meminfo))
local level=(danger severe warning)
local margin=30000
for ((i=0; i<${#meminfo[@]}; i+=3)); do
test ${meminfo[i]} == 'MemAvailable:' && break
done
meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 ))
test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB"
}
function piwigo_private () {
_turn 20 || return
test "$(curl --silent 'http://192.168.0.71/photos/ws.php?format=json&method=pwg.categories.getList' | sum)" = "00569 1" || echo "albums visibles publiquement"
}
function snappymail_version () {
_turn 24 || return
local installed_version=$(</var/www/rainloop/data/VERSION)
local release_url='https://api.github.com/repos/the-djmaze/snappymail/releases/latest'
local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url | jq -r '.name | ltrimstr("v")')
if test $version != $installed_version; then
echo "nouvelle version dispo: $version"
fi
}
function navidrome_version () {
_turn 24 || return
local installed_version=$(find ~navidrome/navidrome -printf "%C@")
local release_url='https://api.github.com/repos/navidrome/navidrome/releases/latest'
local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url \
| jq -r '.assets | .[] | select(.name | contains("linux_armv7")) | .updated_at | fromdateiso8601')
if test $version -gt ${installed_version%.*}; then
echo "nouvelle version dispo"
fi
}