User Login Status über Terminal

  • Ab sofort steht euch hier im Forum die neue Add-on Verwaltung zur Verfügung – eine zentrale Plattform für alles rund um Erweiterungen und Add-ons für den DSM.

    Damit haben wir einen Ort, an dem Lösungen von Nutzern mit der Community geteilt werden können. Über die Team Funktion können Projekte auch gemeinsam gepflegt werden.

    Was die Add-on Verwaltung kann und wie es funktioniert findet Ihr hier

    Hier geht es zu den Add-ons

Status
Für weitere Antworten geschlossen.

m4c_e7e

Benutzer
Registriert
08. Okt. 2011
Beiträge
31
Reaktionspunkte
0
Punkte
0
hi,

wie kann ich übers terminal sehen, das sich wer über webdav oder ftp eingeloggt hat, derweil kann ich nur sehen wenn ich übers webinterface gehen und das systeminfo aufruf.

oder kann man die user mit jabber accounts verknüpfen und wenn die sich dann einloggen dass diese dann auch über jabber online gehen (irc geht auch)

wäre echt ne super hilfe, brauch einfach eine status meldung, wenn sich wer bei mir einloggt.

danke
 
Das wird ein ziemliches Unterfangen werden :-) Jede Anwendung macht das für sich selbst und natürlich anders als andere Anwendungen. Am ehesten hast du Chancen wenn die Anwendung den Loginstatus in ein Logfile schreibt. Das könnte man dann mittels eines regelmässigen Jobs auswerten. Du müsstest also mal gucken was dein Jabber in seine Logfiles schreibt
 
Das ist doch was für mich!

Ein Script, was /var/log/synoconn.log verarbeitet.... Ich zerlege jetzt mal das File... :p

Zusätzliche Dinge kann man ja schon mit /usr/syno/bin/synologset1 loggen.
Events stehen in /usr/syno/synosdk/texts/enu/events, dass man auch um eingene Events erweitern kann...

Stay tuned für eine Lösung, des beliebten Problems :D
 
wie geschrieben, ich brauch ne lösung entweder per irc, jabber oder script eine meldung tu bekommen wenn sich wer einloggt.

wie ich die meldung bekomm is egal, man kan auch per "ipkg: nail" meldung verschicken, hauptsache ich bekomm was
 
Kein Problem, das machen wir mit einem ganz einfachem Wrapper um /usr/syno/bin/synologset1, der bei definierten Events aus /usr/syno/synosdk/texts/enu/events eine Notification verschickt, wie sie im im Log zu sehen ist. Verschicken kannst du das dann über jedes beliebige Kommando.

Hab das binäre Syno Log Format zerlegt. Ist recht simpel. Im Prinzip der Aufruf von synologset1 plus die üblichen Längenbytes vorher.

So, ich geh jetzt erstmal in den Augang! Prost! :D

Ich mach das Script und den Wrapper morgen Abend klar. Können sicherlich etliche gebrauchen einmal die Logs auf der Shell als Text auszugeben und einen Wrapper für Notifications für neue Einträge im Log.
 
Syno Logs ausgeben / Notifications für neue Log Einträge

Hier mal die erste Version für alle zum Testen. Bitte ausprobieren und mir die Bugs melden - gibt da bestimmt einige bevor es ganz rund läuft. Danke.

Rich (BBCode):
#!/usr/bin/perl

# Name: synolog.pl
# Version: 0.1

# Installation:
# 1. copy synolog.pl to a directory in your $PATH (e.g. /opt/bin)
# 2. chmod 755 /opt/bin/synolog.pl
# 3. mv /usr/syno/bin/synologset1 /usr/syno/bin/synologset1.old
# 4  ln -s /opt/bin/synolog.pl /usr/syno/bin/synologset1

use warnings;
use strict;

# customize your notification settings here. Events are defined in '/usr/syno/synosdk/texts/enu/events'
my @NOTIFY_EVENTS    = qw( 11800101 11800102 11B00005 11E00000 );
my $NOTIFY_RECIPIENT = "your\@email.com";
my $NOTIFY_SUBJECT   = "[NAS] ###SUBJECT###";
my $NOTIFY_CMD       = "echo \"###MESSAGE###\" | /opt/bin/nail -s \"###SUBJECT###\" $NOTIFY_RECIPIENT";

my $LOGFILE;
my $EVENTFILE = "/usr/syno/synosdk/texts/enu/events";
my %events;

sub send_notification {
  my %typelist = ( 
    info => 'Information',
    warn => 'Warning',
    err => 'Error',
  );
  
  my $event_type = $ARGV[1] && $typelist{$ARGV[1]} ? $typelist{$ARGV[1]} : "Unknown";
  
  my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
  my $timestamp = sprintf("%02d.%02d.%4d %02d:%02d:%02d", $mday, $mon + 1, $year + 1900, $hour, $min, $sec);

  my $event = $ARGV[2] ? uc($ARGV[2]) : "0x00000000";
  $event =~ s/^0x//i;

  my $message = "$event_type   $timestamp   ";
  $message .= $events{$event} ? $events{$event} : "N/A";

  my $arg1 = $ARGV[3] ? $ARGV[3] : " ";
  my $arg2 = $ARGV[4] ? $ARGV[4] : " "; 
  my $arg3 = $ARGV[5] ? $ARGV[5] : " "; 
  my $arg4 = $ARGV[6] ? $ARGV[6] : " "; 
  $message =~ s/\@1/$arg1/g;;
  $message =~ s/\@2/$arg2/g;;
  $message =~ s/\@3/$arg3/g;;
  $message =~ s/\@4/$arg4/g;;

  $NOTIFY_CMD     =~ s/###MESSAGE###/$message/;
  $NOTIFY_SUBJECT =~ s/###SUBJECT##/$message/;

  system("$NOTIFY_CMD"), if $event =~ /\b (?: ${\join('|', @NOTIFY_EVENTS) }) \b/x;
}

sub load_events {
  open(EVENTS, $EVENTFILE) || die "\nCannot open '$EVENTFILE' for reading $!\n";
  while(my $line = <EVENTS>) {
    chomp $line;
    next, if $line =~ /^$|^#|^\[/;
    my ($event, $text) = split(/=/, $line, 2);
    $event =~ s/^\s+|\s+$//g; 
    $text =~ s/^\s+|\s+$//g;
    $text =~ s/^\"|\"$//g; 
    $events{$event} = $text;
  }
  close EVENTS;
}

sub process_log {
  my $buffer;
  open(LOG, $LOGFILE) || die "\nCannot open '$LOGFILE' for reading $!\n";
  binmode LOG;

  read(LOG, $buffer, 16);
  my ($magic, $version, $file_len) = unpack "a8 L L", $buffer;
  if ($magic ne "SYNO" && $version != 16) {
    close LOG;
    die "\nFormat of '$LOGFILE' not supported.\n";
  }

  print "-" x 170;
  print "\n";
  printf("%-11s | %-19s | %-10s | %-15s | %s\n", "Event Type", "Timestamp", "Event ID", "User", "Message");
  print "-" x 170;
  print "\n";

  while(read(LOG, $buffer, 2)) {
    my $record_len = unpack "S", $buffer;

    read(LOG, $buffer, $record_len - 2);
    my ($event_type, $timestamp, $source_len, $user_len, $event, $arg1_len, $arg2_len, $arg3_len, $arg4_len, $text) = unpack "S L S S H8 S S S S a*", $buffer;

    my @typelist = qw( Unknown Information Warning Error );
    $event_type = $typelist[$event_type] ? $typelist[$event_type] : "Unknown";

    my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($timestamp);
    $timestamp = sprintf("%02d.%02d.%4d %02d:%02d:%02d", $mday, $mon + 1, $year + 1900, $hour, $min, $sec);

    $event = uc(join '', reverse split(/(..)/, $event));

    my ($source, $user, $arg1, $arg2, $arg3, $arg4) = unpack "a$source_len a$user_len a$arg1_len a$arg2_len a$arg3_len a$arg4_len", $text;
    
    my $message = $events{$event} ? $events{$event} : "N/A";
    $message =~ s/\@1/$arg1/g;
    $message =~ s/\@2/$arg2/g;
    $message =~ s/\@3/$arg3/g;
    $message =~ s/\@4/$arg4/g;

    printf("%-11s | %-19s | 0x%-8s | %-15s | %s\n", $event_type, $timestamp, $event, $user, $message);
  }
  close LOG;
}

sub usage {
  print "\nUsage: synolog.pl [FILE]\n";
  print "Prints FILE in Synology log format to standard output.\n";
  print "Example: synolog.pl /var/log/synosys.log\n\n";
}

if ($0 =~ /synologset1$/) {
  load_events;
  send_notification;
  my $args = join(' ', @ARGV);
  system("/usr/syno/bin/synologset1.old $args");
} elsif ($#ARGV != 0 && $0 !~ /synologset1$/) {
  usage;
  exit;
} else {
  $LOGFILE = $ARGV[0];
  load_events();
  process_log();
}
 
Zuletzt bearbeitet:
also ich bekomm das:

Rich (BBCode):
/usr/syno/synosdk/texts/enu/events: line 1197: 12400015: not found
/usr/syno/synosdk/texts/enu/events: line 1198: 12400016: not found
/usr/syno/synosdk/texts/enu/events: line 1200: [12500000]: not found
/usr/syno/synosdk/texts/enu/events: line 1201: 12500001=Local backup failed.: not found
/usr/syno/synosdk/texts/enu/events: line 1202: 12500002=Failed to open file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1203: 12500003=Failed to open directory [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1204: 12500004=Failed to get status of [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1205: 12500005=Failed to copy file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1206: 12500006=Failed to create directory [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1207: 12500007=Failed to remove directory [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1208: 12500008=Failed to remove file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1209: 1250000A=The backup space is insufficient while copying file [@1]: not found
/usr/syno/synosdk/texts/enu/events: line 1210: 1250000B=The backup space is still insufficient in two-pass backup mode while copying file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1211: 1250000C=Backup program stopped while copying file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1212: 1250000D=Backup program encountered an I/O error while copying file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1213: 1250000E=Failed to set access right of [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1214: 1250000F=Process was terminated.: not found
/usr/syno/synosdk/texts/enu/events: line 1215: 12500010=Failed to map file [@1] into memory.: not found
/usr/syno/synosdk/texts/enu/events: line 1216: 12500011=Unexpected error occurred while proceeding [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1217: 12500012=Failed to initiate the backup disk.: not found
/usr/syno/synosdk/texts/enu/events: line 1218: 12500013=Failed to access the backup information.: not found
/usr/syno/synosdk/texts/enu/events: line 1219: 12500014=Local Backup started.: not found
/usr/syno/synosdk/texts/enu/events: line 1220: 12500015=Local Backup finished.: not found
/usr/syno/synosdk/texts/enu/events: line 1221: 12500016=User cancelled the local backup task [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1222: 12500017=Target Disk is not a external backup disk.: not found
/usr/syno/synosdk/texts/enu/events: line 1223: 12500018=Destination is not on-line.: not found
/usr/syno/synosdk/texts/enu/events: line 1224: 12500019=External Disk is being formatted.: not found
/usr/syno/synosdk/texts/enu/events: line 1225: 1250001A=Failed to backup because backup space is insufficient.: not found
/usr/syno/synosdk/texts/enu/events: line 1226: 1250001B=Failed to backup because source volume is not mounted.: not found
/usr/syno/synosdk/texts/enu/events: line 1227: 1250001C=Failed to backup because source disk is initializing.: not found
/usr/syno/synosdk/texts/enu/events: line 1228: 1250001D=Failed to backup file [@1] because the file size exceed the 4G bytes limit of FAT.: not found
/usr/syno/synosdk/texts/enu/events: line 1229: 1250001E=Failed to convert resource fork file [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1230: 1250001F=Failed to backup because external disk is disconnected.: not found
/usr/syno/synosdk/texts/enu/events: line 1231: 12500020=Failed to copy icon of folder [@1].: not found
/usr/syno/synosdk/texts/enu/events: line 1232: syntax error: unexpected redirection
 
Sieht seltsam aus. Vielleicht was beim Copy&Paste schiefgegangen? Kann ich jetzt von dem Output hier nicht sagen, was da nicht ging. Da standen aber doch bestimmt eine Menge Zeilen vorher bzw. was anderes als der Inhalt der Event-Definition...

Sollte so aussehen (kommen leider Linebreaks vom Forum):
Rich (BBCode):
root ~ # synolog.pl /var/log/synosys.log 
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Event Type  | Timestamp           | Event ID   | User            | Message
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Information | 18.11.2011 00:17:21 | 0x11801E12 | admin           | Clear [System log].
Information | 18.11.2011 03:29:49 | 0x11800210 | SYSTEM          | Apple file service was started.
Information | 18.11.2011 04:43:33 | 0x11800D01 | admin           | Shared folder [TimeMachine] was created.
Information | 18.11.2011 04:43:33 | 0x11800D09 | admin           | Shared folder [TimeMachine] was set to show in My Network Places.
Information | 18.11.2011 04:43:50 | 0x11800C00 | admin           | Access right of the shared folder [TimeMachine] was set.
Information | 18.11.2011 04:44:18 | 0x11800211 | SYSTEM          | Apple file service was stopped.
Information | 18.11.2011 04:54:58 | 0x11800210 | SYSTEM          | Apple file service was started.
Information | 19.11.2011 17:41:01 | 0x11B00019 | admin           | System successfully set [Allowing SSL/TLS connection only] to [OFF].
Information | 19.11.2011 18:31:21 | 0x11800211 | SYSTEM          | Apple file service was stopped.
Information | 19.11.2011 18:31:23 | 0x11200001 | SYSTEM          | Windows file service was stopped.
Information | 19.11.2011 18:43:03 | 0x11100002 | SYSTEM          | System started to boot up.
Warning     | 19.11.2011 18:43:11 | 0x11100A00 | SYSTEM          | Share [backup] was restored.
Information | 19.11.2011 18:43:30 | 0x11200002 | SYSTEM          | Windows file service was started.
Information | 19.11.2011 18:43:32 | 0x11800210 | SYSTEM          | Apple file service was started.
Warning     | 19.11.2011 18:43:34 | 0x11100001 | SYSTEM          | System booted up from an improper shutdown.
Information | 19.11.2011 18:43:55 | 0x12300001 | SYSTEM          | External disk [USB Disk 1] is mounted and shared folder [usbshare1] is exported.
Information | 19.11.2011 18:44:03 | 0x12300001 | SYSTEM          | External disk [USB Disk 2] is mounted and shared folder [usbshare2] is exported.
Information | 19.11.2011 18:44:05 | 0x12300001 | SYSTEM          | External disk [USB Disk 3] is mounted and shared folder [usbshare3] is exported.
Warning     | 19.11.2011 18:44:08 | 0x11600072 | SYSTEM          | Space of External disk disk [USB Disk 1] was reaching the limit.
Information | 19.11.2011 18:44:10 | 0x12300001 | SYSTEM          | External disk [USB Disk 4] is mounted and shared folder [usbshare4] is exported.
Information | 19.11.2011 18:51:12 | 0x11800102 | admin           | User [admin] logged in from [192.168.1.111]
Information | 19.11.2011 19:39:26 | 0x11800211 | SYSTEM          | Apple file service was stopped.
Information | 19.11.2011 19:40:48 | 0x11100002 | SYSTEM          | System started to boot up.
Information | 19.11.2011 19:41:17 | 0x11200002 | SYSTEM          | Windows file service was started.
Information | 19.11.2011 19:41:19 | 0x11800210 | SYSTEM          | Apple file service was started.
Warning     | 19.11.2011 19:41:21 | 0x11100001 | SYSTEM          | System booted up from an improper shutdown.
Information | 19.11.2011 19:41:30 | 0x12300001 | SYSTEM          | External disk [USB Disk 1] is mounted and shared folder [usbshare1] is exported.
Information | 19.11.2011 19:41:32 | 0x12300001 | SYSTEM          | External disk [USB Disk 2] is mounted and shared folder [usbshare2] is exported.
Information | 19.11.2011 19:41:33 | 0x12300001 | SYSTEM          | External disk [USB Disk 3] is mounted and shared folder [usbshare3] is exported.
Information | 19.11.2011 19:41:35 | 0x12300001 | SYSTEM          | External disk [USB Disk 4] is mounted and shared folder [usbshare4] is exported.
Warning     | 19.11.2011 19:41:55 | 0x11600072 | SYSTEM          | Space of External disk disk [USB Disk 1] was reaching the limit.
Information | 19.11.2011 22:04:30 | 0x11800211 | SYSTEM          | Apple file service was stopped.
Information | 19.11.2011 22:04:32 | 0x11200001 | SYSTEM          | Windows file service was stopped.
Information | 19.11.2011 22:05:54 | 0x11100002 | SYSTEM          | System started to boot up.
Information | 19.11.2011 22:06:21 | 0x11200002 | SYSTEM          | Windows file service was started.
Information | 19.11.2011 22:06:24 | 0x11800210 | SYSTEM          | Apple file service was started.
Information | 19.11.2011 22:06:35 | 0x12300001 | SYSTEM          | External disk [USB Disk 1] is mounted and shared folder [usbshare1] is exported.
Information | 19.11.2011 22:06:36 | 0x12300001 | SYSTEM          | External disk [USB Disk 2] is mounted and shared folder [usbshare2] is exported.
Information | 19.11.2011 22:06:38 | 0x12300001 | SYSTEM          | External disk [USB Disk 3] is mounted and shared folder [usbshare3] is exported.
Information | 19.11.2011 22:06:39 | 0x12300001 | SYSTEM          | External disk [USB Disk 4] is mounted and shared folder [usbshare4] is exported.
Warning     | 19.11.2011 22:06:59 | 0x11600072 | SYSTEM          | Space of External disk disk [USB Disk 1] was reaching the limit.
Information | 20.11.2011 00:52:03 | 0x11800211 | SYSTEM          | Apple file service was stopped.
Information | 20.11.2011 00:52:06 | 0x11200001 | SYSTEM          | Windows file service was stopped.
Information | 20.11.2011 00:56:39 | 0x11100002 | SYSTEM          | System started to boot up.
Warning     | 20.11.2011 00:56:48 | 0x11100A00 | SYSTEM          | Share [ipkg] was restored.
Information | 20.11.2011 00:57:07 | 0x11200002 | SYSTEM          | Windows file service was started.
Information | 20.11.2011 00:57:09 | 0x11800210 | SYSTEM          | Apple file service was started.
Warning     | 20.11.2011 00:57:11 | 0x11100001 | SYSTEM          | System booted up from an improper shutdown.
Information | 20.11.2011 00:57:21 | 0x12300001 | SYSTEM          | External disk [USB Disk 1] is mounted and shared folder [usbshare1] is exported.
Information | 20.11.2011 00:57:23 | 0x12300001 | SYSTEM          | External disk [USB Disk 2] is mounted and shared folder [usbshare2] is exported.
Information | 20.11.2011 00:57:25 | 0x12300001 | SYSTEM          | External disk [USB Disk 3] is mounted and shared folder [usbshare3] is exported.
Information | 20.11.2011 00:57:26 | 0x12300001 | SYSTEM          | External disk [USB Disk 4] is mounted and shared folder [usbshare4] is exported.
Warning     | 20.11.2011 00:57:44 | 0x11600072 | SYSTEM          | Space of External disk disk [USB Disk 1] was reaching the limit.
Information | 20.11.2011 01:28:18 | 0x11800102 | admin           | User [admin] logged in from [192.168.1.111]
Information | 20.11.2011 01:29:24 | 0x11B00300 | admin           | System successfully started Web Station service.
Warning     | 23.11.2011 05:23:37 | 0x12A00003 | NULL            | Host [222.106.248.49] has been blocked at [Wed Nov 23 05:23:37 2011].
Warning     | 28.11.2011 10:39:58 | 0x11100A00 | admin           | Share [ipkg] was restored.
Information | 28.11.2011 11:03:53 | 0x11B00400 | admin           | System successfully started Mysql service.
Information | 28.11.2011 11:34:35 | 0x13200002 | admin           | iTunes service was started.
Information | 28.11.2011 11:34:51 | 0x13200003 | admin           | iTunes service was restarted.["server name" changed]
Information | 28.11.2011 11:35:30 | 0x11B00700 | admin           | System successfully started Audio Station.
Information | 28.11.2011 11:37:21 | 0x11B00200 | admin           | System successfully started Photo Station service.
Information | 28.11.2011 11:37:21 | 0x11B00203 | admin           | New albums in Photo Station will be set as private by default.
Information | 28.11.2011 11:40:03 | 0x11B00507 | admin           | System successfully changed DMA menu style to [advance].
Information | 28.11.2011 11:40:03 | 0x11B00513 | admin           | System successfully changed DMA music displayed info to [titleartist].
Information | 28.11.2011 11:40:03 | 0x11B00516 | admin           | System successfully enabled albumart setting.
Information | 28.11.2011 11:40:03 | 0x11B00518 | admin           | System successfully updated the albumart filename list.
Information | 28.11.2011 11:40:04 | 0x11B00500 | admin           | System successfully started UPnP media service.
Information | 28.11.2011 11:42:31 | 0x11B00808 | admin           | System successfully enabled transfer log for File Station.
Information | 28.11.2011 11:42:31 | 0x11B00802 | admin           | System successfully started File Station.
Information | 28.11.2011 11:42:32 | 0x11B00806 | admin           | System successfully changed customized File Station HTTP port from [ ] to [7000].
Information | 28.11.2011 11:43:32 | 0x11B00622 | admin           | System successfully started BT/HTTP/FTP/NZB download service.
Information | 28.11.2011 11:48:17 | 0x12600021 | admin           | USB Copy destination folder was set to [incoming].
Information | 28.11.2011 11:48:19 | 0x12610021 | admin           | SD Copy destination folder was set to [incoming].
Information | 28.11.2011 11:53:31 | 0x11B00623 | admin           | System successfully stopped BT/HTTP/FTP/NZB download service.
Information | 28.11.2011 11:53:49 | 0x11B00201 | admin           | System successfully stopped Photo Station service.
Information | 28.11.2011 11:54:41 | 0x11B00501 | admin           | System successfully stopped UPnP media service.
 
jupp, funzt, gibt kein fehler aus, genau so wie bei dir. ka was da los was, nun gehts
 
Status
Für weitere Antworten geschlossen.
 

Kaffeautomat

Wenn du das Forum hilfreich findest oder uns unterstützen möchtest, dann gib uns doch einfach einen Kaffee aus.

Als Dankeschön schalten wir deinen Account werbefrei.

:coffee:

Hier gehts zum Kaffeeautomat