mirror of
https://github.com/pothi/mikrotik-lte-scripts.git
synced 2025-06-20 21:35:46 +02:00
Add email log script
This commit is contained in:
parent
6e4c947eb1
commit
5a9cd12e2f
1 changed files with 48 additions and 0 deletions
48
scripts/email-log.rsc
Normal file
48
scripts/email-log.rsc
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Email the generic-log when it reaches the threshold!
|
||||
|
||||
# Requirements: adminEmail, logTopics
|
||||
:global adminEmail
|
||||
|
||||
# one-time process to be done when bootstrapping the device
|
||||
# :local logTopics {"info"; "error"; "warning"; "critical"; "gsm"; "read"; "write"; "lte,!raw,!packet,!async,!debug"}
|
||||
# :foreach topic in=$logTopics do={ :system logging add topics=$topic action=disk }
|
||||
|
||||
:local emailStatus
|
||||
:local logFile "log.1.txt"
|
||||
|
||||
# check for "flash" folder
|
||||
:do {
|
||||
/file get "log.0.txt"
|
||||
# :log info "Flash folder doesn't exist!"
|
||||
} on-error={
|
||||
:set logFile "flash/log.1.txt"
|
||||
# :log info "Flash folder found!"
|
||||
}
|
||||
|
||||
:do {
|
||||
/file get "$logFile"
|
||||
} on-error={
|
||||
:log info "$logFile file isn't created yet!";
|
||||
:error "$logFile file isn't created yet!";
|
||||
# :log warning "Log file isn't created yet, because it isn't big enough!"
|
||||
}
|
||||
|
||||
# The following gets executed only if the log file is ready!
|
||||
|
||||
:log info "Emailing the log file..."
|
||||
|
||||
/tool e-mail
|
||||
|
||||
:do {
|
||||
send file="$logFile" subject="Log" body="See sub!" to=$adminEmail
|
||||
} on-error={ :log error "The log file could not be sent by email." }
|
||||
|
||||
:do { :delay 3s; :set emailStatus [get last-status] } while=( $emailStatus = "in-progress" )
|
||||
|
||||
:if ( $emailStatus = "succeeded" ) do={
|
||||
:log info "The log file is sent to $adminEmail."
|
||||
} else={
|
||||
:log error "Email failed!"
|
||||
}
|
||||
|
||||
/file remove "$logFile"
|
Loading…
Add table
Add a link
Reference in a new issue