Looking for help or existing examples.
I want to test whether disk logging is already enabled before configuring a device to use disk logging. I wrote the following script that works as expected:
# A script to enable persistent disk logs and set the number of log
# lines based on installed total memory. If 32 MB then 100 lines,
# else 1000 lines.
# Function to show messages and log events.
local DisplayMessages do={
:put "$Msg"
:log info "$Msg"
}
:local TotalMem ([/system resource get total-memory])
:local LogLines 1000
:if ($TotalMem = 33554432) do={
:set LogLines 100
}
$DisplayMessages Msg=("Number of log lines: $LogLines")
/system logging action
set 0 memory-lines=$LogLines memory-stop-on-full=no name=memory target=memory
set 1 disk-file-count=1 disk-file-name=log disk-lines-per-file=$LogLines disk-stop-on-full=no name=disk target=disk
set 2 name=echo remember=yes target=echo
set 3 bsd-syslog=no name=remote remote=0.0.0.0 remote-port=514 src-address=0.0.0.0 syslog-facility=daemon syslog-severity=auto syslog-time-format=bsd-syslog target=remote
/system logging
set 0 action=memory disabled=no prefix="" topics=info
set 1 action=memory disabled=no prefix="" topics=error
set 2 action=memory disabled=no prefix="" topics=warning
set 3 action=memory disabled=no prefix="" topics=critical
add action=disk disabled=no prefix="" topics=critical
add action=disk disabled=no prefix="" topics=error
add action=disk disabled=no prefix="" topics=info
add action=disk disabled=no prefix="" topics=warning
When disk logging is not already enabled then disk logging is enabled. So far so good.
When disk logging is already enabled, then the script creates a another set of disk logging actions each time the script is executed. Not good.
Before the each add action=disk command I want to test whether such an action already exists.
Thanks again.