reachable-watcher 1.0.127 → 1.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reachable-watcher",
3
- "version": "1.0.127",
3
+ "version": "1.0.129",
4
4
  "description": "Check status codes of web servers and sends notification e-mails",
5
5
  "keywords": [
6
6
  "reachable",
@@ -12,7 +12,7 @@
12
12
  "online"
13
13
  ],
14
14
  "homepage": "https://tsickert.com/reachable-watcher",
15
- "license": "CC-BY-3.0",
15
+ "license": "CC-BY-4.0",
16
16
  "repository": {
17
17
  "type": "git",
18
18
  "url": "git+https://github.com/thaibault/reachable-watcher.git"
@@ -34,16 +34,25 @@
34
34
  "test": "bash ./node_modules/.bin/bashlink-doctest --verbose ../../reachable-watcher",
35
35
  "update:documentation": "web-documentation"
36
36
  },
37
+ "dependencies": {
38
+ "bashlink": "^1.0.296"
39
+ },
37
40
  "devDependencies": {
38
- "bashlink": "^1.0.292",
39
41
  "rimraf": "^6.1.4",
40
42
  "shellcheck": "^4.1.0",
41
- "web-documentation": "^1.0.72"
43
+ "web-documentation": "^1.0.74"
42
44
  },
43
45
  "engines": {
44
46
  "node": ">=26",
45
47
  "npm": ">=12",
46
48
  "yarn": ">=4"
47
49
  },
50
+ "webDocumentation": {
51
+ "languages": [
52
+ "enUS",
53
+ "deDE",
54
+ "frFR"
55
+ ]
56
+ },
48
57
  "packageManager": "yarn@4.18.1+sha512.b2e1e7524f654f2749d32b4ebcb4622473cb5bcbc485df2007e12a154e50162a4d795526768bc5f5b8f81717bfd79deb2472813d86fb5ae2eb551fa9c872b08f"
49
58
  }
@@ -1,12 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # region header
3
- # Copyright Torben Sickert (t.sickert["~at~"]gmail.com) 16.12.2012
3
+ # Copyright Torben Sickert (info["~at~"]tsickert.com) 16.12.2012
4
4
 
5
5
  # License
6
6
  # -------
7
7
 
8
8
  # This library written by Torben Sickert stands under a creative commons naming
9
- # 3.0 unported license. See https://creativecommons.org/licenses/by/3.0/deed.de
9
+ # 4.0 international license.
10
+ # See https://creativecommons.org/licenses/by/4.0/deed.de
10
11
  # endregion
11
12
  [Unit]
12
13
  Description=Checks server reachabilities.
@@ -17,7 +18,9 @@ After=network.target network-online.target
17
18
  [Service]
18
19
  Restart=always
19
20
  RestartSec=10
20
- ExecStart=/usr/bin/reachable-watcher
21
+ # NOTE: A relative name is searched in "/usr/local/bin" and "/usr/bin" so that
22
+ # global npm installations are found as well.
23
+ ExecStart=reachable-watcher
21
24
  NotifyAccess=all
22
25
 
23
26
  [Install]
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  # -*- coding: utf-8 -*-
3
3
  # region header
4
- # [Project page](https://tsickert.com/reachableWatcher)
4
+ # [Project page](https://tsickert.com/reachable-watcher)
5
5
 
6
6
  # Copyright Torben Sickert (info["~at~"]tsickert.com) 16.12.2012
7
7
 
@@ -9,7 +9,8 @@
9
9
  # -------
10
10
 
11
11
  # This library written by Torben Sickert stands under a creative commons naming
12
- # 3.0 unported license. See https://creativecommons.org/licenses/by/3.0/deed.de
12
+ # 4.0 international license.
13
+ # See https://creativecommons.org/licenses/by/4.0/deed.de
13
14
  # endregion
14
15
  # shellcheck disable=SC1004,SC2016,SC2034,SC2155
15
16
  shopt -s expand_aliases
@@ -26,9 +27,16 @@ rw_download() {
26
27
  return $?
27
28
  }
28
29
 
29
- if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then
30
+ # NOTE: Resolves symbolic links (e.g. "/usr/bin/reachable-watcher") to find
31
+ # bashlink next to the real script location (installed via npm).
32
+ declare -g RW_SCRIPT_PATH="$(
33
+ dirname "$(readlink --canonicalize "${BASH_SOURCE[0]}")")/"
34
+ if [ -f "${RW_SCRIPT_PATH}node_modules/bashlink/module.sh" ]; then
30
35
  # shellcheck disable=SC1090
31
- source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh"
36
+ source "${RW_SCRIPT_PATH}node_modules/bashlink/module.sh"
37
+ elif [ -f "${RW_SCRIPT_PATH}../bashlink/module.sh" ]; then
38
+ # shellcheck disable=SC1090
39
+ source "${RW_SCRIPT_PATH}../bashlink/module.sh"
32
40
  elif [ -f "/usr/lib/bashlink/module.sh" ]; then
33
41
  # shellcheck disable=SC1091
34
42
  source "/usr/lib/bashlink/module.sh"
@@ -40,6 +48,8 @@ else
40
48
  if ! (
41
49
  [ -f "${BL_MODULE_REMOTE_MODULE_CACHE_PATH}/module.sh" ] || \
42
50
  rw.download \
51
+ --show-error \
52
+ --silent \
43
53
  https://raw.githubusercontent.com/thaibault/bashlink/main/module.sh \
44
54
  >"${BL_MODULE_REMOTE_MODULE_CACHE_PATH}/module.sh"
45
55
  ); then
@@ -126,7 +136,7 @@ declare -gr RW__DOCTEST_SETUP__='
126
136
  # Maps each url to its expected status code followed by its recipients.
127
137
  declare -Ag RW_URLS_TO_CHECK=()
128
138
  # Wait for 5 minutes (60 * 5 = 300).
129
- declare -ig RW_DELAY_BETWEEN_TWO_CONSEQUTIVE_REQUESTS_IN_SECONDS=300
139
+ declare -ig RW_DELAY_BETWEEN_TWO_CONSECUTIVE_REQUESTS_IN_SECONDS=300
130
140
  declare -g RW_DATE_TIME_FORMAT='%T:%N at %d.%m.%Y'
131
141
  declare -g RW_SENDER_E_MAIL_ADDRESS=''
132
142
  # Falls back to the sender address when empty.
@@ -162,10 +172,10 @@ rw_is_status_valid() {
162
172
  1
163
173
 
164
174
  >>> rw.is_status_valid "000" 200; echo $?
165
- 0
175
+ 1
166
176
 
167
177
  >>> rw.is_status_valid "000" 206; echo $?
168
- 0
178
+ 1
169
179
 
170
180
  >>> rw.is_status_valid 206 "000"; echo $?
171
181
  1
@@ -191,14 +201,12 @@ rw_is_status_valid() {
191
201
  # NOTE: Given state "000" resolves to "0" as interpreted integer.
192
202
  local -ir expected_status_code=$1
193
203
  local -ir given_status_code=$2
194
- local -ar valid_ok_codes=(0 200 206)
204
+ # NOTE: Status code "000" indicates that the url is not reachable and is
205
+ # therefore only valid if expected explicitly.
206
+ local -ar valid_ok_codes=(200 206)
195
207
  if (( expected_status_code == given_status_code )); then
196
208
  return 0
197
209
  fi
198
- # NOTE: Status code "000" indicates that the url is not reachable.
199
- if (( given_status_code == 0 )); then
200
- return 1
201
- fi
202
210
  if \
203
211
  bl.array.contains "$expected_status_code" "${valid_ok_codes[@]}" &&
204
212
  bl.array.contains "$given_status_code" "${valid_ok_codes[@]}"
@@ -411,8 +419,8 @@ rw_main() {
411
419
  for url in "${!RW_URLS_TO_CHECK[@]}"; do
412
420
  rw.check_url "$url"
413
421
  done
414
- bl.logging.debug "Wait for $RW_DELAY_BETWEEN_TWO_CONSEQUTIVE_REQUESTS_IN_SECONDS seconds until next check."
415
- sleep "$RW_DELAY_BETWEEN_TWO_CONSEQUTIVE_REQUESTS_IN_SECONDS"
422
+ bl.logging.debug "Wait for $RW_DELAY_BETWEEN_TWO_CONSECUTIVE_REQUESTS_IN_SECONDS seconds until next check."
423
+ sleep "$RW_DELAY_BETWEEN_TWO_CONSECUTIVE_REQUESTS_IN_SECONDS"
416
424
  done
417
425
  }
418
426
  # endregion
package/readme.md CHANGED
@@ -7,11 +7,13 @@ License
7
7
  -------
8
8
 
9
9
  This library written by Torben Sickert stands under a creative commons naming
10
- 3.0 unported license. See https://creativecommons.org/licenses/by/3.0/deed.de
10
+ 4.0 international license.
11
+ See https://creativecommons.org/licenses/by/4.0/deed.de
11
12
  endregion -->
12
13
 
13
14
  <!--|deDE:Projektstatus-->
14
- Project Status
15
+ <!--|frFR:Statut du projet-->
16
+ Project status
15
17
  --------------
16
18
 
17
19
  [![npm](https://img.shields.io/npm/v/reachable-watcher?color=%23d55e5d&label=npm%20package%20version&logoColor=%23d55e5d&style=for-the-badge)](https://www.npmjs.com/package/reachable-watcher)
@@ -25,14 +27,27 @@ Project Status
25
27
  [![deploy web documentation](https://img.shields.io/github/actions/workflow/status/thaibault/reachable-watcher/deploy-web-documentation.yaml?label=deploy%20web%20documentation&style=for-the-badge)](https://github.com/thaibault/reachable-watcher/actions/workflows/deploy-web-documentation.yaml)
26
28
  [![web documentation](https://img.shields.io/website-up-down-green-red/https/tsickert.com/reachable-watcher.svg?label=web-documentation&style=for-the-badge)](https://tsickert.com/reachable-watcher)
27
29
 
28
- <!--|deDE:Verwendung-->
30
+ <!--|deDE:Einsatzmöglichkeiten-->
31
+ <!--|frFR:Cas d'utilisation-->
29
32
  Use case
30
33
  --------
31
34
 
32
- This module checks reachability of webservers. You can map a list of urls to
33
- their expected http status codes and a list of email addresses to inform if one
34
- of the url does not return the expected status code. A check interval is also
35
- configurable.
35
+ Watches the reachability of web servers with a single Bash script. Each
36
+ configured URL is mapped to its expected HTTP status code and to e-mail
37
+ addresses, which get notified as soon as the URL stops responding as expected
38
+ and again when it recovers.
39
+ <!--deDE:
40
+ Überwacht die Erreichbarkeit von Webservern mit einem einzigen
41
+ Bash-Skript. Jede konfigurierte URL wird ihrem erwarteten HTTP-Statuscode
42
+ und E-Mail-Adressen zugeordnet, die benachrichtigt werden, sobald die URL
43
+ nicht mehr wie erwartet antwortet, und erneut, wenn sie sich erholt.
44
+ -->
45
+ <!--frFR:
46
+ Surveille l'accessibilité de serveurs web avec un seul script Bash.
47
+ Chaque URL configurée est associée à son code de statut HTTP attendu et
48
+ à des adresses e-mail, qui sont notifiées dès que l'URL ne répond plus
49
+ comme prévu, puis à nouveau lorsqu'elle se rétablit.
50
+ -->
36
51
 
37
52
  <div class="wd-table-of-contents">
38
53
  <h2 id="content">Content<!--deDE:Inhalt--><!--frFR:Contenu--></h2>
@@ -42,68 +57,202 @@ configurable.
42
57
  Installation
43
58
  ------------
44
59
 
45
- You can install via package manager, simply download the compiled version as
46
- zip file here and inject or request via CDN in HTML:
60
+ On Arch Linux, build and install the "PKGBUILD" of this repository (it needs
61
+ the "bashlink" package) and enable the service:
47
62
  <!--deDE:
48
- Sie können das Paket über den Paketmanager installieren oder einfach die
49
- kompilierte Version als ZIP-Datei hier herunterladen und in HTML einbinden
50
- oder über ein CDN abrufen:
63
+ Unter Arch Linux bauen und installieren Sie das "PKGBUILD" dieses
64
+ Repositorys (es benötigt das Paket "bashlink") und aktivieren den
65
+ Dienst:
51
66
  -->
52
67
  <!--frFR:
53
- Vous pouvez installer le paquet via le gestionnaire de paquets ou
54
- simplement télécharger ici la version compilée sous forme de fichier ZIP,
55
- puis l'intégrer dans une page HTML ou la récupérer via un CDN:
68
+ Sous Arch Linux, construisez et installez le "PKGBUILD" de ce dépôt (il
69
+ nécessite le paquet "bashlink") et activez le service:
56
70
  -->
57
71
 
58
72
  ```bash
59
- npm install reachable-watcher
73
+ makepkg --install --syncdeps
74
+ systemctl enable --now reachable-watcher
60
75
  ```
61
76
 
62
- Features
63
- --------
77
+ Anywhere else, install it globally via npm, which brings its library
78
+ [bashlink](https://tsickert.com/bashlink) along, and link the shipped unit:
79
+ <!--deDE:
80
+ Überall sonst installieren Sie es global über npm, das seine Bibliothek
81
+ [bashlink](https://tsickert.com/bashlink) mitbringt, und verlinken die
82
+ mitgelieferte Unit:
83
+ -->
84
+ <!--frFR:
85
+ Partout ailleurs, installez-le globalement via npm, qui apporte sa
86
+ bibliothèque [bashlink](https://tsickert.com/bashlink), et liez l'unité
87
+ fournie:
88
+ -->
64
89
 
65
- - Configurable interval to check for expected http status codes
66
- - Can be run on any linux machine (minimal dependencies)
67
- - Configure an email address to get notified if any resource doesn't work as
68
- expected or isn't even available.
90
+ ```bash
91
+ npm install --global reachable-watcher
92
+ systemctl link \
93
+ "$(npm root --global)/reachable-watcher/reachable-watcher.service"
94
+ systemctl enable --now reachable-watcher
95
+ ```
69
96
 
70
- <!--|deDE:Beispiel-->
71
- <!--|frFR:Exemple-->
72
- Example
73
- -------
97
+ The unit starts "reachable-watcher" from "/usr/local/bin" or "/usr/bin". The
98
+ script alone works as well: it needs "bash" and "curl" and downloads bashlink
99
+ on its first start if it is missing. E-mails need "msmtp".
100
+ `journalctl -u reachable-watcher` shows what the service does.
101
+ <!--deDE:
102
+ Die Unit startet "reachable-watcher" aus "/usr/local/bin" oder
103
+ "/usr/bin". Das Skript allein funktioniert ebenfalls: Es benötigt "bash"
104
+ und "curl" und lädt bashlink beim ersten Start herunter, wenn es fehlt.
105
+ E-Mails benötigen "msmtp". `journalctl -u reachable-watcher` zeigt, was
106
+ der Dienst tut.
107
+ -->
108
+ <!--frFR:
109
+ L'unité démarre "reachable-watcher" depuis "/usr/local/bin" ou
110
+ "/usr/bin". Le script seul fonctionne aussi: il nécessite "bash" et
111
+ "curl" et télécharge bashlink à son premier démarrage s'il manque. Les
112
+ e-mails nécessitent "msmtp". `journalctl -u reachable-watcher` montre ce
113
+ que fait le service.
114
+ -->
115
+
116
+ Configuration
117
+ -------------
74
118
 
75
- Run this script to initialize the watcher.
119
+ "/etc/reachableWatcher" is a Bash file which overrides the defaults. At least
120
+ the URLs to check and the sender address have to be set. Each URL maps to its
121
+ expected status code, followed by the e-mail addresses to notify:
122
+ <!--deDE:
123
+ "/etc/reachableWatcher" ist eine Bash-Datei, die die Standardwerte
124
+ überschreibt. Mindestens die zu prüfenden URLs und die Absenderadresse
125
+ müssen gesetzt werden. Jede URL wird ihrem erwarteten Statuscode
126
+ zugeordnet, gefolgt von den zu benachrichtigenden E-Mail-Adressen:
127
+ -->
128
+ <!--frFR:
129
+ "/etc/reachableWatcher" est un fichier Bash qui remplace les valeurs par
130
+ défaut. Il faut au minimum définir les URL à vérifier et l'adresse de
131
+ l'expéditeur. Chaque URL est associée à son code de statut attendu,
132
+ suivi des adresses e-mail à notifier:
133
+ -->
76
134
 
77
- ```sh
78
- ./reachableWatcher.sh
135
+ ```bash
136
+ RW_SENDER_E_MAIL_ADDRESS=watcher@example.com
137
+ declare -A RW_URLS_TO_CHECK=(
138
+ ['https://example.com']='200 admin@example.com'
139
+ ['https://example.com/missing']='404 admin@example.com dev@example.com'
140
+ )
141
+ # Optional settings with their defaults:
142
+ RW_DELAY_BETWEEN_TWO_CONSECUTIVE_REQUESTS_IN_SECONDS=300
143
+ RW_NAME=NODE_NAME
144
+ RW_REPLIER_E_MAIL_ADDRESS="$RW_SENDER_E_MAIL_ADDRESS"
145
+ RW_VERBOSE=false
79
146
  ```
80
147
 
81
- or after installation:
148
+ "RW_NAME" names this machine in the e-mail subjects, "RW_VERBOSE=true" logs
149
+ every state change. Run "reachable-watcher" once by hand to check the
150
+ configuration.
151
+ <!--deDE:
152
+ "RW_NAME" benennt diesen Rechner in den E-Mail-Betreffs,
153
+ "RW_VERBOSE=true" protokolliert jeden Zustandswechsel. Führen Sie
154
+ "reachable-watcher" einmal von Hand aus, um die Konfiguration zu prüfen.
155
+ -->
156
+ <!--frFR:
157
+ "RW_NAME" nomme cette machine dans les objets des e-mails,
158
+ "RW_VERBOSE=true" journalise chaque changement d'état. Lancez
159
+ "reachable-watcher" une fois à la main pour vérifier la configuration.
160
+ -->
82
161
 
83
- ```sh
84
- reachable-watcher
85
- ```
162
+ <!--|deDE:Statuscodes-->
163
+ <!--|frFR:Codes de statut-->
164
+ ### Status codes
86
165
 
87
- Configuration
88
- -------------
166
+ Every interval each URL is requested via "HEAD" (certificates are not
167
+ verified). The response is valid if:
168
+ <!--deDE:
169
+ In jedem Intervall wird jede URL per "HEAD" angefragt (Zertifikate werden
170
+ nicht geprüft). Die Antwort ist gültig, wenn:
171
+ -->
172
+ <!--frFR:
173
+ À chaque intervalle, chaque URL est demandée via "HEAD" (les certificats
174
+ ne sont pas vérifiés). La réponse est valide si:
175
+ -->
176
+
177
+ - its status code equals the expected one or<!--deDE:ihr Statuscode dem erwarteten entspricht oder--><!--frFR:son code de statut est égal à celui attendu ou-->
178
+ - both are one of "200" and "206".<!--deDE:beide einer von "200" und "206" sind.--><!--frFR:les deux font partie de "200" et "206".-->
179
+
180
+ An unreachable URL results in "000", which is only valid if "000" is expected,
181
+ e.g. to make sure that an internal service stays hidden.
182
+ <!--deDE:
183
+ Eine nicht erreichbare URL ergibt "000", was nur gültig ist, wenn "000"
184
+ erwartet wird, z. B. um sicherzustellen, dass ein interner Dienst
185
+ verborgen bleibt.
186
+ -->
187
+ <!--frFR:
188
+ Une URL inaccessible donne "000", ce qui n'est valide que si "000" est
189
+ attendu, par exemple pour s'assurer qu'un service interne reste caché.
190
+ -->
191
+
192
+ Recipients are only notified when the state of a URL changes, from valid to
193
+ invalid or back. A URL which is valid on the first check sends nothing.
194
+ <!--deDE:
195
+ Empfänger werden nur benachrichtigt, wenn sich der Zustand einer URL
196
+ ändert, von gültig zu ungültig oder zurück. Eine URL, die bei der ersten
197
+ Prüfung gültig ist, verschickt nichts.
198
+ -->
199
+ <!--frFR:
200
+ Les destinataires ne sont notifiés que lorsque l'état d'une URL change,
201
+ de valide à invalide ou inversement. Une URL valide lors de la première
202
+ vérification n'envoie rien.
203
+ -->
204
+
205
+ <!--|deDE:E-Mails-->
206
+ <!--|frFR:E-mails-->
207
+ ### E-mails
89
208
 
90
- Simply edit the constants region of the provided shell script.
209
+ E-mails are sent via "msmtp", so it needs a working "~/.msmtprc" or
210
+ "/etc/msmtprc", e.g.:
211
+ <!--deDE:
212
+ E-Mails werden über "msmtp" verschickt, es braucht also eine
213
+ funktionierende "~/.msmtprc" oder "/etc/msmtprc", z. B.:
214
+ -->
215
+ <!--frFR:
216
+ Les e-mails sont envoyés via "msmtp", il faut donc un "~/.msmtprc" ou un
217
+ "/etc/msmtprc" fonctionnel, par exemple:
218
+ -->
91
219
 
92
- Installation (under systemd)
93
- ----------------------------
220
+ ```
221
+ defaults
222
+ auth on
223
+ tls on
224
+ tls_starttls on
225
+ tls_trust_file /etc/ssl/certs/ca-certificates.crt
226
+ logfile /tmp/msmtpLog
94
227
 
95
- Copy the script file "reachableWatcher.sh" to "/usr/bin/reachable-watcher" and
96
- the provided service file ("reachableWatcher.service") to
97
- "/etc/systemd/system/reachable-watcher.service" run:
228
+ account mail
229
+ host smtp.example.com
230
+ port 587
231
+ from watcher@example.com
232
+ user watcher@example.com
233
+ password PASSWORD
98
234
 
99
- ```sh
100
- systemctl enable reachable-watcher
235
+ account default : mail
101
236
  ```
102
237
 
103
- to enable the checking logic. After running:
238
+ <!--|deDE:Entwicklung-->
239
+ <!--|frFR:Développement-->
240
+ Development
241
+ -----------
104
242
 
105
- ```sh
106
- systemctl start reachable-watcher
243
+ ```bash
244
+ yarn install
245
+ yarn lint
246
+ yarn test
107
247
  ```
108
248
 
109
- you can see the worker running in your system logs.
249
+ "yarn test" runs the examples in the script's documentation as tests,
250
+ "yarn document" renders this documentation as HTML.
251
+ <!--deDE:
252
+ "yarn test" führt die Beispiele aus der Dokumentation des Skripts als
253
+ Tests aus, "yarn document" erzeugt diese Dokumentation als HTML.
254
+ -->
255
+ <!--frFR:
256
+ "yarn test" exécute les exemples de la documentation du script comme
257
+ tests, "yarn document" génère cette documentation en HTML.
258
+ -->