Community discussions

 
upnort
newbie
Topic Author
Posts: 45
Joined: Wed Aug 15, 2018 2:03 am

Test for existing disk logging before enabling disk logging

Thu Sep 05, 2019 7:01 pm

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. :)
 
pe1chl
Forum Guru
Forum Guru
Posts: 5707
Joined: Mon Jun 08, 2015 12:09 pm

Re: Test for existing disk logging before enabling disk logging

Thu Sep 05, 2019 7:09 pm

You can first check it with "/system logging print where action=disk" maybe also with "and topics=aaa" when you want to test them one by one.
 
upnort
newbie
Topic Author
Posts: 45
Joined: Wed Aug 15, 2018 2:03 am

Re: Test for existing disk logging before enabling disk logging

Thu Sep 05, 2019 8:34 pm

Thank you for the reply. While I could get the action=disk command to succeed, I was unable to get topics= to work.

I found a somewhat sledge hammer solution. Just delete any existing disk log actions. For now that works although I could foresee that not being an ideal solution if custom disk actions exist.
# Remove any existing disk logging actions.
/system logging remove [/system logging find where action=disk]

Who is online

Users browsing this forum: No registered users and 10 guests