Перейти к содержанию

_alex_

Участники форума
  • Постов

    13
  • Зарегистрирован

  • Посещение

Оборудование

  • Кинетик
    Hopper SE (KN-3812) EAEU

Посетители профиля

Блок последних пользователей отключён и не показывается другим пользователям.

Достижения _alex_

Пользователь

Пользователь (2/5)

0

Репутация

  1. Скорее всего, не поможет. То ли /opt/sbin/syslog-ng зависает при старте из-за ошибок в конфиге /opt/etc/syslog-ng.conf То ли /opt/etc/init.d/rc.unslung прекращает работу если что-то не стартует
  2. В какой-то момент настройки opkg перестал стартовать. Спасло то, что сохранил исходные файлы: cp /opt/etc/init.d/S01syslog-ng /opt/etc/init.d/K01syslog-ng cp /opt/etc/syslog-ng.conf /opt/etc/syslog-ng.conf.orig Подключился по ssh на 22 порт, выполнил: ls storage:etc/init.d/ more storage:etc/init.d/S01syslog-ng erase storage:etc/init.d/S01syslog-ng copy storage:etc/init.d/K01syslog-ng storage:etc/init.d/S01syslog-ng ls storage:etc more storage:etc/syslog-ng.conf erase storage:etc/syslog-ng.conf copy storage:etc/syslog-ng.conf.orig storage:etc/syslog-ng.conf И перезагрузился из web. Не пришлось заморачиваться с повторной установкой opkg...
  3. Добавил обработку Severity /opt/etc/init.d/S01syslog-ng: #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" NDMCFILE="/tmp/mnt/USB/log/ndmc.log" SYSNGFILE="/opt/var/syslog-ng.persist" PARTLINE="$(echo `yes =|head -50`|tr -d ' ')" start() { rm -f $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE rm -f $NDMCFILE rm -f $SYSNGFILE return 0 } case $ACTION in start) # opkg mount cDate="$(date +%s)"; while [ ! -f /opt/bin/mount ]; do if [ "$(($(date +%s) - $cDate))" -gt "$((3*60))" ]; then # protection for infinite loop logger -s -p err -t opkg "opkg is destroyed" exit 1 fi sleep 1 done # USB mount cDate="$(date +%s)"; while [ "`/opt/bin/mount | grep -qi /sda1 || echo 1`" ]; do if [ "$(($(date +%s) - $cDate))" -gt "$((3*60))" ]; then # protection for infinite loop logger -s -p err -t opkg "USB Disk is not mounted" exit 1 fi sleep 1 done # waiting 1 minute or until ntp client completed (normal timestamp will be in the log) cDate="$(date +%s)"; while [ "$(($(date +%s) - $cDate))" -lt "$((1*60))" ]; do sleep 1; done; if [ -f $FLAGFILE ]; then #FIRSTLINE="kernel: ${PARTLINE} warm reboot ${PARTLINE}" FIRSTLINE="<14> kernel: ${PARTLINE} warm reboot ${PARTLINE}" else #FIRSTLINE="kernel: ${PARTLINE} cold reboot ${PARTLINE}" FIRSTLINE="<14> kernel: ${PARTLINE} cold reboot ${PARTLINE}" fi # IETF log format message ndmc -c show log | sed ':a;N;$!ba;s/\n \{1,\}/ /g' | cut -c -190 | sed '1,/kernel: Booting Linux/ {/kernel: Booting Linux/!d}' \ | sed 's/^C/<10>/' | sed 's/^E/<11>/' | sed 's/^W/<12>/' | sed 's/^I/<14>/' \ | sed 's/\[.*:..:..\] //' | sed "1 i\\${FIRSTLINE}" | sed '$ d' > ${NDMCFILE} ndmc -c system log server 127.0.0.1:3127 start ;; stop|kill) stop ;; restart) stop start ;; *) echo "ACTION=unknown" | logger -p emerg -t kernel ;; esac . /opt/etc/init.d/rc.func /opt/etc/syslog-ng.conf: # Collect all local logs into a single file /var/log/messages. # See https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # See https://github.com/balabit/syslog-ng-ose-guides @version: 4.7 @include "scl.conf" # cat /opt/etc/syslog-ng.conf | nocomments ############################################################################### # /opt/etc/init.d/S01syslog-ng stop # /opt/etc/init.d/S01syslog-ng start # /opt/etc/init.d/S01syslog-ng restart ############################################################################### # Source drivers available in syslog-ng (syslog-ng PE 7.0.34 Administration Guide) # # file() Opens the specified file and reads messages. # internal() Messages generated internally in syslog-ng. # linux-audit() Reads the logfiles of the auditd application. # network() Receives messages from remote hosts using the BSD-syslog protocol over IPv4 and IPv6. Supports the TCP, UDP, ALTP, and TLS network protocols. # pipe() Opens the specified named pipe and reads messages. # program() Opens the specified application and reads messages from its standard output. # python() and # python-fetcher() Receive or fetch messages using a custom source written in Python. # syslog() Listens for incoming messages using the new IETF-standard syslog protocol. # system() Automatically detects which platform syslog-ng PE is running on, and collects the native log messages of that platform. # systemd-journal() Collects messages directly from the journal of platforms that use systemd. # systemd-syslog() Collects messages from the journal using a socket on platforms that use systemd. # unix-dgram() Opens the specified unix socket in SOCK_DGRAM mode and listens for incoming messages. # unix-stream() Opens the specified unix socket in SOCK_STREAM mode and listens for incoming messages. # windowsevent() Reads messages from the Windows Event Collector tool. ############################################################################### options { chain-hostnames(no); # Enable or disable the chained hostname format. create-dirs(yes); # Enable creating non-existing directories when creating files or socket files. keep-hostname(yes); # Enable or disable hostname rewriting. log-fifo-size(10000); # The number of messages that the output queue can store. log-msg-size(200); # Maximum length of a message in bytes. stats(freq(0)); # The period between two STATS messages (sent by syslog-ng, containing statistics about dropped logs) in seconds. flush-lines(0); # How many lines are flushed to a destination at a time. trim-large-messages(yes); # trims the incoming log message to the size set in log-msg-size() use-fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. ts-format(iso); # To convert all timestamps to the ISODATE format }; source src { internal(); unix-dgram("/dev/log"); # unix-stream("/dev/log"); }; source kernel { file("/proc/kmsg" program_override("kernel")); }; source syslog { syslog(); }; source ndmc { file( "/tmp/mnt/USB/log/ndmc.log" ); }; # ndmc -c system log server 127.0.0.1:3127 source net { network( ip("127.0.0.1") transport("udp") port(3127) keep-timestamp(no) ); }; destination messages { file("/tmp/mnt/USB/log/messages" template("${ISODATE} (${PRIORITY}) ${PROGRAM}: ${MESSAGE}\n") time_zone("Europe/Moscow")); }; destination debug { # file("/tmp/mnt/USB/log/debuglog"); file("/tmp/mnt/USB/log/debuglog" template("${ISODATE} (${PRIORITY}) Keenetic: ${PROGRAM}: ${MESSAGE}\n") time_zone("Europe/Moscow")); }; filter f_kernel { not program(kernel) or (program(kernel) and match ("reboot|error|Linux|Memory|Boot CPU|Machine|Found.*storage" value("MESSAGE"))); }; filter f_ndm { not program(ndm) or (program(ndm) and match("Network Device Manager|Ntp" value("MESSAGE"))); }; filter f_cron { not program(cron) or (program(cron) and match("started|stopped|Hello" value("MESSAGE")) ); }; filter f_ni_ndhcps { not program(ndhcps) or (program(ndhcps) and not match("sending INFORM|sending ACK|received ACK|DHCPDISCOVER|DHCPREQUEST|DHCPINFORM|making OFFER|NDM DHCP" value("MESSAGE")) ); }; filter f_ni_dhcpd { not program(dhcpd) or (program(dhcpd) and not match("Information-request|Sending Reply" value("MESSAGE")) ); }; filter f_no_radvd { not program(radvd); }; filter f_no_telnetd { not program(telnetd); }; filter f_no_bndstrg { not program(bndstrg); }; filter f_no_ndnproxy { not program(ndnproxy); }; filter f_no_avahi { not program(avahi-daemon); }; filter f_no_nimproxy { not program(nimproxy); }; filter f_no_ndhcpc { not program(ndhcpc); }; filter f_no_upnp { not program(upnp); }; filter f_no_coalagent { not program(coalagent); }; filter f_no_dhcpd { not program(dhcpd); }; filter f_no_wind { not program(wind); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); filter(f_kernel); filter(f_ndm); filter(f_cron); filter(f_ni_ndhcps); filter(f_ni_dhcpd); filter(f_no_radvd); filter(f_no_telnetd); filter(f_no_bndstrg); filter(f_no_ndnproxy); filter(f_no_avahi); filter(f_no_nimproxy); filter(f_no_ndhcpc); filter(f_no_upnp); filter(f_no_coalagent); filter(f_no_dhcpd); filter(f_no_wind); destination(messages); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); destination(debug); }; # Include any user settings last so that s/he can override or # supplement all "canned" settings inherited from the distribution. @include "/opt/etc/syslog-ng.d/" # Put any customization files in this directory
  4. Установил и настроил logrotate и cron logrotate /opt/etc/logrotate.d/syslog-ng-message /tmp/mnt/USB/log/messages { weekly rotate 4 copytruncate missingok compress compresscmd /opt/bin/gzip delaycompress } /opt/etc/logrotate.d/syslog-ng-debug /tmp/mnt/USB/log/debuglog { daily rotate 7 copytruncate missingok compress compresscmd /opt/bin/gzip delaycompress } crontab -l @weekly /opt/sbin/logrotate -f /opt/etc/logrotate.d/syslog-ng-message @daily /opt/sbin/logrotate -f /opt/etc/logrotate.d/syslog-ng-debug
  5. Поправил /opt/etc/init.d/S01syslog-ng чтобы не зависал намертво при проблемах со storage и usb #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" NDMCFILE="/tmp/mnt/USB/log/ndmc.log" SYSNGFILE="/opt/var/syslog-ng.persist" PARTLINE="$(echo `yes =|head -50`|tr -d ' ')" start() { rm -f $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE rm -f $NDMCFILE rm -f $SYSNGFILE return 0 } case $ACTION in start) # opkg mount cDate="$(date +%s)"; while [ ! -f /opt/bin/mount ]; do if [ "$(($(date +%s) - $cDate))" -gt "$((3*60))" ]; then # protection for infinite loop logger -s -p err -t opkg "opkg is destroyed" exit 1 fi sleep 1 done # USB mount cDate="$(date +%s)"; while [ "`/opt/bin/mount | grep -qi /sda1 || echo 1`" ]; do if [ "$(($(date +%s) - $cDate))" -gt "$((3*60))" ]; then # protection for infinite loop logger -s -p err -t opkg "USB Disk is not mounted" exit 1 fi sleep 1 done # waiting 1 minute or until ntp client completed (normal timestamp will be in the log) cDate="$(date +%s)"; while [ "$(($(date +%s) - $cDate))" -lt "$((1*60))" ]; do sleep 1; done; if [ -f $FLAGFILE ]; then FIRSTLINE="kernel: ${PARTLINE} warm reboot ${PARTLINE}" else FIRSTLINE="kernel: ${PARTLINE} cold reboot ${PARTLINE}" fi # IETF log format message ndmc -c show log | sed ':a;N;$!ba;s/\n \{1,\}/ /g' | cut -c -190 | sed '1,/kernel: Booting Linux/ {/kernel: Booting Linux/!d}' | sed 's/. \[.*:..:..\] //' | sed "1 i\\${FIRSTLINE}" | awk -F CGG '/^>/ {print; next} {for (i=1; i<=NF; ++i) {printf "%s %s%s", length($i), $i, (i==NF)?"\n":" "}}' | sed '$ d' > ${NDMCFILE} start ;; stop|kill) stop ;; restart) stop start ;; *) echo "ACTION=unknown" | logger -p emerg -t kernel ;; esac . /opt/etc/init.d/rc.func
  6. В итоге получилось так: /opt/etc/init.d/S01syslog-ng #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" NDMCFILE="/tmp/mnt/USB/log/ndmc.log" SYSNGFILE="/opt/var/syslog-ng.persist" PARTLINE="$(echo `yes =|head -50`|tr -d ' ')" start() { rm -f $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE rm -f $NDMCFILE rm -f $SYSNGFILE return 0 } case $ACTION in start) # opkg mount while [ ! -f /opt/bin/mount ]; do sleep 1 done # USB mount while [ "`/opt/bin/mount | grep -qi /sda1 || echo 1`" ]; do sleep 1 done # wait 1 minute or until ntp client completed (normal timestamp will be in the log) cDate="$(date +%s)"; while [ "$(($(date +%s) - $cDate))" -lt "$((1*60))" ] do sleep 1; done; if [ -f $FLAGFILE ]; then FIRSTLINE="kernel: ${PARTLINE} warm reboot ${PARTLINE}" else FIRSTLINE="kernel: ${PARTLINE} cold reboot ${PARTLINE}" fi # IETF log format message ndmc -c show log | sed ':a;N;$!ba;s/\n \{1,\}/ /g' | cut -c -190 | sed '1,/kernel: Booting Linux/ {/kernel: Booting Linux/!d}' | sed 's/. \[.*:..:..\] //' | sed "1 i\\${FIRSTLINE}" | awk -F CGG '/^>/ {print; next} {for (i=1; i<=NF; ++i) {printf "%s %s%s", length($i), $i, (i==NF)?"\n":" "}}' | sed '$ d' > ${NDMCFILE} start ;; stop|kill) stop ;; restart) stop start ;; *) echo "ACTION=unknown" | logger -p emerg -t kernel ;; esac . /opt/etc/init.d/rc.func /opt/etc/syslog-ng.conf # Collect all local logs into a single file /var/log/messages. # See https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # See https://github.com/balabit/syslog-ng-ose-guides @version: 4.7 @include "scl.conf" # cat /opt/etc/syslog-ng.conf | nocomments ############################################################################### # /opt/etc/init.d/S01syslog-ng stop # /opt/etc/init.d/S01syslog-ng start # /opt/etc/init.d/S01syslog-ng restart ############################################################################### # Source drivers available in syslog-ng (syslog-ng PE 7.0.34 Administration Guide) # # file() Opens the specified file and reads messages. # internal() Messages generated internally in syslog-ng. # linux-audit() Reads the logfiles of the auditd application. # network() Receives messages from remote hosts using the BSD-syslog protocol over IPv4 and IPv6. Supports the TCP, UDP, ALTP, and TLS network protocols. # pipe() Opens the specified named pipe and reads messages. # program() Opens the specified application and reads messages from its standard output. # python() and # python-fetcher() Receive or fetch messages using a custom source written in Python. # syslog() Listens for incoming messages using the new IETF-standard syslog protocol. # system() Automatically detects which platform syslog-ng PE is running on, and collects the native log messages of that platform. # systemd-journal() Collects messages directly from the journal of platforms that use systemd. # systemd-syslog() Collects messages from the journal using a socket on platforms that use systemd. # unix-dgram() Opens the specified unix socket in SOCK_DGRAM mode and listens for incoming messages. # unix-stream() Opens the specified unix socket in SOCK_STREAM mode and listens for incoming messages. # windowsevent() Reads messages from the Windows Event Collector tool. ############################################################################### options { chain-hostnames(no); # Enable or disable the chained hostname format. create-dirs(yes); # Enable creating non-existing directories when creating files or socket files. keep-hostname(yes); # Enable or disable hostname rewriting. log-fifo-size(10000); # The number of messages that the output queue can store. log-msg-size(200); # Maximum length of a message in bytes. stats(freq(0)); # The period between two STATS messages (sent by syslog-ng, containing statistics about dropped logs) in seconds. flush-lines(0); # How many lines are flushed to a destination at a time. trim-large-messages(yes); # trims the incoming log message to the size set in log-msg-size() use-fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. ts-format(iso); # To convert all timestamps to the ISODATE format }; source src { internal(); unix-dgram("/dev/log"); # unix-stream("/dev/log"); }; source net { network( ip("127.0.0.1") transport("udp") port(3127) keep-timestamp(no) ); }; source kernel { file("/proc/kmsg" program_override("kernel")); }; source syslog { syslog(); }; source ndm { program("/bin/ndm"); }; source ndmc { # file( "/opt/var/log/ndmc.log" flags(no-parse) ); file( "/tmp/mnt/USB/log/ndmc.log" ); }; destination messages { file("/tmp/mnt/USB/log/messages" template("${ISODATE} (${PRIORITY}) ${PROGRAM}: ${MESSAGE}\n") time_zone("Europe/Moscow")); }; destination debug { file("/tmp/mnt/USB/log/debuglog"); }; filter f_kernel { not program(kernel) or (program(kernel) and match ("reboot|error|Linux|Memory|Boot CPU|Machine|Found.*storage" value("MESSAGE"))); }; filter f_ndm { not program(ndm) or (program(ndm) and match("Network Device Manager|Ntp" value("MESSAGE"))); }; filter f_cron { not program(cron) or (program(cron) and match("started|stopped|Hello" value("MESSAGE")) ); }; filter f_ni_ndhcps { not program(ndhcps) or (program(ndhcps) and not match("sending ACK|received ACK|DHCPDISCOVER|DHCPREQUEST|making OFFER|NDM DHCP" value("MESSAGE")) ); }; filter f_ni_dhcpd { not program(dhcpd) or (program(dhcpd) and not match("Information-request|Sending Reply" value("MESSAGE")) ); }; filter f_no_radvd { not program(radvd); }; filter f_no_telnetd { not program(telnetd); }; filter f_no_bndstrg { not program(bndstrg); }; filter f_no_ndnproxy { not program(ndnproxy); }; filter f_no_avahi { not program(avahi-daemon); }; filter f_no_nimproxy { not program(nimproxy); }; filter f_no_ndhcpc { not program(ndhcpc); }; filter f_no_upnp { not program(upnp); }; filter f_no_coalagent { not program(coalagent); }; filter f_no_dhcpd { not program(dhcpd); }; filter f_no_wind { not program(wind); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); filter(f_kernel); filter(f_ndm); filter(f_cron); filter(f_ni_ndhcps); filter(f_ni_dhcpd); filter(f_no_radvd); filter(f_no_telnetd); filter(f_no_bndstrg); filter(f_no_ndnproxy); filter(f_no_avahi); filter(f_no_nimproxy); filter(f_no_ndhcpc); filter(f_no_upnp); filter(f_no_coalagent); filter(f_no_dhcpd); filter(f_no_wind); destination(messages); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); # source(ndm); destination(debug); }; # Include any user settings last so that s/he can override or # supplement all "canned" settings inherited from the distribution. @include "/opt/etc/syslog-ng.d/" # Put any customization files in this directory
  7. Бесполезно бороться с line wrap. Но sed возвращает всё к первоначальному виду. #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" #reboot flag #NDMCFILE="/opt/var/log/ndmc.log" NDMCFILE="/tmp/mnt/USB/log/ndmc.log" SYSNGFILE="/opt/var/syslog-ng.persist" PARTLINE="$(echo `yes =|head -50`|tr -d ' ')" start() { rm -f $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE rm -f $NDMCFILE rm -f $SYSNGFILE return 0 } case $ACTION in start) if [ -f $FLAGFILE ]; then FIRSTLINE="kernel: ${PARTLINE} soft reboot ${PARTLINE}" else FIRSTLINE="kernel: ${PARTLINE} hard reboot ${PARTLINE}" fi # opkg mount while [ ! -f /opt/bin/mount ]; do sleep 1 done # USB mount while [ "`/opt/bin/mount | grep -qi /sda1 || echo 1`" ]; do sleep 1 done # IETF log format message ndmc -c show log | sed ':a;N;$!ba;s/\n \{1,\}/ /g' | sed '1,/kernel: Booting Linux/ {/kernel: Booting Linux/!d}' | sed 's/. \[.*:..:..\] //' | sed "1 i\\${FIRSTLINE}" | head -n 500 | awk -F CGG '/^>/ {print; next} {for (i=1; i<=NF; ++i) {printf "%s %s%s", length($i), $i, (i==NF)?"\n":" "}}' | sed '$ d' > ${NDMCFILE} start ;; stop|kill) stop ;; restart) stop start ;; *) echo "ACTION=unknown" | logger -p emerg -t kernel ;; esac . /opt/etc/init.d/rc.func
  8. Хотя при тесте всё нормально # test hard reboot /opt/etc/init.d/S01syslog-ng stop ps|grep syslog-ng rm /opt/var/syslog-ng.flag rm /tmp/mnt/USB/log/ndmc.log rm /tmp/mnt/USB/log/messages rm /tmp/mnt/USB/log/debuglog rm /opt/var/syslog-ng.persist ls -lah /tmp/mnt/USB/log/ /opt/etc/init.d/S01syslog-ng start ps|grep syslog-ng ls -lah /tmp/mnt/USB/log/ head -n20 /tmp/mnt/USB/log/ndmc.log sleep 5 head -n20 /tmp/mnt/USB/log/messages #ndmc -c show log | tail #tail /tmp/mnt/USB/log/debuglog #cat /tmp/mnt/USB/log/messages #cat /tmp/mnt/USB/log/debuglog | grep -v "ndm:\|kernel:" #cat /tmp/mnt/USB/log/ndmc.log | grep -v "ndm:\|kernel:" #cat /opt/etc/syslog-ng.conf | nocomments #mcedit /opt/etc/syslog-ng.conf /opt/etc/syslog-ng.conf: # Collect all local logs into a single file /var/log/messages. # See https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # See https://github.com/balabit/syslog-ng-ose-guides @version: 4.7 @include "scl.conf" # cat /opt/etc/syslog-ng.conf | nocomments ############################################################################### # /opt/etc/init.d/S01syslog-ng stop # /opt/etc/init.d/S01syslog-ng start # /opt/etc/init.d/S01syslog-ng restart ############################################################################### options { chain_hostnames(no); # Enable or disable the chained hostname format. create_dirs(yes); keep_hostname(yes); # Enable or disable hostname rewriting. log_fifo_size(10000); # The number of messages that the output queue can store. log_msg_size(200); # Maximum length of a message in bytes. stats(freq(0)); # The period between two STATS messages (sent by syslog-ng, containing statistics about dropped logs) in seconds. flush_lines(0); # How many lines are flushed to a destination at a time. trim-large-messages(yes); # trims the incoming log message to the size set in log-msg-size() use_fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. ts-format(iso); }; # syslog-ng gets messages from syslog-ng (internal) and from /dev/log source src { internal(); unix-dgram("/dev/log"); # unix-stream("/dev/log"); }; source net { # network_localhost(); # udp(ip(127.0.0.1) port(3127)); udp(ip(127.0.0.1) port(3127) keep-timestamp(no)); }; source kernel { file("/proc/kmsg" program_override("kernel")); }; source syslog { syslog(); # logger write }; source ndm { program("/bin/ndm"); }; source ndmc { # file( "/opt/var/log/ndmc.log" flags(no-parse) ); # file( "/tmp/mnt/USB/log/ndmc.log" flags(no-parse) ); file( "/tmp/mnt/USB/log/ndmc.log" ); }; destination messages { # file("/opt/var/log/messages" template("${ISODATE} (${PRIORITY}) ${MESSAGE}\n") time_zone("Europe/Moscow")); file("/tmp/mnt/USB/log/messages" template("${ISODATE} (${PRIORITY}) ${PROGRAM}: ${MESSAGE}\n") time_zone("Europe/Moscow")); }; destination debug { # file("/opt/var/log/debuglog"); file("/tmp/mnt/USB/log/debuglog"); }; filter f_ni_kernel { not program(kernel) or (program(kernel) and match ("reboot|error|Linux|Memory|Boot CPU|Machine|Found.*storage" value("MESSAGE"))); }; filter f_ni_ndm { not program(ndm) or (program(ndm) and match("Network Device Manager|Ntp" value("MESSAGE"))); }; filter f_ni_cron { not program(cron) or (program(cron) and match("started|stopped|Hello" value("MESSAGE")) ); }; #filter f_ni_opkg { not program(opkg) or (program(opkg) and match("" value("MESSAGE")) ); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); filter(f_ni_kernel); filter(f_ni_ndm); filter(f_ni_cron); destination(messages); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); # source(ndm); destination(debug); }; # Include any user settings last so that s/he can override or # supplement all "canned" settings inherited from the distribution. @include "/opt/etc/syslog-ng.d/" # Put any customization files in this directory /tmp/mnt/USB/log/messages 2025-02-15T16:39:41+03:00 (notice) syslog-ng: syslog-ng starting up; version='4.7.1' 2025-02-15T16:39:41+03:00 (notice) kernel: ================================================== hard reboot ================================================== 2025-02-15T16:39:41+03:00 (notice) kernel: Booting Linux on physical CPU 0x0 2025-02-15T16:39:41+03:00 (notice) kernel: Linux version 4.9-ndm-5 (developers@keenetic.com) (gcc version 13.2.0 (crosstool-NG 1.24.0-rc2-ndm-31-1 - NDMS Toolkit 1.0.0) ) #0 SMP Mon Jan 27 13:39:56 2025 2025-02-15T16:39:41+03:00 (notice) kernel: Boot CPU: AArch64 Processor [410fd034] 2025-02-15T16:39:41+03:00 (notice) kernel: Machine model: Keenetic KN-3812 2025-02-15T16:39:41+03:00 (notice) kernel: Memory: 497496K/524288K available (3710K kernel code, 282K rwdata, 996K rodata, 320K init, 195K bss, 26792K reserved, 0K cma-reserved) 2025-02-15T16:39:41+03:00 (notice) ndm: Core::Main: *** Network Device Manager 4.02.C.6.0-0. 2025-02-15T16:39:41+03:00 (notice) kernel: Found 1st storage partition of size 58720256 bytes 2025-02-15T16:39:41+03:00 (notice) kernel: Found 2nd storage partition of size 59244544 bytes 2025-02-15T16:39:41+03:00 (notice) ndm: Ntp::Client: configuration reset. 2025-02-15T16:39:41+03:00 (notice) ndm: Ntp::Client: configuration reset. 2025-02-15T16:40:52+03:00 (info) dhcpd: Information-request message from fe80::4830:fb23:b27e:56e4 port 546, transaction ID 0xC5576300 2025-02-15T16:40:52+03:00 (info) dhcpd: Sending Reply to fe80::4830:fb23:b27e:56e4 port 546
  9. При рестарте по питанию stty cols 512; хоть и не генерит ошибок, но не отрабатывает в /opt/etc/init.d/S01syslog-ng line wrap срабатывает на 63 символа #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" # reboot flag NDMCFILE="/tmp/mnt/USB/log/ndmc.log" PARTLINE="$(echo `yes =|head -50`|tr -d ' ')" FIRSTLINE="kernel: ${PARTLINE} hard reboot ${PARTLINE}" start() { rm $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE echo -n "" > $NDMCFILE return 0 } case $ACTION in start) if [ -f $FLAGFILE ]; then echo "${PARTLINE} soft reboot ${PARTLINE}" | logger -p emerg -t kernel else sleep 120 # IETF log format message stty cols 200; ndmc -c show log | sed '1,/kernel: Booting Linux/ {/kernel: Booting Linux/!d}' | cut -c 21- | sed "1 i\\${FIRSTLINE}" | head -n 500 | awk -F CGG '/^>/ {print; next} {for (i=1; i<=NF; ++i) {printf "%s %s%s", length($i), $i, (i==NF)?"\n":" "}}' | sed '$ d' > ${NDMCFILE} fi start stop|kill) stop restart) stop start *) echo "ACTION=unknown" | logger -p emerg -t kernel esac . /opt/etc/init.d/rc.func Думал, что sleep может помочь. Но не помогло.
  10. А как-то можно повлиять на line wrap в команде "show log" ? Приводит к line wrap в выводе команды ndmc -c show log > /opt/var/log/ndmc.log при запуске opkg KeeneticOS version 4.02.C.5.0-0, copyright (c) 2010-2024 Keenetic Ltd. This software is a subject of Keenetic Ltd. end-user licence agreement. By using it you agree on terms and conditions hereof. For more information please check https://keenetic.com/legal (config)> show log ======================================================================================================================================================= Time Message ======================================================================================================================================================= I [Jan 1 00:00:02] kernel: Booting Linux on physical CPU 0x0 I [Jan 1 00:00:02] kernel: Linux version 4.9-ndm-5 (developers@keenetic.com) (gcc version 13.2.0 (crosstool-NG 1.24.0-rc2-ndm-31-1 - NDMS Toolkit 1.0.0) ) #0 SMP Wed Dec 18 19:28:06 2024 I [Jan 1 00:00:02] kernel: Boot CPU: AArch64 Processor [410fd034] I [Jan 1 00:00:02] kernel: Machine model: Keenetic KN-3812
  11. Классная идея. Всё получилось. # Collect all local logs into a single file /var/log/messages. # See https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # See https://github.com/balabit/syslog-ng-ose-guides @version: 4.7 @include "scl.conf" # cat /opt/etc/syslog-ng.conf | nocomments ############################################################################### # /opt/etc/init.d/S01syslog-ng stop # /opt/etc/init.d/S01syslog-ng start # /opt/etc/init.d/S01syslog-ng restart ############################################################################### options { chain_hostnames(no); # Enable or disable the chained hostname format. create_dirs(yes); keep_hostname(yes); # Enable or disable hostname rewriting. log_fifo_size(256); # The number of messages that the output queue can store. log_msg_size(1024); # Maximum length of a message in bytes. stats(freq(0)); # The period between two STATS messages (sent by syslog-ng, containing statistics about dropped logs) in seconds. flush_lines(0); # How many lines are flushed to a destination at a time. use_fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. ts-format(iso); }; # syslog-ng gets messages from syslog-ng (internal) and from /dev/log source src { internal(); unix-dgram("/dev/log"); }; source net { #network_localhost(); udp(ip(127.0.0.1) port(3127)); }; source kernel { file("/proc/kmsg" program_override("kernel")); }; source syslog { syslog(); # logger write }; source ndmc { file( "/opt/var/log/ndmc.log" # hook-commands( # startup("ndmc -c show log > /opt/var/log/ndmc.log") # shutdown(": > /opt/var/log/ndmc.log") # ) ); }; source ndm { program("/bin/ndm"); }; destination messages { file("/opt/var/log/messages" template("${ISODATE} (${PRIORITY}) ${MESSAGE}\n") time_zone("Europe/Moscow")); }; destination debug { file("/opt/var/log/debuglog"); }; filter f_ni_irm { not ( match("Information-request message" value("MESSAGE")) ); }; filter f_ni_sr { not ( match("Sending Reply" value("MESSAGE")) ); }; log { source(src); source(net); source(kernel); source(syslog); filter(f_ni_irm); filter(f_ni_sr); destination(messages); # uncomment this line to open port 514 to receive messages #source(s_network); }; log { source(src); source(net); source(kernel); source(syslog); source(ndmc); # source(ndm); destination(debug); }; # Include any user settings last so that s/he can override or # supplement all "canned" settings inherited from the distribution. @include "/opt/etc/syslog-ng.d/" # Put any customization files in this directory Пришлось поправить /opt/etc/init.d/S01syslog-ng #!/bin/sh ENABLED=yes PROCS=syslog-ng ARGS="" PREARGS="" DESC=$PROCS PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ACTION=$1 BASENAME="$(basename $0)" FLAGFILE="/opt/var/syslog-ng.flag" # reboot flag NDMCFILE="/opt/var/log/ndmc.log" start() { rm $FLAGFILE 2>/dev/null return 0 } stop() { echo -n "" > $FLAGFILE echo -n "" > $NDMCFILE return 0 } case $ACTION in start) if [ -f $FLAGFILE ]; then echo "===== soft reboot =====" > /dev/null else echo "===== hard reboot =====" | logger -p emerg -t syslog-ng ndmc -c system log server 127.0.0.1:3127 ndmc -c show log > $NDMCFILE fi start ;; stop|kill) stop ;; restart) stop start ;; *) echo "ACTION=unknown" | logger -p emerg -t syslog-ng ;; esac . /opt/etc/init.d/rc.func Осталось только причесать. Для начала подобрать template для source ndmc, чтобы дату отрезать. И с timezone разобраться. Ну это уже надолго. Примеров в интернете мало.
  12. Никто не в курсе, как получить source аналогичный "ndmc -c show log" ? Настраиваю в текущей версии syslog-ng (4.7). В ней, вроде, в этом плане больше возможностей. По документации отсюда Пока так # Collect all local logs into a single file /var/log/messages. # See https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # See https://github.com/balabit/syslog-ng-ose-guides @version: 4.7 @include "scl.conf" # cat /opt/etc/syslog-ng.conf | nocomments ############################################################################### # /opt/etc/init.d/S01syslog-ng stop # /opt/etc/init.d/S01syslog-ng start # /opt/etc/init.d/S01syslog-ng restart ############################################################################### options { chain_hostnames(no); # Enable or disable the chained hostname format. create_dirs(yes); keep_hostname(yes); # Enable or disable hostname rewriting. log_fifo_size(256); # The number of messages that the output queue can store. log_msg_size(1024); # Maximum length of a message in bytes. stats(freq(0)); # The period between two STATS messages (sent by syslog-ng, containing statistics about dropped logs) in seconds. flush_lines(1); # How many lines are flushed to a destination at a time. use_fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. ts-format(iso); }; source kernel { file("/proc/kmsg" program_override("kernel")); }; source syslog { syslog(); # logger write }; source ndm { program("/bin/ndm"); }; source src { internal(); unix-stream("/dev/log"); # unix-dgram("/dev/log"); }; source net { udp(ip(172.27.172.1) port(514)); udp(ip(0.0.0.0) port(514)); }; filter f_ni_irm { not ( match("Information-request message" value("MESSAGE")) ); }; filter f_ni_sr { not ( match("Sending Reply" value("MESSAGE")) ); }; destination messages { file("/opt/var/log/messages" template("${ISODATE} (${PRIORITY}) ${MESSAGE}\n") time_zone("Europe/Moscow")); }; destination debug { file("/opt/var/log/debuglog"); }; log { source(syslog); source(src); source(net); source(kernel); filter(f_ni_irm); filter(f_ni_sr); destination(messages); }; log { source(syslog); source(src); source(net); source(kernel); # source(ndm); destination(debug); }; # put any customization files in this directory @include "/opt/etc/syslog-ng.d/"
×
×
  • Создать...

Важная информация

На этом сайте используются файлы cookie. Нажимая "Я принимаю" или продолжая просмотр сайта, вы разрешаете их использование: Политика конфиденциальности.