deniSun
20-01-18, 21:52
Ο παρακάτω οδηγός αφορά την αποστολή των logs σε έναν syslog server και από εκεί με email στον προσωπικό μας λογαριασμό.
Χρησιμοποιώ ubuntu linux με ΙΡ: 5.36 και name: "Milady"
και το ΜΤ με ΙΡ: 5.33 και name:"porthos".
Ξεκινάω από το ΜΤ:
Send logs to external log server (rsyslog)
*** Send Logs to rsyslog server
System > Logging > Actions
Name: remote
Type: remote
Remote Address: 192.168.5.36
Remote Port: 514
System > Logging > Rules > (+ add new with the same name)
Topics: info
Action: remote
Στο ubuntu κάνουμε τα εξής:
Βρίσκουμε πώς στέλνει το ΜΤ και κάθε άλλη συσκευή τα data:
at rsyslog/conf add lines:
: /var/log/rsyslog.log
& ~
Κάνουμε τις ανάλογες ρυθμίσεις στον rsyslog:
pico /etc/rsyslog.conf
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# at the end of file
:HOSTNAME, isequal, "porthos" /var/log/rsyslog.log
& ~
touch /var/log/rsyslog.log
chmod 640 /var/log/rsyslog.log
chown syslog:adm /var/log/rsyslog.log
service rsyslog restart
netstat -tlnup | grep 514
tail -f /var/log/rsyslog.log
Στήνουμε έναν mail server κάνοντας χρήση των ρυθμίσεων της cosmote [ή όπου αλλού έχουμε λογαριασμό]:
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
Internet Site
System mail name: Milady
pico /etc/postfix/main.cf
relayhost = mailgate.cosmotemail.gr:25
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes
smtp_cname_overrides_servername = no
smtp_sasl_security_options = noanonymous
smtp_generic_maps = hash:/etc/postfix/generic
pico /etc/postfix/sasl_passwd
mailgate.cosmotemail.gr:25 USERNAME:PASSWORD
chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
postmap -q smtp.provider.com:25 /etc/postfix/sasl_passwd
pico /etc/postfix/generic
root@Milady xxx@cosmotemail.gr
postmap /etc/postfix/generic
pico /etc/postfix/master.cf
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
smtps inet n - - - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
/etc/init.d/postfix restart
echo "Test mail from postfix" | mail -s "Test Postfix" xxx@cosmotemail.gr
*** Forward root mail
pico /etc/aliases
root: xxx@cosmotemail.gr
newaliases
*** Send log file via email (for previous day)
pico /usr/local/bin/logview.sh
#!/bin/bash
mailTemp="/var/log/mailTemp"
logfile="/var/log/rsyslog.log"
search=$(date --date='yesterday' "+%F")
grep -r "$search" "$logfile" > "$mailTemp"
if [[ -s $mailTemp ]] ; then
cat "$mailTemp" | mail -s "Milady Logs (Mikrotik, Modem, VoIP)" xxx@cosmotemail.gr
else
echo "No Activity" | mail -s "Milady Logs (Mikrotik, Modem, VoIP)" xxx@cosmotemail.gr
fi ;
chmod 755 /usr/local/bin/logview.sh
./usr/local/bin/logview.sh
crontab -e
00 01 * * * /usr/local/bin/logview.sh >/dev/null 2>&1
Κάθε βράδυ στις 1:00 θα στέλνονται τα Logs τις προηγούμενης ημέρας.
190625
Χρησιμοποιώ ubuntu linux με ΙΡ: 5.36 και name: "Milady"
και το ΜΤ με ΙΡ: 5.33 και name:"porthos".
Ξεκινάω από το ΜΤ:
Send logs to external log server (rsyslog)
*** Send Logs to rsyslog server
System > Logging > Actions
Name: remote
Type: remote
Remote Address: 192.168.5.36
Remote Port: 514
System > Logging > Rules > (+ add new with the same name)
Topics: info
Action: remote
Στο ubuntu κάνουμε τα εξής:
Βρίσκουμε πώς στέλνει το ΜΤ και κάθε άλλη συσκευή τα data:
at rsyslog/conf add lines:
: /var/log/rsyslog.log
& ~
Κάνουμε τις ανάλογες ρυθμίσεις στον rsyslog:
pico /etc/rsyslog.conf
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# at the end of file
:HOSTNAME, isequal, "porthos" /var/log/rsyslog.log
& ~
touch /var/log/rsyslog.log
chmod 640 /var/log/rsyslog.log
chown syslog:adm /var/log/rsyslog.log
service rsyslog restart
netstat -tlnup | grep 514
tail -f /var/log/rsyslog.log
Στήνουμε έναν mail server κάνοντας χρήση των ρυθμίσεων της cosmote [ή όπου αλλού έχουμε λογαριασμό]:
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
Internet Site
System mail name: Milady
pico /etc/postfix/main.cf
relayhost = mailgate.cosmotemail.gr:25
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes
smtp_cname_overrides_servername = no
smtp_sasl_security_options = noanonymous
smtp_generic_maps = hash:/etc/postfix/generic
pico /etc/postfix/sasl_passwd
mailgate.cosmotemail.gr:25 USERNAME:PASSWORD
chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
postmap -q smtp.provider.com:25 /etc/postfix/sasl_passwd
pico /etc/postfix/generic
root@Milady xxx@cosmotemail.gr
postmap /etc/postfix/generic
pico /etc/postfix/master.cf
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
smtps inet n - - - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
/etc/init.d/postfix restart
echo "Test mail from postfix" | mail -s "Test Postfix" xxx@cosmotemail.gr
*** Forward root mail
pico /etc/aliases
root: xxx@cosmotemail.gr
newaliases
*** Send log file via email (for previous day)
pico /usr/local/bin/logview.sh
#!/bin/bash
mailTemp="/var/log/mailTemp"
logfile="/var/log/rsyslog.log"
search=$(date --date='yesterday' "+%F")
grep -r "$search" "$logfile" > "$mailTemp"
if [[ -s $mailTemp ]] ; then
cat "$mailTemp" | mail -s "Milady Logs (Mikrotik, Modem, VoIP)" xxx@cosmotemail.gr
else
echo "No Activity" | mail -s "Milady Logs (Mikrotik, Modem, VoIP)" xxx@cosmotemail.gr
fi ;
chmod 755 /usr/local/bin/logview.sh
./usr/local/bin/logview.sh
crontab -e
00 01 * * * /usr/local/bin/logview.sh >/dev/null 2>&1
Κάθε βράδυ στις 1:00 θα στέλνονται τα Logs τις προηγούμενης ημέρας.
190625