Qnap [Tuto QNAP] Comment envoyer notifications sur QTS

giopas

Grand Maître Jedi
20 Avril 2015
1 084
9
68
EU
Salut à tout le monde,

Parfois il pourrait s’avérer utile d'envoyer une notification à son QTS Desktop, ou bien (à partir de la version QTS 4.2) à son propre téléphone portable.

Cela typiquement peut être le cas si on lance un script, par exemple avec cron, et on veut savoir (sans aller chercher dans les logs) le résultat.

Pour faire cela, il faut utiliser deux commandes:

/sbin/log_tool

Code:
Usage: /sbin/log_tool [OPTION]... 
Manipulate event logs in system.

	-h, --help		Display this help and exit.
	-v, --verbose		Enable verbose output.
	-c, --initdb		Initialize the table for event logs.
	-r, --rmdb		Remove the table for event logs.
	-f, --flushdb		Flush all data in the table for event logs.
	-y, --modifydb		Modify column in the table for event logs.
	-b, --maxlog N		Set the max number of logs to N.
	-a, --append MSG	Append MSG into the event log.
		-t, --type [0-2]	Specify the event type.
		-u, --user USER		Specify the username.
		-p, --ip IP		Specify the IP.
		-m, --comp NAME		Specify the computer name.
		-x, --msgid MSGID		Specify the mesage id.
	-q, --query		Query the data of event logs.
		-s, --sort [0-17]	Set the sort type.
		-l, --lower NUM		Set the lower bound. 
					 (NUM >= 0, NUM <= upper)
		-o, --upper NUM		Set the upper bound. 
					 (NUM >= 0, NUM >= lower)
		-e, --filter [0-3]	Specify the filter type.
		-i, --group [0-9]	group by TBL_FIELD.
		-d, --date1 DATE1		Specify the date1 - date2.
		-g, --date2 DATE2		Specify the date1 - date2.
		-u, --user USER		Specify the username.
		-p, --ip IP		Specify the IP.
		-m, --comp NAME		Specify the computer name.
		-k, --keyword KEYWORD		Filter the keyword in log.

Event types:
	0 = Information
	1 = Warning
	2 = Error

Sort types:
	0 = Sort by date in ascending order.
	1 = Sort by date in descending order.
	2 = Sort by time in ascending order.
	3 = Sort by time in descending order.
	4 = Sort by event type in ascending order.
	5 = Sort by event type in descending order.
	6 = Sort by user in ascending order.
	7 = Sort by user in descending order.
	8 = Sort by IP in ascending order.
	9 = Sort by IP in descending order.
	10 = Sort by computer name in ascending order.
	11 = Sort by computer name in descending order.
	12 = Sort by id in ascending order.
	13 = Sort by id in descending order.
	14 = Sort by msgid in ascending order.
	15 = Sort by msgid in descending order.
	16 = Sort by timet in ascending order.
	17 = Sort by timet in descending order.

Report bugs to <nas_rd@qnap.com>
ou bien

/sbin/notice_log_tool

Code:
Usage: /sbin/notice_log_tool [OPTION]... 
Manipulate notice logs in system.

	-h, --help		Display this help and exit.
	-v, --verbose		Enable verbose output.
	-c, --initdb		Initialize the table for notice logs.
	-r, --rmdb		Remove the table for notice logs.
	-f, --flushdb		Flush all data in the table for notice logs.
	-M, --modifydb		Modify notice logs.
	-R, --rmlog		Remove over 30 days logs.
	-b, --maxlog N		Set the max number of logs to N.
	-E, --sendEng MSG	send MSG into the notice log.
	-a, --append MSG	Append MSG into the notice log.
		-t, --severity [0-7]	Specify the notice severity.
		-u, --user USER		Specify the username.
		-p, --ip IP		Specify the IP.
		-m, --client NAME		Specify the client name.
		-d, --server [0-10]	Specify the notice connect server.
		-n, --action [0-23]	Specify the notice action.
		-i, --serviceName Service Name	Specify the notice service name.
		-y, --facility [0-17]	Specify the notice facility.
		-g, --msgCode CODE	Specify the notice msgCode.
		-j, --varContent Var Content		Specify the var content delimiter ;.
		-N, --task NAME		Specify the task name.
		-S, --task status		Specify the task status.
		-U, --user id		who can get this notice.
		-G, --group id		who can get this notice.
	-q, --query		Query the data of notice logs.
		-s, --sort [0-23]	Set the sort type.
		-l, --lower NUM		Set the lower bound. 
					 (NUM >= 0, NUM <= upper)
		-o, --upper NUM		Set the upper bound. 
					 (NUM >= 0, NUM >= lower)
		-e, --filter [0-1]	Specify the filter type.

Sort types:
	0 = Sort by time in ascending order.
	1 = Sort by time in descending order.
	4 = Sort by notice severity in ascending order.
	5 = Sort by notice severity in descending order.
	6 = Sort by user in ascending order.
	7 = Sort by user in descending order.
	8 = Sort by IP in ascending order.
	9 = Sort by IP in descending order.
	10 = Sort by client name in ascending order.
	11 = Sort by client name in descending order.
	12 = Sort by id in ascending order.
	13 = Sort by id in descending order.
	20 = Sort by facility in ascending order.
	21 = Sort by facility in descending order.
	22 = Sort by msgcode in ascending order.
	23 = Sort by msgcode in descending order.

Report bugs to <nas_rd@qnap.com>
L'utilisation de ces deux commandes peut être très simple.

Par exemple, si je veux juste voir une notification d'information uniquement dans le QTS Desktop , je dois utiliser la commande suivante:
Code:
/sbin/notice_log_tool -a "INFO: Example script x completed." -t 5
Si par contre je veux voir une notification d'alerte ou d'erreur dans le QTS Desktop et sur votre téléphone portable pour l'exécution du script, vous devez utiliser la commande suivante (alerte):
Code:
/sbin/log_tool -a "WARNING: Example script x completed." -t 1

Connaître cela nous permet d'utiliser les notifications directement dans nos scripts.

Exemple de notification d'information:
Code:
#!/bin/sh
OUTPUT="$(hostname)"
/sbin/notice_log_tool -a "${OUTPUT}" -t 5
exit 0
Exemple de notification d'erreur:
Code:
#!/bin/sh
OUTPUT="$(hostname)"
/sbin/log_tool -a "${OUTPUT}" -t 2
exit 0
Il faut noter que /sbin/log_tool -t 0 va créer un information, mais vu que QTS 4.2 permet le "push notification" seulement pour les erreurs et les alertes, ce n'est pas possible de recevoir une notification pour une simple information.

Finalement, les différents degrés (severity) dans /sbin/notice_log_tool ne peuvent être réellement utilisés que dans un système SNMP ou autre système similaire. Si donc l'objectif est de recevoir une notification dans QTS Desktop, la valeur de -t au final n'est pas trop important.

Voilà c'est tout! J'espère que vous avez apprécié.

giopas

CREDITS and REFERENCES:
http://qnap.community/viewtopic.php?f=23&t=127
https://www.qnap.com/i/fr/trade_teach/con_show.php?op=showone&cid=156
 
oui, très fun , surtout le warning sur le téléphone qui marche super. Bon, reste a trouver où l'utiliser...
 
je m'en sert depuis peu, si tu télécharge GitBucket à la première installe tu reçois un message sous QTS comme quoi l'app créé un répertoire dans tes dossiers partagés et il ne sera pas supprimé lors de l’effacement du QPKG. ce sera à l'utilisateur de l’effacer

:ugeek:

Merci à Giopas, pour cette petite astuce
 
Merci à toi Stéphane pour ton travail et conseils! Un autre usage est pour connaitre le nom du tunnel créé par ngrok :)

Sent from my A0001 using Tapatalk