Modul: inotify - Überwachung von Dateiänderungen nach Pfad

Begonnen von marvin78, 29 Januar 2018, 15:24:32

Vorheriges Thema - Nächstes Thema

rudolfkoenig

Viele FHEM Anfaenger verwechseln globbing (das was man im Shell verwendet) mit regexp. Letzteres ist deutlich maechtiger, ist aber nicht kompatibel. * bedeutet im regexp "das letzte Zeichen beliebig oft" und nicht "irgendetwas beliebig oft". Deswegen fuehrt ein * am Anfang bei Regexp zu Fehlermeldung.

marvin78

Danke für's Einspringen @Rudi.

Ich schaue mal, dass ich das an geeigneter Stelle abfange.

marvin78

Die neue Version 0.4.7 kontrolliert auf einigermaßen korrekte Regex bei define und modify (kein * am Anfang). Außerdem werden im watch schon vorhandene fehlerhafte File-Regex nicht mehr verwendet. Es wird das komplette Verzeichnis überwacht. So kommt es an der Stelle nicht mehr zu FHEM Abstürzen.

marvin78

Die neue Version 0.4.8 startet watch neu, wenn ein Unterordner hinzu kommt oder gelöscht wird und das Attribut subfolders auf 1 steht.

JoWiemann

Falls jemand die Debian Pakete wissen möchte:


sudo apt-get install liblinux-inotify2-perl
sudo apt-get install libdata-dump-perl
sudo apt-get install libfile-find-rule-perl


Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

marvin78


JoWiemann

Hallo,

ich habe das Modul jetzt auf meinem Testsystem (RPi, Stretch) laufen.


Internals:
   DEF        /tmp test.*
   FD         20
   FILES      test.*
   NAME       inotify
   NOTIFYDEV  global
   NR         65
   NTFY_ORDER 50-inotify
   PATH       /tmp
   STATE      active
   TYPE       inotify
   VERSION    0.4.8
   READINGS:
     2018-07-11 20:15:04   state           active
   helper:
     dirs:
       /tmp
     masks:
       IN_ALL_EVENTS
Attributes:
   mask       IN_ALL_EVENTS
   room       System
   verbose    5


Wenn ich nun eine Datei test.txt nach /tmp kopieren erhalte ich folgende Log Infos:

2018.07.11 20:15:04 3: inotify (inotify): set Device active
2018.07.11 20:15:05 3: inotify (inotify): startet watching /tmp with the file pattern test.*
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp/test.txt
2018.07.11 20:15:33 5: inotify (inotify): got $VAR1 = bless( {
                 'mask' => 256,
                 'w' => bless( {
                                 'wd' => 1,
                                 'cb' => sub { "DUMMY" },
                                 'name' => '/tmp',
                                 'inotify' => bless( {
                                                       'ignore' => {},
                                                       'w' => {
                                                                '1' => $VAR1->{'w'}
                                                              },
                                                       'fd' => 20
                                                     }, 'Linux::Inotify2' ),
                                 'mask' => 4095
                               }, 'Linux::Inotify2::Watch' ),
                 'wd' => 1,
                 'cookie' => 0,
                 'name' => 'test.txt'
               }, 'Linux::Inotify2::Event' );

2018.07.11 20:15:33 4: inotify (inotify): event is not matching any configured mask: IN_CREATE
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp/test.txt
2018.07.11 20:15:33 5: inotify (inotify): got $VAR1 = bless( {
                 'wd' => 1,
                 'cookie' => 0,
                 'name' => 'test.txt',
                 'w' => bless( {
                                 'wd' => 1,
                                 'cb' => sub { "DUMMY" },
                                 'name' => '/tmp',
                                 'inotify' => bless( {
                                                       'ignore' => {},
                                                       'w' => {
                                                                '1' => $VAR1->{'w'}
                                                              },
                                                       'fd' => 20
                                                     }, 'Linux::Inotify2' ),
                                 'mask' => 4095
                               }, 'Linux::Inotify2::Watch' ),
                 'mask' => 32
               }, 'Linux::Inotify2::Event' );

2018.07.11 20:15:33 4: inotify (inotify): event is not matching any configured mask: IN_OPEN
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp/test.txt
2018.07.11 20:15:33 5: inotify (inotify): got $VAR1 = bless( {
                 'w' => bless( {
                                 'wd' => 1,
                                 'cb' => sub { "DUMMY" },
                                 'name' => '/tmp',
                                 'inotify' => bless( {
                                                       'w' => {
                                                                '1' => $VAR1->{'w'}
                                                              },
                                                       'fd' => 20,
                                                       'ignore' => {}
                                                     }, 'Linux::Inotify2' ),
                                 'mask' => 4095
                               }, 'Linux::Inotify2::Watch' ),
                 'mask' => 2,
                 'wd' => 1,
                 'name' => 'test.txt',
                 'cookie' => 0
               }, 'Linux::Inotify2::Event' );

2018.07.11 20:15:33 4: inotify (inotify): event is not matching any configured mask: IN_MODIFY
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp/test.txt
2018.07.11 20:15:33 5: inotify (inotify): got $VAR1 = bless( {
                 'w' => bless( {
                                 'wd' => 1,
                                 'cb' => sub { "DUMMY" },
                                 'name' => '/tmp',
                                 'inotify' => bless( {
                                                       'w' => {
                                                                '1' => $VAR1->{'w'}
                                                              },
                                                       'fd' => 20,
                                                       'ignore' => {}
                                                     }, 'Linux::Inotify2' ),
                                 'mask' => 4095
                               }, 'Linux::Inotify2::Watch' ),
                 'mask' => 8,
                 'cookie' => 0,
                 'name' => 'test.txt',
                 'wd' => 1
               }, 'Linux::Inotify2::Event' );

2018.07.11 20:15:33 4: inotify (inotify): event is not matching any configured mask: IN_CLOSE_WRITE
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp/test.txt
2018.07.11 20:15:33 5: inotify (inotify): got $VAR1 = bless( {
                 'mask' => 4,
                 'w' => bless( {
                                 'wd' => 1,
                                 'cb' => sub { "DUMMY" },
                                 'name' => '/tmp',
                                 'inotify' => bless( {
                                                       'w' => {
                                                                '1' => $VAR1->{'w'}
                                                              },
                                                       'fd' => 20,
                                                       'ignore' => {}
                                                     }, 'Linux::Inotify2' ),
                                 'mask' => 4095
                               }, 'Linux::Inotify2::Watch' ),
                 'wd' => 1,
                 'name' => 'test.txt',
                 'cookie' => 0
               }, 'Linux::Inotify2::Event' );

2018.07.11 20:15:33 4: inotify (inotify): event is not matching any configured mask: IN_ATTRIB
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp
2018.07.11 20:15:33 5: inotify (inotify): Fullname /tmp
2018.07.11 20:15:33 4: inotify (inotify): path to watch /tmp


Und es wird weder ein Reading gesetzt noch ein Event ausgelöst.

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

marvin78

#22
Funktioniert es, wenn du andere Masks verwendest (bspw. IN_CREATE)?

Probier mal die neue Version 0.4.9. IN_ALL_EVENTS wurde bisher nicht berücksichtigt, das es das entsprechende Event nicht wirklich gibt.

JoWiemann

Zitat von: marvin78 am 11 Juli 2018, 21:13:27
Funktioniert es, wenn du andere Masks verwendest (bspw. IN_CREATE)?

Probier mal die neue Version 0.4.9. IN_ALL_EVENTS wurde bisher nicht berücksichtigt, das es das entsprechende Event nicht wirklich gibt.

Danke, funktioniert.

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

Wolfgang Hochweller

Ich habe das inotify probiert :


Internals:
   DEF        /opt/fhem/www/snapshots/AussenCAM EingangsCAM_snapshot.jpg
   FD         122
   FILES      EingangsCAM_snapshot.jpg
   NAME       inotify
   NOTIFYDEV  global
   NR         328
   NTFY_ORDER 50-inotify
   PATH       /opt/fhem/www/snapshots/AussenCAM
   STATE      active
   TYPE       inotify
   VERSION    0.4.9
   READINGS:
     2018-08-21 15:41:39   lastEventFile   /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
     2018-08-21 15:41:39   lastEventMask   IN_CLOSE_NOWRITE
     2018-08-21 15:36:51   state           active
   helper:
     dirs:
       /opt/fhem/www/snapshots/AussenCAM
     events:
       0:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_CLOSE_NOWRITE
         time       2018-08-21 15:41:39
       1:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_ACCESS
         time       2018-08-21 15:41:38
       2:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_ACCESS
         time       2018-08-21 15:41:38
       3:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_DELETE
         time       2018-08-21 15:41:38
       4:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_ACCESS
         time       2018-08-21 15:41:37
       5:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_OPEN
         time       2018-08-21 15:41:37
       6:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_CLOSE_NOWRITE
         time       2018-08-21 15:41:37
       7:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_ACCESS
         time       2018-08-21 15:41:36
       8:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_OPEN
         time       2018-08-21 15:41:36
       9:
         file       /opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg
         mask       IN_CLOSE_NOWRITE
         time       2018-08-21 15:41:36



Notify :


Internals:
   DEF        inotify:lastEventFile:.* {
HowiMail ( "howi42\@lyse.net", "Snapshot", "Nichts", "'/opt/fhem/www/snapshots/AussenCAM/EingangsCAM_snapshot.jpg'");;

}
   NAME       AussenCAM_notify
   NOTIFYDEV  inotify
   NR         329
   NTFY_ORDER 50-AussenCAM_notify
   REGEXP     inotify:lastEventFile:.*
   STATE      2018-08-21 15:41:39
   TYPE       notify
   READINGS:
     2018-08-21 15:21:43   state           active
Attributes:



Was muss ich tun, damit das notify nur einmal getriggert wird, wenn die Datei neu geschrieben wird ?
So wie oben hoert das nie auf ...., erst, wenn ich die Datei manuell loesche.

Wolfgang Hochweller


Gisbert

Zitat von: howi42 am 21 August 2018, 20:27:33
Erledigt. Ohne 'mask' zu setzen, keine gute Idee !

Hallo howi42,
hallo marvin78,

zuerstmal vielen Dank an marvin78 für dieses Modul.

Was muss ich beim Attribut mask eintragen?
Mein Ziel ist es ein Reading (anscheinend gibt es gleich mehrere, wenn eine neue Datei geschrieben wird, ist aber im Moment nebensächlich) zu bekommen, wenn die Kamera eine neue Aufnahme macht.
Prinzipiell funktioniert da Modul.

Ich lösche einmal wöchentlich alle Aufnahmen, die älter als 1 Monat sind.
Dann gibt es auch auch Readings:
lastEventFile <Pfad/Filename> 2018-12-20 12:51:58
astEventMask IN_DELETE 2018-12-20 12:51:58


Wie muss ich ein DOIF oder notifiy gestalten, damit diese auf neue Files reagieren, nicht aber auf das Löschen von Files?

Viele Grüße Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY

marvin78

Wenn du das Mask Attribut über das Frontend setzt, wird dir eine Auswahl angeboten. Eigentlich alles selbsterklärend. Bitte auch die Doku zu inotify lesen.

Gisbert

Hallo marvin78,

ahh, ich hab nur das leere Feld gesehen, und da wusste ich nicht weiter. Die commandref war an der Stelle nicht sonderlich auskunftsfreudig.
Durch Anklicken des leeren Feldes bekommt man die Auswahlliste.

Ich nehme an, dass die Auswahl "IN_CLOSE_WRITE" die richtige ist, wenn ich ein Event haben möchte, wenn ein neuer File geschrieben wurde.

Vielen Dank Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY

marvin78

Jap. Das wird gehen. Probiere ggf. auch IN_CREATE. Und dein notify erstellst du dann einfach über den Event-Monitor.