{"id":1446,"date":"2013-05-15T17:06:08","date_gmt":"2013-05-15T15:06:08","guid":{"rendered":"http:\/\/www.daniel-ritter.de\/blog\/?p=1446"},"modified":"2013-05-15T17:30:09","modified_gmt":"2013-05-15T15:30:09","slug":"logfile-monitoring-und-e-mail-benachrichtigung-mit-swatch","status":"publish","type":"post","link":"https:\/\/www.daniel-ritter.de\/blog\/logfile-monitoring-und-e-mail-benachrichtigung-mit-swatch\/","title":{"rendered":"Logfile Monitoring und E-Mail Benachrichtigung mit swatch unter Debian und Ubuntu"},"content":{"rendered":"<p><a href=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2013\/05\/logfiles_mit_swatch_monitoren.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2013\/05\/logfiles_mit_swatch_monitoren.jpg\" alt=\"logfiles_mit_swatch_monitoren\" width=\"650\" height=\"295\" class=\"alignnone size-full wp-image-1457\" srcset=\"https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2013\/05\/logfiles_mit_swatch_monitoren.jpg 650w, https:\/\/www.daniel-ritter.de\/blog\/wp-content\/uploads\/2013\/05\/logfiles_mit_swatch_monitoren-300x136.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a><\/p>\n<p>Logfiles enthalten viele wertvolle Informationen. Eine Platte ist defekt, das RAID gibt den Geist auf, ein Backup ist fehlgeschlagen oder die Batterie von der USV ist kaputt. Leider bekommt man von diesen wichtigen Infos wenig mit, wenn man sich \u00fcber auftauchende Probleme nicht automatisiert benachrichtigen l\u00e4sst. Niemand kann (oder will :)) t\u00e4glich alle anfallenden Logs checken.<\/p>\n<p>Ein einfaches und effektives Monitoring kann man sich mit dem kleinen Daemon &#8222;swatch&#8220; einrichten. Swatch liest live Logfiles mit und f\u00fchrt Aktionen aus, wenn bestimmte Schl\u00fcsselworte in den Logfiles auftauchen.<\/p>\n<p>Hier ein Quick and Dirty Setup um das Logfile von rsnapshot, einem Backuptool zu monitoren und bei Problemen eine Mail zu versenden:<\/p>\n<pre>\r\n# swatch installieren\r\napt-get -y install swatch\r\n<\/pre>\n<p>Nun muss man sich das Logfiles das \u00fcberwacht werden soll ansehen und identifizieren, was dort gelogged wird, wenn Fehler auftauchen. Hier als Beispiel das Logfile von rsnapshot nach einem Backup, das Probleme verursacht hat:<\/p>\n<pre>\r\n[15\/May\/2013:01:00:21] require Lchown\r\n[15\/May\/2013:01:00:21] Lchown module loaded successfully\r\n[15\/May\/2013:01:00:21] \/usr\/bin\/rsnapshot daily: started\r\n[15\/May\/2013:01:00:21] Setting locale to POSIX \"C\"\r\n[15\/May\/2013:01:00:21] echo 13895 > \/var\/run\/rsnapshot.pid\r\n[15\/May\/2013:01:00:21] \/root\/scripts\/nas-backup\r\n[15\/May\/2013:01:00:26] \/bin\/rm -rf \/media\/net\/nas1\/data\/daily.6\/\r\n[15\/May\/2013:01:13:30] mv \/media\/net\/nas1\/data\/daily.5\/ \/media\/net\/nas1\/data\/daily.6\/\r\n[15\/May\/2013:01:13:30] mv \/media\/net\/nas1\/data\/daily.4\/ \/media\/net\/nas1\/data\/daily.5\/\r\n[15\/May\/2013:01:13:30] mv \/media\/net\/nas1\/data\/daily.3\/ \/media\/net\/nas1\/data\/daily.4\/\r\n[15\/May\/2013:01:13:30] mv \/media\/net\/nas1\/data\/daily.2\/ \/media\/net\/nas1\/data\/daily.3\/\r\n[15\/May\/2013:01:13:30] mv \/media\/net\/nas1\/data\/daily.1\/ \/media\/net\/nas1\/data\/daily.2\/\r\n[15\/May\/2013:01:13:30] \/bin\/cp -al \/media\/net\/nas1\/data\/daily.0 \/media\/net\/nas1\/data\/daily.1\r\n[15\/May\/2013:01:30:07] \/usr\/bin\/rsync -av --delete --numeric-ids --relative --delete-excluded \/media\/local\/share \/media\/net\/nas1\/data\/daily.0\/localhost\/\r\n[15\/May\/2013:01:32:19] rsync succeeded\r\n[15\/May\/2013:01:32:19] \/usr\/bin\/rsync -av --delete --numeric-ids --relative --delete-excluded \/etc \/media\/net\/nas1\/data\/daily.0\/localhost\/\r\n[15\/May\/2013:01:32:21] rsync succeeded\r\n[15\/May\/2013:01:32:21] \/usr\/bin\/rsync -av --delete --numeric-ids --relative --delete-excluded \/home \/media\/net\/nas1\/data\/daily.0\/localhost\/\r\n[15\/May\/2013:03:28:06] rsync succeeded\r\n[15\/May\/2013:03:28:06] \/usr\/bin\/rsync -av --delete --numeric-ids --relative --delete-excluded \/var \/media\/net\/nas1\/data\/daily.0\/localhost\/\r\n[15\/May\/2013:03:55:06] \/usr\/bin\/rsnapshot daily: <strong>ERROR:<\/strong> \/usr\/bin\/rsync returned 12 while processing \/var\/\r\n[15\/May\/2013:03:55:06] \/usr\/bin\/logger -i -p user.err -t rsnapshot \/usr\/bin\/rsnapshot daily: <strong>ERROR:<\/strong> \/usr\/bin\/rsync returned 12 while processing \/var\/\r\n[15\/May\/2013:03:55:06] touch \/media\/net\/nas1\/data\/daily.0\/\r\n[15\/May\/2013:03:55:08] No directory to delete: \/media\/net\/nas1\/data\/_delete.13895\r\n[15\/May\/2013:03:55:08] rm -f \/var\/run\/rsnapshot.pid\r\n[15\/May\/2013:03:55:08] \/usr\/bin\/logger -i -p user.err -t rsnapshot \/usr\/bin\/rsnapshot daily: <strong>ERROR:<\/strong> \/usr\/bin\/rsnapshot daily: completed, but with some <strong>errors<\/strong>\r\n[15\/May\/2013:03:55:08] \/usr\/bin\/rsnapshot daily: <strong>ERROR:<\/strong> \/usr\/bin\/rsnapshot daily: completed, but with some <strong>errors<\/strong>\r\n\r\n<\/pre>\n<p>Im rsnapshot-Log tauchen also die W\u00f6rter &#8222;ERROR:&#8220; und &#8222;errors&#8220; auf, falls es Probleme gibt. Dies teilt man Swatch in einer neu angelegten Konfigurationsdatei mit:<\/p>\n<pre>\r\n#\/etc\/swatch\/watch_rsnapshot\r\nwatchfor \/ERROR|errors\/\r\nmail addresses=daniel\\@daniel-ritter.de,subject=RSNAPSHOT_BACKUP_HAT_WARNUNG_GENERIERT\r\n<\/pre>\n<p>In der &#8222;watchfor&#8220;-Zeile werden die zu \u00fcberwachenden Schl\u00fcsselw\u00f6rter konfiguriert, in der &#8222;mail&#8220;-Zeile gibt man eine Mail-Adresse und ein Subject f\u00fcr die Warn-Email an.<\/p>\n<p>Nun muss swatch nur noch gestartet werden:<\/p>\n<pre>\r\n\/usr\/bin\/swatch  --config-file=\/etc\/swatch\/watch_rsnapshot --tail-file=\/var\/log\/rsnapshot.log --daemon\r\n<\/pre>\n<p><strong>Fallstricke:<\/strong><\/p>\n<p>&#8211; Das Starten von swatch muss in die Startskripte des Servers eingef\u00fcgt werden, damit swatch nach einem Reboot sofort wieder mit der \u00dcberwachung beginnt.<\/p>\n<p>&#8211; Das E-Mail System des Servers muss funktionieren. Am Besten generiert man eine Testmail und \u00fcberpr\u00fcft, ob sie tats\u00e4chlich bei der konfigurierten E-Mail Adresse ankommt. Daf\u00fcr kann man einfach eines der zu \u00fcberwachenden Schl\u00fcsselworte an die \u00fcberwachte Logdatei anh\u00e4ngen.<\/p>\n<pre>\r\necho \"errors\" >> \/var\/log\/rsnapshot.log\r\n<\/pre>\n<p>Bei Problemen schaut man am Besten in den Logdateien des MTA nach um dem Fehler auf die Schliche zu kommen \/var\/log\/exim4\/mainlog (Exim) oder \/var\/log\/mail.log (Postfix)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logfiles enthalten viele wertvolle Informationen. Eine Platte ist defekt, das RAID gibt den Geist auf, ein Backup ist fehlgeschlagen oder die Batterie von der USV ist kaputt. Leider bekommt man von diesen wichtigen Infos wenig mit, wenn man sich \u00fcber auftauchende Probleme nicht automatisiert benachrichtigen l\u00e4sst. Niemand kann (oder will :)) t\u00e4glich alle anfallenden Logs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1446","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/comments?post=1446"}],"version-history":[{"count":17,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1446\/revisions"}],"predecessor-version":[{"id":1464,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/1446\/revisions\/1464"}],"wp:attachment":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media?parent=1446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/categories?post=1446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/tags?post=1446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}